Ejemplo n.º 1
0
	def __init__( self ):
		breve.Object.__init__( self )
		self.ampShifts = breve.objectList()
		self.limbLengths = breve.objectList()
		self.phaseShifts = breve.objectList()
		self.waveCompression = 0
		MonkeyGenome.init( self )
Ejemplo n.º 2
0
    def mutate(self):
        """Mutates the directed graph.  The mutation adds a random connection, removes a random connection, and mutates the parameters of a random connection and node."""

        connections = breve.objectList()
        nodes = breve.objectList()
        m = 0
        n = 0
        connection = None

        nodes = self.rootNode.getConnectedNodes()
        n = breve.randomExpression((breve.length(nodes) - 1))
        m = breve.randomExpression((breve.length(nodes) - 1))
        connection = nodes[n].connect(nodes[m], [])
        connection.setParameterLength(self._connParamCount)
        connection.randomizeParameters()
        m = breve.randomExpression((breve.length(nodes) - 1))
        connections = nodes[m].getConnections()
        if breve.length(connections) > 1:
            connections.pop(breve.randomExpression((breve.length(connections) - 1)))

        m = breve.randomExpression((breve.length(nodes) - 1))
        connections = nodes[m].getConnections()
        if breve.length(connections):
            connections[breve.randomExpression((breve.length(connections) - 1))].mutate()

        m = breve.randomExpression((breve.length(nodes) - 1))
        nodes[m].mutate()
Ejemplo n.º 3
0
	def __init__( self ):
		breve.Control.__init__( self )
		self.numBirds = 150
		self.numPred = 25
		self.num_dead_birds = 0
		self.num_dead_predators = 0

		# World
		self.minX = -50
		self.maxX = 50
		self.minY = -50
		self.maxY = 50
		self.delta = 1

		# Feeder
		self.maxFoodSupply = 600
		self.minCreatedFoodSupply = 15
		self.maxCreatedFoodSupply = 25
		self.totalFoodSupply = 0

		# List
		self.current_generation = 0
		self.breeding_season = 50
		self.breeding_inc = 0.5
		self.max_pop_predadors = 0.5
		self.pollBirds = breve.objectList()
		self.pollPredators = breve.objectList()

		# Other thing
		Swarm.init( self )
Ejemplo n.º 4
0
	def __init__( self ):
		breve.Control.__init__( self )
		self.numBirds = 150
		self.numPred = 25
		self.num_dead_birds = 0
		self.num_dead_predators = 0

		# World
		self.minX = -50
		self.maxX = 50
		self.minY = -50
		self.maxY = 50
		self.delta = 1

		# Feeder
		self.maxFoodSupply = 400
		self.minCreatedFoodSupply = 15
		self.maxCreatedFoodSupply = 25
		self.totalFoodSupply = 0

		# List
		self.prob_mutation = 0.05
		self.pollBirds = breve.objectList()
		self.pollPredators = breve.objectList()

		# Other thing
		Swarm.init( self )
Ejemplo n.º 5
0
	def __init__( self ):
		breve.MultiBody.__init__( self )
		self.bodyLink = None
		self.bodyShape = None
		self.joints = breve.objectList()
		self.linkShape = None
		self.links = breve.objectList()
		self.lowerLinkShape = None
Ejemplo n.º 6
0
	def __init__( self ):
		breve.MultiBody.__init__( self )
		self.bodyLink = None
		self.bodyShape = None
		self.sensorShape = None
		self.sensors = breve.objectList()
		self.wheelShape = None
		self.wheels = breve.objectList()
		BraitenbergVehicle.init( self )
Ejemplo n.º 7
0
	def __init__( self ):
		breve.PhysicalControl.__init__( self )
		self.currentSeat = 0
		self.lockMenu = None
		self.locked = 0
		self.monkeys = breve.objectList()
		self.seats = breve.objectList()
		self.terrain = None
		self.walker = None
		Walker.init( self )
