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

The following examples show how to use burlap.mdp.core.oo.state.OOState#objects() . 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: IDSimpleHashableState.java    From burlap with Apache License 2.0 6 votes vote down vote up
protected int computeOOHashCode(OOState s){

		int [] hashCodes = new int[s.numObjects()];
		List<ObjectInstance> objects = s.objects();
		for(int i = 0; i < hashCodes.length; i++){
			ObjectInstance o = objects.get(i);
			int oHash = this.computeFlatHashCode(o);
			int classNameHash = o.className().hashCode();
			int nameHash = o.name().hashCode();
			int totalHash = oHash + 31*classNameHash + 31*31*nameHash;
			hashCodes[i] = totalHash;
		}

		//sort for invariance to order
		Arrays.sort(hashCodes);
		HashCodeBuilder hashCodeBuilder = new HashCodeBuilder(17, 31);
		hashCodeBuilder.append(hashCodes);
		return hashCodeBuilder.toHashCode();

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

	List<ObjectInstance> theseObjects = s1.objects();
	for(ObjectInstance ob : theseObjects){
		ObjectInstance oByName = s2.object(ob.name());
		if(oByName == null){
			return false;
		}
		if(!flatStatesEqual(ob, oByName)){
			return false;
		}
	}

	return true;
}
 
Example 3
Source File: IISimpleHashableState.java    From burlap with Apache License 2.0 6 votes vote down vote up
protected int computeOOHashCode(OOState s){

		int [] hashCodes = new int[s.numObjects()];
		List<ObjectInstance> objects = s.objects();
		for(int i = 0; i < hashCodes.length; i++){
			ObjectInstance o = objects.get(i);
			int oHash = this.computeFlatHashCode(o);
			int classNameHash = o.className().hashCode();
			int totalHash = oHash + 31*classNameHash;
			hashCodes[i] = totalHash;
		}

		//sort for invariance to order
		Arrays.sort(hashCodes);
		HashCodeBuilder hashCodeBuilder = new HashCodeBuilder(17, 31);
		hashCodeBuilder.append(hashCodes);
		return hashCodeBuilder.toHashCode();

	}
 
Example 4
Source File: DeepOOState.java    From burlap with Apache License 2.0 4 votes vote down vote up
public DeepOOState(OOState srcOOState) {
	super();
	for(ObjectInstance o : srcOOState.objects()){
		this.addObject((ObjectInstance)o.copy());
	}
}
 
Example 5
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);

}