Пример #1
0
 def runOneSimulation(self, savePath, configName, randomSeed):
     savePath = savePath + str(randomSeed) + "-" + configName + "/"
     os.makedirs(savePath)
     Global.LogStart(savePath)   
     Global.Log("Starting new simulation and world for Config: " + configName)
     try:
         seed(randomSeed)
         config = Config.Get(configName)
         world = World(config)
         Global.World = world
 
         self.agent = Agent(config)
         world.SetAgent(self.agent)
         self.mapRenderer = MapRenderer(self.wxCanvas, Global.Map, self.agent, self, False)
         
         self.currentTestIndex = self.currentTestIndex + 1
         self.mapRenderer.RenderProgress(self, configName)
         self.mapRenderer.RenderProgressInTest(world.step, Global.MaxTestSteps)
         time.sleep(0.1)
         
         elayer = world.agent.intelligence.spaceMap.Layer
         while world.step < Global.MaxTestSteps:
             world.Step()
             self.mapRenderer.RenderToFile(world, savePath + "PIL" + str(world.step).zfill(6) + ".png")
             self.mapRenderer.RenderProgressInTest(world.step, Global.MaxTestSteps)
     
         world.SendAgentOut()
         while world.step < Global.MaxTestSteps + Global.MaxTestStepAfter:
             world.Step()
             self.mapRenderer.RenderToFile(world, savePath + "PIL" + str(world.step).zfill(6) + ".png")
             self.mapRenderer.RenderProgressInTest(world.step, Global.MaxTestSteps)
                 
         if Global.CalculateVisibilityHistory:
             self.mapRenderer.RenderToFile(world, savePath + "visibilityheatmap.png", ["vh"])
         self.mapRenderer.RenderToFile(world, savePath + "visibilityobjectheatmap.png", ["ovh"])
         map = Global.Map
         map.SaveHeatMap()
         self.agent.intelligence.spaceMap.Layer.SaveHeatMap()
     except:
         Global.Log("FATAL ERROR occured: ")
         ss = traceback.format_exc()
         Global.Log(ss)
         time.sleep(1)
         raise
     finally:        
         Global.Log("Stoping simulation...")
         Global.LogEnd()
         Global.Reset()
         self.agent = None
         self.mapRenderer.Clear()
         self.mapRenderer = None
Пример #2
0
   def simulationThread(self):
       world = Global.World
       self.lockBack = Lock()
       self.lockBack.acquire()
       while True:
           world.Step()
           self.RenderState(world)
           self.mapRenderer.RenderToFile(world, "../../exs/PIL" + str(world.step).zfill(6) + ".png", ["agent", "ov", "eps", "info"])
           
           # used only to get EPS of test rooms
           #p=self.wxCanvas.postscript(width="1020",height="1020")
           #f=open("image" + str(world.step) + ".eps", "wb")
           #f.write(p)
           #f.close()
           
           if self.lock.acquire(False): break
           self.playbackLock.acquire()
           self.playbackLock.release()
 
       self.lockBack.release()
       Global.LogEnd()
       return