Documentation of 'org.jgap.gp.CommandGene' Java class
CommandGene
org.jgap.gp

Class CommandGene

    • Field Detail

      • DELTA

        public static final double DELTA
        Delta, useful for comparing doubles and floats.
        See Also:
        Constant Field Values
      • BooleanClass

        public static final java.lang.Class BooleanClass
      • IntegerClass

        public static final java.lang.Class IntegerClass
      • LongClass

        public static final java.lang.Class LongClass
      • FloatClass

        public static final java.lang.Class FloatClass
      • DoubleClass

        public static final java.lang.Class DoubleClass
      • VoidClass

        public static final java.lang.Class VoidClass
      • CharacterClass

        public static final java.lang.Class CharacterClass
      • nodeIndex

        public int nodeIndex
    • Constructor Detail

      • CommandGene

        public CommandGene()
                    throws java.lang.Exception
        Default constructor, only for dynamic instantiation.
        Throws:
        java.lang.Exception
        Since:
        3.3.4
      • CommandGene

        public CommandGene(GPConfiguration a_conf,
                           int a_arity,
                           java.lang.Class a_returnType,
                           int a_subReturnType,
                           int[] a_childSubTypes)
                    throws InvalidConfigurationException
        Allows specifying a sub return type and sub child types.
        Parameters:
        a_conf - the configuration to use
        a_arity - the number of children of the node
        a_returnType - type of the return value of the node
        a_subReturnType - sub type of the return type, optional usage
        a_childSubTypes - sub types of the childs, optional usage
        Throws:
        InvalidConfigurationException
        Since:
        3.2
      • CommandGene

        public CommandGene(GPConfiguration a_conf,
                           int a_arity,
                           java.lang.Class a_returnType,
                           int a_subReturnType)
                    throws InvalidConfigurationException
        Allows specifying a sub return type.
        Parameters:
        a_conf - the configuration to use
        a_arity - the number of children of the node
        a_returnType - type of the return value of the node
        a_subReturnType - sub type of the return type, optional usage
        Throws:
        InvalidConfigurationException
        Since:
        3.2
      • CommandGene

        public CommandGene(GPConfiguration a_conf,
                           int a_arity,
                           java.lang.Class a_returnType,
                           int a_subReturnType,
                           int a_childSubType)
                    throws InvalidConfigurationException
        Command with one child: Allows specifying a sub return type and a sub child type. Convenience version of the called constructor.
        Parameters:
        a_conf - the configuration to use
        a_arity - the number of children of the node
        a_returnType - type of the return value of the node
        a_subReturnType - sub type of the return type, optional usage
        a_childSubType - sub type of a child, optional usage
        Throws:
        InvalidConfigurationException
        Since:
        3.2
    • Method Detail

      • setAllele

        public void setAllele(java.lang.Object a_newValue)
      • getAllele

        public java.lang.Object getAllele()
      • setToRandomValue

        public void setToRandomValue(RandomGenerator a_numberGenerator)
      • cleanup

        public void cleanup()
      • size

        public int size()
      • getArity

        public int getArity(IGPProgram a_indvividual)
        Arity of the command. Override if necessary. The arity is the number of children a node has.
        Parameters:
        a_indvividual - the invididual the command's arity may depend on (in most cases the arity will not depend on the individual)
        Returns:
        arity of the command
        Since:
        3.0
      • dynamizeArity

        public void dynamizeArity()
        Adaptation of the arity so that it represents a value within the interval [m_arityMin, m_arityMax]. Override if necessary. See CommandDynamicArity for an implementation.
        Since:
        3.4
      • compareTo

        public int compareTo(java.lang.Object a_other)
        The compareTo-method. Considers application data when the configuration asks for this.
        Specified by:
        compareTo in interface java.lang.Comparable
        Parameters:
        a_other - the other object to compare
        Returns:
        -1, 0, 1
        Since:
        3.0
      • equals

        public boolean equals(java.lang.Object a_other)
        The equals-method. Considers application data when the configuration asks for this.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        a_other - the other object to compare
        Returns:
        true if the objects are seen as equal
        Since:
        3.0
      • toString

        public abstract java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
        Returns:
        the string representation of the command. Especially usefull to output a resulting formula in human-readable form.
      • execute

        public java.lang.Object execute(ProgramChromosome c,
                                        int n,
                                        java.lang.Object[] args)
        Executes this node without knowing its return type.
        Parameters:
        c - the current Chromosome which is executing
        n - the index of the Function in the Chromosome's Function array which is executing
        args - the arguments to the current Chromosome which is executing
        Returns:
        the object which wraps the return value of this node, or null if the return type is null or unknown
        Throws:
        java.lang.UnsupportedOperationException - if the type of this node is not boolean
        Since:
        3.0
      • getReturnType

        public java.lang.Class getReturnType()
        Returns:
        the return type of this node
        Since:
        3.0
      • setReturnType

        public void setReturnType(java.lang.Class a_type)
        Sets the return type of this node.
        Parameters:
        a_type - the type to set the return type to
        Since:
        3.0
      • execute_boolean

        public boolean execute_boolean(ProgramChromosome c,
                                       int n,
                                       java.lang.Object[] args)
        Executes this node as a boolean. Override to implement.
        Parameters:
        c - ignored here
        n - ignored here
        args - ignored here
        Returns:
        nothing but exception
        Throws:
        java.lang.UnsupportedOperationException
        Since:
        3.0
      • execute_void

        public void execute_void(ProgramChromosome c,
                                 int n,
                                 java.lang.Object[] args)
        Executes this node, returning nothing. Override to implement.
        Parameters:
        c - ignored here
        n - ignored here
        args - ignored here
        Throws:
        java.lang.UnsupportedOperationException
        Since:
        3.0
      • execute_int

        public int execute_int(ProgramChromosome c,
                               int n,
                               java.lang.Object[] args)
        Executes this node as an integer. Override to implement.
        Parameters:
        c - ignored here
        n - ignored here
        args - ignored here
        Returns:
        nothing but exception
        Throws:
        java.lang.UnsupportedOperationException
        Since:
        3.0
      • execute_long

        public long execute_long(ProgramChromosome c,
                                 int n,
                                 java.lang.Object[] args)
        Executes this node as a long. Override to implement.
        Parameters:
        c - ignored here
        n - ignored here
        args - ignored here
        Returns:
        nothing but exception
        Throws:
        java.lang.UnsupportedOperationException
        Since:
        3.0
      • execute_float

        public float execute_float(ProgramChromosome c,
                                   int n,
                                   java.lang.Object[] args)
        Executes this node as a float. Override to implement.
        Parameters:
        c - ignored here
        n - ignored here
        args - ignored here
        Returns:
        nothing but exception
        Throws:
        java.lang.UnsupportedOperationException
        Since:
        3.0
      • execute_double

        public double execute_double(ProgramChromosome c,
                                     int n,
                                     java.lang.Object[] args)
        Executes this node as a double. Override to implement.
        Parameters:
        c - ignored here
        n - ignored here
        args - ignored here
        Returns:
        nothing but exception
        Throws:
        java.lang.UnsupportedOperationException
        Since:
        3.0
      • execute_object

        public java.lang.Object execute_object(ProgramChromosome c,
                                               int n,
                                               java.lang.Object[] args)
        Executes this node as an object. Override to implement.
        Parameters:
        c - ignored here
        n - ignored here
        args - ignored here
        Returns:
        nothing but exception
        Throws:
        java.lang.UnsupportedOperationException
        Since:
        3.0
      • getName

        public java.lang.String getName()
      • getChildType

        public java.lang.Class getChildType(IGPProgram a_ind,
                                            int a_chromNum)
        Gets the type of node allowed from the given child number. Should be overridden in subclasses.
        Parameters:
        a_ind - the individual the child belongs to
        a_chromNum - the chromosome number
        Returns:
        the type of node allowed for that child, or null of no child exists
        Since:
        3.0
      • hashCode

        public int hashCode()
        Retrieves the hash code value for a CommandGene. Override if another hashCode() implementation is necessary or more appropriate than this default implementation.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        this Gene's hash code
        Since:
        3.0
      • isIntegerType

        public boolean isIntegerType()
      • isFloatType

        public boolean isFloatType()
      • isAffectGlobalState

        public boolean isAffectGlobalState()
        Returns:
        true: command affects global state (i.e. stack or memory)
        Since:
        3.0
      • isValid

        public boolean isValid(ProgramChromosome a_program)
        Subclasses capable of validating programs should overwrite this method. See class Push as a sample.
        Parameters:
        a_program - the ProgramChromosome to validate
        Returns:
        true: a_program is (superficially) valid with the current Command
        Since:
        3.0
      • setNoValidation

        public void setNoValidation(boolean a_noValidation)
      • getGPConfiguration

        public GPConfiguration getGPConfiguration()
        Returns:
        the configuration set
        Since:
        3.0
      • setApplicationData

        public void setApplicationData(java.lang.Object a_newData)
        This sets the application-specific data that is attached to this Gene. Attaching application-specific data may be useful for some applications when it comes time to distinguish a Gene from another. JGAP ignores this data functionally.
        Parameters:
        a_newData - the new application-specific data to attach to this Gene
        Since:
        3.0
      • getApplicationData

        public java.lang.Object getApplicationData()
        Retrieves the application-specific data that is attached to this Gene. Attaching application-specific data may be useful for some applications when it comes time to distinguish a Gene from another. JGAP ignores this data functionally.
        Returns:
        the application-specific data previously attached to this Gene, or null if there is no data attached
        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 Gene is losing its identity when application data is set differently!
        Parameters:
        a_doCompare - true: consider application data in method compareTo and equals
        Since:
        2.4
      • isCompareApplicationData

        public boolean isCompareApplicationData()
      • getEnergy

        public double getEnergy()
        Returns:
        energy of the gene
        Since:
        2.3
      • setEnergy

        public void setEnergy(double a_energy)
        Sets the energy of the gene.
        Parameters:
        a_energy - the energy to set
        Since:
        2.3
      • getSubReturnType

        public int getSubReturnType()
        Returns:
        sub return type
        Since:
        3.2
      • getSubChildType

        public int getSubChildType(int a_childNum)
        Parameters:
        a_childNum - the index of the child
        Returns:
        the sub type of the given child
        Since:
        3.2
      • getSubChildTypes

        public int[] getSubChildTypes()
        Returns:
        sub type for all children
        Since:
        3.2
      • ensureUniqueness

        public void ensureUniqueness(ProgramChromosome a_program)
        Ensures that the calling command is unique within the program. Call it on first place from the execute method.
        Parameters:
        a_program - the program to validate
        Since:
        3.3
      • ensureUniqueness

        public void ensureUniqueness(ProgramChromosome a_program,
                                     int a_maxCount)
        Ensures that the calling command is unique within the program. Throws an exception if uniqueness is violated. Call it on first place from the execute method.
        Parameters:
        a_program - the program to validate
        a_maxCount - maximum number of allowed occurences
        Since:
        3.4
      • ensureUniqueness2

        public boolean ensureUniqueness2(ProgramChromosome a_program,
                                         int a_maxCount)
        Ensures that the calling command is unique within the program. Returns false if uniqueness is violated. Call it on first place from the execute method.
        Parameters:
        a_program - the program to validate
        a_maxCount - maximum number of allowed occurences
        Returns:
        false: uniqueness constraint violated
        Since:
        3.4
      • getPersistentRepresentation

        public java.lang.String getPersistentRepresentation()
        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.