Beispiel #1
0
 def ChooseProcessForIntention(self, emotion, intention, parentProcess):
     processes = intention.processes
     if parentProcess != None:
         processes = Global.SetDifference(processes, parentProcess.failedProcesses)
         
     if len(processes) == 0:
         return None
     if intention.name == "Want":    #for Want intention the order of process matters
         return processes[0]
     else:
         return Global.Choice(processes)
Beispiel #2
0
    def StepUpdate(self):
        for ep in self.energyPoints:
            ep.StepUpdate(self.getNodesAround(ep, Global.ELGravityRange))
        for node in self.nodes:
            node.StepUpdate(
                self.getNodesAround(node, Global.ELAntigravityRange))
        for node in self.nodes:
            node.StepUpdateMove()

        if Global.CreatePlaces:
            placesToDelete = []
            for place in self.places:
                place.CalculateAG()
                if place.slowAGamount < Global.PlacesAGMin * (place.level - 1):
                    placesToDelete.append(place)
                    continue

                if place.AGamount > Global.PlacesAGNeeded * (2**(place.level) -
                                                             1):
                    self.createPlaces(place)

                if place.parent != None:
                    place.UpdateLocation()
                    place.CalculateRange()
                place.SaveStatus()

            for place in placesToDelete:
                place.Delete()

            for node in self.nodes:
                p = self.GetPlaceForNode(node)
                if p != node.place:
                    node.place.nodes.remove(node)
                    node.place = p
                    p.nodes.append(node)

        for ep in self.energyPointsToDelete:
            self.energyPoints.remove(ep)
        self.energyPointsToDelete = []

        self.forgetEnergy = self.forgetEnergy + Global.ELForgetNodeRate
        cost = self.GetNodeDeleteCost()
        chanceForget = 100 * float(self.forgetEnergy - cost) / cost

        diceRoll = Global.DiceRoll()
        if diceRoll < chanceForget and len(self.nodes) > 0:
            node = Global.Choice(self.nodes)
            self.forgetEnergy = self.forgetEnergy - (
                cost * log(max(2, node.usage), 2))
            self.DeleteNode(node)

        Global.LogData("nc", self.Status())
Beispiel #3
0
 def GetRandomHighLevelIntention(self):
     return Global.Choice(self.highLevelIntentions)
