/*
  Copyright 2006 by Sean Luke
  Licensed under the Academic Free License version 3.0
  See the file "LICENSE" for more information
*/


package ec.gp.build;
import ec.*;
import ec.util.*;
import ec.gp.*;

/* 
 * PTCFunctionSet.java
 * 
 * Created: Wed Jan 26 21:10:59 2000
 * By: Sean Luke
 */

/**
 * PTCFunctionSet is a GPFunctionSet which adheres to PTCFunctionSetForm, and thus
 * can be used with the PTC1 and PTC2 methods.  Terminal and nonterminal probabilities
 * for nodes used in this function set are determined by the prob parameter
 * for the nodes' GPNodeConstraints object.  That's not the greatest solution,
 * because it could require making a lot of different GPNodeConstraints, customized for each
 * node, but it's the best I can do for now.
 *
 * The nonterminalSelectionProbabilities() method computes nonterminal selection
 * probability using the probabilities above, per type, for the size requested.
 * If the size is small enough (smaller than CACHE_SIZE), then the result is
 * memoized so it doesn't need to be computed again next time.
 * 
 * @author Sean Luke
 * @version 1.0 
 */

public class PTCFunctionSet extends GPFunctionSet implements PTCFunctionSetForm
    {
    /** terminal probabilities[type][thenodes], in organized form */
    public double q_ty[][];
    /** nonterminal probabilities[type][thenodes], in organized form */
    public double q_ny[][];

    public static final int CACHE_SIZE = 1024;
    /** cache of nonterminal selection probabilities -- dense array 
        [size-1][type].  If any items are null, they're not in the dense cache. */
    public double p_y[][];

    public double[] terminalProbabilities(final int type)
        { return q_ty[type]; }

    public double[] nonterminalProbabilities(final int type)
        { return q_ny[type]; }

    public void setup(final EvolutionState state, final Parameter base)
        {
        super.setup(state,base);

        // load our probabilities here.
        
        q_ny = new double[nonterminals.length][];
        q_ty = new double[terminals.length][];
        
        boolean allOnes = true;
        boolean noOnes = true;
        boolean allZeros = true;
        GPInitializer initializer = ((GPInitializer)state.initializer);

        for(int type=0;type 

Ads help maintain this website.