diff --git a/pom.xml b/pom.xml
index c8473ea..20bf53b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -14,7 +14,7 @@
logic
prover
- 0.09
+ 0.84
diff --git a/snark-20120808r02/snark-interface.lisp b/snark-20120808r02/snark-interface.lisp
index 6ce2e97..15ff55f 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 0.05)
+ (snark:run-time-limit 1)
(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 2807158..c1ac9dc 100644
--- a/src/main/java/edu/rpi/rair/Action.java
+++ b/src/main/java/edu/rpi/rair/Action.java
@@ -1,13 +1,13 @@
package edu.rpi.rair;
+import com.naveensundarg.shadow.prover.core.Logic;
import com.naveensundarg.shadow.prover.representations.formula.And;
import com.naveensundarg.shadow.prover.representations.formula.Formula;
import com.naveensundarg.shadow.prover.representations.value.Compound;
import com.naveensundarg.shadow.prover.representations.value.Value;
import com.naveensundarg.shadow.prover.representations.value.Variable;
import com.naveensundarg.shadow.prover.utils.CollectionUtils;
-import com.naveensundarg.shadow.prover.utils.Logic;
-import com.naveensundarg.shadow.prover.utils.Sets;
+ import com.naveensundarg.shadow.prover.utils.Sets;
import java.util.List;
import java.util.Map;
@@ -159,6 +159,11 @@ public class Action {
return trivial;
}
+
+ public Compound getShorthand() {
+ return shorthand;
+ }
+
@Override
public String toString() {
return shorthand.getArguments().length == 0? name: shorthand.toString();
diff --git a/src/main/java/edu/rpi/rair/DepthFirstPlanner.java b/src/main/java/edu/rpi/rair/DepthFirstPlanner.java
index 5054f24..c7d707e 100644
--- a/src/main/java/edu/rpi/rair/DepthFirstPlanner.java
+++ b/src/main/java/edu/rpi/rair/DepthFirstPlanner.java
@@ -3,6 +3,8 @@ package edu.rpi.rair;
import com.naveensundarg.shadow.prover.representations.formula.Formula;
import com.naveensundarg.shadow.prover.utils.Pair;
import com.naveensundarg.shadow.prover.utils.Sets;
+import edu.rpi.rair.utils.PlanningProblem;
+import edu.rpi.rair.utils.Visualizer;
import java.util.*;
import java.util.stream.Collectors;
@@ -13,8 +15,8 @@ import java.util.stream.Collectors;
public class DepthFirstPlanner implements Planner {
- private static int MAX_DEPTH = 4;
- private static boolean EXHAUSTIVE_TILL_MAX_DEPTH = false;
+ private static int MAX_DEPTH = 5;
+ private static boolean EXHAUSTIVE_TILL_MAX_DEPTH = true;
public static int getMaxDepth() {
return MAX_DEPTH;
@@ -59,6 +61,61 @@ public class DepthFirstPlanner implements Planner {
}
+ @Override
+ public Optional> plan(PlanningProblem problem, Set background, Set actions, State start, State goal) {
+
+
+ if (!EXHAUSTIVE_TILL_MAX_DEPTH) {
+
+ return planInternal(Sets.newSet(), 0, MAX_DEPTH, background, actions, start, goal);
+
+ } else {
+
+ Set possiblePlans = Sets.newSet();
+ for (int i = 1; i <= MAX_DEPTH; i++) {
+
+ Optional> plansOpt = planInternal(Sets.newSet(), 0, i, background, actions, start, goal);
+
+ if (plansOpt.isPresent()) {
+
+ Set complyingPlans = plansOpt.get().stream().
+ filter(plan-> plan.getActions().stream().
+ map(Action::getShorthand).
+ noneMatch(shortHand-> {
+
+ return problem.getAvoidIfPossible().
+ stream().map(Object::toString).
+ collect(Collectors.toSet()).
+ contains(shortHand.getName());
+
+ })).
+ collect(Collectors.toSet());
+
+
+ if(!complyingPlans.isEmpty()){
+ return Optional.of(complyingPlans);
+ }
+ else{
+
+ possiblePlans.addAll(plansOpt.get());
+ }
+
+ }
+
+ }
+//
+ if(possiblePlans.isEmpty()){
+ return Optional.empty();
+
+ } else{
+
+ return Optional.of(possiblePlans);
+ }
+
+ }
+
+
+ }
private Optional> planInternal(Set> history, int currentDepth, int maxDepth, Set background, Set actions, State start, State goal) {
@@ -83,9 +140,11 @@ public class DepthFirstPlanner implements Planner {
for (Pair stateActionPair : nextStateActionPairs.get()) {
-
+ Visualizer.push();
Optional> planOpt = planInternal(history, currentDepth + 1, maxDepth, background, actions, stateActionPair.first(), goal);
+ Visualizer.pop();
+
if (planOpt.isPresent()) {
atleastOnePlanFound = true;
@@ -100,6 +159,8 @@ public class DepthFirstPlanner implements Planner {
allPlans.addAll(augmentedPlans);
+ // return Optional.of(allPlans);
+
//TODO: store different plans and return the best plan.
}
}
diff --git a/src/main/java/edu/rpi/rair/Goal.java b/src/main/java/edu/rpi/rair/Goal.java
index 31e6a3e..12bff0f 100644
--- a/src/main/java/edu/rpi/rair/Goal.java
+++ b/src/main/java/edu/rpi/rair/Goal.java
@@ -10,6 +10,8 @@ public class Goal {
private final State goalState;
private final double priority;
private final String name;
+ private final String description;
+
private static final AtomicInteger nameCounter;
static {
@@ -19,12 +21,22 @@ public class Goal {
this.goalState = goalState;
this.priority = priority;
this.name = "G" + nameCounter.incrementAndGet();
+ this.description = goalState.toString();
+
}
private Goal(State goalState, double priority, String name) {
this.goalState = goalState;
this.priority = priority;
this.name = name;
+ this.description = goalState.toString();
+ }
+
+ private Goal(State goalState, double priority, String name, String description) {
+ this.goalState = goalState;
+ this.priority = priority;
+ this.name = name;
+ this.description = description;
}
public static Goal makeGoal(State goalState, double priority){
@@ -32,9 +44,9 @@ public class Goal {
}
- public static Goal makeGoal(State goalState, double priority, String name){
+ public static Goal makeGoal(State goalState, double priority, String name, String description){
- return new Goal(goalState, priority, name);
+ return new Goal(goalState, priority, name, description);
}
@@ -51,13 +63,12 @@ public class Goal {
return name;
}
+ public String getDescription() {
+ return description;
+ }
@Override
public String toString() {
- return "Goal{" +
- "goalState=" + goalState +
- ", priority=" + priority +
- ", name='" + name + '\'' +
- '}';
+ return "(" + name + ": " + description + ": " + priority+ ")";
}
@Override
diff --git a/src/main/java/edu/rpi/rair/GoalTracker.java b/src/main/java/edu/rpi/rair/GoalTracker.java
index 3972294..df4164a 100644
--- a/src/main/java/edu/rpi/rair/GoalTracker.java
+++ b/src/main/java/edu/rpi/rair/GoalTracker.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.Pair;
import com.naveensundarg.shadow.prover.utils.Sets;
+import edu.rpi.rair.utils.PlanningProblem;
import java.util.Comparator;
import java.util.List;
@@ -24,14 +25,16 @@ public class GoalTracker {
private final Set currentGoals;
private final Planner planner;
private final Set actions;
-
- public GoalTracker(Set background, State startState, Set actions) {
+ private final PlanningProblem problem;
+ public GoalTracker(PlanningProblem problem, Set background, State startState, Set actions) {
this.background = background;
this.currentState = startState;
this.currentGoals = CollectionUtils.newEmptySet();
this.planner = new DepthFirstPlanner();
this.actions = actions;
+ this.problem = problem;
+
Operations.reset();
}
@@ -68,7 +71,7 @@ public class GoalTracker {
- Optional> possiblePlans = planner.plan(background, actions, currentState, goal.getGoalState());
+ Optional> possiblePlans = planner.plan(problem, background, actions, currentState, goal.getGoalState());
if (!possiblePlans.isPresent()) {
@@ -151,6 +154,18 @@ public class GoalTracker {
}
+ public Set getBackground() {
+ return background;
+ }
+
+ public State getCurrentState() {
+ return currentState;
+ }
+
+ public PlanningProblem getProblem() {
+ return problem;
+ }
+
public Set getCurrentGoals() {
return currentGoals;
}
diff --git a/src/main/java/edu/rpi/rair/Inducer.java b/src/main/java/edu/rpi/rair/Inducer.java
new file mode 100644
index 0000000..e4c3f8a
--- /dev/null
+++ b/src/main/java/edu/rpi/rair/Inducer.java
@@ -0,0 +1,13 @@
+package edu.rpi.rair;
+
+import edu.rpi.rair.Plan;
+import edu.rpi.rair.utils.PlanningProblem;
+
+/**
+ * Created by naveensundarg on 12/19/17.
+ */
+public interface Inducer {
+
+ Plan induce(PlanningProblem planningProblem, State start, Goal goal, Plan plan);
+
+}
diff --git a/src/main/java/edu/rpi/rair/Operations.java b/src/main/java/edu/rpi/rair/Operations.java
index e6bc989..612218b 100644
--- a/src/main/java/edu/rpi/rair/Operations.java
+++ b/src/main/java/edu/rpi/rair/Operations.java
@@ -3,7 +3,6 @@ package edu.rpi.rair;
import com.naveensundarg.shadow.prover.core.Prover;
import com.naveensundarg.shadow.prover.core.SnarkWrapper;
import com.naveensundarg.shadow.prover.core.proof.Justification;
-import com.naveensundarg.shadow.prover.core.proof.TrivialJustification;
import com.naveensundarg.shadow.prover.representations.formula.BiConditional;
import com.naveensundarg.shadow.prover.representations.formula.Formula;
import com.naveensundarg.shadow.prover.representations.formula.Predicate;
@@ -12,7 +11,9 @@ import com.naveensundarg.shadow.prover.representations.value.Variable;
import com.naveensundarg.shadow.prover.utils.CollectionUtils;
import com.naveensundarg.shadow.prover.utils.ImmutablePair;
import com.naveensundarg.shadow.prover.utils.Pair;
+
import com.naveensundarg.shadow.prover.utils.Sets;
+import edu.rpi.rair.utils.Visualizer;
import org.apache.commons.lang3.tuple.Triple;
import java.util.List;
@@ -30,7 +31,7 @@ import static edu.rpi.rair.State.FALSE;
public class Operations {
private static boolean DEEP_EQUIVALENCE = false;
- private static boolean THROW_AWAY_EMPTY_BINDINGS = false;
+ private static boolean THROW_AWAY_EMPTY_BINDINGS = true;
private static Prover prover;
@@ -46,7 +47,8 @@ public class Operations {
applyCache.clear();
}
static {
- prover = new SnarkWrapper();
+ prover = SnarkWrapper.getInstance();
+
}
@@ -110,7 +112,7 @@ public class Operations {
if(room1.equals(room2)){
- return Optional.of(Justification.trivial(goal));
+ return Optional.of(Justification.trivial(assumptions, goal));
}
}
@@ -172,8 +174,15 @@ public class Operations {
public static synchronized Optional>> proveAndGetMultipleBindings(Set givens, Formula goal, List variables) {
- return prover.proveAndGetMultipleBindings(givens, goal, variables);
+ Optional>>> ans = prover.proveAndGetMultipleBindings(givens, goal, variables);
+ if(ans.isPresent()){
+
+ return Optional.of(ans.get().getRight());
+
+ }else {
+ return Optional.empty();
+ }
/* Future>>> future = new FutureTask<>(()-> prover.proveAndGetMultipleBindings(givens, goal, variables));
Optional>> answer;
@@ -192,9 +201,14 @@ public class Operations {
public static Optional>> apply(Set background, Action action, State state) {
+
if(applyCache.containsKey(Triple.of(background, action, state))){
- return applyCache.get(Triple.of(background, action, state));
+ Optional>> ans = applyCache.get(Triple.of(background, action, state));
+ if(ans.isPresent()){
+ return applyCache.get(Triple.of(background, action, state));
+
+ }
}
Set givens = Sets.union(background, state.getFormulae());
@@ -206,11 +220,14 @@ public class Operations {
if (!bindingsOpt.isPresent()) {
+
applyCache.put(Triple.of(background, action ,state), Optional.empty());
return Optional.empty();
}
+ Visualizer.nested(action.getName());
+
Set> nexts = Sets.newSet();
for (Map binding : bindingsOpt.get()) {
@@ -222,7 +239,7 @@ public class Operations {
Set instantiatedDeletions = action.instantiateDeletions(binding);
Set formulaeToRemove = state.getFormulae().stream().
- filter(f -> instantiatedDeletions.stream().anyMatch(d -> equivalent(background, f, d))).collect(Collectors.toSet());
+ filter(f -> instantiatedDeletions.stream().anyMatch(d -> equivalent(Sets.union(background, state.getFormulae()), f, d))).collect(Collectors.toSet());
Set newFormulae = Sets.union(background, state.getFormulae());
@@ -239,6 +256,7 @@ public class Operations {
}
+
if (nexts.isEmpty()) {
Map emptyBinding = CollectionUtils.newMap();
@@ -262,6 +280,10 @@ public class Operations {
}
+ nexts = nexts.stream().filter(n-> !n.first().getFormulae().equals(state.getFormulae())).collect(Collectors.toSet());;
+
+
+
applyCache.put(Triple.of(background, action ,state), Optional.of(nexts));
return Optional.of(nexts);
diff --git a/src/main/java/edu/rpi/rair/Plan.java b/src/main/java/edu/rpi/rair/Plan.java
index dca0e9d..dd684ff 100644
--- a/src/main/java/edu/rpi/rair/Plan.java
+++ b/src/main/java/edu/rpi/rair/Plan.java
@@ -2,6 +2,7 @@ package edu.rpi.rair;
import com.naveensundarg.shadow.prover.representations.formula.Formula;
import com.naveensundarg.shadow.prover.utils.CollectionUtils;
+import edu.rpi.rair.utils.Visualizer;
import java.util.List;
import java.util.Set;
@@ -63,15 +64,32 @@ public class Plan {
public boolean noConflicts(Set goals){
- return getConflictingGoals(goals).isEmpty();
+ Set conflicts = getConflictingGoals(goals);
+ if(!conflicts.isEmpty()){
+
+ Visualizer.print(this.toString()) ;
+ Visualizer.printRed(" CONFLICTS WITH ");
+ Visualizer.print(conflicts.stream().map(x-> x.getDescription()).collect(Collectors.toSet()).toString());
+ System.out.println();
+
+ }
+
+ return conflicts.isEmpty();
+
+ }
+
+ public static Plan cleanUp(Plan plan){
+
+ List actions = plan.getActions();
+ List states = plan.getExpectedStates();
+
+ return null;
}
@Override
public String toString() {
- return "Plan{" +
- "actions=" + actions +
- '}';
+ return actions.stream().map(x-> x.toString() + " ").reduce((x,y) -> x + y).get();
}
@Override
diff --git a/src/main/java/edu/rpi/rair/PlanMethod.java b/src/main/java/edu/rpi/rair/PlanMethod.java
new file mode 100644
index 0000000..a045040
--- /dev/null
+++ b/src/main/java/edu/rpi/rair/PlanMethod.java
@@ -0,0 +1,123 @@
+package edu.rpi.rair;
+
+import com.naveensundarg.shadow.prover.representations.formula.And;
+import com.naveensundarg.shadow.prover.representations.formula.Formula;
+import com.naveensundarg.shadow.prover.representations.value.Compound;
+import com.naveensundarg.shadow.prover.representations.value.Value;
+import com.naveensundarg.shadow.prover.representations.value.Variable;
+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.utils.PlanningProblem;
+ import us.bpsm.edn.Keyword;
+import us.bpsm.edn.Symbol;
+import us.bpsm.edn.parser.Parseable;
+import us.bpsm.edn.parser.Parser;
+import us.bpsm.edn.parser.Parsers;
+
+import java.io.StringReader;
+import java.util.*;
+import java.util.stream.Collector;
+import java.util.stream.Collectors;
+
+/**
+ * Created by naveensundarg on 12/22/17.
+ */
+public class PlanMethod {
+
+ private final Set backGroundStatePreconditions;
+ private final Set goalPreconditions;
+ private final List freeVariables;
+ private final List actionCompounds;
+
+
+
+ public PlanMethod(Set goalPreconditions, Set backGroundStatePreconditions, List freeVariables, List actionCompounds) {
+ this.goalPreconditions = goalPreconditions;
+ this.backGroundStatePreconditions = backGroundStatePreconditions;
+ this.freeVariables = freeVariables;
+ this.actionCompounds = actionCompounds;
+
+ }
+
+
+ public PlanMethod(Set goalPreconditions, List freeVariables, List actionCompounds) {
+ this.goalPreconditions = goalPreconditions;
+ this.backGroundStatePreconditions = Sets.newSet();
+ this.freeVariables = freeVariables;
+ this.actionCompounds = actionCompounds;
+
+ }
+
+
+ public Optional> apply(Set background, Set start, Set goal, Set actionSpecs) {
+
+
+ Optional>> mappingsOpt = Operations.proveAndGetMultipleBindings(goal, new And(new ArrayList<>(goalPreconditions)), freeVariables);
+
+ if (mappingsOpt.isPresent()) {
+
+ Set