swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: restarting runs


From: Rob Kewley
Subject: Re: restarting runs
Date: Mon, 14 Jul 1997 07:28:27 -0300

James Joseph Clark wrote:
> 
>  Does anybody have a suggestion as to a good way (or the "right way",
> if such a thing exists) of restarting (from the beginning) a
> simulation run (with either the same or different random number
> generator seed). I would like to be able to run my sim over and over
> again with different initial parameter settings. Currently, using the
> ObserverSwarm hacked from heatbugs, I have to kill the program and
> start it up again, with all of the attendent overhead.
> 
> Thanks
> 
> Jim
> address@hidden

One note on random number seeds.  If you reseed your random number
generator with the same seed as you used before, then rerun with the
same data, you will get exactly the same results.  If you reseed your
generator with a new seed, you may introduce a bias into your overall
results - the method of random number seed selection.  In most cases,
the best option is to simply seed the random number generator for at
startup and leave it alone thereafter.  

and Alex Lancaster wrote:
>I too, would be interested in such a beast! Having to quit and then re-run the
>app from the command line, all the time can be a bit of a drag! 

Sorry it took me a little while to answer these, but I have a model that
does just what Jim and Alex are asking.  Instead of dropping and
re-creating objects (an option) or messing with the control panel, I
simply reset my simulation objects to their  initial states, terminate
my dynamic schedule activity, remove all old actions from the dynamic
schedule, fill it with initial actions for the new iteration, then I
reactivate it in the model swarm.  Below  is my code for doing this.  It
all came from a method in my model swarm which checks termination
conditions for the simulation.

**********************
  ...

  if (terminate)  {  // if termination criteria are met

    // increment the iterations counter
    ++iterationsDone;

    // terminate and remove activities from the dynamic schedule
    //   this ensures that activities created for the last battle
    //   will not be executed in the next one.
    // NOTE: a repeating schedule would probably not require any
    //   manipulation for a new iteration.  Once all objects are reset,
    //   it can just keep on repeating.
    [getCurrentScheduleActivity() terminate];
    // based upon recent traffic on the swarm-support list, I probably
    //   need to put a [dynSchedule forEach: M(drop)] here
    [dynSchedule removeAll];

    // collect statistics
    [self collectStats];

    // if not complete with iterations, reinitialize objects
    if (iterationsDone < iterations) {

      [self reinitialize];
      [dynSchedule activateIn: self];

    ...

// Instead of dropping and recreating all simulation objects, this 
//   method simply resets their states to the initial state.  This
//   is most efficient for my simulation, but others may find it 
//   easier to simply drop and recreate all objects.
-reinitialize {

  FILE* initfile;   // file pointer for initialization for new battle

  // initialize the forces for restart
  initfile = fopen(REDINITFILE, "r");
  [redList forEach: M(initialize:): initfile];
  fclose(initfile);
  initfile = fopen(BLUEINITFILE, "r");
  [blueList forEach: M(initialize:): initfile];
  fclose(initfile);
 
  // Create initial actions for combatants
  [dynSchedule at: getCurrentTime() createActionForEach: combatantList 
                         message: M(move)];
  [dynSchedule at: getCurrentTime() createActionForEach: combatantList 
                         message: M(search)];
  [dynSchedule at: getCurrentTime() + (timeval_t) ENDCHECKINT 
                  createActionTo: self message: M(checkEnd)];    

  // clear the dead vehicle lists
  //   NOTE: I don't want to drop the objects on these lists.  I plan
  //           to use  the same objects for the next battle
  [deadRedList removeAll];
  [deadBlueList removeAll];

  // set combatants to appropriate colors
  [redList forEach: M(setColor:): (void*) 201];
  [blueList forEach: M(setColor:): (void*) 202];

}

Hope this helps.
Rob Kewley

                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.
                  ==================================


reply via email to

[Prev in Thread] Current Thread [Next in Thread]