Hi Rick,

Here's how I get my sim to stop.  It's based on advice from Sean Luke:

1.  In the start method of the main simulation include something along the lines of the following:

        // create a multistep to end the simulation after
        // maxnumberOfTrades
        Steppable endSim = new MultiStep(new KillSteppable(), 
                numberOfPeriods*numberOfDays+1, true);

        

Where in the above case you want it to stop at tick numberOfPeriods*numberOfDays+1

2.  Then add the following method to the main simulation:

    /**
     * Class to end the simulation.
     * KillSteppable ends the simulation.
     * 
     */
    public class KillSteppable implements Steppable
    {
    public void step(SimState state)
        {
        state.kill();
        }
    }

I've found this approach to be very reliable for ending the sim.  You may want to look at the following discussions from the archives about stopping and also about stopping when you're charting.

https://listserv.gmu.edu/cgi-bin/wa?A2=ind0610&L=MASON-INTEREST-L&P=R1477&I=-3&X=46326478930E1C3069&Y=mcbridme%40muohio.edu

https://listserv.gmu.edu/cgi-bin/wa?A2=ind0612&L=MASON-INTEREST-L&P=R106&I=-3&X=46326478930E1C3069&Y=mcbridme%40muohio.edu

I've also found Steve Railsback StupidModels useful for getting started.

http://condor.depaul.edu/~slytinen/abm/StupidModel/

Hope this helps.

Mark

Mark E. McBride
Professor                                       Department of Economics
Director of Graduate Studies     208 Laws Hall
513 529-2864                               Miami University
[log in to unmask]      Oxford, OH 45056
http://mcbridme.sba.muohio.edu/


On Apr 15, 2007, at 5:21 AM, Rick wrote:

Hello,

My main question is how do you stop a schedule.scheduleRepeating()?? or is there something better to use for what i want to do??

I am new to MASON and agent based programming in general, so I am sorry if this is a basic problem but I have spent about 12 hours almost straight on this now and have not got anywhere :-(

What I want to do is run a simulation until a flag = true store that result and then run the same simulation again (x number of times). Preferably with the results at the end of each simulation being displayed in a chart. (simulations could run one after another or all together should not matter that much, would maybe like to have an option for either though if one is not a lot more complex than the other.

The problem I am getting at the moment is stopping the schedule.scheduleRepeating() I just cant do it! think i have tried everything but it does not seem to stop.

I have included part of my code so you can see what I am trying to do better:

/*** MODEL CLASS ***/

public void start()
       {
           super.start();            grid = new IntGrid2D(N, N);
           grid = new IntGrid2D(gridWidth, gridHeight);
         NKSpace_Gen nkGen = new NKSpace_Gen(System.currentTimeMillis());
        nkGen.Build_Space();
        nkGen.printAllFiles();

*// ** I basically want to get this **bit below **to repeat x number of time and then get it to stop when the agent flags a variable in the agents step method to be true ***

        Agent agent1 = new Agent(System.currentTimeMillis());
        agent1.selectPoint();
        agent1.getOneMutantNeighbours();

        schedule.scheduleRepeating(agent1);
}

/*** AGENT CLASS ***/

   public void step(SimState state)
   {
       if (mutantNeighbours.numObjs > 0 && higherFitness == false)
       {
           walkLandscape();
             if (higherFitness == true)
           {
               higherFitness = false;
               getOneMutantNeighbours();
           }
       }
       else
       {
           System.out.println(" Higher Fitness Values Found ");
           System.out.println("Fitness Value: "+ localPeak);
           peakFound = true;            *//** this is where I set peakFound to true and where I want to store the localPeak value and stop that agent at present it just keeps printing the two system.out.println to the console forever. (note they are only there for debug I actually will have a graphics showing the values. *
       }
             if (peakFound == false)
       {
       System.out.println("*** Current Fitness Searched ***");
       System.out.println("Fitness Value: "+ currentFitness);
             }
    }

ANY HELP or comments would be MUCH APPRECIATED!!

Many Thanks

Rick