Java Code Examples for burlap.mdp.singleagent.SADomain#getActionTypes()

The following examples show how to use burlap.mdp.singleagent.SADomain#getActionTypes() . 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: ApprenticeshipLearning.java    From burlap with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor initializes the policy, doesn't compute anything here.
 * @param domain Domain object for which we need to plan
 */
private StationaryRandomDistributionPolicy(SADomain domain) {
	this.stateActionMapping = new HashMap<HashableState, Action>();
	this.stateActionDistributionMapping = new HashMap<HashableState, List<ActionProb>>();
	this.actionTypes = domain.getActionTypes();
	this.rando = new Random();
	this.hashFactory = new SimpleHashableStateFactory(true);
}
 
Example 2
Source File: BoltzmannActor.java    From burlap with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes the Actor
 * @param domain the domain in which the agent will act
 * @param hashingFactory the state hashing factory to use for state hashing and equality checks
 * @param learningRate the learning rate that affects how quickly the agent adjusts its action preferences.
 */
public BoltzmannActor(SADomain domain, HashableStateFactory hashingFactory, double learningRate) {
	this.domain = domain;
	this.actionTypes = new ArrayList<ActionType>(domain.getActionTypes());
	this.hashingFactory = hashingFactory;
	this.learningRate = new ConstantLR(learningRate);
	
	this.preferences = new HashMap<HashableState, BoltzmannActor.PolicyNode>();

	
}
 
Example 3
Source File: StateReachability.java    From burlap with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the set of {@link State} objects that are reachable from a source state.
 * @param from the source state
 * @param inDomain the domain of the state
 * @param usingHashFactory the state hashing factory to use for indexing states and testing equality.
 * @return the set of {@link State} objects that are reachable from a source state.
 */
public static Set <HashableState> getReachableHashedStates(State from, SADomain inDomain, HashableStateFactory usingHashFactory){

	if(!(inDomain.getModel() instanceof FullModel)){
		throw new RuntimeException( "State reachablity requires a domain with a FullModel, but one is not provided");
	}

	FullModel model = (FullModel)inDomain.getModel();

	Set<HashableState> hashedStates = new HashSet<HashableState>();
	HashableState shi = usingHashFactory.hashState(from);
	List <ActionType> actionTypes = inDomain.getActionTypes();
	int nGenerated = 0;
	
	LinkedList <HashableState> openList = new LinkedList<HashableState>();
	openList.offer(shi);
	hashedStates.add(shi);
	long firstTime = System.currentTimeMillis();
	long lastTime = firstTime;
	while(!openList.isEmpty()){
		HashableState sh = openList.poll();

		
		List<Action> gas = ActionUtils.allApplicableActionsForTypes(actionTypes, sh.s());
		for(Action ga : gas){
			List <TransitionProb> tps = model.transitions(sh.s(), ga);
			nGenerated += tps.size();
			for(TransitionProb tp : tps){
				HashableState nsh = usingHashFactory.hashState(tp.eo.op);
				
				if (hashedStates.add(nsh) && !tp.eo.terminated) {
					openList.offer(nsh);
				}
			}
		}
		
		long currentTime = System.currentTimeMillis();
		if (currentTime - 1000 >= lastTime) {
			DPrint.cl(debugID, "Num generated: " + (nGenerated) + " Unique: " + (hashedStates.size()) + 
					" time: " + ((double)currentTime - firstTime)/1000.0);				
			lastTime = currentTime;
		}
	}
	
	DPrint.cl(debugID, "Num generated: " + nGenerated + "; num unique: " + hashedStates.size());
	
	return hashedStates;
}
 
Example 4
Source File: TestHashing.java    From burlap with Apache License 2.0 4 votes vote down vote up
public Set <HashableState> getReachableHashedStates(State from, SADomain inDomain, HashableStateFactory usingHashFactory){
	
	Set<HashableState> hashedStates = new HashSet<HashableState>();
	HashableState shi = usingHashFactory.hashState(from);
	List <ActionType> actionTypes = inDomain.getActionTypes();
	
	LinkedList <HashableState> openList = new LinkedList<HashableState>();
	openList.offer(shi);
	hashedStates.add(shi);
	while(!openList.isEmpty()){
		HashableState sh = openList.poll();

		List<Action> gas = ActionUtils.allApplicableActionsForTypes(actionTypes, sh.s());
		for(Action ga : gas){
			List <TransitionProb> tps = ((FullModel)inDomain.getModel()).transitions(sh.s(), ga);
			for(TransitionProb tp : tps){
				HashableState nsh = usingHashFactory.hashState(tp.eo.op);
				
				for (HashableState hashedState : hashedStates) {
					boolean sameObject = (hashedState == nsh);
					boolean valueEquals = (hashedState.equals(nsh));
					boolean hashEquals = (hashedState.hashCode() == nsh.hashCode());
					if (sameObject || valueEquals) {
						assert(hashEquals); // Same state, hashes need to be equal
					}
					if (!hashEquals) {
						assert(!sameObject && !valueEquals);
					}
				}
				
				if(!hashedStates.contains(nsh)){
					openList.offer(nsh);
					hashedStates.add(nsh);
				}
			}
			
		}
		
	}
	
	return hashedStates;
}
 
