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

Fix derivation generations, genreate dot files

parent 857317fc
No related branches found
No related tags found
No related merge requests found
...@@ -14,14 +14,19 @@ class Synthesizer(val r: Reporter, val solvers: List[Solver]) { ...@@ -14,14 +14,19 @@ class Synthesizer(val r: Reporter, val solvers: List[Solver]) {
import r.{error,warning,info,fatalError} import r.{error,warning,info,fatalError}
private[this] var solution: Option[Solution] = None private[this] var solution: Option[Solution] = None
private[this] var derivationTree: DerivationTree = _
var derivationCounter = 1;
def synthesize(p: Problem, rules: List[Rule]): Solution = { def synthesize(p: Problem, rules: List[Rule]): Solution = {
val workList = new PriorityQueue[Task]() val workList = new PriorityQueue[Task]()
val rootTask = new RootTask(this, p) val rootTask = new RootTask(this, p)
workList += rootTask workList += rootTask
solution = None solution = None
derivationTree = new DerivationTree(rootTask)
while (!workList.isEmpty && solution.isEmpty) { while (!workList.isEmpty && solution.isEmpty) {
val task = workList.dequeue() val task = workList.dequeue()
...@@ -48,9 +53,25 @@ class Synthesizer(val r: Reporter, val solvers: List[Solver]) { ...@@ -48,9 +53,25 @@ class Synthesizer(val r: Reporter, val solvers: List[Solver]) {
} }
} }
derivationTree.toDotFile("derivation"+derivationCounter+".dot")
derivationCounter += 1
solution.getOrElse(Solution.none) solution.getOrElse(Solution.none)
} }
def onTaskSucceeded(task: Task, solution: Solution) {
info(" => Solved "+task.problem+" ⊢ "+solution)
derivationTree.recordSolutionFor(task, solution)
if (task.parent eq null) {
info(" SUCCESS!")
this.solution = Some(solution)
} else {
task.parent.subSucceeded(task.problem, solution)
}
}
def solveSAT(phi: Expr): (Option[Boolean], Map[Identifier, Expr]) = { def solveSAT(phi: Expr): (Option[Boolean], Map[Identifier, Expr]) = {
for (s <- solvers) { for (s <- solvers) {
s.solveOrGetCounterexample(Not(phi)) match { s.solveOrGetCounterexample(Not(phi)) match {
...@@ -64,16 +85,6 @@ class Synthesizer(val r: Reporter, val solvers: List[Solver]) { ...@@ -64,16 +85,6 @@ class Synthesizer(val r: Reporter, val solvers: List[Solver]) {
(None, Map()) (None, Map())
} }
def onTaskSucceeded(task: Task, solution: Solution) {
info(" => Solved "+task.problem+" ⊢ "+solution)
if (task.parent eq null) {
info(" SUCCESS!")
this.solution = Some(solution)
} else {
task.parent.subSucceeded(task.problem, solution)
}
}
def synthesizeAll(program: Program) = { def synthesizeAll(program: Program) = {
import purescala.Trees._ import purescala.Trees._
......
...@@ -29,7 +29,7 @@ class DecomposedTask(synth: Synthesizer, ...@@ -29,7 +29,7 @@ class DecomposedTask(synth: Synthesizer,
def subTasks = subProblems.map(new Task(synth, this, _, score)) def subTasks = subProblems.map(new Task(synth, this, _, score))
var subSolutions = Map[Problem, Solution]() var subSolutions = Map[Problem, Solution]()
def isSuccess = subProblems.isEmpty def isSuccess = subProblems.isEmpty
......
...@@ -15,6 +15,8 @@ object SynthesisProceduresToolkit { ...@@ -15,6 +15,8 @@ object SynthesisProceduresToolkit {
def e6(a: Nat, b: Nat): (Nat, NatList) = choose( (x: Nat, y: NatList) => a == Succ(b)) def e6(a: Nat, b: Nat): (Nat, NatList) = choose( (x: Nat, y: NatList) => a == Succ(b))
def e7(a1 : NatList, a2 : Nat, a3 : NatList): (Nat, NatList, Nat, NatList) = choose( (x1 : Nat, x2 : NatList, x3 : Nat, x4 : NatList) => Cons(Succ(x1), x2) == a1 && Succ(x1) != a2 && a3 == Cons(x3, Cons(x3, x4)) || (a1 == a3 && x1 == x3))
abstract class Nat abstract class Nat
case class Z() extends Nat case class Z() extends Nat
case class Succ(n: Nat) extends Nat case class Succ(n: Nat) extends Nat
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment