burlap.behavior.singleagent.planning.deterministic.informed.astar.AStar Java Examples
The following examples show how to use
burlap.behavior.singleagent.planning.deterministic.informed.astar.AStar.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestPlanning.java From burlap with Apache License 2.0 | 5 votes |
@Test public void testAStar() { GridWorldState initialState = new GridWorldState(new GridAgent(0, 0), new GridLocation(10, 10, 0, "loc0")); Heuristic mdistHeuristic = new Heuristic() { @Override public double h(State s) { GridAgent agent = ((GridWorldState)s).agent; GridLocation location = ((GridWorldState)s).locations.get(0); //get agent position int ax = agent.x; int ay = agent.y; //get location position int lx = location.x; int ly = location.y; //compute Manhattan distance double mdist = Math.abs(ax-lx) + Math.abs(ay-ly); return -mdist; } }; //provide A* the heuristic as well as the reward function so that it can keep //track of the actual cost DeterministicPlanner planner = new AStar(domain, goalCondition, hashingFactory, mdistHeuristic); planner.planFromState(initialState); Policy p = new SDPlannerPolicy(planner); Episode analysis = PolicyUtils.rollout(p, initialState, domain.getModel()); this.evaluateEpisode(analysis, true); }
Example #2
Source File: BasicBehavior.java From burlap_examples with MIT License | 4 votes |
public void AStarExample(String outputPath){ Heuristic mdistHeuristic = new Heuristic() { public double h(State s) { GridAgent a = ((GridWorldState)s).agent; double mdist = Math.abs(a.x-10) + Math.abs(a.y-10); return -mdist; } }; DeterministicPlanner planner = new AStar(domain, goalCondition, hashingFactory, mdistHeuristic); Policy p = planner.planFromState(initialState); PolicyUtils.rollout(p, initialState, domain.getModel()).write(outputPath + "astar"); }
Example #3
Source File: TestBlockDude.java From burlap with Apache License 2.0 | 4 votes |
public void testDude(State s) { TerminalFunction tf = new BlockDudeTF(); StateConditionTest sc = new TFGoalCondition(tf); AStar astar = new AStar(domain, sc, new SimpleHashableStateFactory(), new NullHeuristic()); astar.toggleDebugPrinting(false); astar.planFromState(s); Policy p = new SDPlannerPolicy(astar); Episode ea = PolicyUtils.rollout(p, s, domain.getModel(), 100); State lastState = ea.stateSequence.get(ea.stateSequence.size() - 1); Assert.assertEquals(true, tf.isTerminal(lastState)); Assert.assertEquals(true, sc.satisfies(lastState)); Assert.assertEquals(-94.0, ea.discountedReturn(1.0), 0.001); /* BlockDude constructor = new BlockDude(); Domain d = constructor.generateDomain(); List<Integer> px = new ArrayList<Integer>(); List <Integer> ph = new ArrayList<Integer>(); ph.add(15); ph.add(3); ph.add(3); ph.add(3); ph.add(0); ph.add(0); ph.add(0); ph.add(1); ph.add(2); ph.add(0); ph.add(2); ph.add(3); ph.add(2); ph.add(2); ph.add(3); ph.add(3); ph.add(15); State o = BlockDude.getCleanState(d, px, ph, 6); o = BlockDude.setAgent(o, 9, 3, 1, 0); o = BlockDude.setExit(o, 1, 0); o = BlockDude.setBlock(o, 0, 5, 1); o = BlockDude.setBlock(o, 1, 6, 1); o = BlockDude.setBlock(o, 2, 14, 3); o = BlockDude.setBlock(o, 3, 16, 4); o = BlockDude.setBlock(o, 4, 17, 4); o = BlockDude.setBlock(o, 5, 17, 5); TerminalFunction tf = new SinglePFTF(d.getPropFunction(BlockDude.PFATEXIT)); StateConditionTest sc = new SinglePFSCT(d.getPropFunction(BlockDude.PFATEXIT)); RewardFunction rf = new UniformCostRF(); AStar astar = new AStar(d, rf, sc, new DiscreteStateHashFactory(), new NullHeuristic()); astar.toggleDebugPrinting(false); astar.planFromState(o); Policy p = new SDPlannerPolicy(astar); EpisodeAnalysis ea = p.evaluateBehavior(o, rf, tf, 100); State lastState = ea.stateSequence.get(ea.stateSequence.size() - 1); Assert.assertEquals(true, tf.isTerminal(lastState)); Assert.assertEquals(true, sc.satisfies(lastState)); Assert.assertEquals(-94.0, ea.getDiscountedReturn(1.0), 0.001); */ }