Exemplo n.º 1
0
  def mate(self, program):
    childA = Node.copy(self.root)
    childB = Node.copy(program.root)

    nodeA = random.choice(Node.traverseInOrder(childA))
    nodeB = random.choice(Node.traverseInOrder(childB))

    childA = Node.replace(childA, nodeA, nodeB)
    childB = Node.replace(childB, nodeB, nodeA)

    return [Program(childA), Program(childB)]
Exemplo n.º 2
0
    def mate(self, program):
        childA = Node.copy(self.root)
        childB = Node.copy(program.root)

        nodeA = random.choice(Node.traverseInOrder(childA))
        nodeB = random.choice(Node.traverseInOrder(childB))

        childA = Node.replace(childA, nodeA, nodeB)
        childB = Node.replace(childB, nodeB, nodeA)

        return [Program(childA), Program(childB)]
Exemplo n.º 3
0
 def mutate(self):
   for program in self.programs:
     for node in Node.traverseInOrder(program.root):
       if random.random() < self.MUTATION_PROBABILITY:
         if node.isTerminal():
           node.value = self._createTerminalNode(self.problem).value
         else:
           node.value = self._createOperatorNode(self.problem).value
Exemplo n.º 4
0
 def mutate(self):
     for program in self.programs:
         for node in Node.traverseInOrder(program.root):
             if random.random() < self.MUTATION_PROBABILITY:
                 if node.isTerminal():
                     node.value = self._createTerminalNode(
                         self.problem).value
                 else:
                     node.value = self._createOperatorNode(
                         self.problem).value
Exemplo n.º 5
0
 def toString(self):
   return "{0} [{1} nodes]".format(Node.toString(self.root),
                                   len(Node.traverseInOrder(self.root)))
Exemplo n.º 6
0
 def toString(self):
     return "{0} [{1} nodes]".format(Node.toString(self.root),
                                     len(Node.traverseInOrder(self.root)))