MASON-INTEREST-L Archives

June 2005

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:
Sat, 11 Jun 2005 00:58:01 -0400
Content-Type:
text/plain
Parts/Attachments:
text/plain (44 lines)
On Jun 9, 2005, at 4:22 PM, glen e. p. ropella wrote:

> Does RandomSequence work for dynamic data structures?  It appears from
> the code:
[snip]
> that we're using a fixed size array.  And if that's the case, I'd have
> to recreate the RandomSequence at each cycle, thereby defeating the
> purpose.  But, perhaps I'm just not looking deep enough.  To resize an
> array, you'd have to replace the old Sequence instance variable with a
> new array (with the new size), right?

Right.  But remember that most of the utility Steppables (MultiStep,
Sequence, ParallelSequence, RandomSequence, WeakStep, etc.) are our
attempt to handle the 90% most common needs with some pre-built
Steppable classes that we found useful.  There's nothing special about
them.

If you want a resizable array, it's pretty easy to do if you're not
doing parallel threads, something like this:

public class BagSequence implements Steppable
        {
        public Bag steps;
        public Sequence(Bag steps)  // steps must be a Bag of Steppables only
                { this.steps = steps; }
        public void step(SimState state)
                {
                for(int x=0;x<steps.numObjs;x++)
                        {
                        Steppable s = ((Steppable)(steps.objs[x]);
                        if (s!=null) s.step(state);
                        }
                }
        }

The random shuffling version follows straightforwardly from there.
Note that you have to be careful here because if the Bag does not
contain Steppables, you'll get a ClassCastException.  Also, if you
change the Bag from within the step() method of something in the
BagSequence, it'd effect the for-loop of the step() method in
BagSequence in ways that you'd have to think carefully about.

Sean

ATOM RSS1 RSS2