Ejemplo n.º 8
0
	def __init__( self ):
		breve.PhysicalControl.__init__( self )
		self.currentSeat = 0
		self.floor = None
		self.lockMenu = None
		self.locked = 0
		self.monkeys = breve.objectList()
		self.seats = breve.objectList()
		self.wigglyThing = None
		Walker.init( self )
Ejemplo n.º 9
0
	def parse( self, root, n, rootNode, f = 0.000000 ):
		connections = breve.objectList()
		nodeParams = breve.objectList()
		connectionParams = breve.objectList()
		joint = None
		childNode = None
		child = None
		norm = breve.vector()
		size = breve.vector()
		point = breve.vector()
		ppoint = breve.vector()
		cpoint = breve.vector()
		jointRange = 0

		connections = root.getConnections()
		nodeParams = root.getParameters()
		size = ( ( 3.000000 * breve.vector( breve.length( nodeParams[ 0 ] ), breve.length( nodeParams[ 1 ] ), breve.length( nodeParams[ 2 ] ) ) ) + breve.vector( 0.500000, 0.500000, 0.500000 ) )
		if ( ( ( self._linkCount > 20 ) or ( n > 6 ) ) or ( ( n > 1 ) and ( nodeParams[ 9 ] < 0.000000 ) ) ):
			return 0

		for child in connections:
			childNode = self.createNode( child.getTarget(), ( n + 1 ) )
			if childNode:
				connectionParams = child.getParameters()
				point = breve.vector( connectionParams[ 0 ], connectionParams[ 1 ], connectionParams[ 2 ] )
				if f:
					point.x = ( point.x * -1 )

				point.x = ( point.x * size.x )
				point.y = ( point.y * size.y )
				point.z = ( point.z * size.z )
				cpoint = childNode.getShape().getPointOnShape( point )
				ppoint = rootNode.getShape().getPointOnShape( ( -point ) )
				norm = breve.vector( connectionParams[ 4 ], connectionParams[ 5 ], connectionParams[ 6 ] )
				norm = ( norm / breve.length( norm ) )
				if f:
					norm.x = ( norm.x * -1 )

				joint = breve.createInstances( breve.SineJoint, 1 )
				joint.link( norm, ppoint, cpoint, childNode, rootNode )
				joint.setPhaseshift( ( ( n * 3.140000 ) * connectionParams[ 7 ] ) )
				joint.setFrequency( ( 0.100000 + connectionParams[ 8 ] ) )
				jointRange = ( 0.500000 + ( 1 * breve.length( connectionParams[ 9 ] ) ) )
				joint.setDoubleSpring( jointRange, ( -jointRange ), 1 )
				joint.setStrengthLimit( 1000 )
				self.parse( child.getTarget(), ( n + 1 ), childNode )




		return rootNode
Ejemplo n.º 10
0
	def __init__( self ):
		breve.Object.__init__( self )
		self._abortFitnessTest = 0
		self._abortFitnessValue = 0
		self._bestOfGen = None
		self._solutionCountsGeneration = breve.objectList()
		self._solutionCountsTotal = breve.objectList()
		self._solutionRatesGeneration = breve.objectList()
		self._solutionRatesTotal = breve.objectList()
		self._totalErrors = 0
		self._totalSize = 0
		self._useChallenges = 0
		self.crossoverPercent = 0
		self.current = breve.objectList()
		self.currentFitnessTest = 0
		self.currentIndividual = 0
		self.deletionPercent = 0
		self.fitnessTestDuration = 0
		self.generation = 0
		self.generationLimit = 0
		self.inited = 0
		self.interpreter = None
		self.mutationPercent = 0
		self.next = breve.objectList()
		self.pop1 = breve.objectList()
		self.pop2 = breve.objectList()
		self.populationSize = 0
		self.seed = ''
		self.spatialRadius = 0
		self.tournamentSize = 0
		PushGP.init( self )
Ejemplo n.º 11
0
	def getAllConnectedLinks( self ):
		'''Returns all of the OBJECT(Link) objects which comprise the  MultiBody.'''

		links = breve.objectList()
		allObjects = breve.objectList()
		link = None

		allObjects = self.getAllConnectedObjects()
		for link in allObjects:
			if link.isA( 'Link' ):
				links.append( link )



		return links
