|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.sf.tostring0.AToString
com.rubecula.darwin.evolution.Evolver_
com.rubecula.darwin.evolution.Evolution_
public abstract class Evolution_
This class is the base implementation of the Evolution_ interface. It is what
drives the evolution of a set of Evolvable objects. That is to say
that it drives the running of a genetic algorithm, or genetic program.
It can run in automatic mode (initiated by a call to
start(int, boolean), or in manual mode (steps, each invoked by
calling next().
Although not a singleton in the strict sense, there will normally only be one
of these objects.
FIXME application does not terminate cleanly when the rate of evolution is
too fast (the evolution terminates appropriately but a task is left hanging
so that the JVM doesn't release the executable).
| Field Summary | |
|---|---|
protected static int |
_waitPeriod
Period between checks to see if the run method has completed (in milliseconds). |
static int |
MILLISECS_PER_SECOND
1000 |
| 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_()
|
| Method Summary | |
|---|---|
protected boolean |
cancelEvents()
TEST |
protected void |
finalize()
|
long |
getClock()
|
static java.lang.String |
getElapsedTime(long millisecs)
Method to create a String which appropriately represents the accuracy of the elapsed time. |
protected java.util.concurrent.ScheduledExecutorService |
getEventExecutor()
|
protected EvolutionTask |
getEvolutionTask()
|
protected java.lang.Object |
getUi()
TEST |
boolean |
isActive(boolean ignoreEvents)
|
boolean |
isPaused()
|
protected boolean |
isWaitUntilComplete()
|
boolean |
next()
Create a new EvolutionTask and run it. |
void |
pause()
TEST |
void |
postConfigure(java.lang.Object data)
Do nothing - override if you need something doing |
void |
preConfigure(java.lang.Object data)
Method to pre-configure the Evolution object when it is used as part of an application, as opposed to being in an applet. |
void |
resume()
TEST |
void |
run()
By default, the run method for an Evolution_ object starts the evolution going at the rate of one tick per second. |
java.util.concurrent.Future<?> |
scheduleEvent(long millisecs,
java.lang.Runnable event)
Schedule an arbitrary event for execution after a specific number of milliseconds. |
protected void |
setEvolutionTask(EvolutionTask evolutionTask)
|
void |
setUi(java.lang.Object ui)
Called by reflection (during configuration). |
void |
setWaitUntilComplete(boolean waitUntilComplete)
Called by reflection (during configuration). |
boolean |
shutdown()
A terminal shut-down of the Evolution process (including both evolution and scheduled events). |
protected void |
start(int rate,
boolean run)
This method starts a new evolution with generations potentially occurring at given rate (in milliseconds) [a particular Evolvable object
might not undergo a new generation for every "tick" of this evolutionary
clock.]
The result of calling
ScheduledExecutorService.scheduleAtFixedRate(Runnable, long, long, TimeUnit)
results in a new thread being started with the name formed from
EvolutionThreadFactory#namePrefix, space and a sequence number. |
protected void |
startAndWait(int rate,
boolean run,
boolean stopFirst)
|
boolean |
stop()
XXX the following comment seems totally wrong. |
protected boolean |
stopExecutor(java.util.concurrent.ScheduledExecutorService executor,
int timeoutSeconds)
Shutdown the given executor and wait for the tasks to terminate |
boolean |
stoppable()
|
boolean |
waitUntilComplete(int delay)
Wait for this Evolution to become inactive, then return. |
| 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 |
|---|
public static final int MILLISECS_PER_SECOND
protected static int _waitPeriod
| Constructor Detail |
|---|
protected Evolution_()
| Method Detail |
|---|
public static java.lang.String getElapsedTime(long millisecs)
millisecs -
public long getClock()
getClock in interface ClockedgetClock in class Evolver_
public boolean isActive(boolean ignoreEvents)
throws EvolutionException
isActive in interface EvolutionignoreEvents - XXX
EvolutionExceptionEvolution.isActive(boolean)public boolean isPaused()
isPaused in interface EvolutionEvolutionTask.isPaused() returns true for the
evolutionTask (if evolutionTask is null then
return true.
XXX is this OK?EvolutionTask.isPaused()
public boolean next()
throws EvolutionException
EvolutionTask and run it. This method has works
quite differently in the two different modes (manual versus auto). When
this Evolution is in auto mode, we is intended for manual
stepping of the evolutionary process.
next in interface Evolvernext in class Evolver_EvolutionExceptionEvolver.next()
public void pause()
throws EvolutionException
pause in interface EvolutionEvolutionExceptionEvolution.pause()public void postConfigure(java.lang.Object data)
Evolver_
postConfigure in interface com.rubecula.beanpot.ConfigurablepostConfigure in class Evolver_Evolver_.postConfigure(java.lang.Object)public void preConfigure(java.lang.Object data)
preConfigure in interface com.rubecula.beanpot.ConfigurablepreConfigure in class Evolver_Evolver_.preConfigure(java.lang.Object)
public void resume()
throws EvolutionException
resume in interface EvolutionEvolutionExceptionEvolution.resume()public void run()
MILLISECS_PER_SECOND and true. Then, if
isWaitUntilComplete() returns true, we invoke
waitUntilComplete(int) with the value of #_waitPeriod.
Thus, if you do not want to wait for the evolution to finish, simply
invoke setWaitUntilComplete(boolean) with false before calling
run.
NOTE: this method may be overridden by sub-classes.
run in interface java.lang.RunnableRunnable.run()
public java.util.concurrent.Future<?> scheduleEvent(long millisecs,
java.lang.Runnable event)
Evolution
scheduleEvent in interface Evolutionmillisecs - the number of millisecs before the event is to be run.event - the event to be run.
Evolution.scheduleEvent(long,
java.lang.Runnable)public void setUi(java.lang.Object ui)
ui - public void setWaitUntilComplete(boolean waitUntilComplete)
waitUntilComplete - the waitUntilComplete to set
public boolean shutdown()
throws EvolutionException
pause() and stop().
shutdown in interface EvolutionExecutorService.awaitTermination(long, TimeUnit)
which, roughly speaking, will be true if everything shut down in
an orderly fashion.
EvolutionExceptionEvolution.stop()
public boolean stop()
throws EvolutionException
stop in interface EvolutionstopExecutor(ScheduledExecutorService, int) which,
roughly speaking, will be true if everything shut down in an
orderly fashion.
EvolutionExceptionEvolution.stop()public boolean stoppable()
stoppable in interface EvolutionEvolution.
public boolean waitUntilComplete(int delay)
throws EvolutionException
Evolution to become inactive, then return.
waitUntilComplete in interface Evolutiondelay - delay between tests (in milliseconds)
EvolutionExceptionprotected boolean cancelEvents()
protected void finalize()
throws java.lang.Throwable
finalize in class java.lang.Objectjava.lang.Throwableprotected java.util.concurrent.ScheduledExecutorService getEventExecutor()
protected EvolutionTask getEvolutionTask()
protected java.lang.Object getUi()
setUi(Object).protected boolean isWaitUntilComplete()
protected void setEvolutionTask(EvolutionTask evolutionTask)
evolutionTask - the evolutionTask to set
protected void start(int rate,
boolean run)
Evolvable object
might not undergo a new generation for every "tick" of this evolutionary
clock.]
The result of calling
ScheduledExecutorService.scheduleAtFixedRate(Runnable, long, long, TimeUnit)
results in a new thread being started with the name formed from
EvolutionThreadFactory#namePrefix, space and a sequence number.
rate - the rate of ticking, in millisecondsrun - whether to start in the run state (or otherwise in the paused
state).
protected void startAndWait(int rate,
boolean run,
boolean stopFirst)
rate - run - stopFirst - XXX
protected boolean stopExecutor(java.util.concurrent.ScheduledExecutorService executor,
int timeoutSeconds)
throws EvolutionException
executor - timeoutSeconds - the number of seconds to wait for tasks to shutdown.
ExecutorService.awaitTermination(long, TimeUnit)
EvolutionException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||