burlap.mdp.auxiliary.stateconditiontest.StateConditionTest Java Examples

The following examples show how to use burlap.mdp.auxiliary.stateconditiontest.StateConditionTest. 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: DFS.java    From burlap with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor of DFS with specification of depth limit, whether to maintain a closed list that affects exploration, and whether paths
 * generated by options should be explored first.
 * @param domain the domain in which to plan
 * @param gc indicates the goal states
 * @param hashingFactory the state hashing factory to use
 * @param maxDepth depth limit of DFS. -1 specifies no limit.
 * @param maintainClosed whether to maintain a closed list or not
 * @param optionsFirst whether to explore paths generated by options first.
 */
protected void DFSInit(SADomain domain, StateConditionTest gc, HashableStateFactory hashingFactory, int maxDepth, boolean maintainClosed, boolean optionsFirst){
	this.deterministicPlannerInit(domain, gc, hashingFactory);
	this.maxDepth = maxDepth;
	this.maintainClosed = maintainClosed;
	if(optionsFirst){
		this.setOptionsFirst();
	}
	
	rand = RandomFactory.getMapped(0);
}
 
Example #2
Source File: SubgoalOption.java    From burlap with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes.
 * @param name the name of the option
 * @param p the option's policy
 * @param init the initiation states of the option
 * @param terminationStates the deterministic termination states of the option.
 */
public SubgoalOption(String name, Policy p, StateConditionTest init, StateConditionTest terminationStates){
	this.name = name;
	this.policy = p;
	this.initiationTest = init;
	this.terminationStates = terminationStates;
	
}
 
Example #3
Source File: TestBlockDude.java    From burlap with Apache License 2.0 4 votes vote down vote up
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);
	*/
}
 
Example #4
Source File: SubgoalOption.java    From burlap with Apache License 2.0 4 votes vote down vote up
public void setInitiationTest(StateConditionTest initiationTest) {
	this.initiationTest = initiationTest;
}
 
Example #5
Source File: SubgoalOption.java    From burlap with Apache License 2.0 4 votes vote down vote up
public StateConditionTest getTerminationStates() {
	return terminationStates;
}
 
Example #6
Source File: SubgoalOption.java    From burlap with Apache License 2.0 4 votes vote down vote up
public void setTerminationStates(StateConditionTest terminationStates) {
	this.terminationStates = terminationStates;
}
 
Example #7
Source File: GoalConditionTF.java    From burlap with Apache License 2.0 4 votes vote down vote up
public GoalConditionTF(StateConditionTest goalCondition) {
	this.goalCondition = goalCondition;
}
 
Example #8
Source File: DeterministicPlanner.java    From burlap with Apache License 2.0 3 votes vote down vote up
/**
 * Initializes the valueFunction. Automatically sets discount factor 1.
 * @param domain the domain in which to plan.
 * @param gc test for goal conditions that should return true for goal states and false for non-goal states.
 * @param hashingFactory the hashing factory to use for states.
 */
public void deterministicPlannerInit(SADomain domain, StateConditionTest gc, HashableStateFactory hashingFactory){
	
	this.solverInit(domain, 1., hashingFactory); //goal condition doubles as termination function for deterministic planners
	this.gc = gc;
	this.internalPolicy = new HashMap<HashableState, Action>();


}
 
Example #9
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 #10
Source File: LimitedMemoryDFS.java    From burlap with Apache License 2.0 3 votes vote down vote up
/**
 * Constructor for memory limited DFS
 * @param domain the domain in which to plan
 * @param gc indicates the goal states
 * @param hashingFactory the state hashing factory to use
 * @param maxDepth depth limit of DFS. -1 specifies no limit.
 * @param maintainClosed whether to maintain a closed list or not
 * @param optionsFirst whether to explore paths generated by options first.
 * @param memorySize the number of most recently expanded nodes to remember.
 */
public LimitedMemoryDFS(SADomain domain, StateConditionTest gc, HashableStateFactory hashingFactory, int maxDepth,
						boolean maintainClosed, boolean optionsFirst, int memorySize) {
	super(domain, gc, hashingFactory, maxDepth, maintainClosed,
			optionsFirst);
	
	this.memorySize = memorySize;
	
}
 
Example #11
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 &gt; 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 #12
Source File: BFS.java    From burlap with Apache License 2.0 2 votes vote down vote up
/**
 * BFS only needs reference to the domain, goal conditions, and hashing factory. The reward function is considered UniformCost, but is
 * not used. No states are considered terminal states, but planning will stop when it finds the goal state.
 * @param domain the domain in which to plan
 * @param gc the test for goal states
 * @param hashingFactory the state hashing factory to use.
 */
public BFS(SADomain domain, StateConditionTest gc, HashableStateFactory hashingFactory){
	this.deterministicPlannerInit(domain, gc, hashingFactory);
}
 
Example #13
Source File: UCT.java    From burlap with Apache License 2.0 2 votes vote down vote up
/**
 * Tells the valueFunction to stop planning if a goal state is ever found.
 * @param gc a {@link burlap.mdp.auxiliary.stateconditiontest.StateConditionTest} object used to specify goal states (whereever it evaluates as true).
 */
public void useGoalConditionStopCriteria(StateConditionTest gc){
	this.goalCondition = gc;
}
 
Example #14
Source File: GoalBasedRF.java    From burlap with Apache License 2.0 2 votes vote down vote up
/**
 * Initializes with transitions to goal states returning a reward of 1 and all others returning 0
 * @param gc {@link burlap.mdp.auxiliary.stateconditiontest.StateConditionTest} object that specifies goal states.
 */
public GoalBasedRF(StateConditionTest gc) {
	this.gc = gc;
}
 
Example #15
Source File: GoalBasedRF.java    From burlap with Apache License 2.0 2 votes vote down vote up
/**
 * Initializes with transitions to goal states returning the given reward and all others returning 0.
 * @param gc {@link burlap.mdp.auxiliary.stateconditiontest.StateConditionTest} object that specifies goal states.
 * @param goalReward the reward returned for transitions to goal states.
 */
public GoalBasedRF(StateConditionTest gc, double goalReward) {
	this.gc = gc;
	this.goalReward = goalReward;
}
 
Example #16
Source File: GoalBasedRF.java    From burlap with Apache License 2.0 2 votes vote down vote up
/**
 * Initializes with transitions to goal states returning the given reward and all others returning 0.
 * @param gc {@link burlap.mdp.auxiliary.stateconditiontest.StateConditionTest} object that specifies goal states.
 * @param goalReward the reward returned for transitions to goal states.
 * @param defaultReward the default reward returned for all non-goal state transitions.
 */
public GoalBasedRF(StateConditionTest gc, double goalReward, double defaultReward) {
	this.gc = gc;
	this.goalReward = goalReward;
	this.defaultReward = defaultReward;
}
 
Example #17
Source File: GoalBasedRF.java    From burlap with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the goal condition for this reward function.
 * @return the goal condition for this reward function.
 */
public StateConditionTest getGoalCondition(){
	return this.gc;
}
 
Example #18
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 &lt;= w &lt;= 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 #19
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 &gt; 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 #20
Source File: DFS.java    From burlap with Apache License 2.0 2 votes vote down vote up
/**
 * Constructor of DFS with specification of depth limit, whether to maintain a closed list that affects exploration, and whether paths
 * generated by options should be explored first.
 * @param domain the domain in which to plan
 * @param gc indicates the goal states
 * @param hashingFactory the state hashing factory to use
 * @param maxDepth depth limit of DFS. -1 specifies no limit.
 * @param maintainClosed whether to maintain a closed list or not
 * @param optionsFirst whether to explore paths generated by options first.
 */
public DFS(SADomain domain, StateConditionTest gc, HashableStateFactory hashingFactory, int maxDepth, boolean maintainClosed, boolean optionsFirst){
	this.DFSInit(domain, gc, hashingFactory, maxDepth, maintainClosed, optionsFirst);
}
 
Example #21
Source File: DFS.java    From burlap with Apache License 2.0 2 votes vote down vote up
/**
 * Constructor of DFS with specification of depth limit and whether to maintain a closed list that affects exploration.
 * @param domain the domain in which to plan
 * @param gc indicates the goal states
 * @param hashingFactory the state hashing factory to use
 * @param maxDepth depth limit of DFS. -1 specifies no limit.
 * @param maintainClosed whether to maintain a closed list or not
 */
public DFS(SADomain domain, StateConditionTest gc, HashableStateFactory hashingFactory, int maxDepth, boolean maintainClosed){
	this.DFSInit(domain, gc, hashingFactory, maxDepth, maintainClosed, false);
}
 
Example #22
Source File: DFS.java    From burlap with Apache License 2.0 2 votes vote down vote up
/**
 * Basic constructor for standard DFS with a depth limit
 * @param domain the domain in which to plan
 * @param gc indicates the goal states
 * @param hashingFactory the state hashing factory to use
 * @param maxDepth depth limit of DFS. -1 specifies no limit.
 */
public DFS(SADomain domain, StateConditionTest gc, HashableStateFactory hashingFactory, int maxDepth){
	this.DFSInit(domain, gc, hashingFactory, maxDepth, false, false);
}
 
Example #23
Source File: DFS.java    From burlap with Apache License 2.0 2 votes vote down vote up
/**
 * Basic constructor for standard DFS without a depth limit
 * @param domain the domain in which to plan
 * @param gc indicates the goal states
 * @param hashingFactory the state hashing factory to use
 */
public DFS(SADomain domain, StateConditionTest gc, HashableStateFactory hashingFactory){
	this.DFSInit(domain, gc, hashingFactory, -1, false, false);
}
 
Example #24
Source File: SubgoalOption.java    From burlap with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the object defining the initiation states.
 * @return the object defining the initiation states.
 */
public StateConditionTest getInitiationTest(){
	return this.initiationTest;
}
 
Example #25
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;
	
}