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 )
예제 #2
0
	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
예제 #3
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 )
예제 #6
0
    def printConnectedObjects(self):
        '''Initiates a recursive printing of all connected objects in the graph.'''

        h = breve.hash()

        self.printConnectedObjectsInternal(h)
예제 #7
0
    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)
예제 #8
0
파일: Creatures.py 프로젝트: pemby/breve
 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 )
예제 #10
0
    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)
예제 #11
0
파일: Creatures.py 프로젝트: B-Rich/breve
	def __init__( self ):
		breve.GeneticAlgorithmIndividual.__init__( self )
		self.genome = None
		self.h = breve.hash()
		SimsGAIndividual.init( self )
예제 #12
0
파일: Creatures.py 프로젝트: B-Rich/breve
	def __init__( self ):
		breve.GeneticAlgorithm.__init__( self )
		self.h = breve.hash()
		SimsGA.init( self )
예제 #13
0
    def printConnectedObjects(self):
        """Initiates a recursive printing of all connected objects in the graph."""

        h = breve.hash()

        self.printConnectedObjectsInternal(h)
예제 #14
0
    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, [])
예제 #15
0
    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 )
예제 #18
0
    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)
예제 #19
0
    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, [])
예제 #20
0
    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)
예제 #21
0
파일: Creatures.py 프로젝트: pemby/breve
 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)