示例#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 startSimulation(self, configName):
        if not os.path.exists("../../exs/"): os.makedirs("../../exs/")
        dirList = os.listdir("../../exs/")
        for fname in dirList:
            os.remove("../../exs/" + fname)
        Global.LogStart("../../exs/")
        Global.Log("Starting new simulation and world for Config: " + configName)
        
        seed(Global.RandomSeeds[0])
        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)
         
        self.lock = Lock()
        self.lock.acquire()
        self.playbackLock = Lock()
        th = Thread(None, self.simulationThread, name="simulationThread")
        th.start()