com.rubecula.darwin.evolution
Class Evolution_Timed

java.lang.Object
  extended by net.sf.tostring0.AToString
      extended by com.rubecula.darwin.evolution.Evolver_
          extended by com.rubecula.darwin.evolution.Evolution_
              extended by com.rubecula.darwin.evolution.Evolution_Timed
All Implemented Interfaces:
com.rubecula.beanpot.Configurable, Evolution, Evolver, Timed, Clocked, java.lang.Runnable, net.sf.tostring0.IToString
Direct Known Subclasses:
Evolution_Calendar, Evolution_Standard

public abstract class Evolution_Timed
extends Evolution_
implements Timed

This abstract class extends the notion of an Evolution_ by adding the properties start, rate for continuously evolving processes [the Evolution_ class can be run in continuous evolution mode too but it doesn't really know about rate and start. Time properties for this class are real time. This class also allows for the scheduling of arbitrary future events in terms of real time. This class has a sub-class Evolution_Calendar which allows for evolution to be timed in non-real-time, for example geological time.

Author:
Robin Hillyard

Field Summary
protected  int rate
           
 
Fields inherited from class com.rubecula.darwin.evolution.Evolution_
_waitPeriod, MILLISECS_PER_SECOND
 
Fields inherited from class com.rubecula.darwin.evolution.Evolver_
LOG
 
Fields inherited from interface net.sf.tostring0.IToString
ANGBR_OPEN, ANGBRA_CLSE, BRA_CLSE, BRA_OPEN, BRCE_OPEN, BRCS_CLSE, COLON, LIST_SEPARATOR, MAX_ELEMENTS_DEFAULT, S_MT, S_PERCENT, SEPARATOR, SPACE
 
Constructor Summary
protected Evolution_Timed(boolean run)
           
protected Evolution_Timed(java.util.Calendar start, boolean run)
           
 
Method Summary
 int getRate()
           
protected  java.util.Calendar getStart()
           
protected  double getStartAdjustment()
          This gives us the adjustment (in milliseconds) to be applied to the actual start time, which takes into account any changes in rate along the way.
 java.util.Calendar getTime()
          Get the current time of this evolution
protected  java.util.Calendar getTime(int period, double quantity)
           
protected  boolean isRun()
           
 void run()
          First, stop any currently running tasks.
 void scheduleEvent(java.util.Calendar when, java.lang.Runnable event)
           
 java.util.concurrent.Future<?> scheduleEvent(long ticks, java.lang.Runnable event)
          Schedule an arbitrary event for execution after a specific number of milliseconds.
 void setRate(int newRate)
          Change the rate of ticking of this Timed object.
 
Methods inherited from class com.rubecula.darwin.evolution.Evolution_
cancelEvents, finalize, getClock, getElapsedTime, getEventExecutor, getEvolutionTask, getUi, isActive, isPaused, isWaitUntilComplete, next, pause, postConfigure, preConfigure, resume, setEvolutionTask, setUi, setWaitUntilComplete, shutdown, start, startAndWait, stop, stopExecutor, stoppable, waitUntilComplete
 
Methods inherited from class com.rubecula.darwin.evolution.Evolver_
addEvolvable, addEvolvable, addListener, addVisualizableListener, cleanup, getClockWatcher, getEvolvableKeys, getEvolvables, getListeners, getVisualizableListeners, init, putEvolvable, removeEvolvable, seedEvolvables, setClockWatcher, setEvolvables, setListeners, setVisualizableListeners, showTime, showTime
 
Methods inherited from class net.sf.tostring0.AToString
toString, toString, toStringBrief, toStringId
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.rubecula.darwin.evolution.Evolver
addEvolvable, addEvolvable, addListener, cleanup, getClockWatcher, getEvolvableKeys, init, removeEvolvable, seedEvolvables, setClockWatcher
 

Field Detail

rate

protected int rate
Constructor Detail

Evolution_Timed

protected Evolution_Timed(boolean run)
Parameters:
run - XXX

Evolution_Timed

protected Evolution_Timed(java.util.Calendar start,
                          boolean run)
Parameters:
start - XXX
run - XXX
Method Detail

getRate

public int getRate()
Specified by:
getRate in interface Timed
Returns:
the rate, i.e. the number of milliseconds between successive "ticks" for this Timed object, typically an Evolution.
See Also:
Timed.getRate()

getTime

public java.util.Calendar getTime()
                           throws EvolutionException
Get the current time of this evolution

Specified by:
getTime in interface Timed
Returns:
real time of this evolution
Throws:
EvolutionException
See Also:
Timed.getTime()

run

public void run()
First, stop any currently running tasks. Then start a new repeating task with parameters from getRate() and isRun(). Then, if Evolution_.isWaitUntilComplete() returns true, we invoke Evolution_.waitUntilComplete(int) with the value of #_waitPeriod. Thus, if you do not want to wait for the evolution to finish, simply invoke Evolution_.setWaitUntilComplete(boolean) with false before calling run.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class Evolution_
See Also:
Runnable.run()

scheduleEvent

public void scheduleEvent(java.util.Calendar when,
                          java.lang.Runnable event)
Parameters:
when -
event -

scheduleEvent

public final java.util.concurrent.Future<?> scheduleEvent(long ticks,
                                                          java.lang.Runnable event)
Description copied from interface: Evolution
Schedule an arbitrary event for execution after a specific number of milliseconds. The event will fire is scheduled independently of any new generations (and will run in a different thread). Typically, this will be used to change a property in the environment at a certain time. TODO consider implementing in such a way that we can specify a certain number of ticks (the ability to pause/resume makes this complex).

Specified by:
scheduleEvent in interface Evolution
Overrides:
scheduleEvent in class Evolution_
Parameters:
ticks - the number of ticks before the event is run.
event - the event to be run. NOTE that the number of ticks will not necessarily match the ticks of a running evolution because of pauses (which don't increment the tick number). TODO consider making the ticks correspond properly.
Returns:
the future which is returned by the scheduler for the event.
See Also:
Evolution_.scheduleEvent(long, java.lang.Runnable)

setRate

public void setRate(int newRate)
             throws EvolutionException
Description copied from interface: Timed
Change the rate of ticking of this Timed object.

Specified by:
setRate in interface Timed
Parameters:
newRate - the new rate, in milliseconds.
Throws:
EvolutionException
See Also:
Timed.setRate(int)

getStart

protected java.util.Calendar getStart()
Returns:
the moment that the start of evolution corresponds to. Typically this is the real time when evolution started, but in a simulation, it can be an arbitrary historical or future time.

getStartAdjustment

protected double getStartAdjustment()
This gives us the adjustment (in milliseconds) to be applied to the actual start time, which takes into account any changes in rate along the way. The formula for current evolutionary time is therefore _start + startAdjustment + Evolution_.getClock() * getRate().

Returns:
the startAdjustment

getTime

protected java.util.Calendar getTime(int period,
                                     double quantity)
Parameters:
period -
quantity -
Returns:
if quantity can be represented in terms of period in a Calendar object, then a new Calendar object, otherwise null.

isRun

protected boolean isRun()
Returns:
true if the evolution is to start immediately


Copyright © 2010 Rubecula Software, LLC. All Rights Reserved.