vsTASKER 7 User Manual
×
Menu
Index

Batch

 
A Batch object manages a set of simulation runs for a given scenario, changing input variables and analyzing outputs to adjust inputs for a search of optimum or specific goals.
Batch objects can be linked together to perform various processes.
Optimization strategies are not the only use for batches, hundreds or thousands of runs of a single scenario can prove some outcomes in spite of the numerous stochastic models included in the simulation.
A Batch object is persistent compared to the Scenario object. It contains variables that persists the run (start-stop) of a scenario.
These variables can then store or accumulate data for later use or statistics.
It is not the Batch itself that start and stop a given scenario. The RTC is first ticking the current Batch (runtime part) then starts the associated Scenario. From inside the Scenario, the current (or any other) Batch can be retrieved to store or read any of its (persistent) variables. Reading some variables might be used to configure the scenario accordingly to computations or assumptions made in the Batch itself. Writing values to Batch variables will be done during the course of the scenario or at the end for subsequent analysis.
The Scenario must stop itself ! The RTC nor the Batch won't interrupt a scenario run. It is mandatory to implement inside the scenario a condition for stopping it. This condition can be put into a Logic attached to the Scenario Player.
Batches are raw mechanism to perform data analysis like gradient base searches or heuristic methods. It is up to the user to implement such mechanisms in the batch themselves.
 
 
In this sample, we will run a batch that will start in sequence 5 scenarios. Each scenario creates an arbitrary number of entities, specified by the batch, then waits for 15 seconds and terminates.
When a scenario ends, the batch is reactivated and cycle again.
 
First, we create the batch object:
 
 
 
 Then, we open its property windows and rename it "myBatch" and make it active: .
 
We set 5 runs.
In Variable panel, we declare the number of entities to create by each scenario:
 
In the Runtime panel, we put this code:
printf("Run %d\n", cIter());
nb_entities = RANDOM(1,10);
Sleep(1000); // to give GUI some time to clean up
 
Note that Batch Mode is enabled and visible on the terrain map:
 
Now, we are ready to setup a scenario that will extract from the batch the number of entities to create, then terminates.
For that, we creates a logic that will be given to the player.
For Action createEntities:
 
 myBatch_BatDef* batch = (myBatch_BatDef*) R:batchs->find("myBatch");
 if (batch) {
    printf("Scenario creates %d entities\n", batch->nb_entities);
    for (int i=0; i<batch->nb_entities; i++) {
       WCoord pos;
       pos.setRandom(300);
       new Entity("default", pos);
    }
 }
 
For Action Terminates:
 
  if (condition == true) {  // condition == whatever decides when to stop
    puts("Scenario stops!");
    R:stop();
 }
 
 
Generate the simulation engine and run.
The console will display:
 
Start the simulation from the GUI, then display the Batch symbol in Environment::Analysis.
The current cIter() value (current run number) is displayed in parenthesis right to the batch name.
 
Terrain map will display random entities created at each run, for 15 seconds.
 
To stop a Batch run, using the button only terminates the current scenario but the batch will restart it until all runs expire or if the Runtime part returns QUIT.
To force the batch mode to terminate, use the Detach option:
A simple way to stop scenario execution is to use the Code::Runtime part of the Scenario or by giving a Logic to the Scenario Player. In all situations, when the exit condition occurs, the following code will force the scenario run to stop: R:stop(); 
The Exit Condition, called every second, can also be used to stop a scenario and iterates the batch object.
 
 
scen() or S: is a macro that returns a pointer to the Scenario instance.
R: is a macro that returns a pointer to the Runtime Controller (Vt_RTC).