burlap.mdp.core.oo.propositional.PropositionalFunction Java Examples

The following examples show how to use burlap.mdp.core.oo.propositional.PropositionalFunction. 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: VisualActionObserver.java    From burlap with Apache License 2.0 6 votes vote down vote up
private void updatePropTextArea(State s){

		if(domain == null || !(s instanceof OOState)){
			return ;
		}

	    StringBuilder buf = new StringBuilder();
		
		List <PropositionalFunction> props = ((OODomain)domain).propFunctions();
		for(PropositionalFunction pf : props){
			List<GroundedProp> gps = pf.allGroundings((OOState)s);
			for(GroundedProp gp : gps){
				if(gp.isTrue((OOState)s)){
					buf.append(gp.toString()).append("\n");
				}
			}
		}
		propViewer.setText(buf.toString());
		
		
	}
 
Example #2
Source File: GridWorldDQN.java    From burlap_caffe with Apache License 2.0 6 votes vote down vote up
public GridWorldDQN(String solverFile, double gamma) {

        //create the domain
        gwdg = new GridWorldDomain(11, 11);
        gwdg.setMapToFourRooms();
        rf = new UniformCostRF();
        tf = new SinglePFTF(PropositionalFunction.findPF(gwdg.generatePfs(), GridWorldDomain.PF_AT_LOCATION));
        gwdg.setRf(rf);
        gwdg.setTf(tf);
        domain = gwdg.generateDomain();

        goalCondition = new TFGoalCondition(tf);

        //set up the initial state of the task
        initialState = new GridWorldState(new GridAgent(0, 0), new GridLocation(10, 10, "loc0"));

        //set up the state hashing system for tabular algorithms
        hashingFactory = new SimpleHashableStateFactory();

        //set up the environment for learners algorithms
        env = new SimulatedEnvironment(domain, initialState);

        dqn = new DQN(solverFile, actionSet, new NNGridStateConverter(), gamma);
    }
 
Example #3
Source File: VisualExplorer.java    From burlap with Apache License 2.0 6 votes vote down vote up
/**
 * Updates the propositional function evaluation text display for the given state.
 * @param s the input state on which propositional functions are to be evaluated.
 */
protected void updatePropTextArea(State s){

	if(!(domain instanceof OODomain) || !(s instanceof OOState)){
		return ;
	}

    StringBuilder buf = new StringBuilder();
	
	List <PropositionalFunction> props = ((OODomain)domain).propFunctions();
	for(PropositionalFunction pf : props){
		List<GroundedProp> gps = pf.allGroundings((OOState)s);
		for(GroundedProp gp : gps){
			if(gp.isTrue((OOState)s)){
				buf.append(gp.toString()).append("\n");
			}
		}
	}
	propViewer.setText(buf.toString());
	
	
}
 
Example #4
Source File: VisualWorldObserver.java    From burlap with Apache License 2.0 6 votes vote down vote up
private void updatePropTextArea(State s){

		if(!(domain instanceof OODomain) || !(s instanceof OOState)){
			return ;
		}

	    StringBuilder buf = new StringBuilder();
		
		List <PropositionalFunction> props = ((OODomain)domain).propFunctions();
		for(PropositionalFunction pf : props){
			//List<GroundedProp> gps = s.getAllGroundedPropsFor(pf);
			List<GroundedProp> gps = pf.allGroundings((OOState)s);
			for(GroundedProp gp : gps){
				if(gp.isTrue((OOState)s)){
					buf.append(gp.toString()).append("\n");
				}
			}
		}
		propViewer.setText(buf.toString());
		
		
	}
 
Example #5
Source File: SGVisualExplorer.java    From burlap with Apache License 2.0 6 votes vote down vote up
protected void updatePropTextArea(State s){

		if(!(domain instanceof OODomain) || !(s instanceof OOState)){
			return;
		}

	    StringBuilder buf = new StringBuilder();
		
		List <PropositionalFunction> props = ((OODomain)domain).propFunctions();
		for(PropositionalFunction pf : props){
			List<GroundedProp> gps = pf.allGroundings((OOState)s);
			for(GroundedProp gp : gps){
				if(gp.isTrue((OOState)s)){
					buf.append(gp.toString()).append("\n");
				}
			}
		}
		

		propViewer.setText(buf.toString());
		
		
	}
 
