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
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
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
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