Ejemplo n.º 12
0
	def __init__( self ):
		breve.Control.__init__( self )
		self.chemicals = breve.objectList()
		self.colors = breve.objectList()
		self.cube = None
		self.diffusion = None
		self.inflow = None
		self.reactionRates = breve.objectList()
		self.reactions = breve.objectList()
		self.rgb = breve.objectList()
		self.temp = None
		self.tempreact = None
		self.texture = None
		self.totalConcentration = None
		GS.init( self )
Ejemplo n.º 13
0
	def __init__(self, size = breve.vector(7,1,4)):
		breve.MultiBody.__init__(self)
		self.sensors = breve.objectList()
		self.wheels = breve.objectList()

		self.bodyShape = breve.createInstances(breve.Cube, 1)
		self.bodyShape.initWith(size)

		self.bodyShape.setDensity(self.getDensity())
		self.bodyLink = breve.createInstances(breve.Link, 1)
		self.bodyLink.setShape(self.bodyShape)
		self.bodyLink.setMu(-1.000000)
		self.bodyLink.setET(0.800000)

		self.setRoot(self.bodyLink)
		self.setTextureScale(1.500000)
Ejemplo n.º 14
0
Archivo: Real.py Proyecto: B-Rich/breve
	def dearchive( self ):
		handler = breve.objectList()

		self.setCollisionShape( self.collisionShape )
		self.setDisplayShape( self.displayShape )
		self.move( self.archiveLocation )
		self.setRotationMatrix( self.archiveRotation )
		for handler in self.collisionHandlerList:
			if handler[ 1 ]:
				breve.breveInternalFunctionFinder.addCollisionHandler( self, self, handler[ 0 ], handler[ 1 ] )

			if handler[ 2 ]:
				breve.breveInternalFunctionFinder.setIgnoreCollisionsWith( self, self, handler[ 0 ], 1 )



		if self.archiveTextureImage:
			self.setTextureImage( self.archiveTextureImage )

		if self.archiveLightmapImage:
			self.setLightmap( self.archiveLightmapImage )

		if self.archiveBitmapImage:
			self.setBitmapImage( self.archiveBitmapImage )

		self.setTextureScaleX( self.archiveTextureScaleX )
		self.setTextureScaleY( self.archiveTextureScaleY )
		self.setNeighborhoodSize( self.neighborhoodSize )
		self.setColor( self.color )
		breve.breveInternalFunctionFinder.realSetCollisionProperties( self, self.realWorldPointer, self.e, self.mu )
		return breve.Object.dearchive( self )
Ejemplo n.º 15
0
	def closestOther( self ):
		others = breve.objectList()
		item = None
		closestDistance = 0
		thisDistance = 0
		closestOther = None

		for item in self.getNeighbors():
			if item.isA( 'Bird' ):
				if ( self.isFriend( item ) == 0 ):
					others.append( item )





		if ( breve.length( others ) < 1 ):
			closestOther = self

		else:
			closestDistance = 1000000
			for item in others:
				thisDistance = breve.length( ( item.getLocation() - self.getLocation() ) )
				if ( thisDistance < closestDistance ):
					closestDistance = thisDistance
					closestOther = item






		return closestOther
Ejemplo n.º 16
0
	def __init__( self ):
		breve.Object.__init__( self )
		self.menus = breve.objectList()
		self.multibodyPointer = None
		self.rootLink = None
		self.selfCollisions = 0
		MultiBody.init( self )
Ejemplo n.º 17
0
	def randomize( self ):
		patch = None
		patchList = breve.objectList()

		patchList = self.patches.getPatches()
		for patch in patchList:
			patch.setState( breve.randomExpression( 1 ) )
