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

Get best solution so far including a node

parent 04953925
No related branches found
No related tags found
No related merge requests found
...@@ -3,9 +3,14 @@ ...@@ -3,9 +3,14 @@
package leon package leon
package synthesis package synthesis
import purescala.Trees._
import purescala.TreeOps._
import purescala.DefOps._
import purescala.Common._
import graph._ import graph._
class PartialSolution(g: Graph, includeUntrusted: Boolean) { class PartialSolution(g: Graph, includeUntrusted: Boolean = false) {
def includeSolution(s: Solution) = { def includeSolution(s: Solution) = {
includeUntrusted || s.isTrusted includeUntrusted || s.isTrusted
...@@ -15,6 +20,49 @@ class PartialSolution(g: Graph, includeUntrusted: Boolean) { ...@@ -15,6 +20,49 @@ class PartialSolution(g: Graph, includeUntrusted: Boolean) {
Solution.choose(p) Solution.choose(p)
} }
def solutionAround(n: Node): Option[Expr => Solution] = {
def solveWith(optn: Option[Node], sol: Solution): Option[Solution] = optn match {
case None =>
Some(sol)
case Some(n) => n.parent match {
case None =>
Some(sol)
case Some(on: OrNode) =>
solveWith(on.parent, sol)
case Some(an: AndNode) =>
val ssols = for (d <- an.descendents) yield {
if (d == n) {
sol
} else {
getSolutionFor(d)
}
}
an.ri.onSuccess(ssols).flatMap { nsol =>
solveWith(an.parent, nsol)
}
}
}
val anchor = FreshIdentifier("anchor").setType(n.p.outType)
val s = Solution(BooleanLiteral(true), Set(), anchor.toVariable)
solveWith(Some(n), s) map {
case s @ Solution(pre, defs, term) =>
(e: Expr) =>
Solution(replaceFromIDs(Map(anchor -> e), pre),
defs.map(preMapOnFunDef({
case Variable(`anchor`) => Some(e)
case _ => None
})),
replaceFromIDs(Map(anchor -> e), term),
s.isTrusted)
}
}
def getSolution(): Solution = { def getSolution(): Solution = {
getSolutionFor(g.root) getSolutionFor(g.root)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment