Exemplo n.º 1
0
	def NextNode(self, Target, deterministic=False):
		" determines the most attractive neighbouring node when heading to Target"
		if len(self.Table):
			if deterministic:
				return max([(self.Table[Target][n], n) for n in self.Table[Target]])[1]
			return self.Table[Target].keys()[ET.fortune_wheel(self.Table[Target].values())]
		return None
Exemplo n.º 2
0
 def NextNode(self, Target, deterministic=False):
     " determines the most attractive neighbouring node when heading to Target"
     if len(self.Table):
         if deterministic:
             return max([(self.Table[Target][n], n)
                         for n in self.Table[Target]])[1]
         return list(self.Table[Target].keys())[ET.fortune_wheel(
             self.Table[Target].values())]
     return None
Exemplo n.º 3
0
	def Sniff(self):
		" Looks for the next place to go "
		# The ant makes a biased choice of its next location
		# More probable links leading from neighbouring nodes to the ant's origin are more likely to be chosen
		Neighbours = self.location.Neighbours[:]
		if self.Origin in Neighbours: Neighbours.remove(self.Origin)
		Probabilities = [n.Table[self.Origin][self.location] for n in Neighbours]
		if Probabilities:
			NodeRank = ET.fortune_wheel(Probabilities)	# chooses a neighbour based on probabilities
			return Neighbours[NodeRank]
		return None
Exemplo n.º 4
0
 def Sniff(self):
     " Looks for the next place to go "
     # The ant makes a biased choice of its next location
     # More probable links leading from neighbouring nodes to the ant's origin are more likely to be chosen
     Neighbours = self.location.Neighbours[:]
     if self.Origin in Neighbours: Neighbours.remove(self.Origin)
     Probabilities = [
         n.Table[self.Origin][self.location] for n in Neighbours
     ]
     if Probabilities:
         NodeRank = ET.fortune_wheel(
             Probabilities)  # chooses a neighbour based on probabilities
         return Neighbours[NodeRank]
     return None