Java Code Examples for burlap.mdp.core.oo.state.OOState#objectsOfClass()

The following examples show how to use burlap.mdp.core.oo.state.OOState#objectsOfClass() . 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: GoldBlockTF.java    From burlapcraft with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Find the gold block and return its pose.
 * @param s the state
 * @return the pose of the agent being one unit above the gold block.
 */
public static HelperGeometry.Pose getGoalPose(State s) {

	OOState os = (OOState)s;

	List<ObjectInstance> blocks = os.objectsOfClass(HelperNameSpace.CLASS_BLOCK);
	for (ObjectInstance oblock : blocks) {
		BCBlock block = (BCBlock)oblock;
		if (block.type == 41) {
			int goalX = block.x;
			int goalY = block.y;
			int goalZ = block.z;

			return HelperGeometry.Pose.fromXyz(goalX, goalY + 1, goalZ);
		}
	}
	return null;
}
 
Example 2
Source File: GridGameStandardMechanics.java    From burlap with Apache License 2.0 6 votes vote down vote up
/**
 * Returns true if the agent objects between these two states are equal
 * @param s1 the first state
 * @param s2 the second state
 * @return true if the agent objects between these two states are equal
 */
protected boolean agentsEqual(OOState s1, OOState s2){
	
	List<ObjectInstance> agents1 = s1.objectsOfClass(GridGame.CLASS_AGENT);
	for(ObjectInstance a1 : agents1){
		ObjectInstance a2 = s2.object(a1.name());
		
		int x1 = (Integer)a1.get(GridGame.VAR_X);
		int x2 = (Integer)a2.get(GridGame.VAR_X);
		
		int y1 = (Integer)a1.get(GridGame.VAR_Y);
		int y2 = (Integer)a2.get(GridGame.VAR_Y);
		
		if(x1 != x2 || y1 != y2){
			return false;
		}
		
	}
	
	return true;
}
 
Example 3
Source File: IDDiscMaskedHashableState.java    From burlap with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean ooStatesEqual(OOState s1, OOState s2) {
	if (s1 == s2) {
		return true;
	}

	for(Map.Entry<String, List<ObjectInstance>> e1 : OOStateUtilities.objectsByClass(s1).entrySet()){

		String oclass = e1.getKey();

		if(config.maskedObjectClasses.contains(oclass)){
			continue;
		}

		List<ObjectInstance> objects = e1.getValue();

		List<ObjectInstance> oobjects = s2.objectsOfClass(oclass);
		if(objects.size() != oobjects.size()){
			return false;
		}

		for(ObjectInstance o : objects){
			ObjectInstance oo = s2.object(o.name());
			if(oo == null || !flatStatesEqual(o, oo)){
				return false;
			}
		}

	}

	return true;
}
 
Example 4
Source File: IDMaskedHashableState.java    From burlap with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean ooStatesEqual(OOState s1, OOState s2) {
	if (s1 == s2) {
		return true;
	}

	for(Map.Entry<String, List<ObjectInstance>> e1 : OOStateUtilities.objectsByClass(s1).entrySet()){

		String oclass = e1.getKey();

		if(config.maskedObjectClasses.contains(oclass)){
			continue;
		}

		List<ObjectInstance> objects = e1.getValue();

		List<ObjectInstance> oobjects = s2.objectsOfClass(oclass);
		if(objects.size() != oobjects.size()){
			return false;
		}

		for(ObjectInstance o : objects){
			ObjectInstance oo = s2.object(o.name());
			if(oo == null || !flatStatesEqual(o, oo)){
				return false;
			}
		}

	}

	return true;
}
 
Example 5
Source File: IISimpleHashableState.java    From burlap with Apache License 2.0 5 votes vote down vote up
protected boolean ooStatesEqual(OOState s1, OOState s2){
	if(s1 == s2){
		return true;
	}
	if(s1.numObjects() != s2.numObjects()){
		return false;
	}

	Set<String> matchedObjects = new HashSet<String>();
	for(Map.Entry<String, List<ObjectInstance>> e1 : OOStateUtilities.objectsByClass(s1).entrySet()){
		String oclass = e1.getKey();
		List<ObjectInstance> objects = e1.getValue();

		List<ObjectInstance> oobjects = s2.objectsOfClass(oclass);
		if(objects.size() != oobjects.size()){
			return false;
		}

		for(ObjectInstance o : objects){
			boolean foundMatch = false;
			for(ObjectInstance oo : oobjects){
				String ooname = oo.name();
				if(matchedObjects.contains(ooname)){
					continue;
				}
				if(flatStatesEqual(o, oo)){
					foundMatch = true;
					matchedObjects.add(ooname);
					break;
				}
			}
			if(!foundMatch){
				return false;
			}
		}

	}

	return true;
}
 
Example 6
Source File: GridGame.java    From burlap with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isTrue(OOState s, String... params) {
	
	ObjectInstance agent = s.object(params[0]);
	int ax = (Integer)agent.get(VAR_X);
	int ay = (Integer)agent.get(VAR_Y);
	int apn = (Integer)agent.get(VAR_PN);
	
	//find all universal goals
	List <ObjectInstance> goals = s.objectsOfClass(CLASS_GOAL);
	for(ObjectInstance goal : goals){
		
		int gt = (Integer)goal.get(VAR_GT);
		if(gt == apn+1){
		
			int gx = (Integer)goal.get(VAR_X);
			int gy = (Integer)goal.get(VAR_Y);
			if(gx == ax && gy == ay){
				return true;
			}
			
		}
		
		
	}
	
	return false;
}
 
Example 7
Source File: GridGameStandardMechanics.java    From burlap with Apache License 2.0 5 votes vote down vote up
protected String agentName(int agentNum, OOState s){
	for(ObjectInstance o : s.objectsOfClass(GridGame.CLASS_AGENT)){
		int opn = (Integer)o.get(GridGame.VAR_PN);
		if(opn == agentNum){
			return o.name();
		}
	}
	return null;
}
 
Example 8
Source File: IIDiscMaskedHashableState.java    From burlap with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean ooStatesEqual(OOState s1, OOState s2) {
	if(s1 == s2){
		return true;
	}

	Set<String> matchedObjects = new HashSet<String>();
	for(Map.Entry<String, List<ObjectInstance>> e1 : OOStateUtilities.objectsByClass(s1).entrySet()){

		String oclass = e1.getKey();

		if(config.maskedObjectClasses.contains(oclass)){
			continue;
		}

		List<ObjectInstance> objects = e1.getValue();

		List<ObjectInstance> oobjects = s2.objectsOfClass(oclass);
		if(objects.size() != oobjects.size()){
			return false;
		}

		for(ObjectInstance o : objects){
			boolean foundMatch = false;
			for(ObjectInstance oo : oobjects){
				String ooname = oo.name();
				if(matchedObjects.contains(ooname)){
					continue;
				}
				if(flatStatesEqual(o, oo)){
					foundMatch = true;
					matchedObjects.add(ooname);
					break;
				}
			}
			if(!foundMatch){
				return false;
			}
		}

	}

	return true;
}
 
Example 9
Source File: IIMaskedHashableState.java    From burlap with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean ooStatesEqual(OOState s1, OOState s2) {
	if(s1 == s2){
		return true;
	}

	Set<String> matchedObjects = new HashSet<String>();
	for(Map.Entry<String, List<ObjectInstance>> e1 : OOStateUtilities.objectsByClass(s1).entrySet()){

		String oclass = e1.getKey();

		if(config.maskedObjectClasses.contains(oclass)){
			continue;
		}

		List<ObjectInstance> objects = e1.getValue();

		List<ObjectInstance> oobjects = s2.objectsOfClass(oclass);
		if(objects.size() != oobjects.size()){
			return false;
		}

		for(ObjectInstance o : objects){
			boolean foundMatch = false;
			for(ObjectInstance oo : oobjects){
				String ooname = oo.name();
				if(matchedObjects.contains(ooname)){
					continue;
				}
				if(flatStatesEqual(o, oo)){
					foundMatch = true;
					matchedObjects.add(ooname);
					break;
				}
			}
			if(!foundMatch){
				return false;
			}
		}

	}

	return true;
}
 
Example 10
Source File: GridGame.java    From burlap with Apache License 2.0 3 votes vote down vote up
@Override
public boolean isTrue(OOState s, String... params) {
	
	ObjectInstance agent = s.object(params[0]);
	int ax = (Integer)agent.get(VAR_X);
	int ay = (Integer)agent.get(VAR_Y);
	
	
	//find all universal goals
	List <ObjectInstance> goals = s.objectsOfClass(CLASS_GOAL);
	for(ObjectInstance goal : goals){
		
		int gt = (Integer)goal.get(VAR_GT);
		if(gt == 0){
		
			int gx = (Integer)goal.get(VAR_X);
			int gy = (Integer)goal.get(VAR_Y);
			if(gx == ax && gy == ay){
				return true;
			}
			
		}
		
		
	}
	
	return false;
}