Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package edu.kit.aquaplanning.planners.heuristic;
- import java.util.List;
- import java.util.ArrayList;
- import edu.kit.aquaplanning.model.ground.Action;
- import edu.kit.aquaplanning.model.ground.AtomSet;
- import edu.kit.aquaplanning.model.ground.Atom;
- import edu.kit.aquaplanning.model.ground.Plan;
- import edu.kit.aquaplanning.model.ground.Goal;
- import edu.kit.aquaplanning.model.ground.State;
- import edu.kit.aquaplanning.model.ground.GroundPlanningProblem;
- import edu.kit.aquaplanning.planners.GroundRelaxedPlanningGraph;
- import edu.kit.aquaplanning.model.lifted.PlanningProblem;
- import edu.kit.aquaplanning.planners.SearchNode;
- /**
- * Rename this class: [Lastname]sHeuristic .
- */
- public class FroleyksHeuristic extends Heuristic {
- // All information your heuristic should need
- // (together with the search node)
- private GroundPlanningProblem groundProblem;
- private PlanningProblem liftedProblem;
- // Define more members, if needed ...
- /**
- * Constructor (please do not change the signature except for the class name)
- */
- public FroleyksHeuristic(GroundPlanningProblem groundProblem, PlanningProblem liftedProblem) {
- this.groundProblem = groundProblem;
- this.liftedProblem = liftedProblem;
- List<Action> ac = groundProblem.getActions();
- System.out.println(ac.get(0));
- }
- /**
- * Implement this method.
- */
- @Override
- public int value(SearchNode node) {
- State state = node.state;
- // Is the goal already satisfied (in a relaxed definition)?
- if (groundProblem.getGoal().isSatisfiedRelaxed(state)) {
- return 0;
- }
- // Traverse deletion-relaxed planning graph
- List<State> states = new ArrayList<>();
- states.add(state);
- GroundRelaxedPlanningGraph graph = new GroundRelaxedPlanningGraph(state, groundProblem.getActions());
- while (graph.hasNextLayer()) {
- State nextState = graph.computeNextLayer();
- states.add(nextState);
- State g_hat = new State(groundProblem.getGoal().getAtoms());
- List<Action> allActions = groundProblem.getActions();
- Plan p = new Plan();
- // Goal reached?
- // if (g_hat.isSatisfiedRelaxed(nextState)) {
- if (nextState.holdsAllTrueAtomsFrom(g_hat)) {
- for (int stateIndex = states.size() - 2; stateIndex > -1; --stateIndex) {
- State s_hat = states.get(stateIndex);
- List<Action> A = new ArrayList<>();
- // Choose set of actions − with a sledgehammer
- for (Action action : allActions) {
- if (s_hat.holdsAllTrueAtomsFrom(g_hat)) {
- break;
- }
- if (action.isApplicableRelaxed(s_hat)) {
- A.add(action);
- action.applyRelaxed(s_hat);
- }
- }
- for (Action action : A) {
- p.appendAtFront(action);
- g_hat.removeAll(action.getEffectsPos());
- }
- for (Action action : A) {
- g_hat.removeAll(action.getPreconditionsPos());
- }
- }
- return p.getLength();
- }
- }
- // Goals could not be reached: unsolvable from this state
- return Integer.MAX_VALUE;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement