Print

Print


>My model is working now, so thanks for all the suggestions so far. Still,
I would like a run to stop after 10 steps, this is a parameter that the
user can set in the UI, but I don't know how to pass it to the SimState...

Try changing this:
static void main(String[] args) throws Exception {
        SimState state = new SimulationEnvironment(System.currentTimeMillis());
        state.nameThread();
        doLoop(SimulationEnvironment.class, args);
        System.exit(0);}


Into:
static void main(String[] args) throws Exception {
        int stepsPerSimulation = 10;
        int numberOfSimulations = 20;



        for(int i=0; i< numberOfSimulations; i++){
            SimState state = new
SimulationEnvironment(System.currentTimeMillis());
            state.nameThread();
            state.start();
            for(int j=0; j< stepsPerSimulation; j++)
            {
                state.schedule.step(state);
            }
            state.finish();
        }}


Or something similar.

On Mon, Sep 1, 2014 at 7:18 PM, Simone Gabbriellini <
[log in to unmask]> wrote:

> Hello List,
>
> I wrote some emails in the past months, thanks for the suggestions. The
> fact is that I am translating a complex model from C to Mason, and the
> scheduling thing is the one that puzzled me the most.
> I think I have something more reliable now, which looks something like:
>
> static void main(String[] args) throws Exception {
>         SimState state = new
> SimulationEnvironment(System.currentTimeMillis());
>         state.nameThread();
>         doLoop(SimulationEnvironment.class, args);
>         System.exit(0);
> }
>
> and a start() method like:
>
> public void start() {
>         super.start();
>
>         marketSpace.clear();
>         // two Bag
>         capitalGoodFirms.clear();
>         consumptionGoodFirms.clear();
>
>         for (int i = 0; i < N1; i++) {
>             CapitalGoodFirm p = new CapitalGoodFirm();
>             p.setId(i);
>             marketSpace.setObjectLocation(p,
>                     new Int2D(random.nextInt(marketSpace.getWidth()),
>                             random.nextInt(marketSpace.getHeight())));
>             capitalGoodFirms.add(p);
>         }
>         for (int i = 0; i < N2; i++) {
>             ConsumptionGoodFirm p = new ConsumptionGoodFirm();
>             p.setId(i);
>             marketSpace.setObjectLocation(p,
>                     new Int2D(random.nextInt(marketSpace.getWidth()),
>                             random.nextInt(marketSpace.getHeight())));
>             consumptionGoodFirms.add(p);
>         }
>         // do some stuff just once
>         Initialize.initialize((SimulationEnvironment) this);
>         // what agents have to do at each step
>         schedule.scheduleRepeating(
>                 new Steppable() {
>                     @Override
>                     public void step(SimState state) {
>                         // this follows a bit the C structure I had, where
> different procedures
>                         // were called and each of the procedure called
> both agents types
>                         CallProcedureOne((SimulationEnvironment) state);
>                         CallProcedureTwo((SimulationEnvironment) state);
>                         ...
>                     }
>                 }, 0, 1);
> }
>
>  My model is working now, so thanks for all the suggestions so far.
> Still, I would like a run to stop after 10 steps, this is a parameter that
> the user can set in the UI, but I don't know how to pass it to the
> SimState...
>
> I understand that from command line I can specify the maximum steps and
> the number of jobs, like do this simulation 20 times and each of the runs
> stops after 10 steps. What I am missing now is: is it possible to stop from
> the UI the simulation after x steps?
>
> Thanks in advance for your help.
>
> Best,
> Simone
>
> --
> -----------------------------------------------------------------
>
> Simone Gabbriellini, PhD
>
> Post-doctoral Researcher
> ANR founded research project "DIFFCERAM"
> GEMASS, CNRS & Paris-Sorbonne.
>
> mobile: +39 340 39 75 626
> email: [log in to unmask]
>



-- 
Ernesto Carrella
http://carrknight.github.io/