Ejemplo n.º 18
0
	def closestFriend( self ):
		friends = breve.objectList()
		item = None
		closestDistance = 0
		thisDistance = 0
		closestFriend = None

		for item in self.getNeighbors():
			if item.isA( 'Bird' ):
				if self.isFriend( item ):
					friends.append( item )





		if ( breve.length( friends ) < 1 ):
			closestFriend = self

		else:
			closestDistance = 1000000
			for item in friends:
				thisDistance = breve.length( ( item.getLocation() - self.getLocation() ) )
				if ( thisDistance < closestDistance ):
					closestDistance = thisDistance
					closestFriend = item






		return closestFriend
Ejemplo n.º 19
0
    def send(self, message):
        qtest = 0
        agents = breve.objectList()
        i = None
        col = 0

        col = breve.randomExpression(100)
        self.updatePos()
        self.draw.clear()
        agents = breve.allInstances("basicAgent")
        self.draw.setColor(breve.vector(1, 0, 0))
        self.draw.drawLine(self.getLocation(), (self.getLocation() + (self.getRotation() * breve.vector(0, 0, 27))))
        for i in agents:
            if i != self.owner:
                qtest = 233 * breve.breveInternalFunctionFinder.calculateQualityToObject(
                    self,
                    self.realWorldPointer_owner,
                    self.getLocation(),
                    self.getRotation(),
                    i.getRealWorldPointer(),
                    self.sensorType,
                )
                self.draw.setColor(breve.vector(0, 0, 0))
                if qtest > self.communicationThreshold:
                    i.receiveMessage2(message, self.getOwner())
Ejemplo n.º 20
0
	def __init__( self ):
		breve.Control.__init__( self )
		self.m1 = None
		self.m2 = None
		self.m3 = None
		self.particles = breve.objectList()
		Fountain.init( self )
Ejemplo n.º 21
0
	def clear( self ):
		patch = None
		patchList = breve.objectList()

		patchList = self.patches.getPatches()
		for patch in patchList:
			patch.setState( 0 )
Ejemplo n.º 22
0
	def selectParent( self, specie):
		birds = breve.objectList()
		for item in breve.allInstances( specie ):
			if item.isAlive:
				birds.append( item )
		parent = self.tournament(birds, 5)
		return parent
Ejemplo n.º 23
0
	def get3dMooreNeighborhood( self ):
		'''Returns a list of the 3D Moore neighbors of this patch.  The  3D Moore neighborhood consists of the 26 patches  adjacent to this patch, including diagonally, in three dimensions. <P> If you intend to use the neighborhood frequently, you should  call this method once and keep a copy of the list.'''

		result = breve.objectList()
		z = 0
		y = 0
		x = 0
		patch = None

		x = -1
		while ( x <= 1 ):
			y = -1
			while ( y <= 1 ):
				z = -1
				while ( z <= 1 ):
					patch = self.grid.getPatchAt( ( x + self.xIndex ), ( y + self.yIndex ), ( z + self.zIndex ) )
					if ( patch and ( patch != self ) ):
						result.append( patch )


					z = ( z + 1 )


				y = ( y + 1 )


			x = ( x + 1 )

		return result
Ejemplo n.º 24
0
	def untrack( self, theDiffusable ):
		'''Removes a OBJECT(PatchChemcial) from the patch grid.'''

		chem = None
		newChems = breve.objectList()

		if self.chemicalConcentrationMatrix[ theDiffusable ]:
			breve.deleteInstances( self.chemicalConcentrationMatrix[ theDiffusable ] )
			for chem in self.chemicals:
				if ( chem != theDiffusable ):
					newChems.append( chem )


			self.chemicals = newChems
			for chem in self.diffusingChemicals:
				if ( chem != theDiffusable ):
					newChems.append( chem )


			self.diffusingChemicals = newChems
			for chem in self.linearlyDecayingChemicals:
				if ( chem != theDiffusable ):
					newChems.append( chem )


			self.linearlyDecayingChemicals = newChems
			for chem in self.exponentiallyDecayingChemicals:
				if ( chem != theDiffusable ):
					newChems.append( chem )


			self.exponentiallyDecayingChemicals = newChems
