These pages are auto-generated from self-documenting comments embedded in class files.
For more information on breve and steve, refer to the breve homepage.

Object : PushProgram

Class description:

Summary: a single program in the Push programming language.

A PushProgram object is a program in the Push programming language. To be used in conjunction with the class PushInterpreter.

Methods:

  • copyFrom
  • crossover
  • deleteRandomSubtree
  • flattenRandomSubtree
  • getCodePointer
  • getDiscrepancy
  • getFirstFloat
  • getList
  • getSize
  • getString
  • getTopLevelDifference
  • getTopLevelSize
  • makeRandomCode
  • mutate
  • parse
  • read
  • setCodePointer
  • setFrom
  • swapSublists
  • write
    copyFrom( self, otherProgram )

    Copies the contents of otherProgram to this object.


    crossover( self, p1, p2, interpreter )

    Sets this object to a genetic crossover of p1 and p2.


    deleteRandomSubtree( self )

    Removes a random subtree from the code.


    flattenRandomSubtree( self )

    Flattens a random subtree in the code.


    getCodePointer( self )

    Used internally.


    getDiscrepancy( self, otherProgram )

    Determines the discrepancy between this program and otherProgram. This is defined as the number of points (atoms and subtrees) found in this program which do not exist in otherProgram, plus the number of points found in otherProgram that do not exist in this program.

    This method considers the order of points in a program, and considers all sublists found in a program. For this reason, it is a good measure of similarity between two evolved programs. For a simpler comparison operator, suitable for comparing lists in which order should be preserved, see get-top-level-difference.


    getFirstFloat( self )

    Returns the first float value found in the Push program.


    getList( self )

    Returns a list representation of this push program.


    getSize( self )

    Returns the size of this push program.


    getString( self )

    Returns the string representation of this push program.


    getTopLevelDifference( self, otherProgram )

    Determines the top level difference between this program and otherProgram. This is calculated by comparing each element of the program against the corresponding element of otherProgram, with every mismatch counting as one point of difference. Sublists are not considered; each element in the top level list is treated as an atomic element.

    This method is well suited for comparing lists produced as output of push programs. Because it does not consider sublists or order, it is not well suited for determining the true level of similarity between two programs as one might with to do with evolved code. For that type of functionality, see the method get-discrepancy.


    getTopLevelSize( self )

    Returns the "top-level" size of this push program, meaning that sublists are counted as one item, and not counted recursively.


    makeRandomCode( self, interpreter, size )

    Makes a random push program of length size. Size is an optional argument with a default value of 100. The size may also be equal to -1, which indicates that the MAX-POINTS-IN-RANDOM-EXPRESSION value from the Push configuration file should be used. The interpreter provided specifies the instruction set used to generate the random code.


    mutate( self, interpreter, leafBias, sizeScale, ignored )

    Modifies this code object by mutating a subtree of the program. The leafBias parameter indicates the probability that a leaf node will be selected (as opposed to a non-leaf subtree).

    Mutation is implemented as "fair" mutation, in which the new code size is determined by the size of the subtree it is replacing, plus or minus a factor of sizeScale.

    The interpreter argument determines the instruction set used to generate the random code.

    The max-new-code-size argument is ignored, but included for backwards compatibility.


    parse( self, codeString )

    Sets the content of this code to the newly parsed string. The with-interpreter keyword is no longer required.


    read( self, fileName )

    Reads a push program from a text file.


    setCodePointer( self, newCodePointer )

    Used internally.


    setFrom( self, newCodeList )

    Sets this code's object using the contents of newCodeList. The list can contain literals, sublists or subprograms.


    swapSublists( self, x, y )

    Swaps the positions of the top level sublists x and y.


    write( self, fileName )

    Writes this push program to a text file.