/* * * MAML TUTORIAL (Model 3) * For full description refer to * http://www.syslab.ceu.hu/maml/tutorial/ * * (c) 1998, CEU Systems Laboratory * */ @model m3 { @agent Competitor { @var: int row, distance; @sub: (void) jump { distance += [uniformIntRand getIntegerWithMin: 1 withMax: 3]; // generate random integers } } $define numOfRows: "10"; // a "macro" definition (like in C) @var: [] Competitor competitors; // an array of agents @schedule cyclic (1) { 0: @forEach groupOfCompetitor jump; // send the message to all of the } // agents, that is groupOfCompetitor @init: @create [numOfRows:i] Competitor competitors { // create an array of agents competitors[i] -> row = i; // use index i in initialization competitors[i] -> distance = 0; } } @observe m3 { // no name needed for observe @var: int row, distance; @sub: (void) searchForFront { int i; // standard C code (in fact ObjC) for (i=0; idistance > distance) { row = competitors[i]->row; distance = competitors[i]->distance; } } } @probe: var "row", var "distance"; @extendAgent Competitor { @probe: var "row", var "distance"; } @schedule cyclic (1) { 0: @to model searchForFront; // send message to model } @init: maxTimeSteps = 100; @buildProbes; @initModel; row = -1; distance = 0; [competitors[0] probe]; [model probe]; }