Documentation of 'org.jgap.gp.impl.ProgramChromosome' Java class
ProgramChromosome
org.jgap.gp.impl

Class ProgramChromosome

    • Method Detail

      • setArgTypes

        public void setArgTypes(java.lang.Class[] a_argTypes)
      • clone

        public java.lang.Object clone()
        Overrides:
        clone in class java.lang.Object
      • cleanup

        public void cleanup()
        Clean up the chromosome.
        Specified by:
        cleanup in interface IGPChromosome
        Since:
        3.0
      • growOrFull

        public void growOrFull(int a_num,
                               int a_depth,
                               java.lang.Class a_type,
                               java.lang.Class[] a_argTypes,
                               CommandGene[] a_functionSet,
                               boolean a_grow,
                               int a_tries)
        Initialize this chromosome using the grow or the full method.
        Parameters:
        a_num - the chromosome's index in the individual of this chromosome
        a_depth - the maximum depth of the chromosome to create
        a_type - the type of the chromosome to create
        a_argTypes - the array of argument types for this chromosome
        a_functionSet - the set of nodes valid to pick from
        a_grow - true: use grow method; false: use full method
        a_tries - maximum number of tries to create a valid program
        Since:
        3.0
      • toString

        public java.lang.String toString(int a_startNode)
        Output program in left-hand notion (e.g.: "+ X Y" for "X + Y").
        Parameters:
        a_startNode - node to start with
        Returns:
        output in left-hand notion
        Since:
        3.0
      • toStringNorm

        public java.lang.String toStringNorm(int a_startNode)
        Output program in "natural" notion (e.g.: "X + Y" for "X + Y").
        Specified by:
        toStringNorm in interface IGPChromosome
        Parameters:
        a_startNode - the node to start with, e.g. 0 for a complete dump of the program
        Returns:
        output in normalized notion
        Since:
        3.0
      • getBusinessKey

        public java.lang.String getBusinessKey()
        Specified by:
        getBusinessKey in interface IBusinessKey
        Returns:
        business key of the chromosome
        Since:
        3.4
      • toStringDebug

        public java.lang.String toStringDebug()
        Returns:
        debug representation of progrm chromosome, containing class names of all children
        Since:
        3.4
      • isPossible

        public boolean isPossible(java.lang.Class a_returnType,
                                  int a_subReturnType,
                                  CommandGene[] a_nodeSet,
                                  boolean a_function,
                                  boolean a_growing)
        Determines whether there exists a function or terminal in the given node set with the given return and sub return type.
        Parameters:
        a_returnType - the return type to look for
        a_subReturnType - the sub return type to look for
        a_nodeSet - the array of nodes to look through
        a_function - true to look for a function, false to look for a terminal
        a_growing - true: grow mode, false: full mode
        Returns:
        true if such a node exists, false otherwise
        Since:
        3.0
      • redepth

        public void redepth()
        Recalculate the depth of each node.
        Specified by:
        redepth in interface IGPChromosome
        Since:
        3.0
      • getChild

        public int getChild(int a_index,
                            int a_child)
        Gets the a_child'th child of the a_index'th node in this chromosome. This is the same as the a_child'th node whose depth is one more than the depth of the a_index'th node.
        Specified by:
        getChild in interface IGPChromosome
        Parameters:
        a_index - the node number of the parent
        a_child - the child number (starting from 0) of the parent
        Returns:
        the node number of the child, or -1 if not found
        Since:
        3.01
      • getChild

        public int getChild(CommandGene a_node,
                            int a_child)
      • setFunctionSet

        public void setFunctionSet(CommandGene[] a_functionSet)
      • getSize

        public int getSize(int a_index)
        Gets the number of nodes in the branch starting at the a_index'th node.
        Parameters:
        a_index - the index of the node at which to start counting
        Returns:
        the number of nodes in the branch starting at the a_index'th node
        Since:
        3.0
      • getDepth

        public int getDepth(int a_index)
        Gets the depth of the branch starting at the a_index'th node.
        Parameters:
        a_index - the index of the node at which to check the depth
        Returns:
        the depth of the branch starting at the a_index'th node
        Since:
        3.0
      • getParentNode

        public int getParentNode(int a_child)
        Gets the node which is the parent of the given node in this chromosome. If the child is at depth d then the parent is the first function at depth d-1 when iterating backwards through the function list starting from the child.
        Parameters:
        a_child - the child node
        Returns:
        the parent node, or null if the child is the root node
        Since:
        3.0
      • getNode

        public CommandGene getNode(java.lang.Class a_type,
                                   boolean a_exactMatch)
        Checks whether a node with a given type is contained in the program.
        Parameters:
        a_type - the type to look for
        a_exactMatch - true: look for exactly the given type: false: also look for sub types
        Returns:
        true specific node found
        Since:
        3.2.1
      • getNode

        public CommandGene getNode(java.lang.Class a_type,
                                   boolean a_exactMatch,
                                   int a_startIndex)
      • execute_boolean

        public boolean execute_boolean(java.lang.Object[] args)
        Executes this node as a boolean.
        Parameters:
        args - the arguments for execution
        Returns:
        the boolean return value of this node
        Throws:
        java.lang.UnsupportedOperationException - if the type of this node is not boolean
        Since:
        3.0
      • execute_boolean

        public boolean execute_boolean(int n,
                                       int child,
                                       java.lang.Object[] args)
        Executes this node as a boolean.
        Parameters:
        n - the index of the parent node
        child - the child number of the node to execute
        args - the arguments for execution
        Returns:
        the boolean return value of this node
        Throws:
        java.lang.UnsupportedOperationException - if the type of this node is not boolean
        Since:
        3.0
      • execute_void

        public void execute_void(java.lang.Object[] args)
        Executes this node, returning nothing.
        Parameters:
        args - the arguments for execution
        Throws:
        java.lang.UnsupportedOperationException - if the type of this node is not void
        Since:
        3.0
      • execute_void

        public void execute_void(int n,
                                 int child,
                                 java.lang.Object[] args)
      • execute_int

        public int execute_int(java.lang.Object[] args)
        Executes this node as an integer.
        Parameters:
        args - the arguments for execution
        Returns:
        the integer return value of this node
        Throws:
        java.lang.UnsupportedOperationException - if the type of this node is not integer
        Since:
        3.0
      • execute_int

        public int execute_int(int n,
                               int child,
                               java.lang.Object[] args)
      • execute_long

        public long execute_long(java.lang.Object[] args)
        Executes this node as a long.
        Parameters:
        args - the arguments for execution
        Returns:
        the long return value of this node
        Throws:
        java.lang.UnsupportedOperationException - if the type of this node is not long
        Since:
        3.0
      • execute_long

        public long execute_long(int n,
                                 int child,
                                 java.lang.Object[] args)
      • execute_float

        public float execute_float(java.lang.Object[] args)
        Executes this node as a float.
        Parameters:
        args - the arguments for execution
        Returns:
        the float return value of this node
        Throws:
        java.lang.UnsupportedOperationException - if the type of this node is not float
        Since:
        3.0
      • execute_float

        public float execute_float(int n,
                                   int child,
                                   java.lang.Object[] args)
      • execute_double

        public double execute_double(java.lang.Object[] args)
        Executes this node as a double.
        Parameters:
        args - the arguments for execution
        Returns:
        the double return value of this node
        Throws:
        java.lang.UnsupportedOperationException - if this node's type is not double
        Since:
        3.0
      • execute_double

        public double execute_double(int n,
                                     int child,
                                     java.lang.Object[] args)
      • execute_object

        public java.lang.Object execute_object(java.lang.Object[] args)
        Executes this node as an object.
        Parameters:
        args - the arguments for execution
        Returns:
        the object return value of this node
        Throws:
        java.lang.UnsupportedOperationException - if the type of this node is not of type Object
        Since:
        3.0
      • execute_object

        public java.lang.Object execute_object(int n,
                                               int child,
                                               java.lang.Object[] args)
      • execute

        public java.lang.Object execute(java.lang.Object[] args)
        Executes this node without knowing its return type.
        Parameters:
        args - the arguments for execution
        Returns:
        the Object which wraps the return value of this node, or null if the return type is null or unknown
        Since:
        3.0
      • execute

        public java.lang.Object execute(int n,
                                        int child,
                                        java.lang.Object[] args)
      • setGene

        public void setGene(int index,
                            CommandGene a_gene)
      • getArgTypes

        public java.lang.Class[] getArgTypes()
      • getArity

        public int getArity()
      • size

        public int size()
        Returns:
        number of functions and terminals present
        Since:
        3.0
      • compareTo

        public int compareTo(java.lang.Object a_other)
        Compares the given chromosome to this chromosome. This chromosome is considered to be "less than" the given chromosome if it has a fewer number of genes or if any of its gene values (alleles) are less than their corresponding gene values in the other chromosome.
        Specified by:
        compareTo in interface java.lang.Comparable
        Parameters:
        a_other - the chromosome against which to compare this chromosome
        Returns:
        a negative number if this chromosome is "less than" the given chromosome, zero if they are equal to each other, and a positive number if this chromosome is "greater than" the given chromosome
        Since:
        3.0
      • equals

        public boolean equals(java.lang.Object a_other)
        Compares this chromosome against the specified object.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        a_other - the object to compare against
        Returns:
        true: if the objects are the same, false otherwise
        Since:
        3.0
      • setCompareApplicationData

        public void setCompareApplicationData(boolean a_doCompare)
        Should we also consider the application data when comparing? Default is "false" as "true" means a Chromosome is losing its identity when application data is set differently!
        Parameters:
        a_doCompare - true: consider application data in method compareTo
        Since:
        3.0
      • isCompareApplicationData

        public boolean isCompareApplicationData()
      • getApplicationData

        public java.lang.Object getApplicationData()
        Retrieves the application-specific data that is attached to this Chromosome. Attaching application-specific data may be useful for some applications when it comes time to evaluate this Chromosome in the fitness function. JGAP ignores this data functionally.
        Returns:
        the application-specific data previously attached to this Chromosome, or null if there is no data attached
        Since:
        3.0
      • getGene

        public CommandGene getGene(int a_locus)
        Returns the Gene at the given index (locus) within the Chromosome. The first gene is at index zero and the last gene is at the index equal to the size of this Chromosome - 1.
        Parameters:
        a_locus - index of the gene value to be returned
        Returns:
        Gene at the given index
        Since:
        3.0
      • getPersistentRepresentation

        public java.lang.String getPersistentRepresentation()
        Specified by:
        getPersistentRepresentation in interface IGPChromosome
        Returns:
        the persistent representation of the chromosome, including all genes
        Since:
        3.3

DMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.