MASON-INTEREST-L Archives

April 2006

MASON-INTEREST-L@LISTSERV.GMU.EDU

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
Subject:
From:
Sean Luke <[log in to unmask]>
Reply To:
MASON Multiagent Simulation Toolkit <[log in to unmask]>
Date:
Tue, 4 Apr 2006 16:04:21 -0400
Content-Type:
text/plain
Parts/Attachments:
text/plain (55 lines)
Hi Michael.  MASON doesn't have these built-in, but the following  
should do the trick. This is a place where Bag significantly
outperforms ArrayList. Note that if you're using ParallelSequence or
AsynchronousSteppable, you don't want to add objects to the list from
within those threads as it'd create a race condition that's not
checked for in the code below.

Sean

public class ExpandableSequence implements Steppable
{
public Bag steps;

public ExpandableSequence(Bag steps) { this.steps = steps; }
public ExpandableSequence() { this.steps = new Bag(); }
public ExpandableSequence(Steppable[] steps) { this.steps = new Bag
(steps); }
public void step(SimState state)
{
for(int x=0;x<steps.numObjs; x++)
((Steppable)(steps.objs[x])).step(state);
}
}


public class RandomExpandableSequence extends ExpandableSequence
{
public RandomExpandableSequence(Bag steps) { super(steps); }
public RandomExpandableSequence() { super(); }
public RandomExpandableSequence(Steppable[] steps) { super(steps); }

public void step(SimState state)
{
synchronized(state.random)
{ steps.shuffle(state.random); }
super.step(state);
}
}


On Apr 4, 2006, at 11:04 AM, Michael Lees wrote:

> Hi,
>
> This is my first post to the list, I've been using mason for a few
> weeks now.
>
> I'm using the Sequence class but have found the steps array
> inflexible in terms of adding new Steppables during execution.
>
> I've implemented an ExpandableSequence which uses an arrayList
> rather than an array. I was wondering if something already exists
> for this? I might use RandomSequence at some point, which would
> mean re-implementing RandomSequence to extend ExpandableSequence.

ATOM RSS1 RSS2