diff --git a/src/main/java/edu/rpi/rair/Action.java b/src/main/java/edu/rpi/rair/Action.java index 8cc567a..2807158 100644 --- a/src/main/java/edu/rpi/rair/Action.java +++ b/src/main/java/edu/rpi/rair/Action.java @@ -6,6 +6,7 @@ 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 java.util.List; @@ -27,6 +28,7 @@ public class Action { private final Formula precondition; private int weight; + private final boolean trivial; private final Compound shorthand; @@ -52,6 +54,8 @@ public class Action { List valuesList = freeVariables.stream().collect(Collectors.toList());; this.shorthand = new Compound(name, valuesList); + + this.trivial = computeTrivialOrNot(); } private Action(String name, Set preconditions, Set additions, @@ -78,6 +82,8 @@ public class Action { deletions.stream().mapToInt(Formula::getWeight).sum(); this.shorthand = shorthand; + this.trivial = computeTrivialOrNot(); + } @@ -139,12 +145,19 @@ public class Action { return name; } + public boolean isNonTrivial() { + return !trivial; + } - public boolean isNonTrivial(){ + public boolean computeTrivialOrNot(){ boolean case1Trivial = Sets.subset(additions, preconditions) && deletions.isEmpty(); - return !case1Trivial; + boolean case2Trivial = additions.isEmpty() && deletions.stream().allMatch(x->preconditions.stream().anyMatch(y->y.equals(Logic.negated(x)))); + + boolean trivial = case1Trivial || case2Trivial; + + return trivial; } @Override public String toString() { diff --git a/src/main/java/edu/rpi/rair/DepthFirstPlanner.java b/src/main/java/edu/rpi/rair/DepthFirstPlanner.java index 81d39ec..605345e 100644 --- a/src/main/java/edu/rpi/rair/DepthFirstPlanner.java +++ b/src/main/java/edu/rpi/rair/DepthFirstPlanner.java @@ -1,11 +1,9 @@ package edu.rpi.rair; 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 javax.swing.text.html.Option; import java.util.*; import java.util.stream.Collectors; diff --git a/src/main/java/edu/rpi/rair/utils/RunDemo.java b/src/main/java/edu/rpi/rair/utils/RunDemo.java index 6aca9a0..a819d08 100644 --- a/src/main/java/edu/rpi/rair/utils/RunDemo.java +++ b/src/main/java/edu/rpi/rair/utils/RunDemo.java @@ -32,13 +32,13 @@ public class RunDemo { List problems = ProblemReader.readFrom(Sandbox.class.getResourceAsStream("firstorder-completness-tests.clj")); problems.forEach(problem -> { - for (int i = 0; i < 5; i++) { + for (int i = 0; i < 10; i++) { prover.prove(problem.getAssumptions(), problem.getGoal()); } }); - planningProblemWarmUp(); + planningProblemWarmUp(); System.out.println("\nWARM UP DONE"); } catch (Reader.ParsingException e) { e.printStackTrace(); @@ -88,7 +88,7 @@ public class RunDemo { cp.clear(); cp.print(" "); cp.setAttribute(Ansi.Attribute.BOLD); - cp.print((end - start) / 1000 + "s"); + cp.print((end - start) / 1000.0 + "s"); @@ -97,9 +97,8 @@ public class RunDemo { public static void planningProblemWarmUp() throws Reader.ParsingException { - for (int i = 0; i < 5; i++) { + for (int i = 0; i < 10; i++) { - System.out.println(); List goalTrackingProblemList = (GoalTrackingProblem.readFromFile(Planner.class.getResourceAsStream("goal_management_1.clj"))); @@ -121,20 +120,14 @@ public class RunDemo { goalTracker.adoptGoal(g1); - System.out.print("."); - goalTracker.adoptGoal(g2); - System.out.print("."); - goalTracker.adoptGoal(g3); - System.out.print("."); goalTracker.adoptGoal(g4); - System.out.print("."); goalTracker.adoptGoal(g5);