mirror of
https://github.com/RAIRLab/Spectra.git
synced 2024-11-21 08:26:30 -05:00
More tweaks.
This commit is contained in:
parent
c9201bc0b2
commit
afde7793e5
7 changed files with 69 additions and 33 deletions
|
@ -36,7 +36,7 @@ public class DepthFirstPlanner implements Planner {
|
|||
|
||||
if (Operations.satisfies(background, start, goal)) {
|
||||
//Already satisfied. Do nothing. Return a set with an empty plan.
|
||||
return Optional.of(Sets.with(Plan.newEmptyPlan(goal, background)));
|
||||
return Optional.of(Sets.with(Plan.newEmptyPlan(start, background)));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -3,7 +3,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 java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
@ -50,16 +52,19 @@ public class GoalTracker {
|
|||
|
||||
Set<Plan> plans = possiblePlans.get();
|
||||
|
||||
Optional<Plan> noConflictPlan = plans.stream().filter(plan -> plan.noConflicts(currentGoals)).findAny();
|
||||
Optional<Plan> possibleNoConflictPlan = plans.stream().filter(plan -> plan.noConflicts(currentGoals)).
|
||||
sorted(Comparator.comparing(plan->plan.getActions().size())).findAny();
|
||||
|
||||
|
||||
if (noConflictPlan.isPresent()) {
|
||||
if (possibleNoConflictPlan.isPresent()) {
|
||||
|
||||
/*
|
||||
* If there is any plan without any goal conflicts, then adopt the goal.
|
||||
*/
|
||||
Plan noConflictPlan = possibleNoConflictPlan.get();
|
||||
currentGoals.add(goal);
|
||||
return noConflictPlan;
|
||||
currentState = noConflictPlan.getExpectedStates().get(noConflictPlan.getExpectedStates().size()-1);
|
||||
return possibleNoConflictPlan;
|
||||
|
||||
} else {
|
||||
|
||||
|
@ -72,30 +77,35 @@ public class GoalTracker {
|
|||
*/
|
||||
|
||||
boolean feasiblePlanExists = false;
|
||||
int bestPlanSize = Integer.MAX_VALUE;
|
||||
double bestPriorityGap = 0;
|
||||
Set<Goal> bestRemovalCandidates = null;
|
||||
Plan feasiblePlan = null;
|
||||
Set<Plan> feasiblePlans = Sets.newSet();
|
||||
for (Plan plan : plans) {
|
||||
|
||||
Set<Goal> conflictingGoals = plan.getConflictingGoals(currentGoals);
|
||||
double conflictSum = conflictingGoals.stream().mapToDouble(Goal::getPriority).sum();
|
||||
double gap = goal.getPriority() - conflictSum;
|
||||
|
||||
if(gap > 0 && gap > bestPriorityGap ){
|
||||
if(gap > 0 && gap >= bestPriorityGap && plan.getActions().size() <= bestPlanSize){
|
||||
|
||||
feasiblePlanExists = true;
|
||||
bestPriorityGap = gap;
|
||||
feasiblePlan = plan;
|
||||
bestPlanSize = plan.getActions().size();
|
||||
feasiblePlans.add(plan);
|
||||
bestRemovalCandidates= conflictingGoals;
|
||||
}
|
||||
}
|
||||
|
||||
if(feasiblePlan!=null){
|
||||
if(!feasiblePlans.isEmpty()){
|
||||
|
||||
Plan bestPlan = feasiblePlans.stream().
|
||||
min(Comparator.comparing(plan->plan.getActions().stream().mapToInt(Action::getWeight).sum())).get();
|
||||
currentGoals.removeAll(bestRemovalCandidates);
|
||||
currentGoals.add(goal);
|
||||
currentState = bestPlan.getExpectedStates().get(bestPlan.getExpectedStates().size()-1);
|
||||
|
||||
return Optional.of(feasiblePlan);
|
||||
return Optional.of(bestPlan);
|
||||
}
|
||||
else {
|
||||
|
||||
|
|
|
@ -31,6 +31,10 @@ public class Plan {
|
|||
return actions;
|
||||
}
|
||||
|
||||
public List<State> getExpectedStates() {
|
||||
return expectedStates;
|
||||
}
|
||||
|
||||
public Plan getPlanByStartingWith(Action action, State state){
|
||||
List<Action> newActions = CollectionUtils.newEmptyList();
|
||||
newActions.addAll(actions);
|
||||
|
|
|
@ -60,26 +60,21 @@
|
|||
]
|
||||
}
|
||||
|
||||
:goals {G1 {:priority 1.0
|
||||
:goals {G1 {:priority 6.0
|
||||
:state [(not (open (door room1)))]}
|
||||
|
||||
G2 {:priority 1.0
|
||||
G2 {:priority 6.0
|
||||
:state [(in prisoner room1)]}
|
||||
|
||||
G3 {:priority 1.0
|
||||
G3 {:priority 6.0
|
||||
:state [(forall [?room]
|
||||
(if (in prisoner ?room)
|
||||
(in self ?room)))]}
|
||||
|
||||
G4 {:priority 2.0
|
||||
|
||||
:state [(interrogates commander prisoner)]}
|
||||
|
||||
G5 {:priority 1.0
|
||||
G4 {:priority 3.0
|
||||
:state [(in prisoner room2)
|
||||
(in self room2)]}
|
||||
(in self room2)]}
|
||||
G5 {:priority 2.0
|
||||
|
||||
|
||||
}
|
||||
:state [(interrogates commander prisoner)]}}
|
||||
|
||||
}
|
16
src/main/resources/edu/rpi/rair/temp.clj
Normal file
16
src/main/resources/edu/rpi/rair/temp.clj
Normal file
|
@ -0,0 +1,16 @@
|
|||
{G1 {:priority 6.0
|
||||
:state [(not (open (door room1)))]}
|
||||
|
||||
G2 {:priority 6.0
|
||||
:state [(in prisoner room1)]}
|
||||
|
||||
G3 {:priority 6.0
|
||||
:state [(forall [?room]
|
||||
(if (in prisoner ?room)
|
||||
(in self ?room)))]}
|
||||
G4 {:priority 3.0
|
||||
:state [(in prisoner room2)
|
||||
(in self room2)]}
|
||||
G5 {:priority 2.0
|
||||
|
||||
:state [(interrogates commander prisoner)]}}
|
|
@ -60,26 +60,21 @@
|
|||
]
|
||||
}
|
||||
|
||||
:goals {G1 {:priority 1.0
|
||||
:goals {G1 {:priority 6.0
|
||||
:state [(not (open (door room1)))]}
|
||||
|
||||
G2 {:priority 1.0
|
||||
G2 {:priority 6.0
|
||||
:state [(in prisoner room1)]}
|
||||
|
||||
G3 {:priority 1.0
|
||||
G3 {:priority 6.0
|
||||
:state [(forall [?room]
|
||||
(if (in prisoner ?room)
|
||||
(in self ?room)))]}
|
||||
|
||||
G4 {:priority 2.0
|
||||
|
||||
:state [(interrogates commander prisoner)]}
|
||||
|
||||
G5 {:priority 1.0
|
||||
G4 {:priority 3.0
|
||||
:state [(in prisoner room2)
|
||||
(in self room2)]}
|
||||
(in self room2)]}
|
||||
G5 {:priority 2.0
|
||||
|
||||
|
||||
}
|
||||
:state [(interrogates commander prisoner)]}}
|
||||
|
||||
}
|
16
target/classes/edu/rpi/rair/temp.clj
Normal file
16
target/classes/edu/rpi/rair/temp.clj
Normal file
|
@ -0,0 +1,16 @@
|
|||
{G1 {:priority 6.0
|
||||
:state [(not (open (door room1)))]}
|
||||
|
||||
G2 {:priority 6.0
|
||||
:state [(in prisoner room1)]}
|
||||
|
||||
G3 {:priority 6.0
|
||||
:state [(forall [?room]
|
||||
(if (in prisoner ?room)
|
||||
(in self ?room)))]}
|
||||
G4 {:priority 3.0
|
||||
:state [(in prisoner room2)
|
||||
(in self room2)]}
|
||||
G5 {:priority 2.0
|
||||
|
||||
:state [(interrogates commander prisoner)]}}
|
Loading…
Reference in a new issue