Ejemplo n.º 25
0
	def report( self, bestIndividual ):
		'''Logs information to the output at every generation.  This method  may be overridden to provide more (or less) output data.   <P> The argument bestIndividual is the best individual in the population and is provided so that it may be inspected by the user if this method is overridden.'''

		bestFitness = 0
		errors = breve.objectList()
		n = 0

		self._totalSize = ( self._totalSize / self.populationSize )
		self._totalErrors = ( self._totalErrors / self.populationSize )
		bestFitness = bestIndividual.getFitness()
		errors = bestIndividual.getErrors()
		print ';;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;'
		print ''';; -*- Report at generation %s''' % (  self.generation )
		print ''';; Best Individual: '''
		print bestIndividual.getString()
		print ''';; Errors for best individual: ''', errors
		print ''';; Problem solution rates this generation: ''', self._solutionRatesGeneration
		print ''';; Problem solution rates all generations: ''', self._solutionRatesTotal
		print ''';; Total errors for best individual: %s''' % (  bestFitness )
		print ''';; Size of best individual (points):''', bestIndividual.getSize()
		print ';;'
		print ''';; Average total errors in population: %s''' % (  self._totalErrors )
		print ''';; Average program size in population (points): %s''' % (  self._totalSize )
		print ''
		self.controller.setDisplayText( '''Best Fitness: %s''' % (  bestFitness ), -0.900000, -0.900000, 2 )
Ejemplo n.º 26
0
	def __init__( self ):
		breve.Control.__init__( self )

		self.showCorpse = True
		self.isToLoad = False
		self.isToSave = False
		self.isToRecord = True
		self.movie = None

		# Simulation
		self.initialNumPreys = 150
		self.initialNumPredators = 25
		self.numPreys = 150
		self.numPredators = 25
		self.numDeadPreys = 0
		self.numDeadPredators = 0

		# World
		self.minX = -200
		self.maxX = 200
		self.minY = -100
		self.maxY = 100
		self.targetZone = 50
		self.socialZone = 20

		# Feeder
		self.feederMinDistance = 25
		self.maxFoodSupply = 200
		self.minCreatedFoodSupply = 7
		self.maxCreatedFoodSupply = 15
		self.totalFoodSupply = 0

		# List
		self.pollPreys = breve.objectList()
		self.pollPredators = breve.objectList()

		# Generation
		self.maxGeneration = 5000
		self.current_generation = 0
		self.breeding_season = 50
		self.breeding_inc = 0.5
		self.max_pop_predators = 0.6
		self.prob_mutation = 0.05

		# Other thing
		Swarm.init( self )
Ejemplo n.º 27
0
	def __init__( self ):
		breve.MultiBody.__init__( self )
		self.joint = None
		self.links = breve.objectList()
		self.shape = None
		self.smallShape = None
		self.worldJoint = None
		JointTestBody.init( self )
Ejemplo n.º 28
0
	def init( self ):
		t = breve.objectList()

		t = breve.createInstances( breve.Things, 150 )
		self.pointCamera( breve.vector( 0, 0, 0 ), breve.vector( 0, 0, 50 ) )
		self.setDisplayText( '''Select an object to highlight its neighbors''', -0.950000, -0.900000 )
		self.enableSmoothDrawing()
		self.updateNeighbors()
Ejemplo n.º 29
0
	def __init__( self ):
		breve.Control.__init__( self )
		self.autoCameraMenu = None
		self.autoCameraMode = 0
		self.birds = breve.objectList()
		self.breveTexture = 0
		self.cloudTexture = None
		self.deaths = 0
		self.doMutations = 0
		self.drawEveryFrameMenu = None
		self.feeders = breve.objectList()
		self.item = None
		self.iteration = 0
		self.manualCameraMenu = None
		self.selection = None
		self.skipFramesIfNecessaryMenu = None
		Swarm.init( self )
Ejemplo n.º 30
0
	def __init__( self ):
		breve.Drawing.__init__( self )
		self.currentColor = breve.vector()
		self.currentDirection = breve.vector()
		self.penDown = 0
		self.states = breve.objectList()
		self.turtle = None
		TurtleDrawing.init( self )