@model Segregation {
@uses ;			// We need this Swarm package
					// to store the grid

// Model parameters
@var: int citySize, numOfResidents, ratio, minAgeLimit, maxAgeLimit;
@var: float minLimit, maxLimit;

// The grid holding the agents
@var: id city;

// Parameter: whether to consider empty locations as friendly
@var: boolean emptyIsOK;

$import "resident.maml.stub";

@schedule cyclic (1) {
  0: @forEach groupOfResident step;	// The step method is to be called
  					// at each timestep of the model
  					// for each resident (agent).

  @sub: (void) createNewResident: (Resident) r {
  int color, x, y, age;
  float limit;

    color = [uniformIntRand getIntegerWithMin: 0 withMax: 100];
    if (color= maxLimit)		// This branch is needed because
      limit = minLimit;			// RNG does like if min=max
      limit = (float)[uniformDblRand getDoubleWithMin: (double) minLimit
                                           withMax: (double) maxLimit ];

    // Setting the maxAge parameter randomly in the given range    
    if (minAgeLimit >= maxAgeLimit)	// This branch is needed because
      age = minAgeLimit;		// RNG does like if min=max
      age = [uniformIntRand getIntegerWithMin: minAgeLimit
                                      withMax: maxAgeLimit];

    [r setColor: color maxAge: age AndLimit: limit];

    do {
      x = [uniformIntRand getIntegerWithMin: 0 withMax: (citySize-1)];
      y = [uniformIntRand getIntegerWithMin: 0 withMax: (citySize-1)];
    } while ([city getObjectAtX: x Y: y] != nil);      
    [r setX: x Y: y];

@var: [] Resident residents;


  @create Discrete2d city {
    [city setSizeX: citySize Y: citySize];

  if (numOfResidents > citySize*citySize)
    numOfResidents = citySize*citySize;

  @create [numOfResidents] Resident residents {
        [model createNewResident: residents[_i1_]];


ButtonReturn to Contents of this issue

© Copyright Journal of Artificial Societies and Social Simulation, 1999