Ejemplo n.º 1
0
        /// <summary>
        /// Sets up a prototypical GPIndividual with those features which it
        /// shares with other GPIndividuals in its species, and nothing more.
        /// </summary>
        public override void Setup(IEvolutionState state, IParameter paramBase)
        {
            base.Setup(state, paramBase); // actually unnecessary (Individual.Setup() is empty)

            var def = DefaultBase;

            // set my evaluation to false
            Evaluated = false;

            // how many trees?
            var t = state.Parameters.GetInt(paramBase.Push(P_NUMTREES), def.Push(P_NUMTREES), 1); // at least 1 tree for GP!

            if (t <= 0)
            {
                state.Output.Fatal("A GPIndividual must have at least one tree.", paramBase.Push(P_NUMTREES), def.Push(P_NUMTREES));
            }

            // load the trees
            Trees = new GPTree[t];

            for (var x = 0; x < t; x++)
            {
                var p = paramBase.Push(P_TREE).Push("" + x);
                Trees[x]       = (GPTree)(state.Parameters.GetInstanceForParameterEq(p, def.Push(P_TREE).Push("" + x), typeof(GPTree)));
                Trees[x].Owner = this;
                Trees[x].Setup(state, p);
            }

            // now that our function sets are all associated with trees,
            // give the nodes a chance to determine whether or not this is
            // going to work for them (especially the ADFs).

            var initializer = ((GPInitializer)state.Initializer);

            for (var x = 0; x < t; x++)
            {
                foreach (var gpfi in Trees[x].Constraints(initializer).FunctionSet.Nodes)
                {
                    foreach (var t1 in gpfi)
                    {
                        t1.CheckConstraints(state, x, this, paramBase);
                    }
                }
            }
            // because I promised with checkConstraints(...)
            state.Output.ExitIfErrors();
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Returns true if I am "genetically" the same as tree, though we may have different owners.
 /// </summary>
 public virtual bool TreeEquals(GPTree tree)
 {
     return(Child.RootedTreeEquals(tree.Child));
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Enumerates filtered GPNodes in the tree starting with the root (tree.Child).
 /// Results are filtered by the nodesearch argument (0=All, 1=Terminals, 2=Nonterminals).
 /// </summary>
 public static IEnumerable <GPNode> Descendants(this GPTree tree, int nodesearch)
 {
     return(Descendants(tree.Child, nodesearch));
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Enumerates filtered GPNodes in the tree starting with the root (tree.Child).
 /// Results are filtered by the GPNodeGatherer which tests each node to decide
 /// if it qualifies.
 /// </summary>
 public static IEnumerable <GPNode> Descendants(this GPTree tree, GPNodeGatherer gatherer)
 {
     return(Descendants(tree.Child, gatherer));
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Enumerates all of the GPNodes in the tree starting with the root (tree.Child).
 /// </summary>
 public static IEnumerable <GPNode> Descendants(this GPTree tree)
 {
     return(Descendants(tree.Child));
 }