/* * * HEATBUGS in MAML * (c) 1998, CEU Systems Laboratory * * This simulation is based on the following model: * * Heatbugs application. Copyright (C) 1996 Santa Fe Institute. * This library is distributed without any warranty; without even the * implied warranty of merchantability or fitness for a particular purpose. * See file LICENSE for details and terms of copying. * */ // The simple agent of the model @agent Heatbug { @uses ; // We need this Swarm // package as Grid2d is // there (check out the // variable storing the // reference to the world // the state of the agent @var: double unhappiness; // my current unhappiness @var: int x, y; // my spatial coordinates @var: HeatValue idealTemperature; // my ideal temperature @var: HeatValue outputHeat; // how much heat I put out @var: float randomMoveProbability; // chance of moving randomly // devices to its environment @var: Grid2d world; // the world I live in @var: HeatSpace heat; // the heat for the world // for programmers only (helps in optimizing the code) @var: int worldXSize, worldYSize; // how big the world is // Setting the named parameters (at initialization) @sub: (void) setWorld: (Grid2d) w Heat: (HeatSpace) h { world = w; heat = h; } // End of create phase. Finishes the initialization @sub: (id) createEnd { worldXSize = [world getSizeX]; worldYSize = [world getSizeY]; return self; } // Setting the named parameters @sub: (void) setIdealTemperature: (HeatValue) i { idealTemperature = i; } @sub: (void) setOutputHeat: (HeatValue) o { outputHeat = o; } @sub: (void) setRandomMoveProbability: (float) p { randomMoveProbability = (float) p; } @sub: (void) setX: (int) inX Y: (int) inY { x = inX; y = inY; // Administrate it on the global (model level) grid [world putObject: self atX: x Y: y]; } // Making a step @sub: (void) step { HeatValue heatHere; int newX, newY; int tries; // Calculating local values (heat/unhappiness) heatHere = [heat getValueAtX: x Y: y]; unhappiness = ( (heatHere