Print

Print


Hi Sean,


Thanks for your response. I didn't spot that Mason had a bag 
implementation. From reading the comments in the code it seems to be 
significantly faster than arrayLists.

Thanks

-Mike

Sean Luke wrote:
> 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.


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.