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
def Status(self): strObjs = str(len(self.area.objects)) s = str(Global.GetStep()) + ';' + str(len(self.nodes)) + ";" + str( self.stepEPCreated) + ";" + str( self.stepELNodesCreated) + ";" + str( self.desiredNodeCount) + ";" + strObjs self.stepEPCreated = 0 self.stepELNodesCreated = 0 return s
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)
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)