Skip to content
Snippets Groups Projects
Commit 857317fc authored by Etienne Kneuss's avatar Etienne Kneuss
Browse files

Make sure model is complete, simplify rule

parent 9568eccc
No related branches found
No related tags found
No related merge requests found
...@@ -38,41 +38,36 @@ class OnePoint(synth: Synthesizer) extends Rule("One-point", synth) { ...@@ -38,41 +38,36 @@ class OnePoint(synth: Synthesizer) extends Rule("One-point", synth) {
val p = task.problem val p = task.problem
p.phi match { val TopLevelAnds(exprs) = p.phi
case TopLevelAnds(exprs) =>
val candidates = exprs.collect {
case eq @ Equals(Variable(x), e) if (p.xs contains x) && !(variablesOf(e) contains x) =>
(x, e, eq)
case eq @ Equals(e, Variable(x)) if (p.xs contains x) && !(variablesOf(e) contains x) =>
(x, e, eq)
}
if (!candidates.isEmpty) {
val (x, e, eq) = candidates.head
val others = exprs.filter(_ != eq) val candidates = exprs.collect {
val oxs = p.xs.filter(_ != x) case eq @ Equals(Variable(x), e) if (p.xs contains x) && !(variablesOf(e) contains x) =>
(x, e, eq)
case eq @ Equals(e, Variable(x)) if (p.xs contains x) && !(variablesOf(e) contains x) =>
(x, e, eq)
}
val newProblem = Problem(p.as, subst(x -> e, And(others)), oxs) if (!candidates.isEmpty) {
val (x, e, eq) = candidates.head
val onSuccess: List[Solution] => Solution = { val others = exprs.filter(_ != eq)
case List(Solution(pre, term, sc)) => val oxs = p.xs.filter(_ != x)
if (oxs.isEmpty) {
Solution(pre, Tuple(e :: Nil), sc)
} else {
Solution(pre, LetTuple(oxs, term, subst(x -> e, Tuple(p.xs.map(Variable(_))))), sc)
}
case _ => Solution.none
}
List(task.decompose(this, List(newProblem), onSuccess, 100)) val newProblem = Problem(p.as, subst(x -> e, And(others)), oxs)
} else {
Nil
}
val onSuccess: List[Solution] => Solution = {
case List(Solution(pre, term, sc)) =>
if (oxs.isEmpty) {
Solution(pre, Tuple(e :: Nil), sc)
} else {
Solution(pre, LetTuple(oxs, term, subst(x -> e, Tuple(p.xs.map(Variable(_))))), sc)
}
case _ => Solution.none
}
case _ => List(task.decompose(this, List(newProblem), onSuccess, 100))
Nil } else {
Nil
} }
} }
} }
...@@ -87,7 +82,7 @@ class Ground(synth: Synthesizer) extends Rule("Ground", synth) { ...@@ -87,7 +82,7 @@ class Ground(synth: Synthesizer) extends Rule("Ground", synth) {
synth.solveSAT(p.phi) match { synth.solveSAT(p.phi) match {
case (Some(true), model) => case (Some(true), model) =>
List(task.solveUsing(this, Solution(BooleanLiteral(true), Tuple(p.xs.map(model)).setType(tpe), 200), 200)) List(task.solveUsing(this, Solution(BooleanLiteral(true), Tuple(p.xs.map(id => model.getOrElse(id, simplestValue(Variable(id))))).setType(tpe), 200), 200))
case (Some(false), model) => case (Some(false), model) =>
List(task.solveUsing(this, Solution(BooleanLiteral(false), Error(p.phi+" is UNSAT!").setType(tpe), 200), 200)) List(task.solveUsing(this, Solution(BooleanLiteral(false), Error(p.phi+" is UNSAT!").setType(tpe), 200), 200))
case _ => case _ =>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment