MASON-INTEREST-L Archives

July 2015

MASON-INTEREST-L@LISTSERV.GMU.EDU

Options: Use Proportional Font
Show HTML Part by Default
Condense Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Mime-Version:
1.0
Sender:
MASON Multiagent Simulation Toolkit <[log in to unmask]>
Subject:
From:
Stewart Aitken <[log in to unmask]>
Date:
Thu, 30 Jul 2015 15:16:52 -0400
Message-ID:
Content-Type:
multipart/mixed; boundary="part-A9M6y8uYbnOx0mEKV8zo98XbVaSY33AAAndPHfCAy2igI"
Reply-To:
MASON Multiagent Simulation Toolkit <[log in to unmask]>
Parts/Attachments:
text/plain (2718 bytes) , one.png (2747 bytes) , two.png (2664 bytes) , three.png (2753 bytes)
I have a simple agent spawning a child in an Object2Dgrid and I am having difficulty overcoming an issue that can be seen in the three pictures.
One is the run and when it occupies the next space I expect it to stop.
Two is the space occupied and Three is two steps later when the agent has teleported through the occupied cell and spawned once again.
Here is a copy of the Agent code.
Any advice will be gratefully received.

Kind regards 
Stewart Aitken

package sim.alg1;

import sim.engine.SimState;
import sim.engine.Steppable;
import sim.field.grid.Grid2D;
import sim.field.grid.ObjectGrid2D;
import sim.util.Bag;
import sim.util.Int2D;
import sim.util.IntBag;

/**
 * Created by Your PC on 14/06/2015.
 */
public class Agent implements Steppable {
    public static final int gridWidth = 12;
    public static final int gridHeight = 10;

    private int myX, myY, nextX, nextY;
    private double age;
    
    // This constructor for offspring
    public Agent(){
        age = 0.0;
    }

    public Agent(SimEnviro theModel) {
        placeFirstAgent(theModel);
        age = 1.0;
    }

    public void placeFirstAgent(SimEnviro theModel) {
        ObjectGrid2D mySpace = theModel.getAgentSpace();

		do {
			myX = theModel.random.nextInt(gridWidth);
			myY = theModel.random.nextInt(gridHeight);
		}
		
        while (mySpace.field[myX][myY] != null);
        mySpace.field[myX][myY] = this;
    }

    public void step(SimState state) {

    public void replicate(SimState state) {
        SimEnviro theModel = (SimEnviro) state;
        Bag theAgents = theModel.getAgents();

        ObjectGrid2D mySpace = theModel.getAgentSpace();
        
        Bag vNObjects = new Bag(4);
        IntBag xNeighbors = new IntBag(4);
        IntBag yNeighbors = new IntBag(4);

   		mySpace.getVonNeumannNeighbors(myX, myY, 1, Grid2D.BOUNDED, false, vNObjects, xNeighbors, yNeighbors);

   		
        int len = xNeighbors.size();
        for (int i=0; i<len; i++) {
            Agent child = new Agent();
                nextX = mySpace.tx(xNeighbors.get(i));
                nextY = mySpace.tx(yNeighbors.get(i));
                if (mySpace.field[nextX][nextY]== null) {
                	System.out.print(" nextX = " + nextX);
                	System.out.println(" : NextY = " + nextY);
                    mySpace.field[nextX][nextY] = child;
                    child.myX = nextX;
                    child.myY = nextY;
                    theAgents.add(child);
                    break;
                }
        		
            } myX = nextX; myY = nextY; age++;
    }

	private void checkIfFinished(Bag theAgents) {
		// TODO Auto-generated method stub
		
	}
}





ATOM RSS1 RSS2