Beispiel #4
0
    def GetAtomicActionforSmartProcess(self, emotion, excProcess):
        if (excProcess.process.name == "SearchRandom"):

            if (excProcess.data["step"] == "MoveTo"):
                
                if excProcess.data["waypoints"] == None:
                    map = Global.Map
                    ws = copy(map.wayPoints)
                    ws.sort(lambda a,b: cmp(a.lastVisited,b.lastVisited))
                    excProcess.data["waypoints"] = ws
                    
                if len(excProcess.data["waypoints"]) < 1:
                    self.processArea.TerminateProcess(emotion, False)
                    return self.GetAction(emotion)
                
                wayPointToGo = Global.Choice(excProcess.data["waypoints"])
                excProcess.data["waypoints"].remove(wayPointToGo)
                excProcess.data["step"] = "Explore"
                
                canMove = False
                map = Global.Map
                while not canMove:
                    newX = Global.Randint(-Global.WayPointNoise, Global.WayPointNoise) + wayPointToGo.x
                    newY = Global.Randint(-Global.WayPointNoise, Global.WayPointNoise) + wayPointToGo.y
                    canMove = map.IsInside( Point(newX,newY) )
                    
                atomicProcess = self.processArea.ActivateProcess(emotion, self.processes.atomic["MoveTo"], excProcess.excParentIntention, excProcess)
                atomicProcess.data["process"] = excProcess.process
                atomicProcess.data["newx"] = newX
                atomicProcess.data["newy"] = newY
                return self.GetAtomicActionforSmartProcess(emotion, atomicProcess)                                
                
            elif (excProcess.data["step"] == "Explore"):
                excProcess.data["step"] = "MoveTo"
                atomicProcess = self.processArea.ActivateProcess(emotion, self.processes.atomic["Explore"], excProcess.excParentIntention, excProcess)
                atomicProcess.data["parent"] = "process"
                atomicProcess.data["process"] = excProcess.excParentIntention.parentExcProcess
                atomicProcess.data["affordance"] = excProcess.data["affordance"]
                return atomicProcess
            
        elif (excProcess.process.name == "LookUpInMemory"):
            
            if (excProcess.data["step"] == "Remember"):
                excProcess.data["step"] = "MoveTo"
                atomicProcess = self.processArea.ActivateProcess(emotion, self.processes.atomic["Remember"], excProcess.excParentIntention, excProcess)
                atomicProcess.data["process"] = excProcess.process
                atomicProcess.data["affordance"] = excProcess.data["affordance"]
                return atomicProcess
            
            elif (excProcess.data["step"] == "MoveTo"):
                excProcess.data["step"] = "LookForObject"
                atomicProcess = self.processArea.ActivateProcess(emotion, self.processes.atomic["MoveTo"], excProcess.excParentIntention, excProcess)
                atomicProcess.data["process"] = excProcess.process
                
                memObj = excProcess.data["phantom"].object
                atomicProcess.data["newx"] = memObj.x
                atomicProcess.data["newy"] = memObj.y
                return self.GetAtomicActionforSmartProcess(emotion, atomicProcess)
            
            elif (excProcess.data["step"] == "LookForObject"):
                atomicProcess = self.processArea.ActivateProcess(emotion, self.processes.atomic["LookForObject"], excProcess.excParentIntention, excProcess)
                atomicProcess.data["process"] = excProcess.process
                atomicProcess.data["affordance"] = excProcess.data["affordance"]
                atomicProcess.data["phantom"] = excProcess.data["phantom"]
                return atomicProcess    
            
            return None    
        elif (excProcess.process.name == "MoveTo"):
            if excProcess.data["path"] == None:
                map = Global.Map
                path = map.GetPath(self.agent, excProcess.data["newx"], excProcess.data["newy"])
                if path == None:
                    self.processArea.TerminateProcess(emotion, False)
                    return self.GetAction(emotion)
                excProcess.data["path"] = path[1:]
            #we have path (without start)
            nextPoint = excProcess.data["path"].pop(0)
            atomicProcess = self.processArea.ActivateProcess(emotion, self.processes.atomic["MoveToPartial"], excProcess.excParentIntention, excProcess)
            atomicProcess.data["process"] = excProcess.process
            atomicProcess.data["newx"] = nextPoint.x
            atomicProcess.data["newy"] = nextPoint.y
            return atomicProcess
        elif (excProcess.process.name == "Execute"):
            
            if 'phantom' not in excProcess.data: 
                #expecting enough E-phantoms, we choose one and let go the rest
                #Future: for |process.sources|>1 add selection of phantoms regarding theirs affs
                if len(excProcess.parent.resources)> 1:
                    phantoms = filter(lambda x:x.GetType()=="e", excProcess.parent.resources)
                    phToDist = {}
                    map = Global.Map
                    for p in phantoms:
                        phToDist[p] = map.DistanceObj(self.agent.newX, self.agent.newY, p.object) #Future: use object.attractivity, .visibility in sort/cmp etc.
                    phantoms.sort(lambda a,b: cmp(phToDist[a], phToDist[b]))
                    phantom = phantoms[0]
                else:
                    phantom = excProcess.parent.resources[0]
                excProcess.data['phantom'] = phantom            #Future: list instead of one phantom

            #following test of in range is paranoid - could be done only in first iteration
            object = excProcess.data['phantom'].object
            map = Global.Map
            dist = map.DistanceObj(self.agent.newX, self.agent.newY, object)
            if dist < Global.MapPickUpDistance:
                 atomicProcess = self.processArea.ActivateProcess(emotion, self.processes.atomic["ExecuteReal"], excProcess.excParentIntention, excProcess)
                 atomicProcess.data["process"] = excProcess.data["process"]
                 atomicProcess.data["phantom"] = excProcess.data["phantom"]
                 atomicProcess.duration = excProcess.duration
                 excProcess.parent.resources = [excProcess.data["phantom"]]
                 return atomicProcess
            else:
                atomicProcess = self.processArea.ActivateProcess(emotion, self.processes.atomic["MoveTo"], excProcess.excParentIntention, excProcess)
                atomicProcess.data["newx"] = object.x
                atomicProcess.data["newy"] = object.y
                return self.GetAtomicActionforSmartProcess(emotion, atomicProcess)
        else:
            return excProcess