Example #6
Source File: GameSequenceVisualizer.java    From burlap with Apache License 2.0 6 votes vote down vote up
private void updatePropTextArea(State s){

		if(!(domain instanceof OODomain) || !(s instanceof OOState)){
			return ;
		}

	    StringBuilder buf = new StringBuilder();
		
		List <PropositionalFunction> props = ((OODomain)domain).propFunctions();
		for(PropositionalFunction pf : props){
			List<GroundedProp> gps = pf.allGroundings((OOState)s);
			for(GroundedProp gp : gps){
				if(gp.isTrue((OOState)s)){
					buf.append(gp.toString()).append("\n");
				}
			}
		}
		
		propViewer.setText(buf.toString());
		
		
		
	}
 
Example #7
Source File: FrostbiteDomain.java    From burlap with Apache License 2.0 6 votes vote down vote up
public List<PropositionalFunction> generatePFs(){

		int numberPlatformCol = 4;

		int gameHeight = 130 * scale;
		int gameWidth = 160 * scale;
		int platformSpeed = 1 * scale;
		int agentSize = 8 * scale;
		int gameIceHeight = gameHeight / 4;

		List<PropositionalFunction> pfs = Arrays.asList(
				new PlatformActivePF(PF_PLATFORM_ACTIVE),
				new OnPlatformPF(PF_ON_PLATFORM, gameWidth, agentSize),
				new InWaterPF(PF_IN_WATER, gameWidth, agentSize, gameHeight, numberPlatformCol, platformSpeed),
				new OnIcePF(PF_ON_ICE, agentSize, gameIceHeight),
				new IglooBuiltPF(PF_IGLOO_BUILT));


		return pfs;
	}
 
Example #8
Source File: PFFeatures.java    From burlap with Apache License 2.0 6 votes vote down vote up
@Override
public double[] features(State s) {
	
	List<Double> featureValueList = new LinkedList<Double>();
	for(PropositionalFunction pf : this.pfsToUse){
		//List<GroundedProp> gps = s.getAllGroundedPropsFor(pf);
		List<GroundedProp> gps = pf.allGroundings((OOState)s);
		for(GroundedProp gp : gps){
			if(gp.isTrue((OOState)s)){
				featureValueList.add(1.);
			}
			else{
				featureValueList.add(0.);
			}
		}
	}
	
	double [] fv = new double[featureValueList.size()];
	int i = 0;
	for(double f : featureValueList){
		fv[i] = f;
		i++;
	}
	
	return fv;
}
 
Example #9
Source File: EpisodeSequenceVisualizer.java    From burlap with Apache License 2.0 6 votes vote down vote up
protected void updatePropTextArea(State s){

		if(!(domain instanceof OODomain) || !(s instanceof OOState)){
			return ;
		}

	    StringBuilder buf = new StringBuilder();
		
		List <PropositionalFunction> props = ((OODomain)domain).propFunctions();
		for(PropositionalFunction pf : props){
			//List<GroundedProp> gps = s.getAllGroundedPropsFor(pf);
			List<GroundedProp> gps = pf.allGroundings((OOState)s);
			for(GroundedProp gp : gps){
				if(gp.isTrue((OOState)s)){
					buf.append(gp.toString()).append("\n");
				}
			}
		}
		
		propViewer.setText(buf.toString());
		
		
		
	}
 
