Java Code Examples for burlap.mdp.core.oo.state.ObjectInstance#name()

The following examples show how to use burlap.mdp.core.oo.state.ObjectInstance#name() . 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: OOStateGridder.java    From burlap with Apache License 2.0 6 votes vote down vote up
/**
 * Generates a set of states spaced along along. If there are objects in the input state for which a gridding
 * has not been specified, objects of those classes will be held constant in the returned states over the grid.
 * @param s the input state to grid
 * @return a set of states spaced along along
 */
public List<State> gridState(MutableOOState s){

	//generate specs for all object-wise keys
	FlatStateGridder flatGridder = new FlatStateGridder();
	for(Map.Entry<String, FlatStateGridder> classGird : this.classesToGrid.entrySet()){

		List<ObjectInstance> objects = s.objectsOfClass(classGird.getKey());
		for(ObjectInstance o : objects){
			for(Map.Entry<Object, VariableGridSpec> spec : classGird.getValue().specs()){
				OOVariableKey okey = new OOVariableKey(o.name(), spec.getKey());
				flatGridder.gridDimension(okey, spec.getValue());
			}
		}

	}

	//then grid
	return flatGridder.gridState(s);

}
 
Example 2
Source File: DeepOOState.java    From burlap with Apache License 2.0 5 votes vote down vote up
@Override
public MutableState set(Object variableKey, Object value) {

	OOVariableKey key = OOStateUtilities.generateKey(variableKey);
	ObjectInstance ob = this.object(key.obName);
	if(ob == null){
		throw new UnknownObjectException(key.obName);
	}
	if(!(ob instanceof MutableState)){
		throw new RuntimeException("Cannot set value for object " + ob.name() + " because it does not implement MutableState");
	}
	((MutableState)ob).set(key.obVarKey, value);

	return this;
}
 
Example 3
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 4
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 5
Source File: BlocksWorldState.java    From burlap with Apache License 2.0 5 votes vote down vote up
@Override
public Object get(Object variableKey) {
	OOVariableKey key = OOStateUtilities.generateKey(variableKey);
	ObjectInstance ob = this.blocks.get(key.obName);
	if(ob == null){
		throw new RuntimeException("Unknown object " + ob.name());
	}
	return ob.get(key.obVarKey);
}
 
Example 6
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 7
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 8
Source File: BlocksWorldVisualizer.java    From burlap with Apache License 2.0 3 votes vote down vote up
@Override
public void paintObject(Graphics2D g2, OOState s, ObjectInstance ob, float cWidth, float cHeight) {

	List <ObjectInstance> objects = s.objects();
	List <String> obNames = new ArrayList<String>(objects.size());
	for(ObjectInstance o : objects){
		obNames.add(o.name());
	}
	Collections.sort(obNames);

	String indName = this.getStackBottom((OOState)s, (BlocksWorldBlock)ob);

	int ind = obNames.indexOf(indName);
	int maxSize = obNames.size();

	float blockWidth = cWidth / maxSize;
	float blockHeight = cHeight / maxSize;

	float hGap = 10;

	g2.setColor(((BlocksWorldBlock)ob).color);

	float rx = ind*blockWidth;
	float ry = cHeight - blockHeight - this.getHeight(s, (BlocksWorldBlock)ob)*blockHeight;

	g2.fill(new Rectangle2D.Float(rx + (hGap), ry, blockWidth - 2*hGap, blockHeight));


	g2.setColor(Color.black);
	g2.setFont(new Font("Helvetica", Font.PLAIN, fontSize));

	String valueString = ob.name();
	int stringLen = (int)g2.getFontMetrics().getStringBounds(valueString, g2).getWidth();
	int stringHeight = (int)g2.getFontMetrics().getStringBounds(valueString, g2).getHeight();
	int stringX = (int)((rx + (blockWidth/2)) - (stringLen/2));
	int stringY = (int)((ry + (blockHeight/2)) + (stringHeight/2));

	g2.drawString(valueString, stringX, stringY);

}