com.caplet.manna
Class GA

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Canvas
              |
              +--com.caplet.manna.GA
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class GA
extends java.awt.Canvas

The genetic algorithm itself. For speed purposes, the parameters that can be changed while the GA is running are public instance variables, rather than get/set bean properties.

Author:
Mark S. Miller, markm@caplet.com, Terry Stanley, tstanley@cocoon.com
See Also:
Serialized Form

Field Summary
 boolean amConsumed
          Is Manna consumed by the creatures that land on it?
 boolean amGray
          Do we encode position in binary or gray code?
 boolean amLocal
          Are closer creatures more likely to mate than more distant creatures? The alternative is that distance doesn't matter.
 boolean amUniform
          Uniform crossover means that for each bit position, a random determination is made as to which child gets dad's allele and which gets mom's allele.
 float myMutationRate
          How often is a bit flipped in one of the genomes?
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
GA()
          Creates and initializes a GA to default values.
 
Method Summary
 void addManna(int cx, int cy, int amount)
          Add a block of new manna at this position.
 void paint(java.awt.Graphics gfx)
          Show the manna and the creatures
 int popSize()
          What's the carrying capacity of the ecology?
 void setPopSize(int new_size)
          Changes the carrying capacity of the ecology
 void step(java.awt.Graphics gfx)
          Do one crossover operation.
 
Methods inherited from class java.awt.Canvas
addNotify, createBufferStrategy, createBufferStrategy, getAccessibleContext, getBufferStrategy, update
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

myMutationRate

public float myMutationRate
How often is a bit flipped in one of the genomes?

Defaults to 2%.


amGray

public boolean amGray
Do we encode position in binary or gray code?

Defaults to binary.


amUniform

public boolean amUniform
Uniform crossover means that for each bit position, a random determination is made as to which child gets dad's allele and which gets mom's allele.

The alternative is two point crossover, which treats the genome as a ring, cuts it at two random places, and swaps corresponding segments from mom & dad in order to make the two kids.

Defaults to uniform crossover.


amLocal

public boolean amLocal
Are closer creatures more likely to mate than more distant creatures? The alternative is that distance doesn't matter.

Defaults to no locality effect.


amConsumed

public boolean amConsumed
Is Manna consumed by the creatures that land on it?

Defaults to true.

Constructor Detail

GA

public GA()
Creates and initializes a GA to default values.

Method Detail

popSize

public int popSize()
What's the carrying capacity of the ecology?


setPopSize

public void setPopSize(int new_size)
Changes the carrying capacity of the ecology


step

public void step(java.awt.Graphics gfx)
Do one crossover operation. Occasionally also mutate according to the mutation rate. note: not synchronized for efficiency. Call only with lock held


paint

public void paint(java.awt.Graphics gfx)
Show the manna and the creatures

Overrides:
paint in class java.awt.Canvas

addManna

public void addManna(int cx,
                     int cy,
                     int amount)
Add a block of new manna at this position.