2

I have an agent called truck, which will perform some actions (e.g. loading packages). The problem here is related to the random sequence of agents executing actions. For instance, suppose I have three trucks, the loading sequence is random at each different run.

Run-1: truck-1, truck-3, truck-2
Run-2: truck-2, truck-1, truck-3
Run-3: truck-3, truck-1, truck-2
...

How to make sure the agent(truck) executing actions based on a sequence, e.g. by their id so that we can always get the consistant result from the simulation.

Run-1: truck-1, truck-2, truck-3
Run-2: truck-1, truck-2, truck-3
Run-3: truck-1, truck-2, truck-3
...
Jack
  • 1,131
  • 1
  • 8
  • 17

1 Answers1

3

There's at least 3 ways to do this.

  1. If you set the random seed, the order of the trucks should be the same across runs, all other things being equal. It most likely won't be ordered by id, but it should be the same.

  2. Add all the trucks to an ArrayList when they are created. Sort this list by id and each tick of the simulation iterate through this list, executing the truck action on each truck. A quick google should show you how to order a Java List using a Comparator.

  3. Adapt the scheduling to reflect truck id - for example, truck 1 executes at 1.0 and every tick thereafter, truck 2 at 1.1 and every tick thereafter, truck 3 at 1.2, and so on.

  4. A kind of variation on 3. Set the scheduling priority by id -- all the trucks could execute at 1.0 and every tick thereafter, but with truck 1 having the highest priority, truck 2 the next, and so on.

As a side note, the random iteration of the items in a schedule is the default to prevent common ABM behavior execution ordering issues, such as first mover advantage.

Nick Collier
  • 1,239
  • 7
  • 9