Link them together and run the simulation

Example with two Netlogo random walk models

The models used are a simple random walk where, for each simulation step, agents (so-called walkers) choose a random direction and step forward. In our example, the walker can go from one model to another. That is, we define one boundary in each model, when a walker cross that boundary, it is sent to the other model.

The Netlogo models specifications available here and here. The exchanged data will be here the walkers positions (x,y) and the walker ID.  The output port of one model is linked to the input of the other.

random walk example 2

Make them work together

Now that we have created all the needed entities (two model-artefacts, two model-agents and two coupling-artefacts), the last thing to do is to link them together and to run the simulation process.

We have to make a main class in which we create an instance of the model-agent 1, the model-artefact-1, the right coupling-artefact ports as said previously. We do this twice (for the model 1 and for the model 2). As a consequence we have two main procedures we can launch into two separate JVMs. Both programs will interact through their coupling-artefacts (i.e. JMS platform). (Get the code)

public class TestModel2 {

   @param args
  public static void main(String[] args) {

    // create the agent model
    RandomWalkModelAgent2 agent2 = new RandomWalkModelAgent2();

    // create the model artifact and link it with the agent
    RandomWalkModelArtefact2 modelArtefact2 = new RandomWalkModelArtefact2(

    // link agent and model artifact

    // create the coupling artifacts and link them with the agent

    // output port (linked with agent 2)
    OPCA_ExchangedTurtles1 et_opca2 = new OPCA_ExchangedTurtles1(

    // input port (linked with agent 2)
    IPCA_ExchangedTurtles2 et_ipca2 = new IPCA_ExchangedTurtles2(

    // link

    // agent 2 with the coupling artifact ports


    // initialize, post ouptuData and execute the model