Пример #1
0
 def SaveHeatMap(self):
     for n in self.nodes:
         nStr = "%d;%d;%.4f" % (int(n.x), int(n.y), n.usage)
         Global.LogData("elnodeheatmap", nStr)
     for n in self.nodes:
         nStr = "%d;%d;%.4f" % (int(n.x), int(n.y), n.AGamount)
         Global.LogData("elnodeheatmapag", nStr)
Пример #2
0
    def updateMemoryObjectLocation(self, memObject):
        links = memObject.linkToNodes
        x = 0
        y = 0
        if 0 == len(links):
            return memObject
        sumIntensity = 0
        for link in links:
            x += (link.node.x * link.intensity)
            y += (link.node.y * link.intensity)
            sumIntensity += link.intensity
        x = x / sumIntensity
        y = y / sumIntensity
        p = Point(x, y)
        if not self.map.IsInside(
                p):  #this should not happen, quick hack - go closer to memObj
            hit = self.map.CanMoveEx(memObject, p.x, p.y)
            if hit.hit:
                p = hit
            else:
                Global.Log(
                    "Programmer.Error: SpaceMap: not inside but canMove-not-hit"
                )
        memObject.x = p.x
        memObject.y = p.y

        step = Global.GetStep()
        error = self.map.DistanceObjs(p, memObject.object)
        errorStr = '%.2f' % error
        trained = memObject.object.trainHistory
        line = str(step) + ";" + str(
            trained) + ";" + errorStr + ";" + memObject.object.IdStr()
        Global.LogData("rememberinfo", line)

        return memObject
Пример #3
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())
Пример #4
0
    def StepUpdateMove(self, normalStep=True):
        massCoef = 1.0 / max(1, self.usage)

        dx = self.stepDiffX * massCoef
        dy = self.stepDiffY * massCoef

        distToMove2 = dx * dx + dy * dy
        maxDif = Global.MaxELNodeMove
        if distToMove2 > (maxDif * maxDif):
            distToMove = sqrt(distToMove2)
            coef = maxDif / distToMove
            dx = dx * coef
            dy = dy * coef

        newX = self.x + dx
        newY = self.y + dy
        hit = self.area.CanMoveEx(self, newX, newY)
        if hit.hit:
            newX = hit.x
            newY = hit.y

            ldx = newX - self.x
            ldy = newY - self.y
            distToMove2 = ldx * ldx + ldy * ldy
            if distToMove2 < 0.0001:
                newX = self.x
                newY = self.y

        if normalStep and Global.SaveELNodesStatus:
            ldx = newX - self.x
            ldy = newY - self.y
            distToMove = sqrt(ldx * ldx + ldy * ldy)

        if self.area.IsInside(Point(newX, newY)):
            self.x = newX
            self.y = newY
        self.stepDiffX = self.stepDiffY = 0

        if normalStep:
            self.usage -= Global.ELNodeUsageFadeOut
            if self.usage < 0: self.usage = 0
            self.AGamount -= Global.ELAGFadeOut

        if normalStep and Global.SaveELNodesStatus:
            status = str(Global.GetStep()) + ";" + str(
                self.index) + ";%.4f;%.4f;%.4f" % (distToMove, self.usage,
                                                   self.AGamount)
            Global.LogData("elnode-status", status)
Пример #5
0
 def RenderState(self, world):
     self.mapRenderer.RenderObjectVisibility()
     self.mapRenderer.RenderSpaceMap()
     self.mapRenderer.RenderAgent(world.agent)
     #self.mapRenderer.RenderObjects() - only for dynamic worlds
     if Global.RenderVisibilityHistory:
         self.mapRenderer.RenderVisibilityHistory()
     else:
         self.mapRenderer.HideVisibilityHistory()
     
     self.wxCanvas.delete("infotxt")
     txt =  "Step:  " + str(world.step).zfill(6) + "\nTime:  " + Global.TimeToHumanFormat(True)
     self.txtTime = self.wxCanvas.create_text(1080, 5, text=txt, width=200, anchor=NW, tags="infotxt")
     strXY = "%.4f,%.4f" % (self.agent.x, self.agent.y)
     txt =  "Agent:  " + strXY
     nc = len(world.agent.intelligence.spaceMap.Layer.nodes)
     txt = txt + "\nEnergyLayer.nodeCount: " + str(nc)
     self.txtAgentInfo = self.wxCanvas.create_text(1300, 5, text=txt, width=200, anchor=NW, tags="infotxt")
     pa = self.agent.intelligence.processArea
     txt = "ProcessArea:\n" + "\n".join(self.agent.paText)
     self.txtPA = self.wxCanvas.create_text(1050, 50, text=txt, width=200, anchor=NW, tags="infotxt")
     ma = self.agent.intelligence.memoryArea
     txt = "MemoryArea:\n  "
     for phantom in ma.memoryPhantoms:
         txt = txt + phantom.ToString() + "\n  "  
     self.txtMA = self.wxCanvas.create_text(1050, 200, text=txt, width=400, anchor=NW, tags="infotxt")
     pf = self.agent.intelligence.perceptionField
     txt = "PerceptionField:\n  "
     for phantom in pf.environmentPhantoms:
         txt = txt + phantom.ToString() + "\n  "
     self.txtPF = self.wxCanvas.create_text(1050, 300, text=txt, width=400, anchor=NW, tags="infotxt")
     txt = "Log:\n  "
     for line in Global.logLines:
         txt = txt + line + "\n  "
     self.txtLog = self.wxCanvas.create_text(1050, 550, text=txt, width=450, anchor=NW, tags="infotxt")
     
     Global.LogData("nc", world.agent.intelligence.spaceMap.Layer.Status())
Пример #6
0
 def SaveStatus(self):
     status = str(Global.GetStep()) + ";" + str(
         self.index) + ";%.4f;%.4f;%.4f;%.4f;%.4f;%.4f;%.4f" % (
             self.x, self.y, self.level, self.range, self.AGamount,
             self.totalAGamount, self.slowAGamount)
     Global.LogData("place-status", status)
Пример #7
0
 def SaveScenario(self):
     for i in self.intentions:
         Global.LogData("scenario", i.name)