Example #10
Source File: TestGridWorld.java    From burlap with Apache License 2.0 5 votes vote down vote up
public void assertPFs(State s, boolean[] expectedValues) {
	OOState os = (OOState)s;
	PropositionalFunction atLocation = domain.propFunction(GridWorldDomain.PF_AT_LOCATION);
	List<GroundedProp> gpAt = atLocation.allGroundings(os);
	Assert.assertEquals(1, gpAt.size());
	Assert.assertEquals(expectedValues[0], gpAt.get(0).isTrue((OOState)s));
	
	PropositionalFunction pfWallNorth = domain.propFunction(GridWorldDomain.PF_WALL_NORTH);
	List<GroundedProp> gpWallNorth = pfWallNorth.allGroundings(os);
	Assert.assertEquals(1, gpWallNorth.size());
	Assert.assertEquals(expectedValues[1], gpWallNorth.get(0).isTrue((OOState)s));
	
	
	PropositionalFunction pfWallSouth = domain.propFunction(GridWorldDomain.PF_WALL_SOUTH);
	List<GroundedProp> gpWallSouth = pfWallSouth.allGroundings(os);
	Assert.assertEquals(1, gpWallSouth.size());
	Assert.assertEquals(expectedValues[2], gpWallSouth.get(0).isTrue((OOState)s));
	
	
	PropositionalFunction pfWallEast = domain.propFunction(GridWorldDomain.PF_WALL_EAST);
	List<GroundedProp> gpWallEast = pfWallEast.allGroundings(os);
	Assert.assertEquals(1, gpWallEast.size());
	Assert.assertEquals(expectedValues[3], gpWallEast.get(0).isTrue((OOState)s));
	
	
	PropositionalFunction pfWallWest = domain.propFunction(GridWorldDomain.PF_WALL_WEST);
	List<GroundedProp> gpWallWest = pfWallWest.allGroundings(os);
	Assert.assertEquals(1, gpWallWest.size());
	Assert.assertEquals(expectedValues[4], gpWallWest.get(0).isTrue((OOState)s));
	

}
 
Example #11
Source File: BlocksWorld.java    From burlap with Apache License 2.0 5 votes vote down vote up
public List<PropositionalFunction> generatePfs(){
	List<PropositionalFunction> pfsI =  Arrays.asList(new OnBlockPF(PF_ON_BLOCK), new OnTablePF(PF_ON_TABLE), new ClearPF(PF_CLEAR));
	List<PropositionalFunction> pfs = new ArrayList<PropositionalFunction>(pfsI);
	for(NamedColor col : colors){
		pfs.add(new ColorPF(col));
	}
	return pfs;
}
 
Example #12
Source File: LunarLanderDomain.java    From burlap with Apache License 2.0 5 votes vote down vote up
public List<PropositionalFunction> generatePfs(){
	return Arrays.asList(
			new OnPadPF(PF_ON_PAD),
			new TouchPadPF(PF_TOUTCH_PAD),
			new TouchSurfacePF(PF_TOUCH_SURFACE),
			new TouchGroundPF(PF_ON_GROUND, this.physParams.ymin));
}
 
Example #13
Source File: GridWorldDomain.java    From burlap with Apache License 2.0 5 votes vote down vote up
public List<PropositionalFunction> generatePfs(){
	List<PropositionalFunction> pfs = Arrays.asList(
			new AtLocationPF(PF_AT_LOCATION, new String[]{CLASS_AGENT, CLASS_LOCATION}),
		new WallToPF(PF_WALL_NORTH, new String[]{CLASS_AGENT}, 0),
		new WallToPF(PF_WALL_SOUTH, new String[]{CLASS_AGENT}, 1),
		new WallToPF(PF_WALL_EAST, new String[]{CLASS_AGENT}, 2),
		new WallToPF(PF_WALL_WEST, new String[]{CLASS_AGENT}, 3));

	return pfs;
}
 
Example #14
Source File: PFFeatures.java    From burlap with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes using all propositional functions that belong to the domain
 * @param domain the domain containing all the propositional functions to use
 */
public PFFeatures(OODomain domain){
	
	this.pfsToUse = new PropositionalFunction[domain.propFunctions().size()];
	int i = 0;
	for(PropositionalFunction pf : domain.propFunctions()){
		this.pfsToUse[i] = pf;
		i++;
	}
	
}
 
Example #15
Source File: CommandCheckProps.java    From burlapcraft with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void processCommand(ICommandSender sender, String[] args) {

	MinecraftDomainGenerator mdg = new MinecraftDomainGenerator();
	OOSADomain domain = mdg.generateDomain();

	boolean printFalse = false;
	if(args.length > 0){
		if(args[0].equals("+not")){
			printFalse = true;
		}
	}

	State s = MinecraftStateGeneratorHelper.getCurrentState(BurlapCraft.currentDungeon);

	List<GroundedProp> gps = PropositionalFunction.allGroundingsFromList(domain.propFunctions(), (OOState)s);
	StringBuffer buf = new StringBuffer();
	buf.append("\n");
	for(GroundedProp gp : gps){
		if(!gp.isTrue((OOState)s)){
			if(printFalse) {
				buf.append("NOT ");
				buf.append(gp.toString());
				buf.append("\n");
			}
		}
		else{
			buf.append(gp.toString());
			buf.append("\n");
		}

	}
	


	sender.addChatMessage(new ChatComponentText(buf.toString()));

}
 
