uchicago.src.repastdemos.genetic
Class GeneticChangeModel

java.lang.Object
  extended by uchicago.src.sim.engine.SimModelImpl
      extended by uchicago.src.sim.engine.SimpleModel
          extended by uchicago.src.repastdemos.genetic.GeneticChangeModel
All Implemented Interfaces:
DescriptorContainer, SimEventProducer, SimModel

public class GeneticChangeModel
extends SimpleModel

This demo illustrates the use of the genetic algorithm package in an agent. The premise of this model is that there is a simple competition where the competitors must make a particular amount of change with the least amount of coins possible. Each step a judge will judge the competitors based on the number of coins they used and the total change they have. For example, if the goal amount is $0.79, an agent should have 3 quarters and 4 pennies.

The number of coins the competitor has is determined by a genetic algorithm. This is a simple example, but shows the way in which the GA can be incorporated into an agent, and the procedures neccessary to have the GA work. Even with a small initial genetic pool the GA finds the correct solution usually in the first few ticks.

When a competitor performs the correct action she moves towards the center of the display.

Version:
$Revision: 1.1 $ $Date: 2005/08/12 20:04:55 $
Author:
Jerry Vos

Field Summary
protected  CompetitionSpace space
           
 
Fields inherited from class uchicago.src.sim.engine.SimpleModel
agentList, autoStep, isGui, name, params, schedule, seed, shuffle, startAt
 
Fields inherited from class uchicago.src.sim.engine.SimModelImpl
descriptors, modelManipulator
 
Constructor Summary
GeneticChangeModel()
           
 
Method Summary
 void begin()
          Begins a simulation run.
protected  void buildDisplay()
          This builds the display surface for the competition
 int getCompetitorCount()
           
 double getGoalAmountInDollars()
           
 java.lang.String[] getInitParam()
          Gets the names of the initial model parameters to set.
 java.lang.String getName()
          Gets the name of this model.
 int getSpaceHeight()
           
 int getSpaceWidth()
           
static void main(java.lang.String[] args)
           
protected  void postStep()
           
protected  void preStep()
           
 void setCompetitorCount(int employeeCount)
           
 void setGoalAmountInDollars(double goalAmountInDollars)
           
 void setSpaceHeight(int officeHeight)
           
 void setSpaceWidth(int officeWidth)
           
 void setup()
          Sets up the model for the next run, clears out all the old employees and the old displays
protected  void step()
           
 
Methods inherited from class uchicago.src.sim.engine.SimpleModel
atEnd, atPause, buildModel, buildSchedule, getNextDoubleFromTo, getNextIntFromTo, getSchedule, run, runAutoStep, setRngSeed, setStoppingTime, setStoppingTime
 
Methods inherited from class uchicago.src.sim.engine.SimModelImpl
addPropertyListener, addSimEventListener, clearMediaProducers, clearPropertyListeners, fireBooleanPropertyEvent, fireEndSim, fireNumericPropertyEvent, fireObjectPropertyEvent, firePauseSim, fireSimEvent, fireStopSim, fireStringPropertyEvent, generateNewSeed, getController, getMediaProducers, getModelManipulator, getParameterDescriptors, getPropertiesValues, getRngSeed, getTickCount, pause, registerDisplaySurface, registerMediaProducer, removePropertyListener, removeSimEventListener, setController, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

space

protected CompetitionSpace space
Constructor Detail

GeneticChangeModel

public GeneticChangeModel()
Method Detail

getInitParam

public java.lang.String[] getInitParam()
Description copied from interface: SimModel
Gets the names of the initial model parameters to set. These names must have get and set methods supplied by the model. For example, for the parameter maxAge, the model must have getMaxAge and setMaxAge methods.

Specified by:
getInitParam in interface SimModel
Overrides:
getInitParam in class SimpleModel
Returns:
a String[] of the initial parameter names

begin

public void begin()
Description copied from interface: SimModel
Begins a simulation run. All initialization, building the model, diplay, etc. should take place here. This method is called whenever the start button (or the step button if the run has not yet begun) is clicked. If running in batch mode this is called to kick off a new simulation run.

Specified by:
begin in interface SimModel
Overrides:
begin in class SimpleModel

buildDisplay

protected void buildDisplay()
This builds the display surface for the competition


setup

public void setup()
Sets up the model for the next run, clears out all the old employees and the old displays

Specified by:
setup in interface SimModel
Overrides:
setup in class SimpleModel

preStep

protected void preStep()
Overrides:
preStep in class SimpleModel

step

protected void step()
Overrides:
step in class SimpleModel

postStep

protected void postStep()
Overrides:
postStep in class SimpleModel

getName

public java.lang.String getName()
Description copied from class: SimpleModel
Gets the name of this model.

Specified by:
getName in interface SimModel
Overrides:
getName in class SimpleModel
Returns:
the name of the model/simulation

getCompetitorCount

public int getCompetitorCount()
Returns:
Returns the number of employees in the office.

setCompetitorCount

public void setCompetitorCount(int employeeCount)
Parameters:
employeeCount - The number of employees in the office.

getSpaceHeight

public int getSpaceHeight()
Returns:
returns the officeHeight

setSpaceHeight

public void setSpaceHeight(int officeHeight)
Parameters:
officeHeight - the officeHeight

getSpaceWidth

public int getSpaceWidth()
Returns:
returns the officeWidth

setSpaceWidth

public void setSpaceWidth(int officeWidth)
Parameters:
officeWidth - the officeWidth

getGoalAmountInDollars

public double getGoalAmountInDollars()
Returns:
Returns the goalAmountInDollars.

setGoalAmountInDollars

public void setGoalAmountInDollars(double goalAmountInDollars)
Parameters:
goalAmountInDollars - The amount the agents are going for.

main

public static void main(java.lang.String[] args)