Java Code Examples for burlap.mdp.core.action.Action#actionName()

The following examples show how to use burlap.mdp.core.action.Action#actionName() . 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: BlockDudeModel.java    From burlap with Apache License 2.0 6 votes vote down vote up
@Override
public State sample(State s, Action a) {

	BlockDudeState bs = (BlockDudeState)s.copy();
	String aname = a.actionName();
	if(aname.equals(ACTION_WEST)){
		moveHorizontally(bs, -1);
	}
	else if(aname.equals(ACTION_EAST)){
		moveHorizontally(bs, 1);
	}
	else if(aname.equals(ACTION_UP)){
		moveUp(bs);
	}
	else if(aname.equals(ACTION_PICKUP)){
		putdownBlock(bs);
	}
	else if(aname.equals(ACTION_PUT_DOWN)){
		pickupBlock(bs);
	}
	else {
		throw new RuntimeException("Unknown action " + aname);
	}
	return bs;
}
 
Example 2
Source File: MinecraftModel.java    From burlapcraft with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public State sample(State s, Action a) {

	GenericOOState gs = (GenericOOState)s.copy();

	String aname = a.actionName();
	if(aname.equals(HelperNameSpace.ACTION_MOVE)){
		simMove(gs);
	}
	else if(aname.equals(HelperNameSpace.ACTION_ROTATE_LEFT)){
		simRotate(gs, HelperNameSpace.RotDirection.size - 1);
	}
	else if(aname.equals(HelperNameSpace.ACTION_ROTATE_RIGHT)){
		simRotate(gs, 1);
	}
	else if(aname.equals(HelperNameSpace.ACTION_AHEAD)){
		simPitch(gs, 0);
	}
	else if(aname.equals(HelperNameSpace.ACTION_DOWN_ONE)){
		simPitch(gs, HelperNameSpace.VertDirection.size - 1);
	}
	else if(aname.equals(HelperNameSpace.ACTION_PLACE_BLOCK)){
		simPlace(gs);
	}
	else if(aname.equals(HelperNameSpace.ACTION_DEST_BLOCK)){
		simDestroy(gs);
	}
	else if(aname.equals(HelperNameSpace.ACTION_CHANGE_ITEM)){
		simChangeItem(gs);
	}
	else{
		throw new RuntimeException("MinecraftModel is not defined for action " + aname);
	}

	return gs;
}
 
Example 3
Source File: FrostbiteModel.java    From burlap with Apache License 2.0 5 votes vote down vote up
@Override
public State sample(State s, Action a) {

	FrostbiteState fs = (FrostbiteState)s.copy();

	String aname = a.actionName();
	if(aname.equals(ACTION_EAST)){
		move(fs, 1, 0);
	}
	else if(aname.equals(ACTION_WEST)){
		move(fs, -1, 0);
	}
	else if(aname.equals(ACTION_NORTH)){
		move(fs, 0, -1);
	}
	else if(aname.equals(ACTION_SOUTH)){
		move(fs, 0, 1);
	}
	else if(aname.equals(ACTION_IDLE)){
		move(fs, 0, 0);
	}
	else{
		throw new RuntimeException("Unknown action " + a.toString());
	}

	return fs;
}
 
Example 4
Source File: CPCorrectModel.java    From burlap with Apache License 2.0 5 votes vote down vote up
@Override
public State sample(State s, Action a) {

	s = s.copy();

	if(a.actionName().equals(CartPoleDomain.ACTION_RIGHT)){
		return moveCorrectModel(s, 1);
	}
	else if(a.actionName().equals(CartPoleDomain.ACTION_LEFT)){
		return moveCorrectModel(s, -1);
	}
	throw new RuntimeException("Unknown action " + a.actionName());

}
 
Example 5
Source File: CPClassicModel.java    From burlap with Apache License 2.0 5 votes vote down vote up
@Override
public State sample(State s, Action a) {
	s = s.copy();

	if(a.actionName().equals(CartPoleDomain.ACTION_RIGHT)){
		return moveClassicModel(s, 1);
	}
	else if(a.actionName().equals(CartPoleDomain.ACTION_LEFT)){
		return moveClassicModel(s, -1);
	}
	throw new RuntimeException("Unknown action " + a.actionName());

}
 
Example 6
Source File: TigerObservations.java    From burlap with Apache License 2.0 5 votes vote down vote up
@Override
public State sample(State state, Action action){
	//override for faster sampling
	if(action.actionName().equals(TigerDomain.ACTION_LEFT) || action.actionName().equals(TigerDomain.ACTION_RIGHT)){
		return this.observationReset();
	}
	else if(action.actionName().equals(TigerDomain.ACTION_LISTEN)){
		String tigerVal = (String)state.get(TigerDomain.VAR_DOOR);
		double r = RandomFactory.getMapped(0).nextDouble();
		if(r < this.listenAccuracy){
			if(tigerVal.equals(TigerDomain.VAL_LEFT)){
				return this.observationLeft();
			}
			else{
				return this.observationRight();
			}
		}
		else{
			//then nosiy listen; reverse direction
			if(tigerVal.equals(TigerDomain.VAL_LEFT)){
				return this.observationRight();
			}
			else{
				return this.observationLeft();
			}
		}
	}
	else if(action.actionName().equals(TigerDomain.ACTION_DO_NOTHING)){
		return this.observationNothing();
	}

	throw new RuntimeException("Unknown action " + action.actionName() + "; cannot return observation sample.");
}
 
Example 7
Source File: TigerObservations.java    From burlap with Apache License 2.0 4 votes vote down vote up
@Override
public double probability(State observation, State state,
						  Action action) {


	String oVal = (String)observation.get(TigerDomain.VAR_HEAR);
	String tigerVal = (String)state.get(TigerDomain.VAR_DOOR);

	if(action.actionName().equals(TigerDomain.ACTION_LEFT) || action.actionName().equals(TigerDomain.ACTION_RIGHT)){
		if(oVal.equals(TigerDomain.DOOR_RESET)){
			return 1.;
		}
		return 0.;
	}

	if(action.actionName().equals(TigerDomain.ACTION_LISTEN)){
		if(tigerVal.equals(TigerDomain.VAL_LEFT)){
			if(oVal.equals(TigerDomain.HEAR_LEFT)){
				return this.listenAccuracy;
			}
			else if(oVal.equals(TigerDomain.HEAR_RIGHT)){
				return 1.-this.listenAccuracy;
			}
			else{
				return 0.;
			}
		}
		else{
			if(oVal.equals(TigerDomain.HEAR_LEFT)){
				return 1.-this.listenAccuracy;
			}
			else if(oVal.equals(TigerDomain.HEAR_RIGHT)){
				return this.listenAccuracy;
			}
			else{
				return 0.;
			}
		}
	}

	//otherwise we're in the noop
	if(action.actionName().equals(TigerDomain.ACTION_DO_NOTHING)){
		if(oVal.equals(TigerDomain.HEAR_NOTHING)){
			return 1.;
		}
		else{
			return 0.;
		}
	}

	throw new RuntimeException("Unknown action " + action.actionName() + "; cannot return observation probability.");
}