Esempio n. 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
Esempio n. 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()     
Esempio n. 3
0

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="Run implementation")
    parser.add_argument('input_path', type=str, help="Path to input images")

    args = parser.parse_args()

    # Get all images
    images = sorted([
        f for f in listdir(args.input_path) if isfile(join(args.input_path, f))
    ])

    # Init segmentation network
    seg_network = Segmentation("{}/{}".format(args.input_path, images[0]))
    mr = MapRenderer("data/map.osm")

    # Parse objects, locations and ways from the map
    objects, locations, ways = parse_map("data/map.osm")
    route = ways[0]
    current_location = list(filter(lambda x: x.node_id == -137971,
                                   locations))[0]

    output_file = open("output.csv", "w")
    fps_file = open("fps.txt", "w")
    vp = (0.5, 0.5)

    for i, image_path in enumerate(images):
        time_data = []
        fps_start = time.time()
        img = cv2.imread("{}/{}".format(args.input_path, image_path))