diff --git a/src/main/scala/leon/synthesis/SimpleSearch.scala b/src/main/scala/leon/synthesis/SimpleSearch.scala new file mode 100644 index 0000000000000000000000000000000000000000..9d6f65704bfa796bf63fd29154d326ec9999edfe --- /dev/null +++ b/src/main/scala/leon/synthesis/SimpleSearch.scala @@ -0,0 +1,62 @@ +package leon +package synthesis + +import synthesis.search._ + +case class TaskRunRule(problem: Problem, rule: Rule, app: RuleApplication) extends AOAndTask[Solution] { + val cost = RuleApplicationCost(rule, app) + + def composeSolution(sols: List[Solution]): Solution = { + app.onSuccess(sols) + } + + override def toString = rule.name +} + +case class TaskTryRules(p: Problem) extends AOOrTask[Solution] { + val cost = ProblemCost(p) + + override def toString = p.toString +} + +class SimpleSearch(synth: Synthesizer, + problem: Problem, + rules: Set[Rule]) extends AndOrGraphSearch[TaskRunRule, TaskTryRules, Solution](new AndOrGraph(TaskTryRules(problem))) { + + import synth.reporter._ + + val sctx = SynthesisContext.fromSynthesizer(synth) + + def processAndLeaf(t: TaskRunRule) = { + val prefix = "[%-20s] ".format(Option(t.rule).getOrElse("?")) + + t.app.apply() match { + case RuleSuccess(sol) => + info(prefix+"Got: "+t.problem) + info(prefix+"Solved with: "+sol) + + ExpandSuccess(sol) + case RuleDecomposed(sub, onSuccess) => + info(prefix+"Got: "+t.problem) + info(prefix+"Decomposed into:") + for(p <- sub) { + info(prefix+" - "+p) + } + + Expanded(sub.map(TaskTryRules(_))) + + case RuleApplicationImpossible => + ExpandFailure() + } + } + + def processOrLeaf(t: TaskTryRules) = { + val sub = rules.flatMap ( r => r.attemptToApplyOn(sctx, t.p).alternatives.map(TaskRunRule(t.p, r, _)) ) + + if (!sub.isEmpty) { + Expanded(sub.toList) + } else { + ExpandFailure() + } + } +} diff --git a/src/main/scala/leon/synthesis/Synthesizer.scala b/src/main/scala/leon/synthesis/Synthesizer.scala index a708ecf068b75d137f27a54133db4e24857d2e58..3c8adc96353ed66b0d1585d39636ed25cdf696e5 100644 --- a/src/main/scala/leon/synthesis/Synthesizer.scala +++ b/src/main/scala/leon/synthesis/Synthesizer.scala @@ -29,7 +29,7 @@ class Synthesizer(val reporter: Reporter, def synthesize(): Solution = { - val search = new AOSearch(this, problem, rules) + val search = new SimpleSearch(this, problem, rules) val sigINT = new Signal("INT") var oldHandler: SignalHandler = null @@ -59,61 +59,6 @@ class Synthesizer(val reporter: Reporter, res.getOrElse(Solution.choose(problem)) } - case class TaskRunRule(problem: Problem, rule: Rule, app: RuleApplication) extends AOAndTask[Solution] { - val cost = RuleApplicationCost(rule, app) - - def composeSolution(sols: List[Solution]): Solution = { - app.onSuccess(sols) - } - - override def toString = rule.name - } - - case class TaskTryRules(p: Problem) extends AOOrTask[Solution] { - val cost = ProblemCost(p) - - override def toString = p.toString - } - - class AOSearch(synth: Synthesizer, - problem: Problem, - rules: Set[Rule]) extends AndOrGraphSearch[TaskRunRule, TaskTryRules, Solution](new AndOrGraph(TaskTryRules(problem))) { - - val sctx = SynthesisContext.fromSynthesizer(synth) - - def processAndLeaf(t: TaskRunRule) = { - val prefix = "[%-20s] ".format(Option(t.rule).getOrElse("?")) - - t.app.apply() match { - case RuleSuccess(sol) => - info(prefix+"Got: "+t.problem) - info(prefix+"Solved with: "+sol) - - ExpandSuccess(sol) - case RuleDecomposed(sub, onSuccess) => - info(prefix+"Got: "+t.problem) - info(prefix+"Decomposed into:") - for(p <- sub) { - info(prefix+" - "+p) - } - - Expanded(sub.map(TaskTryRules(_))) - - case RuleApplicationImpossible => - ExpandFailure() - } - } - - def processOrLeaf(t: TaskTryRules) = { - val sub = rules.flatMap ( r => r.attemptToApplyOn(sctx, t.p).alternatives.map(TaskRunRule(t.p, r, _)) ) - - if (!sub.isEmpty) { - Expanded(sub.toList) - } else { - ExpandFailure() - } - } - } }