def randomize( self, nMax, np, cp, p = 0.500000 ): '''Randomizes this genome by creating a directed graph containing up to nMax nodes. Sets the number of node and connection parameters to np and cp, respectively. The optional connection probability, p, specifies the probability that a connection will be made from one node to another.''' count = 0 nodes = breve.objectList() m = None n = None connection = None keep = breve.hash() self.deleteRootNode() count = ( breve.randomExpression( ( nMax - 1 ) ) + 1 ) if ( count < 2 ): count = ( count + 1 ) nodes = breve.createInstances( breve.GADirectedGraphNodes, count ) nodes.setParameterLength( np ) nodes.randomizeParameters() for n in nodes: for m in nodes: if ( ( n != m ) and ( breve.randomExpression( 1.000000 ) < p ) ): connection = n.connect( m, [] ) connection.setParameterLength( cp ) connection.randomizeParameters() self.rootNode = self.pickRootNode( nodes ) if ( not self.rootNode ): self.rootNode = breve.createInstances( breve.GADirectedGraphNode, 1 ) self.rootNode.setParameterLength( np ) self.rootNode.randomizeParameters() for n in self.rootNode.getConnectedNodes(): keep[ n ] = 1 for n in nodes: if ( not keep[ n ] ): breve.deleteInstances( n ) self.addDependency( self.rootNode )
def __init__( self ): breve.Abstract.__init__( self ) self.blueChemicalMatrix = None self.chemicalConcentrationMatrix = breve.hash() self.chemicals = breve.objectList() self.diffusingChemicals = breve.objectList() self.exponentiallyDecayingChemicals = breve.objectList() self.greenChemicalMatrix = None self.gridPointer = None self.linearlyDecayingChemicals = breve.objectList() self.location = breve.vector() self.patchSize = breve.vector() self.patchVolume = 0 self.patches = breve.objectList() self.redChemicalMatrix = None self.tempMatrix = None self.xSize = 0 self.ySize = 0 self.zSize = 0
def randomize(self, nMax, np, cp, p=0.500000): '''Randomizes this genome by creating a directed graph containing up to nMax nodes. Sets the number of node and connection parameters to np and cp, respectively. The optional connection probability, p, specifies the probability that a connection will be made from one node to another.''' count = 0 nodes = breve.objectList() m = None n = None connection = None keep = breve.hash() self._nodeParamCount = np self._connParamCount = cp self.deleteRootNode() count = (breve.randomExpression((nMax - 1)) + 1) if (count < 2): count = (count + 1) nodes = breve.createInstances(breve.GADirectedGraphNodes, count) nodes.setParameterLength(np) nodes.randomizeParameters() for n in nodes: for m in nodes: if ((n != m) and (breve.randomExpression(1.000000) < p)): connection = n.connect(m, []) connection.setParameterLength(cp) connection.randomizeParameters() self.rootNode = self.pickRootNode(nodes) if (not self.rootNode): self.rootNode = breve.createInstances(breve.GADirectedGraphNode, 1) self.rootNode.setParameterLength(np) self.rootNode.randomizeParameters() for n in self.rootNode.getConnectedNodes(): keep[n] = 1 for n in nodes: if (not keep[n]): breve.deleteInstances(n) self.addDependency(self.rootNode)
def destroyConnectedObjects( self ): '''Initiates a recursive freeing of this object and all connected objects, both directly and indiretly connected.''' h = breve.hash() self.internalDestroyConnectedObjects( h )
def crossover( self, p1, p2 ): '''Sets this child's genome to be a genetic crossover of p1 and p2.''' positions = breve.hash() keep = breve.hash() childnodes = breve.objectList() nodes2 = breve.objectList() nodes1 = breve.objectList() source = None temp = None connection = None index = 0 n = 0 cross = 0 max = 0 first = 0 self.deleteRootNode() if breve.randomExpression( 1 ): temp = p1 p1 = p2 p2 = temp nodes1 = p1.getRoot().getConnectedNodes() nodes2 = p2.getRoot().getConnectedNodes() n = 0 while ( n < breve.length( nodes1 ) ): positions[ nodes1[ n ] ] = n n = ( n + 1 ) n = 0 while ( n < breve.length( nodes2 ) ): positions[ nodes2[ n ] ] = n n = ( n + 1 ) first = breve.randomExpression( 1 ) max = breve.length( nodes2 ) cross = breve.randomExpression( ( max - 1 ) ) if ( cross >= breve.length( nodes1 ) ): cross = breve.length( nodes1 ) if ( max < 2 ): childnodes.append( breve.createInstances( breve.GADirectedGraphNodes, 1 ) ) else: childnodes = breve.createInstances( breve.GADirectedGraphNodes, max ) n = 0 while ( n < max ): if ( n < cross ): source = nodes1[ n ] else: source = nodes2[ n ] childnodes[ n ].setParameters( source.getParameters() ) for connection in source.getConnections(): index = positions[ connection.getTarget() ] if ( index >= breve.length( childnodes ) ): index = breve.randomExpression( ( breve.length( childnodes ) - 1 ) ) childnodes[ n ].connect( childnodes[ index ], connection.getParameters() ) n = ( n + 1 ) self.rootNode = self.pickRootNode( childnodes ) if ( not self.rootNode ): self.rootNode = childnodes[ 0 ] keep[ self.rootNode ] = 1 for temp in self.rootNode.getConnectedNodes(): keep[ temp ] = 1 for temp in childnodes: if ( not keep[ temp ] ): print '''freeing ''', temp breve.deleteInstances( temp ) self.addDependency( self.rootNode )
def printConnectedObjects(self): '''Initiates a recursive printing of all connected objects in the graph.''' h = breve.hash() self.printConnectedObjectsInternal(h)
def destroyConnectedObjects(self): """Initiates a recursive freeing of this object and all connected objects, both directly and indiretly connected.""" h = breve.hash() self.destroyConnectedObjectsInternal(h)
def __init__(self): breve.GeneticAlgorithm.__init__(self) self.h = breve.hash() SimsGA.init(self)
def printConnectedObjects( self ): '''Initiates a recursive printing of all connected objects in the graph.''' h = breve.hash() self.printConnectedObjects( h )
def crossover(self, p1, p2): '''Sets this child's genome to be a genetic crossover of p1 and p2.''' positions = breve.hash() keep = breve.hash() childnodes = breve.objectList() nodes2 = breve.objectList() nodes1 = breve.objectList() source = None temp = None connection = None index = 0 n = 0 cross = 0 max = 0 first = 0 self._connParamCount = p1['_connParamCount'] self._nodeParamCount = p1['_nodeParamCount'] self.deleteRootNode() if breve.randomExpression(1): temp = p1 p1 = p2 p2 = temp nodes1 = p1.getRoot().getConnectedNodes() nodes2 = p2.getRoot().getConnectedNodes() n = 0 while (n < breve.length(nodes1)): positions[nodes1[n]] = n n = (n + 1) n = 0 while (n < breve.length(nodes2)): positions[nodes2[n]] = n n = (n + 1) first = breve.randomExpression(1) max = breve.length(nodes2) cross = breve.randomExpression((max - 1)) if (cross >= breve.length(nodes1)): cross = breve.length(nodes1) if (max < 2): childnodes.append( breve.createInstances(breve.GADirectedGraphNodes, 1)) else: childnodes = breve.createInstances(breve.GADirectedGraphNodes, max) n = 0 while (n < max): if (n < cross): source = nodes1[n] else: source = nodes2[n] childnodes[n].setParameters(source.getParameters()) for connection in source.getConnections(): index = positions[connection.getTarget()] if (index >= breve.length(childnodes)): index = breve.randomExpression( (breve.length(childnodes) - 1)) childnodes[n].connect(childnodes[index], connection.getParameters()) n = (n + 1) self.rootNode = self.pickRootNode(childnodes) if (not self.rootNode): self.rootNode = childnodes[0] keep[self.rootNode] = 1 for temp in self.rootNode.getConnectedNodes(): keep[temp] = 1 for temp in childnodes: if (not keep[temp]): breve.deleteInstances(temp) self.addDependency(self.rootNode)
def __init__( self ): breve.GeneticAlgorithmIndividual.__init__( self ) self.genome = None self.h = breve.hash() SimsGAIndividual.init( self )
def __init__( self ): breve.GeneticAlgorithm.__init__( self ) self.h = breve.hash() SimsGA.init( self )
def printConnectedObjects(self): """Initiates a recursive printing of all connected objects in the graph.""" h = breve.hash() self.printConnectedObjectsInternal(h)
def getConnectedNodes(self): """Recursively generates a list of all nodes connected to this root node, both directly and indirectly.""" h = breve.hash() return self.getConnectedNodesInternal(h, [])
def duplicate(self): """Duplicates the object, which triggers recursive duplication of all connected objects. To be used on root nodes only.""" h = breve.hash() return self.duplicateInternal(h)
def getConnectedNodes( self ): '''Recursively generates a list of all nodes connected to this root node, both directly and indirectly.''' h = breve.hash() return self.internalGetConnectedNodes( h, [] )
def mutate( self ): '''Mutates the object, which triggers recursive mutation of all connected objects. To be used on root nodes only.''' h = breve.hash() return self.mutate( h )
def destroyConnectedObjects(self): '''Initiates a recursive freeing of this object and all connected objects, both directly and indiretly connected.''' h = breve.hash() self.destroyConnectedObjectsInternal(h)
def getConnectedNodes(self): '''Recursively generates a list of all nodes connected to this root node, both directly and indirectly.''' h = breve.hash() return self.getConnectedNodesInternal(h, [])
def mutate(self): '''Mutates the object, which triggers recursive mutation of all connected objects. To be used on root nodes only.''' h = breve.hash() return self.mutateInternal(h)
def __init__(self): breve.GeneticAlgorithmIndividual.__init__(self) self.genome = None self.h = breve.hash() SimsGAIndividual.init(self)
def duplicate(self): '''Duplicates the object, which triggers recursive duplication of all connected objects. To be used on root nodes only.''' h = breve.hash() return self.duplicate(h)