Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/complete-model #44

Merged
merged 2 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/scala/satify/dsl/DSL.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ object DSL:
@targetName("notSymbol")
def unary_! : Expression = not
@targetName("xorSymbol")
def (exp2: Expression): Expression = xor(exp2)
def ^(exp2: Expression): Expression = xor(exp2)
6 changes: 6 additions & 0 deletions src/main/scala/satify/model/Problem.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package satify.model

enum Problem:
case NQueens(n: Int)
case NurseScheduling()
case ColoringGraph()
47 changes: 33 additions & 14 deletions src/main/scala/satify/model/State.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,58 @@ package satify.model
trait State:
/** A general expression of boolean logic, it is the user input */
type Expression
// val expression: Option[Expression] = None
val expression: Option[Expression]

/** The input expression converted to Conjunctive Normal Form (CNF) */
type CNF
// val cnf: Option[CNF] = None
val cnf: Option[CNF]

/** An entity containing the solution of the problem (SAT or UNSAT, optional Assignment), it is the output of DPLL */
type Solution
// val solution: Option[Solution] = None
val solution: Option[Solution]

/** An entity representing the problem to solve */
type Problem
// val problem: Option[Problem] = None
val problem: Option[Problem]

/** Factory for [[satify.model.State]] instances. */
object State:
/** Creates a new application state.
*
* @return a new State instance.
/** Creates a new empty application state.
* @return a new [[State]] instance.
*/
def apply(): State = StateImpl()

/** Creates a new application state with the given CNF.
* @param cnf the CNF to set
* @return a new State instance.
/** Creates a new application state with input expression and its CNF.
* @param exp the input [[Expression]]
* @param cnf the [[CNF]]
* @return a new [[State]] instance.
*/
def apply(exp: Expression, cnf: CNF): State = StateImpl(Some(exp), Some(cnf))

/** Creates a new application state with the input expression, its CNF and the solution.
* @param exp the input [[Expression]]
* @param cnf the [[CNF]]
* @param sol the [[Solution]]
* @return a new [[State]] instance.
*/
def apply(exp: Expression, cnf: CNF, sol: Solution): State = StateImpl(Some(exp), Some(cnf), Some(sol))

/** Creates a new application state with an input problem, its CNF, and its solution.
* @param cnf the [[CNF]]
* @param sol the [[Solution]]
* @param problem the [[Problem]] selected
* @return a new [[State]] instance.
*/
def apply(cnf: CNF, sol: Solution, problem: Problem): State =
StateImpl(None, Some(cnf), Some(sol), Some(problem))

private case class StateImpl(
expression: Option[Expression] = None,
cnf: Option[CNF] = None,
solution: Option[Solution] = None
override val expression: Option[Expression] = None,
override val cnf: Option[CNF] = None,
override val solution: Option[Solution] = None,
override val problem: Option[Problem] = None
) extends State:
override type Expression = satify.model.Expression
override type CNF = satify.model.CNF
override type Solution = satify.model.Solution
// type Problem = satify.model.Problem
override type Problem = satify.model.Problem
4 changes: 2 additions & 2 deletions src/test/scala/satify/dsl/MathOperatorsTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ class MathOperatorsTest extends AnyFlatSpec:
!"A" shouldBe not("A")
}

""" "A" "B" """ should """ be equal to "A" xor "B" """ in {
"A" "B" shouldBe ("A" xor "B")
""" "A" ^ "B" """ should """ be equal to "A" xor "B" """ in {
"A" ^ "B" shouldBe ("A" xor "B")
}