|Maintainer||Jan Snajder <firstname.lastname@example.org>|
Implementation of the
GenProg.GenExpr interface for members of
Data typeclass. The implementation is based on SYB and SYZ
generic programming frameworks (see
http://hackage.haskell.org/package/syz for details).
NB: Subexpressions that are candidates for crossover points or mutation must be of the same type as the expression itself, and must be reachable from the root node by type-preserving traversal. See below for an example.
This module re-exports
This typeclass defines an interface to expressions
that can be genetically programmed. The operations that must be
provided by instances of this class are used for the generation
of random individuals as well as crossover and mutation operations.
(An instance for members of the
Data typeclass is provided in
Exchanges subtrees of two expressions:
exchange e1 n1 e2 n2 replaces the subexpression of
e1 rooted in node
n1 with the subexpression of
e2 rooted in
n2, and vice versa.
Maps a monadic transformation function over the immediate children of the given node.
Maps a query function over the immediate children of the given node and returns a list of results.
A list of indices of internal (functional) and external (terminal) nodes of an expression.
Adjusts a subexpression rooted at the given node by applying a monadic transformation function.
Number of nodes an expression has.
The depth of an expression. Equals 1 for single-node expressions.
Suppose you have a datatype defined as
data E = A E E | B String [E] | C deriving (Eq,Show,Typeable,Data)
and an expression defined as
e = A (A C C) (B "abc" [C,C])
The subexpressions of a
e are considered to be only the subvalues of
e that are of the same type as
e. Thus, the number of nodes of
because subvalues of node
B are of different type than expression
e and therefore not considered as subexpressions.
Consequently, during a genetic programming run, subexpressions that are of a different type than the expression itself, or subexpression that cannot be reached from the root node by a type-preserving traversal, cannot be chosen as crossover points nor can they be mutated.