Example #16
Source File: MinecraftDomainGenerator.java    From burlapcraft with GNU Lesser General Public License v3.0 5 votes vote down vote up
public List<PropositionalFunction> generatePfs(){
	List<PropositionalFunction> pfs = new ArrayList<PropositionalFunction>();
	pfs.add(new PFAgentOnBlock(HelperNameSpace.PF_AGENT_ON_BLOCK, new String[] {CLASS_AGENT, HelperNameSpace.CLASS_BLOCK}));

	for(Block b : HelperActions.mineableBlocks) {
		int id = Block.getIdFromBlock(b);
		pfs.add(new PFBlockIsType(HelperNameSpace.PF_BLOCK_IS_TYPE +id, new String[]{HelperNameSpace.CLASS_BLOCK}, id));
	}
	return pfs;
}
 
Example #17
Source File: TestPlanning.java    From burlap with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
	this.gw = new GridWorldDomain(11, 11);
	this.gw.setMapToFourRooms();
	this.gw.setRf(new UniformCostRF());
	TerminalFunction tf = new SinglePFTF(PropositionalFunction.findPF(gw.generatePfs(), PF_AT_LOCATION));
	this.gw.setTf(tf);
	this.domain = this.gw.generateDomain();
	this.goalCondition = new TFGoalCondition(tf);
	this.hashingFactory = new SimpleHashableStateFactory();
}
 
Example #18
Source File: BlockDude.java    From burlap with Apache License 2.0 4 votes vote down vote up
public List<PropositionalFunction> generatePfs(){
	return Arrays.asList(new HoldingBlockPF(), new AtExitPF());
}
 
Example #19
Source File: GridGame.java    From burlap with Apache License 2.0 4 votes vote down vote up
List<PropositionalFunction> generatePFs(){
	return Arrays.asList(new AgentInUGoal(PF_IN_U_GOAL), new AgentInPGoal(PF_IN_P_GOAL));
}
 
Example #20
Source File: ListPropFunctions.java    From burlap with Apache License 2.0 4 votes vote down vote up
@Override
public int call(BurlapShell shell, String argString, Scanner is, PrintStream os) {
	Environment env = ((EnvironmentShell)shell).getEnv();

	OptionSet oset = this.parser.parse(argString.split(" "));

	if(oset.has("h")){
		os.println("[s]\nCommand to list all true (or false) grounded propositional function for the current environment observation.\n" +
				"-f: list false grounded propositional functions, rather than true ones. " +
				"-n: list the name of all propositional functions, rather than grounded evaluations\n" +
				"-s: evaluate propositional functions on POMDP environment hidden state, rather than environment observation. Environment must extend SimulatedPOEnvironment");

		return 0;
	}


	if(!(shell.getDomain() instanceof OODomain)){
		os.println("cannot query propositional functions because the domain is not an OODomain");
		return 0;
	}

	if(oset.has("n")){
		for(PropositionalFunction pf : ((OODomain)shell.getDomain()).propFunctions()){
			os.println(pf.getName());
		}
		return 0;
	}


	State qs = env.currentObservation();

	if(oset.has("s")){
		if(!(env instanceof SimulatedPOEnvironment)){
			os.println("Cannot query applicable actions with respect to POMDP hidden state, because the environment does not extend SimulatedPOEnvironment.");
			return 0;
		}
		qs = ((SimulatedPOEnvironment)env).getCurrentHiddenState();
	}

	List<GroundedProp> gps = PropositionalFunction.allGroundingsFromList(((OODomain)shell.getDomain()).propFunctions(), (OOState)qs);
	for(GroundedProp gp : gps){
		if(gp.isTrue((OOState)qs) == !oset.has("f")){
			os.println(gp.toString());
		}
	}

	return 0;
}
 
Example #21
Source File: FrostbiteDomain.java    From burlap with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a new frostbite domain.
 *
 * @return the generated domain object
 */
@Override
public OOSADomain generateDomain() {

	OOSADomain domain = new OOSADomain();

	domain.addStateClass(CLASS_AGENT, FrostbiteAgent.class)
			.addStateClass(CLASS_IGLOO, FrostbiteIgloo.class)
			.addStateClass(CLASS_PLATFORM, FrostbitePlatform.class);

	//add actions
	domain.addActionType(new UniversalActionType(ACTION_NORTH))
			.addActionType(new UniversalActionType(ACTION_SOUTH))
			.addActionType(new UniversalActionType(ACTION_EAST))
			.addActionType(new UniversalActionType(ACTION_WEST))
			.addActionType(new UniversalActionType(ACTION_IDLE));



	//add pfs
	List<PropositionalFunction> pfs = this.generatePFs();
	for(PropositionalFunction pf : pfs){
		domain.addPropFunction(pf);
	}


	FrostbiteModel smodel = new FrostbiteModel(scale);
	RewardFunction rf = this.rf;
	TerminalFunction tf = this.tf;
	if(rf == null){
		rf = new FrostbiteRF(domain);
	}
	if(tf == null){
		tf = new FrostbiteTF(domain);
	}


	FactoredModel model = new FactoredModel(smodel, rf, tf);
	domain.setModel(model);

	return domain;
}
 
Example #22
Source File: OODomain.java    From burlap with Apache License 2.0 4 votes vote down vote up
/**
 * Adds all {@link PropositionalFunction} objects to the given {@link OODomain}
 * @param domain the receiving {@link OODomain}
 * @param pfs the {@link PropositionalFunction}s to add.
 */
public static void addPfsToDomain(OODomain domain, PropositionalFunction...pfs){
	for(PropositionalFunction pf : pfs){
		domain.addPropFunction(pf);
	}
}
 
Example #23
Source File: OOSADomain.java    From burlap with Apache License 2.0 4 votes vote down vote up
@Override
public OOSADomain addPropFunction(PropositionalFunction prop) {
	this.propFunctionMap.put(prop.getName(), prop);
	return this;
}
 
Example #24
Source File: OODomain.java    From burlap with Apache License 2.0 4 votes vote down vote up
/**
 * Adds all {@link PropositionalFunction} objects to the given {@link OODomain}
 * @param domain the receiving {@link OODomain}
 * @param pfs a list of the {@link PropositionalFunction}s to add.
 */
public static void addPfsToDomain(OODomain domain, List<PropositionalFunction> pfs){
	for(PropositionalFunction pf : pfs){
		domain.addPropFunction(pf);
	}
}
 
Example #25
Source File: OOSGDomain.java    From burlap with Apache License 2.0 4 votes vote down vote up
@Override
public List<PropositionalFunction> propFunctions() {
	return new ArrayList<PropositionalFunction>(this.propFunctionMap.values());
}
 
Example #26
Source File: IRLExample.java    From burlap_examples with MIT License 4 votes vote down vote up
public LocationFeatures(int numLocations, PropositionalFunction inLocationPF) {
	this.numLocations = numLocations;
	this.inLocationPF = inLocationPF;
}
 
Example #27
Source File: ExampleOOGridWorld.java    From burlap_examples with MIT License 4 votes vote down vote up
public List<PropositionalFunction> generatePfs(){
	return Arrays.<PropositionalFunction>asList(new AtLocation());
}
 
Example #28
Source File: PFFeatures.java    From burlap with Apache License 2.0 4 votes vote down vote up
/**
 * Initializes using the list of given propositional functions.
 * @param pfs the propositional functions to use.
 */
public PFFeatures(List<PropositionalFunction> pfs){
	this.pfsToUse = new PropositionalFunction[pfs.size()];
	this.pfsToUse = pfs.toArray(this.pfsToUse);
}
 
Example #29
Source File: OOSGDomain.java    From burlap with Apache License 2.0 4 votes vote down vote up
@Override
public PropositionalFunction propFunction(String name) {
	return this.propFunctionMap.get(name);
}
 
Example #30
Source File: OOSGDomain.java    From burlap with Apache License 2.0 4 votes vote down vote up
@Override
public OOSGDomain addPropFunction(PropositionalFunction prop) {
	this.propFunctionMap.put(prop.getName(), prop);
	return this;
}