burlap.behavior.singleagent.planning.deterministic.informed.Heuristic Java Examples

The following examples show how to use burlap.behavior.singleagent.planning.deterministic.informed.Heuristic. 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 vote down vote up
@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 vote down vote up
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: IDAStar.java    From burlap with Apache License 2.0 3 votes vote down vote up
/**
 * Initializes.
 * @param domain the domain in which to plan
 * @param gc should evaluate to true for goal states; false otherwise
 * @param hashingFactory the state hashing factory to use
 * @param heuristic the planning heuristic. Should return non-positive values.
 */
public IDAStar(SADomain domain, StateConditionTest gc, HashableStateFactory hashingFactory, Heuristic heuristic){
	
	this.deterministicPlannerInit(domain, gc, hashingFactory);
	
	this.heuristic = heuristic;
	nodeComparator = new PrioritizedSearchNode.PSNComparator();
	
}
 
Example #4
Source File: DynamicWeightedAStar.java    From burlap with Apache License 2.0 2 votes vote down vote up
/**
 * Initializes
 * @param domain the domain in which to plan
 * @param gc should evaluate to true for goal states; false otherwise
 * @param hashingFactory the state hashing factory to use
 * @param heuristic the planning heuristic. Should return non-positive values.
 * @param epsilon parameter > 1 indicating greediness; the larger the value the more greedy.
 * @param expectedDepth the expected depth of the plan
 */
public DynamicWeightedAStar(SADomain domain, StateConditionTest gc, HashableStateFactory hashingFactory, Heuristic heuristic, double epsilon, int expectedDepth) {
	super(domain, gc, hashingFactory, heuristic);
	this.epsilon = epsilon;
	this.expectedDepth = expectedDepth;
}
 
Example #5
Source File: WeightedGreedy.java    From burlap with Apache License 2.0 2 votes vote down vote up
/**
 * Initializes the valueFunction.
 * @param domain the domain in which to plan
 * @param rf the reward function that represents costs as negative reward
 * @param gc should evaluate to true for goal states; false otherwise
 * @param hashingFactory the state hashing factory to use
 * @param heuristic the planning heuristic. Should return non-positive values.
 * @param costWeight a fraction 0 <= w <= 1. When w = 0, the search is fully greedy. When w = 1, the search is optimal and equivalent to A*.
 */
public WeightedGreedy(SADomain domain, RewardFunction rf, StateConditionTest gc, HashableStateFactory hashingFactory, Heuristic heuristic, double costWeight) {
	super(domain, gc, hashingFactory, heuristic);
	this.costWeight = costWeight;
}
 
Example #6
Source File: StaticWeightedAStar.java    From burlap with Apache License 2.0 2 votes vote down vote up
/**
 * Initializes. Returned solution will be at most \epsilon times the optimal solution cost.
 * @param domain the domain in which to plan
 * @param gc should evaluate to true for goal states; false otherwise
 * @param hashingFactory the state hashing factory to use
 * @param heuristic the planning heuristic. Should return non-positive values.
 * @param epsilon parameter > 1. The larger the value the more greedy.
 */
public StaticWeightedAStar(SADomain domain, StateConditionTest gc, HashableStateFactory hashingFactory, Heuristic heuristic, double epsilon) {
	super(domain, gc, hashingFactory, heuristic);
	this.epsilonP1 = 1. + epsilon;
}
 
Example #7
Source File: AStar.java    From burlap with Apache License 2.0 1 votes vote down vote up
/**
 * Initializes A*. Goal states are indicated by gc evaluating to true. The costs are stored as negative rewards in the reward function.
 * By default there are no terminal states except teh goal states, so a terminal function is not taken.
 * @param domain the domain in which to plan
 * @param gc should evaluate to true for goal states; false otherwise
 * @param hashingFactory the state hashing factory to use
 * @param heuristic the planning heuristic. Should return non-positive values.
 */
public AStar(SADomain domain, StateConditionTest gc, HashableStateFactory hashingFactory, Heuristic heuristic){
	
	this.deterministicPlannerInit(domain, gc, hashingFactory);
	
	this.heuristic = heuristic;
	
}