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

Improve search by making it more deterministic

parent 94e82a7b
No related branches found
No related tags found
No related merge requests found
...@@ -42,14 +42,13 @@ class SimpleSearch(synth: Synthesizer, ...@@ -42,14 +42,13 @@ class SimpleSearch(synth: Synthesizer,
def expandAndTask(t: TaskRunRule): ExpandResult[TaskTryRules] = { def expandAndTask(t: TaskRunRule): ExpandResult[TaskTryRules] = {
val prefix = "[%-20s] ".format(Option(t.rule).getOrElse("?")) val prefix = "[%-20s] ".format(Option(t.rule).getOrElse("?"))
info(prefix+"Got: "+t.problem)
t.app.apply(sctx) match { t.app.apply(sctx) match {
case RuleSuccess(sol) => case RuleSuccess(sol) =>
info(prefix+"Got: "+t.problem)
info(prefix+"Solved with: "+sol) info(prefix+"Solved with: "+sol)
ExpandSuccess(sol) ExpandSuccess(sol)
case RuleDecomposed(sub) => case RuleDecomposed(sub) =>
info(prefix+"Got: "+t.problem)
info(prefix+"Decomposed into:") info(prefix+"Decomposed into:")
for(p <- sub) { for(p <- sub) {
info(prefix+" - "+p) info(prefix+" - "+p)
...@@ -58,6 +57,8 @@ class SimpleSearch(synth: Synthesizer, ...@@ -58,6 +57,8 @@ class SimpleSearch(synth: Synthesizer,
Expanded(sub.map(TaskTryRules(_))) Expanded(sub.map(TaskTryRules(_)))
case RuleApplicationImpossible => case RuleApplicationImpossible =>
info(prefix+"Failed")
ExpandFailure() ExpandFailure()
} }
} }
......
...@@ -40,7 +40,7 @@ case object ADTInduction extends Rule("ADT Induction") with Heuristic { ...@@ -40,7 +40,7 @@ case object ADTInduction extends Rule("ADT Induction") with Heuristic {
val innerPhi = substAll(residualMap + (origId -> Variable(inductOn)), p.phi) val innerPhi = substAll(residualMap + (origId -> Variable(inductOn)), p.phi)
val innerPC = substAll(residualMap + (origId -> Variable(inductOn)), p.pc) val innerPC = substAll(residualMap + (origId -> Variable(inductOn)), p.pc)
val subProblemsInfo = for (dcd <- cd.knownDescendents) yield dcd match { val subProblemsInfo = for (dcd <- cd.knownDescendents.sortBy(_.id.name)) yield dcd match {
case ccd : CaseClassDef => case ccd : CaseClassDef =>
var recCalls = Map[List[Identifier], List[Expr]]() var recCalls = Map[List[Identifier], List[Expr]]()
var postFs = List[Expr]() var postFs = List[Expr]()
......
...@@ -14,7 +14,7 @@ case object ADTSplit extends Rule("ADT Split.") { ...@@ -14,7 +14,7 @@ case object ADTSplit extends Rule("ADT Split.") {
val candidates = p.as.collect { val candidates = p.as.collect {
case IsTyped(id, AbstractClassType(cd)) => case IsTyped(id, AbstractClassType(cd)) =>
val optCases = for (dcd <- cd.knownDescendents) yield dcd match { val optCases = for (dcd <- cd.knownDescendents.sortBy(_.id.name)) yield dcd match {
case ccd : CaseClassDef => case ccd : CaseClassDef =>
val toSat = And(p.pc, Not(CaseClassInstanceOf(ccd, Variable(id)))) val toSat = And(p.pc, Not(CaseClassInstanceOf(ccd, Variable(id))))
......
...@@ -77,11 +77,7 @@ class AndOrGraph[AT <: AOAndTask[S], OT <: AOOrTask[S], S](val root: OT, val cos ...@@ -77,11 +77,7 @@ class AndOrGraph[AT <: AOAndTask[S], OT <: AOOrTask[S], S](val root: OT, val cos
} }
def expandLeaf(l: OrLeaf, succ: List[AT]) { def expandLeaf(l: OrLeaf, succ: List[AT]) {
val n = new OrNode(this, Map(), l.task) subProblems += l.task -> new OrNode(this, succ, l.task)
n.alternatives = succ.map(t => t -> new AndLeaf(n, t)).toMap
n.updateMin()
subProblems += l.task -> n
} }
def notifySolution(sub: OrTree, sol: S) { def notifySolution(sub: OrTree, sol: S) {
...@@ -106,11 +102,7 @@ class AndOrGraph[AT <: AOAndTask[S], OT <: AOOrTask[S], S](val root: OT, val cos ...@@ -106,11 +102,7 @@ class AndOrGraph[AT <: AOAndTask[S], OT <: AOOrTask[S], S](val root: OT, val cos
object RootNode extends OrLeaf(null, root) { object RootNode extends OrLeaf(null, root) {
override def expandWith(succ: List[AT]) { override def expandWith(succ: List[AT]) {
val n = new OrNode(null, Map(), root) tree = new OrNode(null, succ, root)
n.alternatives = succ.map(t => t -> new AndLeaf(n, t)).toMap
n.updateMin()
tree = n
} }
} }
...@@ -122,10 +114,13 @@ class AndOrGraph[AT <: AOAndTask[S], OT <: AOOrTask[S], S](val root: OT, val cos ...@@ -122,10 +114,13 @@ class AndOrGraph[AT <: AOAndTask[S], OT <: AOOrTask[S], S](val root: OT, val cos
} }
class OrNode(val parent: AndNode, var alternatives: Map[AT, AndTree], val task: OT) extends OrTree with Node[AndTree] { class OrNode(val parent: AndNode, val altTasks: List[AT], val task: OT) extends OrTree with Node[AndTree] {
var triedAlternatives = Map[AT, AndTree]() var alternatives: Map[AT, AndTree] = altTasks.map(t => t -> new AndLeaf(this, t)).toMap
var minAlternative: AndTree = _ var triedAlternatives = Map[AT, AndTree]()
var minCost = costModel.taskCost(task) var minAlternative: AndTree = _
var minCost = costModel.taskCost(task)
updateMin()
def updateMin() { def updateMin() {
if (!alternatives.isEmpty) { if (!alternatives.isEmpty) {
......
...@@ -20,7 +20,7 @@ abstract class AndOrGraphSearch[AT <: AOAndTask[S], ...@@ -20,7 +20,7 @@ abstract class AndOrGraphSearch[AT <: AOAndTask[S],
case l: g.Leaf => case l: g.Leaf =>
collectLeaf(WL(l, newCosts.reverse)) collectLeaf(WL(l, newCosts.reverse))
case a: g.AndNode => case a: g.AndNode =>
for (o <- (a.subProblems -- a.subSolutions.keySet).values) { for (o <- a.subTasks.filterNot(a.subSolutions.keySet).map(a.subProblems)) {
collectFromOr(o, newCosts) collectFromOr(o, newCosts)
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment