Beispiel #1
0
    def __init__(self, env, size=None, update_delay=1.0, display=True,  live_plot=True):
        self.env = env
        self.size = size if size is not None else ((self.env.grid_size[0] + 1) * self.env.block_size, (self.env.grid_size[1] + 1) * self.env.block_size)
        self.width, self.height = self.size
        self.road_width = 44
        self.bg_color = self.colors['gray']
        self.road_color = self.colors['black']
        self.line_color = self.colors['mustard']
        self.stop_color = self.colors['red']
        self.go_color = self.colors['green']
        self.boundary = self.colors['black']

        self.quit = False
        self.start_time = None
        self.current_time = 0.0
        self.last_updated = 0.0
        self.update_delay = update_delay  # duration between each step (in secs)

        self.display = display
        if self.display:
            try:
                self.pygame = importlib.import_module('pygame')
                self.pygame.init()
                self.screen = self.pygame.display.set_mode(self.size)

                self.frame_delay = max(1, int(self.update_delay * 1000))  # delay between GUI frames in ms (min: 1)
                self.agent_sprite_size = (32, 32)
                self.agent_circle_radius = 20  # radius of circle, when using simple representation
                for agent in self.env.agent_states:
                    agent._sprite = self.pygame.transform.smoothscale(self.pygame.image.load(os.path.join("images", "car-{}.png".format(agent.color))), self.agent_sprite_size)
                    agent._sprite_size = (agent._sprite.get_width(), agent._sprite.get_height())

                self.font = self.pygame.font.Font(None, 28)
                self.paused = False
            except ImportError as e:
                self.display = False
                print "Simulator.__init__(): Unable to import pygame; display disabled.\n{}: {}".format(e.__class__.__name__, e)
            except Exception as e:
                self.display = False
                print "Simulator.__init__(): Error initializing GUI objects; display disabled.\n{}: {}".format(e.__class__.__name__, e)
        
        self.live_plot = live_plot
        
        self.rep0 = Reporter(metrics=[metric_TR_pt, metric_CAVG], live_plot=self.live_plot)
        self.rep1 = Reporter(metrics=[metric_STD_pt, metric_CAVG], live_plot=self.live_plot)
        self.rep2 = Reporter(metrics=[metric_TNR_pt,metric_CAVG], live_plot=self.live_plot) 
        self.rep3 = Reporter(metrics=[metric_TNR_pt ], live_plot=self.live_plot) 
        self.rep4 = Reporter(metrics=[metric_TNR_pspt], live_plot=self.live_plot)  
        self.rep5 = Reporter(metrics=[metric_states], live_plot=self.live_plot) 
        
        self.avg_net_reward_window = 0