From e6cfb3e654d435be2d51a512c2da22e7a9b99c06 Mon Sep 17 00:00:00 2001 From: Naveen Sundar Govindarajulu Date: Tue, 2 Jan 2018 14:32:09 -0800 Subject: [PATCH] A lot of commits. --- snark-20120808r02/snark-interface.lisp | 2 +- src/main/java/edu/rpi/rair/Action.java | 12 +++ .../java/edu/rpi/rair/ContextNormPlanner.java | 26 ++++++ .../java/edu/rpi/rair/DepthFirstPlanner.java | 88 +++++++++++++++++++ src/main/java/edu/rpi/rair/Inducer.java | 2 +- src/main/java/edu/rpi/rair/PlanMethod.java | 17 ++-- src/main/java/edu/rpi/rair/Planner.java | 3 + .../edu/rpi/rair/inducers/SimpleInducer.java | 34 ++++--- src/main/java/edu/rpi/rair/utils/Commons.java | 25 ++---- .../rpi/rair/utils/GoalTrackingProblem.java | 18 +++- .../edu/rpi/rair/utils/LearningSystem.java | 6 +- .../edu/rpi/rair/utils/PlanningProblem.java | 14 ++- src/main/java/edu/rpi/rair/utils/RunDemo.java | 13 ++- src/main/java/edu/rpi/rair/utils/Sandbox.java | 10 +++ .../rpi/rair/problems/seriated/methods.clj | 8 +- .../seriated/seriated_challenge_1.clj | 15 ++-- .../seriated/seriated_challenge_2.clj | 7 +- 17 files changed, 239 insertions(+), 61 deletions(-) create mode 100644 src/main/java/edu/rpi/rair/ContextNormPlanner.java diff --git a/snark-20120808r02/snark-interface.lisp b/snark-20120808r02/snark-interface.lisp index 15ff55f..6ce2e97 100644 --- a/snark-20120808r02/snark-interface.lisp +++ b/snark-20120808r02/snark-interface.lisp @@ -91,7 +91,7 @@ (snark:initialize :verbose verbose) (if (not verbose) (snark-deverbose) ) (temp-sorts) - (snark:run-time-limit 1) + (snark:run-time-limit 0.05) (snark:assert-supported t) (snark:assume-supported t) (snark:prove-supported t) diff --git a/src/main/java/edu/rpi/rair/Action.java b/src/main/java/edu/rpi/rair/Action.java index c1ac9dc..1e214ab 100644 --- a/src/main/java/edu/rpi/rair/Action.java +++ b/src/main/java/edu/rpi/rair/Action.java @@ -105,6 +105,18 @@ public class Action { return precondition; } + public Set getPreconditions() { + return preconditions; + } + + public Set getAdditions() { + return additions; + } + + public Set getDeletions() { + return deletions; + } + public List openVars() { return freeVariables; diff --git a/src/main/java/edu/rpi/rair/ContextNormPlanner.java b/src/main/java/edu/rpi/rair/ContextNormPlanner.java new file mode 100644 index 0000000..3e942cb --- /dev/null +++ b/src/main/java/edu/rpi/rair/ContextNormPlanner.java @@ -0,0 +1,26 @@ +package edu.rpi.rair; + +import com.naveensundarg.shadow.prover.representations.formula.Formula; +import edu.rpi.rair.utils.PlanningProblem; + +import java.util.List; +import java.util.Optional; +import java.util.Set; + +public class ContextNormPlanner implements Planner { + + private static DepthFirstPlanner depthFirstPlanner = new DepthFirstPlanner(); + @Override + public Optional> plan(Set background, Set actions, State start, State goal) { + return depthFirstPlanner.plan(background, actions, start, goal); + + + } + + @Override + public Optional> plan(PlanningProblem problem, Set background, Set actions, State start, State goal) { + List methods = problem.getPlanMethods(); + + + } +} diff --git a/src/main/java/edu/rpi/rair/DepthFirstPlanner.java b/src/main/java/edu/rpi/rair/DepthFirstPlanner.java index c7d707e..f3ea8ed 100644 --- a/src/main/java/edu/rpi/rair/DepthFirstPlanner.java +++ b/src/main/java/edu/rpi/rair/DepthFirstPlanner.java @@ -1,12 +1,16 @@ package edu.rpi.rair; +import com.naveensundarg.shadow.prover.core.proof.Justification; import com.naveensundarg.shadow.prover.representations.formula.Formula; +import com.naveensundarg.shadow.prover.utils.CollectionUtils; import com.naveensundarg.shadow.prover.utils.Pair; import com.naveensundarg.shadow.prover.utils.Sets; +import edu.rpi.rair.utils.Commons; import edu.rpi.rair.utils.PlanningProblem; import edu.rpi.rair.utils.Visualizer; import java.util.*; +import java.util.function.Function; import java.util.stream.Collectors; /** @@ -18,6 +22,8 @@ public class DepthFirstPlanner implements Planner { private static int MAX_DEPTH = 5; private static boolean EXHAUSTIVE_TILL_MAX_DEPTH = true; + private static boolean USE_METHODS = true; + public static int getMaxDepth() { return MAX_DEPTH; } @@ -64,6 +70,15 @@ public class DepthFirstPlanner implements Planner { @Override public Optional> plan(PlanningProblem problem, Set background, Set actions, State start, State goal) { + if(USE_METHODS){ + + Optional> optionalPlansFromMethods = plan(problem, background, actions, start, goal, problem.getPlanMethods()); + + if(optionalPlansFromMethods.isPresent()){ + return optionalPlansFromMethods; + } + } + if (!EXHAUSTIVE_TILL_MAX_DEPTH) { @@ -117,6 +132,79 @@ public class DepthFirstPlanner implements Planner { } + + public Optional> plan(PlanningProblem problem, Set background, Set actions, State start, State goal, List planMethods){ + + Set plans = Sets.newSet(); + + Function> verifier = (planSketch) -> verify(background, start, goal, planSketch); + + for (PlanMethod planMethod: planMethods){ + + Optional> optionalPlanSketches = planMethod.apply(background, start.getFormulae(), goal.getFormulae(), problem.getActions()); + + optionalPlanSketches.ifPresent(planSketches -> planSketches.forEach(planSketch -> verifier.apply(planSketch).ifPresent(plans::add))); + + } + + + if(!plans.isEmpty()){ + + return Optional.of(plans); + + } else { + + return Optional.empty(); + + } + + + + + } + + + public Optional verify(Set background, State start, State goal, PlanSketch planSketch){ + + List sketchActions = planSketch.getActions(); + List expectedStates = CollectionUtils.newEmptyList(); + + Set current = Sets.union(background, start.getFormulae()); + + expectedStates.add(State.initializeWith(current)); + for(Action action: sketchActions){ + + Set preconditions = action.getPreconditions(); + Set additions = action.getAdditions(); + Set deletions = action.getDeletions(); + + Optional optPrecond = Operations.proveCached(current, Commons.makeAnd(preconditions)); + + if(optPrecond.isPresent()){ + + current.addAll(additions); + current.removeAll(deletions); + expectedStates.add(State.initializeWith(current)); + + } else { + + return Optional.empty(); + } + + } + + + if(!Operations.proveCached(current, Commons.makeAnd(goal.getFormulae())).isPresent()){ + + return Optional.empty(); + } + + return Optional.of(new Plan(sketchActions, expectedStates, background)); + + + } + + private Optional> planInternal(Set> history, int currentDepth, int maxDepth, Set background, Set actions, State start, State goal) { if (currentDepth >= maxDepth) { diff --git a/src/main/java/edu/rpi/rair/Inducer.java b/src/main/java/edu/rpi/rair/Inducer.java index e4c3f8a..18a0730 100644 --- a/src/main/java/edu/rpi/rair/Inducer.java +++ b/src/main/java/edu/rpi/rair/Inducer.java @@ -8,6 +8,6 @@ import edu.rpi.rair.utils.PlanningProblem; */ public interface Inducer { - Plan induce(PlanningProblem planningProblem, State start, Goal goal, Plan plan); + PlanMethod induce(PlanningProblem planningProblem, State start, Goal goal, Plan plan); } diff --git a/src/main/java/edu/rpi/rair/PlanMethod.java b/src/main/java/edu/rpi/rair/PlanMethod.java index a045040..adbb558 100644 --- a/src/main/java/edu/rpi/rair/PlanMethod.java +++ b/src/main/java/edu/rpi/rair/PlanMethod.java @@ -111,13 +111,18 @@ public class PlanMethod { } + /* (define-method planMethod [?b ?c ?d] + {:goal [(In ?b ?c) (In ?c ?d)] + :while [(In ?b ?d) (Empty ?c) + (< (size ?c) (size ?d)) + (< (size ?b) (size ?c))] + :actions [(removeFrom ?b ?d) (placeInside ?b ?c) (placeInside ?c ?d)]}) +*/ @Override public String toString() { - return "PlanMethod{" + - "backGroundStatePreconditions=" + backGroundStatePreconditions + - ", goalPreconditions=" + goalPreconditions + - ", freeVariables=" + freeVariables + - ", actionCompounds=" + actionCompounds + - '}'; + return "(define-method planMethod " + freeVariables.toString().replace(",", " ") + "\n" + + "\t{:goal " + goalPreconditions.toString().replace(",", " ") + "\n" + + "\t:while " + backGroundStatePreconditions.toString().replace(",", " ") + "\n" + + "\t:actions " + actionCompounds.toString().replace(",", " ") + "})"; } } diff --git a/src/main/java/edu/rpi/rair/Planner.java b/src/main/java/edu/rpi/rair/Planner.java index b6abf0d..05a3ce1 100644 --- a/src/main/java/edu/rpi/rair/Planner.java +++ b/src/main/java/edu/rpi/rair/Planner.java @@ -15,4 +15,7 @@ public interface Planner { Optional> plan(Set background, Set actions, State start, State goal); Optional> plan(PlanningProblem problem, Set background, Set actions, State start, State goal); + + + } diff --git a/src/main/java/edu/rpi/rair/inducers/SimpleInducer.java b/src/main/java/edu/rpi/rair/inducers/SimpleInducer.java index 7567e2d..9fec231 100644 --- a/src/main/java/edu/rpi/rair/inducers/SimpleInducer.java +++ b/src/main/java/edu/rpi/rair/inducers/SimpleInducer.java @@ -10,19 +10,18 @@ import edu.rpi.rair.*; import edu.rpi.rair.utils.Commons; import edu.rpi.rair.utils.PlanningProblem; -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; /** * Created by naveensundarg on 12/19/17. */ -public class SimpleInducer implements Inducer{ + +public class SimpleInducer implements Inducer { + @Override - public Plan induce(PlanningProblem planningProblem, State start, Goal goal, Plan plan) { + public PlanMethod induce(PlanningProblem planningProblem, State start, Goal goal, Plan plan) { List actionList = plan.getActions(); @@ -41,9 +40,14 @@ public class SimpleInducer implements Inducer{ Map valueVariableMap = Commons.makeVariables(values); - Function,Set> getRelevantFormula = formulae -> formulae.stream(). - filter(formula -> !Sets.intersection(values, formula.valuesPresent()).isEmpty()). - collect(Collectors.toSet()); + Function,Set> getRelevantFormula = formulae -> { + + return formulae.stream(). + filter(formula -> Sets.difference(formula.valuesPresent().stream().filter(Value::isConstant).collect(Collectors.toSet()), + values).isEmpty() && + !Sets.intersection(values, formula.valuesPresent()).isEmpty()). + collect(Collectors.toSet()); + }; Set relevantBackgroundFormula = getRelevantFormula.apply(backgroundFormula); Set relevantInitFormula = getRelevantFormula.apply(initFormula); @@ -58,6 +62,14 @@ public class SimpleInducer implements Inducer{ System.out.println(relevantInitFormula); System.out.println(relevantGoalFormula); - return null; - } + //PlanMethod(Set goalPreconditions, Set backGroundStatePreconditions, List freeVariables, List actionCompounds + + + return new PlanMethod(Commons.generalize(valueVariableMap, relevantGoalFormula), + Sets.union(Commons.generalize(valueVariableMap, relevantBackgroundFormula), + Commons.generalize(valueVariableMap, relevantInitFormula)), + new ArrayList<>(valueVariableMap.values()), actionCompounds.stream().map(x-> (Compound) x.generalize(valueVariableMap)). + collect(Collectors.toList())); + + } } diff --git a/src/main/java/edu/rpi/rair/utils/Commons.java b/src/main/java/edu/rpi/rair/utils/Commons.java index 2b97770..267922e 100644 --- a/src/main/java/edu/rpi/rair/utils/Commons.java +++ b/src/main/java/edu/rpi/rair/utils/Commons.java @@ -12,6 +12,7 @@ import com.naveensundarg.shadow.prover.utils.Sets; import edu.rpi.rair.State; import us.bpsm.edn.parser.Parseable; +import java.util.ArrayList; import java.util.Map; import java.util.Set; import java.util.function.BiFunction; @@ -49,25 +50,10 @@ public class Commons { return valueVariableMap; } - public static Formula generalize(Map universalValueVariableMap, Set formulae){ - - Set allValues = formulae.stream().map(Formula::valuesPresent).reduce(Sets.newSet(), Sets::union).stream().filter(x->x.isConstant()).collect(Collectors.toSet()); - - Map existentialValueVariableMap = makeVariables(Sets.difference(allValues, universalValueVariableMap.keySet()), universalValueVariableMap.size() + 1); + public static Set generalize(Map universalValueVariableMap, Set formulae){ - Map combinedMap = combine((universalValueVariableMap), (existentialValueVariableMap)); - Formula f = (new And(formulae.stream().collect(Collectors.toList()))).generalize(combinedMap); - - Variable[] universalVars = new Variable[universalValueVariableMap.values().size()]; - universalVars = universalValueVariableMap.values().toArray(universalVars); - - Variable[] existentialVars = new Variable[existentialValueVariableMap.values().size()]; - existentialVars = existentialValueVariableMap.values().toArray(existentialVars); - - - System.out.println(new Universal(universalVars, new Existential(existentialVars, f))); - return new Universal(universalVars, new Existential(existentialVars, f)); + return formulae.stream().map(x->x.generalize(universalValueVariableMap)).collect(Collectors.toSet()); } public static Map reverse(Map map){ @@ -104,5 +90,10 @@ public class Commons { return w; } + + public static And makeAnd(Set formulae){ + + return new And(new ArrayList<>(formulae)); + } } diff --git a/src/main/java/edu/rpi/rair/utils/GoalTrackingProblem.java b/src/main/java/edu/rpi/rair/utils/GoalTrackingProblem.java index 0542ce0..32e29b5 100644 --- a/src/main/java/edu/rpi/rair/utils/GoalTrackingProblem.java +++ b/src/main/java/edu/rpi/rair/utils/GoalTrackingProblem.java @@ -4,6 +4,7 @@ import com.naveensundarg.shadow.prover.representations.formula.Formula; import com.naveensundarg.shadow.prover.utils.CollectionUtils; import com.naveensundarg.shadow.prover.utils.Reader; import edu.rpi.rair.Goal; +import edu.rpi.rair.PlanMethod; import edu.rpi.rair.State; import us.bpsm.edn.Keyword; import us.bpsm.edn.parser.Parseable; @@ -16,6 +17,8 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.util.*; +import static edu.rpi.rair.utils.Reader.readPlanMethodsFrom; + /** * Created by naveensundarg on 1/13/17. */ @@ -32,6 +35,7 @@ public class GoalTrackingProblem { private static final Keyword PRIORITY = Keyword.newKeyword("priority"); private static final Keyword STATE = Keyword.newKeyword("state"); + public GoalTrackingProblem(PlanningProblem planningProblem, Set goals) { this.planningProblem = planningProblem; this.goals = goals; @@ -44,7 +48,19 @@ public class GoalTrackingProblem { } - public static List readFromFile(InputStream inputStream) throws Reader.ParsingException { + public static List readFromFiles(InputStream definitionInputStream, InputStream methodsInputStream) throws Reader.ParsingException { + + List goalTrackingProblems = readFromFile(definitionInputStream); + + List planMethods = readPlanMethodsFrom(methodsInputStream); + + goalTrackingProblems.stream().map(GoalTrackingProblem::getPlanningProblem).forEach(x->x.addToPlanMethods(planMethods)); + + return goalTrackingProblems; + } + + + public static List readFromFile(InputStream inputStream) throws Reader.ParsingException { Parseable parseable = Parsers.newParseable(new InputStreamReader(inputStream)); Parser parser = Parsers.newParser(Parsers.defaultConfiguration()); diff --git a/src/main/java/edu/rpi/rair/utils/LearningSystem.java b/src/main/java/edu/rpi/rair/utils/LearningSystem.java index c1b48af..a773302 100644 --- a/src/main/java/edu/rpi/rair/utils/LearningSystem.java +++ b/src/main/java/edu/rpi/rair/utils/LearningSystem.java @@ -39,8 +39,10 @@ public class LearningSystem { Visualizer.setShouldVisualize(false); - List goalTrackingProblemList1 = (GoalTrackingProblem.readFromFile(Planner.class.getResourceAsStream("seriated_challenge_1.clj"))); - List goalTrackingProblemList2 = (GoalTrackingProblem.readFromFile(Planner.class.getResourceAsStream("seriated_challenge_2.clj"))); + List goalTrackingProblemList1 = (GoalTrackingProblem.readFromFiles(Sandbox.class.getResourceAsStream("../problems/seriated/seriated_challenge_1.clj"), + Sandbox.class.getResourceAsStream("../problems/seriated/methods.clj"))); + List goalTrackingProblemList2 = (GoalTrackingProblem.readFromFiles(Sandbox.class.getResourceAsStream("../problems/seriated/seriated_challenge_2.clj"), + Sandbox.class.getResourceAsStream("../problems/seriated/methods.clj"))); GoalTrackingProblem goalTrackingProblem1 = goalTrackingProblemList1.get(0); diff --git a/src/main/java/edu/rpi/rair/utils/PlanningProblem.java b/src/main/java/edu/rpi/rair/utils/PlanningProblem.java index a6fdea7..7223dee 100644 --- a/src/main/java/edu/rpi/rair/utils/PlanningProblem.java +++ b/src/main/java/edu/rpi/rair/utils/PlanningProblem.java @@ -9,6 +9,7 @@ import com.naveensundarg.shadow.prover.utils.CollectionUtils; import com.naveensundarg.shadow.prover.utils.Reader; import com.naveensundarg.shadow.prover.utils.Sets; import edu.rpi.rair.Action; +import edu.rpi.rair.PlanMethod; import edu.rpi.rair.State; import us.bpsm.edn.Keyword; import us.bpsm.edn.Symbol; @@ -38,6 +39,7 @@ public class PlanningProblem { private Map actionMap; private Set avoidIfPossible; + private final List planMethods; private static final Keyword BACKGROUND = Keyword.newKeyword("background"); private static final Keyword START = Keyword.newKeyword("start"); @@ -63,7 +65,7 @@ public class PlanningProblem { this.name = name; this.actionMap = CollectionUtils.newMap(); this.avoidIfPossible = avoidIfPossible; - + this.planMethods = CollectionUtils.newEmptyList(); this.expectedActionSequencesOpt = Optional.empty(); } @@ -77,6 +79,7 @@ public class PlanningProblem { this.name = name; this.actionMap = CollectionUtils.newMap(); this.avoidIfPossible = avoidIfPossible; + this.planMethods = CollectionUtils.newEmptyList(); this.expectedActionSequencesOpt = Optional.of(expectedActionSequences); } @@ -340,6 +343,15 @@ public class PlanningProblem { return avoidIfPossible; } + + public List getPlanMethods() { + return planMethods; + } + + public void addToPlanMethods(List methods){ + + planMethods.addAll(methods); + } @Override public String toString() { return "PlanningProblem{" + diff --git a/src/main/java/edu/rpi/rair/utils/RunDemo.java b/src/main/java/edu/rpi/rair/utils/RunDemo.java index 2dce90e..45f6a38 100644 --- a/src/main/java/edu/rpi/rair/utils/RunDemo.java +++ b/src/main/java/edu/rpi/rair/utils/RunDemo.java @@ -5,8 +5,7 @@ import com.diogonunes.jcdp.color.api.Ansi; import com.google.common.collect.Sets; import com.naveensundarg.shadow.prover.core.Prover; import com.naveensundarg.shadow.prover.core.SnarkWrapper; -import com.naveensundarg.shadow.prover.sandboxes.Sandbox; -import com.naveensundarg.shadow.prover.utils.Problem; + import com.naveensundarg.shadow.prover.utils.Problem; import com.naveensundarg.shadow.prover.utils.ProblemReader; import com.naveensundarg.shadow.prover.utils.Reader; import edu.rpi.rair.*; @@ -62,14 +61,14 @@ public class RunDemo { Visualizer.setShouldVisualize(false); - runProblem("seriated_challenge_1.clj"); + runProblem("../problems/seriated/seriated_challenge_1.clj"); // runProblem("seriated_challenge_2.clj"); } private static void runProblem(String name) throws Reader.ParsingException { - List goalTrackingProblemList = (GoalTrackingProblem.readFromFile(Planner.class.getResourceAsStream(name))); + List goalTrackingProblemList = (GoalTrackingProblem.readFromFile(Sandbox.class.getResourceAsStream(name))); GoalTrackingProblem goalTrackingProblem = goalTrackingProblemList.get(0); @@ -130,10 +129,10 @@ public class RunDemo { public static void planningProblemWarmUp() throws Reader.ParsingException { - for (int i = 0; i < 0; i++) { + for (int i = 0; i < 1; i++) { - List goalTrackingProblemList = (GoalTrackingProblem.readFromFile(Planner.class.getResourceAsStream("goal_management_1.clj"))); + List goalTrackingProblemList = (GoalTrackingProblem.readFromFile(Sandbox.class.getResourceAsStream("../problems/prisoner/goal_management_1.clj"))); GoalTrackingProblem goalTrackingProblem = goalTrackingProblemList.get(0); @@ -184,7 +183,7 @@ public class RunDemo { Optional possibleGoalPlan = goalTracker.adoptGoal(g); if (possibleGoalPlan.isPresent()) { - simpleInducer.induce(goalTracker.getProblem(), goalTracker.getProblem().getStart(), g, possibleGoalPlan.get()); + System.out.println(simpleInducer.induce(goalTracker.getProblem(), goalTracker.getProblem().getStart(), g, possibleGoalPlan.get())); printSuccessLater("Successfully added:", g.getName()); printDebug1Later("Current Goals and Constraint:", "\n" + goalTracker.getCurrentGoals().stream().collect(Collectors.toSet()).toString()); diff --git a/src/main/java/edu/rpi/rair/utils/Sandbox.java b/src/main/java/edu/rpi/rair/utils/Sandbox.java index 5902fed..4f1ff24 100644 --- a/src/main/java/edu/rpi/rair/utils/Sandbox.java +++ b/src/main/java/edu/rpi/rair/utils/Sandbox.java @@ -17,6 +17,7 @@ public class Sandbox { List goalTrackingProblemList1 = (GoalTrackingProblem.readFromFile(Sandbox.class.getResourceAsStream("../problems/seriated/seriated_challenge_1.clj"))); + List goalTrackingProblemList2 = (GoalTrackingProblem.readFromFile(Sandbox.class.getResourceAsStream("../problems/seriated/seriated_challenge_2.clj"))); System.out.println(seriatedPlanMethod.apply(goalTrackingProblemList1.get(0).getPlanningProblem().getBackground(), goalTrackingProblemList1.get(0).getPlanningProblem().getStart().getFormulae(), @@ -26,6 +27,15 @@ public class Sandbox { )); + System.out.println(seriatedPlanMethod.apply(goalTrackingProblemList2.get(0).getPlanningProblem().getBackground(), + goalTrackingProblemList2.get(0).getPlanningProblem().getStart().getFormulae(), + goalTrackingProblemList2.get(0).getGoalNamed("G1").getGoalState().getFormulae(), + goalTrackingProblemList2.get(0).getPlanningProblem().getActions() + + )); + + + } } diff --git a/src/main/resources/edu/rpi/rair/problems/seriated/methods.clj b/src/main/resources/edu/rpi/rair/problems/seriated/methods.clj index 951aadd..18258dc 100644 --- a/src/main/resources/edu/rpi/rair/problems/seriated/methods.clj +++ b/src/main/resources/edu/rpi/rair/problems/seriated/methods.clj @@ -1,9 +1,7 @@ ;; (removeFrom ?x ?y) => "Remove ?x from ?y" ;; (placeInside ?x ?y) ==> "Place ?x inside ?y" -(define-method planMethod [?b ?c ?d] - {:goal [(In ?b ?c) (In ?c ?d)] - :while [(In ?b ?d) (Empty ?c) - (< (size ?c) (size ?d)) - (< (size ?b) (size ?c))] +(define-method planMethod [?b ?d ?c] + {:goal [(In ?b ?c) (In ?c ?d)] + :while [(< (size ?c) (size ?d)) (< (size ?b) (size ?c)) (In ?b ?d) (Empty ?c)] :actions [(removeFrom ?b ?d) (placeInside ?b ?c) (placeInside ?c ?d)]}) \ No newline at end of file diff --git a/src/main/resources/edu/rpi/rair/problems/seriated/seriated_challenge_1.clj b/src/main/resources/edu/rpi/rair/problems/seriated/seriated_challenge_1.clj index 7696e49..5be373d 100644 --- a/src/main/resources/edu/rpi/rair/problems/seriated/seriated_challenge_1.clj +++ b/src/main/resources/edu/rpi/rair/problems/seriated/seriated_challenge_1.clj @@ -20,16 +20,12 @@ ;;; Sizes of cups (< (size a) (size b)) (< (size b) (size c)) - (< (size c) (size d)) - (< (size d) (size e)) - (< (size e) (size f)) - (< (size f) (size g)) - (< (size g) (size h))] + (< (size c) (size d))] :start [(In a b) (In b d) - (Empty c)] + (Empty c)] :goal [ ] @@ -46,12 +42,17 @@ :deletions [(In ?x ?y)]})]} :goals {G1 {:priority 1.0 + :context { :work-from-scratch false + :plan-methods + (define-method planMethod [?b ?d ?c] + {:goal [(In ?b ?c) (In ?c ?d)] + :while [(< (size ?c) (size ?d)) (< (size ?b) (size ?c)) (In ?b ?d) (Empty ?c)] + :actions [(removeFrom ?b ?d) (placeInside ?b ?c) (placeInside ?c ?d)]})} :state [(In a b) (In b c) (In c d)]}} -;;(removeFrom b d) (placeInside b c) (placeInside c d) } diff --git a/src/main/resources/edu/rpi/rair/problems/seriated/seriated_challenge_2.clj b/src/main/resources/edu/rpi/rair/problems/seriated/seriated_challenge_2.clj index ac3aea9..96d7415 100644 --- a/src/main/resources/edu/rpi/rair/problems/seriated/seriated_challenge_2.clj +++ b/src/main/resources/edu/rpi/rair/problems/seriated/seriated_challenge_2.clj @@ -54,14 +54,17 @@ } :goals {G1 {:priority 1.0 + + :state [(In a b) (In b c) (In c d) (In d e) (In e f) (In f g) - (In g h) -]}} + (In g h)] + + }} ;;(removeFrom b d) (placeInside b c) (placeInside c d)