mirror of
https://github.com/RAIRLab/Spectra.git
synced 2025-10-26 22:51:19 +00:00
Solving a seriated cup challenge.
This commit is contained in:
parent
cdb9c455c8
commit
381bbc60af
10 changed files with 305 additions and 97 deletions
|
|
@ -13,7 +13,7 @@ import java.util.stream.Collectors;
|
|||
public class DepthFirstPlanner implements Planner {
|
||||
|
||||
|
||||
private static int MAX_DEPTH = 5;
|
||||
private static int MAX_DEPTH = 4;
|
||||
private static boolean EXHAUSTIVE_TILL_MAX_DEPTH = false;
|
||||
|
||||
public static int getMaxDepth() {
|
||||
|
|
|
|||
|
|
@ -3,8 +3,10 @@ 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;
|
||||
import com.naveensundarg.shadow.prover.representations.value.Value;
|
||||
import com.naveensundarg.shadow.prover.representations.value.Variable;
|
||||
import com.naveensundarg.shadow.prover.utils.CollectionUtils;
|
||||
|
|
@ -58,7 +60,7 @@ public class Operations {
|
|||
|
||||
}
|
||||
|
||||
Optional<Map.Entry<Pair<Set<Formula>, Formula>, Optional<Justification>>> cachedOptional = proverCache.entrySet().stream().filter(pairOptionalEntry -> {
|
||||
Optional<Map.Entry<Pair<Set<Formula>, Formula>, Optional<Justification>>> cachedOptionalSuccessful = proverCache.entrySet().stream().filter(pairOptionalEntry -> {
|
||||
|
||||
Set<Formula> cachedAssumptions = pairOptionalEntry.getKey().first();
|
||||
Formula cachedGoal = pairOptionalEntry.getKey().second();
|
||||
|
|
@ -67,9 +69,53 @@ public class Operations {
|
|||
}).findAny();
|
||||
|
||||
|
||||
if(cachedOptional.isPresent() && cachedOptional.get().getValue().isPresent()){
|
||||
if(cachedOptionalSuccessful.isPresent() && cachedOptionalSuccessful.get().getValue().isPresent()){
|
||||
|
||||
return cachedOptionalSuccessful.get().getValue();
|
||||
}
|
||||
|
||||
|
||||
Optional<Map.Entry<Pair<Set<Formula>, Formula>, Optional<Justification>>> cachedOptionalFailed = proverCache.entrySet().stream().filter(pairOptionalEntry -> {
|
||||
|
||||
Set<Formula> cachedAssumptions = pairOptionalEntry.getKey().first();
|
||||
Formula cachedGoal = pairOptionalEntry.getKey().second();
|
||||
|
||||
return cachedGoal.equals(goal) && Sets.subset(assumptions, cachedAssumptions);
|
||||
}).findAny();
|
||||
|
||||
|
||||
if(cachedOptionalFailed.isPresent() && !cachedOptionalFailed.get().getValue().isPresent()){
|
||||
|
||||
return cachedOptionalFailed.get().getValue();
|
||||
}
|
||||
|
||||
if(goal instanceof Predicate && ((Predicate) goal).getName().equals("sameroom")){
|
||||
|
||||
Predicate p = (Predicate) goal;
|
||||
|
||||
Value v1 = p.getArguments()[0];
|
||||
Value v2 = p.getArguments()[1];
|
||||
|
||||
Optional<Formula> inOptv1 = assumptions.stream().filter(x-> x instanceof Predicate &&
|
||||
((Predicate)x).getName().equals("in") && ((Predicate) x).getArguments()[0].equals(v1)).findAny();
|
||||
|
||||
Optional<Formula> inOptv2 = assumptions.stream().filter(x-> x instanceof Predicate &&
|
||||
((Predicate)x).getName().equals("in") && ((Predicate) x).getArguments()[0].equals(v2)).findAny();
|
||||
|
||||
|
||||
if(inOptv1.isPresent() && inOptv2.isPresent()){
|
||||
|
||||
Value room1 = ((Predicate)inOptv1.get()).getArguments()[1];
|
||||
Value room2 = ((Predicate)inOptv2.get()).getArguments()[1];
|
||||
|
||||
if(room1.equals(room2)){
|
||||
|
||||
return Optional.of(Justification.trivial(goal));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return cachedOptional.get().getValue();
|
||||
}
|
||||
|
||||
{
|
||||
|
|
@ -178,7 +224,7 @@ public class Operations {
|
|||
Set<Formula> formulaeToRemove = state.getFormulae().stream().
|
||||
filter(f -> instantiatedDeletions.stream().anyMatch(d -> equivalent(background, f, d))).collect(Collectors.toSet());
|
||||
|
||||
Set<Formula> newFormulae = state.getFormulae();
|
||||
Set<Formula> newFormulae = Sets.union(background, state.getFormulae());
|
||||
|
||||
newFormulae = Sets.union(newFormulae, action.instantiateAdditions(binding));
|
||||
|
||||
|
|
|
|||
14
src/main/java/edu/rpi/rair/utils/ProceduralAttachment.java
Normal file
14
src/main/java/edu/rpi/rair/utils/ProceduralAttachment.java
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
package edu.rpi.rair.utils;
|
||||
|
||||
import com.naveensundarg.shadow.prover.representations.formula.Formula;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Created by naveensundarg on 1/26/17.
|
||||
*/
|
||||
public interface ProceduralAttachment {
|
||||
|
||||
Optional<Boolean> satisfies(Set<Formula> base, Formula goal);
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
package edu.rpi.rair.utils;
|
||||
import com.diogonunes.jcdp.color.ColoredPrinter;
|
||||
import com.diogonunes.jcdp.color.api.Ansi;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.naveensundarg.shadow.prover.Sandbox;
|
||||
import com.naveensundarg.shadow.prover.core.Problem;
|
||||
import com.naveensundarg.shadow.prover.core.Prover;
|
||||
|
|
@ -15,6 +16,7 @@ import edu.rpi.rair.utils.GoalTrackingProblem;
|
|||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
|
|
@ -32,13 +34,13 @@ public class RunDemo {
|
|||
List<Problem> problems = ProblemReader.readFrom(Sandbox.class.getResourceAsStream("firstorder-completness-tests.clj"));
|
||||
|
||||
problems.forEach(problem -> {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
for (int i = 0; i < 30; i++) {
|
||||
prover.prove(problem.getAssumptions(), problem.getGoal());
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
// planningProblemWarmUp();
|
||||
planningProblemWarmUp();
|
||||
System.out.println("\nWARM UP DONE");
|
||||
} catch (Reader.ParsingException e) {
|
||||
e.printStackTrace();
|
||||
|
|
@ -53,7 +55,7 @@ public class RunDemo {
|
|||
|
||||
System.out.println();
|
||||
|
||||
List<GoalTrackingProblem> goalTrackingProblemList = (GoalTrackingProblem.readFromFile(Planner.class.getResourceAsStream("goal_management_6.clj")));
|
||||
List<GoalTrackingProblem> goalTrackingProblemList = (GoalTrackingProblem.readFromFile(Planner.class.getResourceAsStream("seriated_challenge_1.clj")));
|
||||
|
||||
|
||||
GoalTrackingProblem goalTrackingProblem = goalTrackingProblemList.get(0);
|
||||
|
|
@ -65,21 +67,30 @@ public class RunDemo {
|
|||
long start = System.currentTimeMillis();
|
||||
|
||||
Goal g1 = goalTrackingProblem.getGoalNamed("G1");
|
||||
|
||||
/*
|
||||
Goal g2 = goalTrackingProblem.getGoalNamed("G2");
|
||||
|
||||
|
||||
Goal g3 = goalTrackingProblem.getGoalNamed("G3");
|
||||
Goal g4 = goalTrackingProblem.getGoalNamed("G4");
|
||||
Goal g5 = goalTrackingProblem.getGoalNamed("G5");
|
||||
|
||||
*/
|
||||
|
||||
tryAndAddGoal(g1, goalTracker);
|
||||
|
||||
/* tryAndAddGoal(g2, goalTracker);
|
||||
|
||||
|
||||
tryAndAddGoal(g2, goalTracker);
|
||||
// tryAndAddGoal(g2b, goalTracker);
|
||||
|
||||
tryAndAddGoal(g3, goalTracker);
|
||||
|
||||
tryAndAddGoal(g4, goalTracker);
|
||||
|
||||
tryAndAddGoal(g5, goalTracker);
|
||||
*/
|
||||
|
||||
long end = System.currentTimeMillis();
|
||||
|
||||
|
|
@ -99,7 +110,7 @@ public class RunDemo {
|
|||
public static void planningProblemWarmUp() throws Reader.ParsingException {
|
||||
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
for (int i = 0; i < 0; i++) {
|
||||
|
||||
|
||||
List<GoalTrackingProblem> goalTrackingProblemList = (GoalTrackingProblem.readFromFile(Planner.class.getResourceAsStream("goal_management_1.clj")));
|
||||
|
|
@ -146,11 +157,19 @@ public class RunDemo {
|
|||
System.out.println("========================");
|
||||
printInfo("Trying to Add Goal:", g.getName());
|
||||
|
||||
Set<String> oldGoals = goalTracker.getCurrentGoals().stream().map(Goal::getName).collect(Collectors.toSet());
|
||||
Optional<Plan> possibleGoalPlan = goalTracker.adoptGoal(g);
|
||||
if (possibleGoalPlan.isPresent()) {
|
||||
|
||||
printSuccess("Successfully added:", g.getName());
|
||||
printDebug1("Current Goals:", goalTracker.getCurrentGoals().stream().map(Goal::getName).collect(Collectors.toSet()).toString());
|
||||
|
||||
Set<String> newGoals = goalTracker.getCurrentGoals().stream().map(Goal::getName).collect(Collectors.toSet());
|
||||
|
||||
if(!Sets.difference(oldGoals, newGoals).isEmpty()){
|
||||
printDropped("Dropped Goals:" + Sets.difference(oldGoals, newGoals));
|
||||
|
||||
}
|
||||
Plan plan = possibleGoalPlan.get();
|
||||
printDebug2("Plan:", plan.getActions().isEmpty() ? "No plan needed. Already satisfied." : plan.getActions().toString());
|
||||
|
||||
|
|
@ -225,4 +244,17 @@ public class RunDemo {
|
|||
cp.println("");
|
||||
cp.clear();
|
||||
}
|
||||
|
||||
static void printDropped(String message) {
|
||||
|
||||
cp.setForegroundColor(Ansi.FColor.WHITE);
|
||||
cp.setBackgroundColor(Ansi.BColor.RED); //setting format
|
||||
cp.print("Dropped Goals:");
|
||||
cp.clear();
|
||||
cp.print(" ");
|
||||
cp.setAttribute(Ansi.Attribute.BOLD);
|
||||
cp.print(message);
|
||||
cp.println("");
|
||||
cp.clear();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue