September 2006


Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

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

Print Reply
Sean Luke <[log in to unmask]>
Reply To:
MASON Multiagent Simulation Toolkit <[log in to unmask]>
Sat, 2 Sep 2006 20:25:43 -0400
text/plain (96 lines)
A great many agents have multiple phases -- one really common  
situation is for all your agents to READ the world and then all of  
them (in random order) to CHANGE the world, so you have a READ phase  
and a WRITE phase for each agent.  Of course, there are plenty of  
other approaches too.

The problem you're discovering is that Steppables only have one step 
() method.  This was intentional; it reduces complexity of the system  
internally.  So how do you schedule an agent to, say, have its read()  
method called at one time and its write() method to be called at a  
different time?  Easy: just use closures.  Let's say your agent is  
stored in a local variable called 'myAgent' and is of the class, erm,  
'Agent'.  And you want it scheduled repeating with read() happening  
in ordering 0 and write() happening in ordering 1, every timestep.   
Then you could do this:

final Agent ag = myAgent;
schedule.scheduleRepeating(new Steppable() { public void step()  
{; } }, 0);
schedule.scheduleRepeating(new Steppable() { public void step()  
{ ag.write(); } }, 1);


On Aug 31, 2006, at 11:03 AM, Michael Lees wrote:

> Hi all,
> I seem to writing a lot of emails with suggestions and questions.  
> Hopefully I'll be able to contribute answers soon.
> Anyway,
> For the purposes of my simulation I've designed a new type of  
> steppable which has a phase. The design is not particularly elegant  
> so I was wondering if there is a correct way of doing what I'm  
> attempting.
> Basically the way I've understood and learnt mason is that agents  
> are steppables. You implement an agent by extending some form of  
> steppable. You then schedule the agent and perhaps repeat the step  
> every time-step. So say you have n agents the schedule at each time- 
> step looks like:
> [a_1,a_2,...,a_n]
> Where a_i is the step method of agent i.
> What I want to be able to do is basically split the step method of  
> each agent in a single time-step, so we have the agent i has two  
> step methods a_i and a'_i.
> This would allow to have a repeatable schedule as...
> [a_1,a_2,...,a_n, b, a'_1,a'_2,...,a'_n]
> Where b is some other form of steppable.
> The steppable would then have a flag which indcates the current  
> 'phase' of the agent and which flipped on each call to step. The  
> invocation of step would call a different step method (a_i or a'_i)  
> according to the current value of the flag or 'phase'. (This could  
> be generalised to n phases)
> You would then schedule the agent in the same schedule multiple  
> times at different orderings to achieve the desired affect.
> ie.,
> schedule.scheduleRepeating(a_i,1,1.0d);
> schedule.scheduleRepeating(b,2,1.0d);
> schedule.scheduleRepeating(a_i,3,1.0d);
> So I thought about it some more and I wasn't sure if I was thinking  
> about steppables in the correct way. You can think of steppables as  
> events rather than agents? So rather than implementing your agent  
> by extending steppable, the agent contains steppables which  
> represent the events the agent can schedule. This way seems cleaner  
> and slightly more natural to me, but I wasn't sure which way I  
> should think about steppables. I have currently implemented the  
> former but was thinking about changing.
> Thanks
> -- 
> Mike
> This message has been checked for viruses but the contents of an  
> attachment
> may still contain software viruses, which could damage your  
> computer system:
> you are advised to perform your own checks. Email communications  
> with the
> University of Nottingham may be monitored as permitted by UK  
> legislation.