Example 5
Source File: PotentialShapedRMax.java    From burlap with Apache License 2.0 3 votes vote down vote up
/**
 * Initializes for a tabular model, VI valueFunction, and standard RMax paradigm
 * @param domain the real world domain
 * @param gamma the discount factor
 * @param hashingFactory the hashing factory to use for VI and the tabular model
 * @param maxReward the maximum possible reward
 * @param nConfident the number of observations required for the model to be confident in a transition
 * @param maxVIDelta the maximum change in value function for VI to terminate
 * @param maxVIPasses the maximum number of VI iterations per replan.
 */
public PotentialShapedRMax(SADomain domain, double gamma, HashableStateFactory hashingFactory, double maxReward, int nConfident,
						   double maxVIDelta, int maxVIPasses){
	
	this.solverInit(domain, gamma, hashingFactory);
	this.model = new RMaxModel(new TabularModel(domain, hashingFactory, nConfident),
			new RMaxPotential(maxReward, gamma), gamma, domain.getActionTypes());

	
	this.modelPlanner = new VIModelLearningPlanner(domain, this.model, gamma, hashingFactory, maxVIDelta, maxVIPasses);
	
}
 
Example 6
Source File: PotentialShapedRMax.java    From burlap with Apache License 2.0 3 votes vote down vote up
/**
 * Initializes for a tabular model, VI valueFunction, and potential shaped function.
 * @param domain the real world domain
 * @param gamma the discount factor
 * @param hashingFactory the hashing factory to use for VI and the tabular model
 * @param potential the admissible potential function
 * @param nConfident the number of observations required for the model to be confident in a transition
 * @param maxVIDelta the maximum change in value function for VI to terminate
 * @param maxVIPasses the maximum number of VI iterations per replan.
 */
public PotentialShapedRMax(SADomain domain, double gamma, HashableStateFactory hashingFactory, PotentialFunction potential, int nConfident,
		double maxVIDelta, int maxVIPasses){
	
	this.solverInit(domain, gamma, hashingFactory);
	this.model = new RMaxModel(new TabularModel(domain, hashingFactory, nConfident),
			potential, gamma, domain.getActionTypes());


	
	this.modelPlanner = new VIModelLearningPlanner(domain, this.model, gamma, hashingFactory, maxVIDelta, maxVIPasses);
	
}
 
Example 7
Source File: PotentialShapedRMax.java    From burlap with Apache License 2.0 3 votes vote down vote up
/**
 * Initializes for a given model, model learning planner, and potential shaped function.
 * @param domain the real world domain
 * @param hashingFactory a state hashing factory for indexing states
 * @param potential the admissible potential function
 * @param model the model/model-learning algorithm to use
 * @param plannerGenerator a generator for a model valueFunction
 */
public PotentialShapedRMax(SADomain domain, HashableStateFactory hashingFactory, PotentialFunction potential,
		KWIKModel model, ModelLearningPlanner plannerGenerator){
	
	this.solverInit(domain, gamma, hashingFactory);
	this.model = new RMaxModel(model,
			potential, gamma, domain.getActionTypes());


	this.modelPlanner = plannerGenerator;
	this.modelPlanner.setModel(this.model);

	
}
 
Example 8
Source File: RandomPolicy.java    From burlap with Apache License 2.0 2 votes vote down vote up
/**
 * Initializes by copying all the primitive actions references defined for the domain into an internal action
 * list for this policy.
 * @param domain the domain containing all the primitive actions.
 */
public RandomPolicy(SADomain domain){
	this.actionTypes = new ArrayList<ActionType>(domain.getActionTypes());
}
 
Example 9
Source File: SARSCollector.java    From burlap with Apache License 2.0 2 votes vote down vote up
/**
 * Initializes the collector's action set using the actions that are part of the domain.
 * @param domain the domain containing the actions to use
 */
public SARSCollector(SADomain domain){
	this.actionTypes = domain.getActionTypes();
}