This section describes how to terminate algorithm. Related classes can be found in the package org.evolvica.core.terminate.
No algorithm may run forever so there must be termination criterion defined. Such a criterion is used inside
a special operator called router. A router is a fork operator - it has one input and an arbitrary
number of outputs. Dependent on some condition it routes the input data to one of its outputs.
In most algorithms a true/false condition is sufficient. A router handling true/false conditions can be found
in org.evolvica.core.terminate.ConditionalRouter. Based on a condition which can be set via
the method setCondition( ICondition condition ) it routes its input to output 0 if the condition
evaluates to false and to output 1 if the condition evaluates to true.
Conditions are defined by the interface org.evolvica.core.terminate.ICondition. This interface has
one single method: boolean isTrue( IIndividualSet set ). The individual set parameter is the set
received by the router on its input. The individuals in the set may or may not incorporated in the evaluation
of the condition. Examples for both would be the comparison of the best score in the set with a certain value
of simply the comparison of the current time with certain maximal point of time.
The method must return true or false if the condition evaluates to true or false. In the termination package
you can find several predefined termination conditions. Please refer to the API documentation to find out
what they do.
Conditions can also be combined. The appropriate interface for such a condition is org.evolvica.core.terminate.IMultiCondition. This interface specifies two additional methods for getting and setting an array of conditions. The conditions in this array are evaluated and their return values are related logically (but there's no specification in which logical way!). There are two multi conditions already provided: org.evolvica.core.terminate.AndCondition and org.evolvica.core.terminate.OrCondition. The first one is true if all contained conditions are true and the second one becomes true, if at least one of the contained conditions evaluates to true. It is possible to combine both: use the AND-condition, put two OR-conditions into it and put some other conditions inside the two OR-conditions. In doing so it is possible to create some kind of logical trees and express any logical relationship between boolean values.