Print

Print


On Jul 16, 2014, at 6:19 AM, Simone Gabbriellini <[log in to unmask]> wrote:

> I have an old simulation in C and I am trying to port it in MASON. I have two types of agents, say A and B. Now, each of these agents has to to run different procedures, say procedure1 and procedure2 (I have many more...). My point is: how to schedule right this logic in MASON?

So in short you have two kinds agents which must each call a certain procedure, and this must all be done within a certain timestep, and the A agents must all be before the B agents for each procedure.  This would be done using (1) anonyomous steppables [or if you must, sim.engine.MethodStep] and (2) the "ordering" facility in the schedule.  You'd do this in your start() method:

for(each agent of type A)
	{
	final AgentA a = agent;
	state.scheduleRepeating(
		new Steppable() { public void step(SimState state) a.procedure1(); } }, 
		0, 1);
	}

for(each agent of type B)
	{
	final AgentB b = agent;
	state.scheduleRepeating(
		new Steppable() { public void step(SimState state) b.procedure1(); } }, 
		1, 1);
	}

for(each agent of type A)
	{
	final AgentA a = agent;
	state.scheduleRepeating(
		new Steppable() { public void step(SimState state) a.procedure1(); } }, 
		2, 1);
	}

for(each agent of type B)
	{
	final AgentB b = agent;
	state.scheduleRepeating(
		new Steppable() { public void step(SimState state) b.procedure1(); } }, 
		3, 1);
	}

> My main so far is:
> 
> public static void main(String[] args) {
>         // main loop for the model
>         SimState state = new SimulationEnvironment(System.currentTimeMillis());
>         state.nameThread();
>         for (int job = 0; job < MC; job++) { // MC is the number of runs
>             state.setJob(job);
>             state.start();
>             do
>                 if(!state.schedule.step(state)) break;
>             while(state.schedule.getSteps() < T); // T is the steps limit for a single run
>             state.finish();
>         }
>         System.exit(0);
>     }

Why are you doing a main?  Why not just use doLoop?

> BTW: my agents are on a SparseGrid2D, when I retrieve them should I randomize their order or is it done automagically somewhere?

SparseGrid2D is a representation of space.  It has nothing to do with the schedule, which is a representation of time.  So it won't make any difference.

Sean