Exemplo n.º 1
0
	def mostSimilarPacketInMemory(self, packet):
		"""Check the ant's short term memory for a pattern that is similar to the one now in its hands"""
		simIndex = 0
		simValue = 9999
		for i, memPacket in enumerate(self.shortTermMemory):
			if not memPacket.inHand and memPacket is not self.packetInHand:
				memPacketVarience = varience(self.packetInHand.pattern['p'], memPacket.pattern['p'])
				if memPacketVarience < simValue:
					simValue = memPacketVarience
					simIndex = i
		return self.shortTermMemory[simIndex]
Exemplo n.º 2
0
	def grabMostDifferentOfNeighbors(self):
		"""Return the neighboring packet most different from all of the its peers"""
		highestVarienceValue = 0.0
		highestVarienceIndex = 0
		for i, p in enumerate(self.close['Packet']):
			pVarienceSum = 0.0
			for op in self.close['Packet']:
				if p is not op:
					pVarienceSum = pVarienceSum + varience(p.pattern['p'], op.pattern['p'])
			if not p.inHand and pVarienceSum > highestVarienceValue:
				highestVarienceValue = pVarienceSum
				highestVarienceIndex = i
		if not self.close['Packet'][highestVarienceIndex].inHand:
			self.packetInHand = self.close['Packet'][highestVarienceIndex]
			self.packetInHand.moveTo(self.position.x, self.position.y)
			self.mostSimilarPacketSeen = self.mostSimilarPacketInMemory(self.packetInHand)
			self.packetInHand.inHand = True
			self.carrying = True
Exemplo n.º 3
0
	def setOnMostSimilarOfNeightbors(self):
		"""Return the neighboring packet most similar to the packet in the ant's hands"""
		lowestVarienceValue = 99999.0
		lowestVarienceIndex = 0
		for i, op in enumerate(self.close['Packet']):
			if op is not self.packetInHand:
				opVarience = 0.0
				if self.packetInHand is not op:
					opVarience = varience(self.packetInHand.pattern['p'], op.pattern['p'])
					if opVarience < lowestVarienceValue:
						lowestVarienceValue = opVarience
						lowestVarienceIndex = i
		msn = self.close['Packet'][lowestVarienceIndex]

		ang = self.angleTo(msn)+np.pi%(2*np.pi)
		self.packetInHand.moveTo(np.cos(ang)*2+msn.position.x, np.sin(ang)*2+msn.position.y)

		# self.packetInHand.moveTo(msn.position.x, msn.position.y)
		self.packetInHand.inHand = False
		self.carrying = False