mirror of
https://github.com/RAIRLab/Spectra.git
synced 2026-01-05 00:30:33 +00:00
changes
This commit is contained in:
parent
fc1cbfb5ab
commit
96688ccf2e
16 changed files with 290 additions and 34 deletions
|
|
@ -23,6 +23,7 @@ public class Action {
|
|||
private final Set<Formula> additions;
|
||||
private final Set<Formula> deletions;
|
||||
private final List<Variable> freeVariables;
|
||||
private final List<Variable> interestedVars;
|
||||
|
||||
private final String name;
|
||||
private final Formula precondition;
|
||||
|
|
@ -32,7 +33,7 @@ public class Action {
|
|||
|
||||
private final Compound shorthand;
|
||||
|
||||
public Action(String name, Set<Formula> preconditions, Set<Formula> additions, Set<Formula> deletions, List<Variable> freeVariables) {
|
||||
public Action(String name, Set<Formula> preconditions, Set<Formula> additions, Set<Formula> deletions, List<Variable> freeVariables, List<Variable> interestedVars) {
|
||||
this.name = name;
|
||||
this.preconditions = preconditions;
|
||||
|
||||
|
|
@ -52,10 +53,11 @@ public class Action {
|
|||
additions.stream().mapToInt(Formula::getWeight).sum() +
|
||||
deletions.stream().mapToInt(Formula::getWeight).sum();
|
||||
|
||||
List<Value> valuesList = freeVariables.stream().collect(Collectors.toList());;
|
||||
List<Value> valuesList = interestedVars.stream().collect(Collectors.toList());;
|
||||
this.shorthand = new Compound(name, valuesList);
|
||||
|
||||
this.trivial = computeTrivialOrNot();
|
||||
this.interestedVars = interestedVars;
|
||||
}
|
||||
|
||||
public Action(String name, Set<Formula> preconditions, Set<Formula> additions,
|
||||
|
|
@ -83,6 +85,7 @@ public class Action {
|
|||
|
||||
this.shorthand = shorthand;
|
||||
this.trivial = computeTrivialOrNot();
|
||||
this.interestedVars = freeVariables;
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -93,7 +96,17 @@ public class Action {
|
|||
Set<Formula> deletions,
|
||||
List<Variable> freeVariables) {
|
||||
|
||||
return new Action(name, preconditions, additions, deletions, freeVariables);
|
||||
return new Action(name, preconditions, additions, deletions, freeVariables, freeVariables);
|
||||
|
||||
}
|
||||
|
||||
public static Action buildActionFrom(String name,
|
||||
Set<Formula> preconditions,
|
||||
Set<Formula> additions,
|
||||
Set<Formula> deletions,
|
||||
List<Variable> freeVariables, List<Variable> interestedVars) {
|
||||
|
||||
return new Action(name, preconditions, additions, deletions, freeVariables, interestedVars);
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -148,7 +161,7 @@ public class Action {
|
|||
}
|
||||
}
|
||||
|
||||
List<Value> valuesList = freeVariables.stream().collect(Collectors.toList());;
|
||||
List<Value> valuesList = interestedVars.stream().collect(Collectors.toList());;
|
||||
Compound shorthand = (Compound)(new Compound(name, valuesList)).apply(binding);
|
||||
return new Action(name, newPreconditions, newAdditions, newDeletions, newFreeVraibles, shorthand);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ public class DepthFirstPlanner implements Planner {
|
|||
|
||||
|
||||
private static int MAX_DEPTH = 5;
|
||||
private static boolean EXHAUSTIVE_TILL_MAX_DEPTH = true;
|
||||
private static boolean EXHAUSTIVE_TILL_MAX_DEPTH = false;
|
||||
|
||||
private boolean USE_METHODS, WORK_FROM_SCRATCH;
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,6 @@ import java.util.Set;
|
|||
public class IndefiniteAction extends Action {
|
||||
|
||||
private IndefiniteAction(String name, Set<Formula> preconditions, Set<Formula> additions, Set<Formula> deletions, List<Variable> freeVariables) {
|
||||
super(name, preconditions, additions, deletions, freeVariables);
|
||||
super(name, preconditions, additions, deletions, freeVariables, freeVariables);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -312,7 +312,10 @@ public class PlanningProblem {
|
|||
Set<Formula> additions = readFrom((List<?>) actionSpec.get(ADDITIONS));
|
||||
Set<Formula> deletions = readFrom((List<?>) actionSpec.get(DELETIONS));
|
||||
|
||||
return Action.buildActionFrom(name, preconditions, additions, deletions, vars);
|
||||
List<Variable> interestedVars = CollectionUtils.newEmptyList();
|
||||
interestedVars.addAll(vars);
|
||||
vars.addAll(preconditions.stream().map(Formula::variablesPresent).reduce(Sets.newSet(), Sets::union));
|
||||
return Action.buildActionFrom(name, preconditions, additions, deletions, vars, interestedVars);
|
||||
|
||||
|
||||
} catch (Reader.ParsingException e) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
package com.naveensundarg.planner.utils;
|
||||
|
||||
import com.naveensundarg.planner.DepthFirstPlanner;
|
||||
import com.naveensundarg.planner.PlanMethod;
|
||||
import com.naveensundarg.planner.Planner;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -9,9 +11,9 @@ import java.util.List;
|
|||
*/
|
||||
public class Sandbox {
|
||||
|
||||
public static void main(String[] args) throws com.naveensundarg.shadow.prover.utils.Reader.ParsingException {
|
||||
public static void demoPlanMethods(String[] args) throws com.naveensundarg.shadow.prover.utils.Reader.ParsingException {
|
||||
|
||||
PlanMethod seriatedPlanMethod = (Reader.readPlanMethodsFrom(Sandbox.class.getResourceAsStream("../problems/seriated/methods.clj"))).get(0);
|
||||
PlanMethod seriatedPlanMethod = (Reader.readPlanMethodsFrom(Sandbox.class.getResourceAsStream("../problems/learning/dry.clj"))).get(0);
|
||||
|
||||
|
||||
List<GoalTrackingProblem> goalTrackingProblemList1 = (GoalTrackingProblem.readFromFile(Sandbox.class.getResourceAsStream("../problems/seriated/seriated_challenge_1.clj")));
|
||||
|
|
@ -36,5 +38,22 @@ public class Sandbox {
|
|||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws com.naveensundarg.shadow.prover.utils.Reader.ParsingException {
|
||||
|
||||
List<PlanningProblem> planningProblemList = (PlanningProblem.readFromFile(Sandbox.class.getResourceAsStream("../problems/learning/reasoning_5.clj")));
|
||||
|
||||
Planner depthFirstPlanner = new DepthFirstPlanner();
|
||||
|
||||
PlanningProblem planningProblem = planningProblemList.stream().filter(problem -> problem.getName().equals("learning")).findFirst().get();
|
||||
|
||||
|
||||
depthFirstPlanner.plan(planningProblem.getBackground(), planningProblem.getActions(), planningProblem.getStart(), planningProblem.getGoal()).ifPresent(
|
||||
System.out::println
|
||||
);
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue