Esempio n. 1
0
    def setMapSize(self,
                   size,
                   print_map=False,
                   PADDING=0,
                   static_builds=True,
                   parallel_gui=False,
                   render_gui=False,
                   empty_start=True):
        self.empty_start = empty_start
        if type(size) == int:
            self.MAP_X = size
            self.MAP_Y = size
        else:
            self.MAP_X = size[0]
            self.MAP_Y = size[1]
        self.obs_width = self.MAP_X + PADDING * 2
        self.micro = MicropolisControl(self.MAP_X,
                                       self.MAP_Y,
                                       PADDING,
                                       parallel_gui=parallel_gui)
        self.static_builds = True
        if self.static_builds:
            self.micro.map.initStaticBuilds()
        self.win1 = self.micro.win1
        self.micro.SHOW_GUI = self.SHOW_GUI
        self.num_step = 0
        self.minFunds = 5000
        self.initFunds = 10000000
        self.num_tools = self.micro.num_tools
        self.num_zones = self.micro.num_zones
        self.num_scalars = 1
        # traffic, power, density
        self.num_obs_channels = self.micro.map.num_features + self.num_scalars + 3
        if self.static_builds:
            self.num_obs_channels += 1

    #ac_low = np.zeros((3))
    #ac_high = np.array([self.num_tools - 1, self.MAP_X - 1, self.MAP_Y - 1])
    #self.action_space = spaces.Box(low=ac_low, high=ac_high, dtype=int)
        self.action_space = spaces.Discrete(self.num_tools * self.MAP_X *
                                            self.MAP_Y)
        self.last_state = None
        self.metadata = {'runtime.vectorized': True}

        low_obs = np.zeros((self.num_obs_channels, self.MAP_X, self.MAP_Y))
        high_obs = np.full((self.num_obs_channels, self.MAP_X, self.MAP_Y),
                           fill_value=1)
        # TODO: can/should we use Tuples of MultiBinaries instead, for greater efficiency?
        self.observation_space = spaces.Box(low=low_obs,
                                            high=high_obs,
                                            dtype=int)
        self.state = None
        self.intsToActions = {}
        self.mapIntsToActions
        self.mapIntsToActions()
        self.last_pop = 0
        self.last_num_roads = 0
        #       self.past_actions = np.full((self.num_tools, self.MAP_X, self.MAP_Y), False)
        self.print_map = print_map
        self.render_gui = render_gui
Esempio n. 2
0
    def setMapSize(self, size, max_step=None, rank=None, print_map=False,
            PADDING=0, static_builds=True, parallel_gui=False,
            render_gui=False, empty_start=True, simple_reward=False,
            power_puzzle=False, record=False):
        if record: raise NotImplementedError
        if max_step is not None:
            self.max_step = max_step
        else:
            self.max_step = 1000
        self.empty_start = empty_start
        self.simple_reward = simple_reward
        self.power_puzzle = power_puzzle
        if type(size) == int:
            self.MAP_X = size
            self.MAP_Y = size
        else:
            self.MAP_X = size[0]
            self.MAP_Y = size[1]
        self.obs_width = self.MAP_X + PADDING * 2
        self.micro = MicropolisControl(self.MAP_X, self.MAP_Y, PADDING, parallel_gui=parallel_gui, rank=rank,
                power_puzzle=power_puzzle)
        self.static_builds = True
        self.win1 = self.micro.win1
        self.micro.SHOW_GUI=self.SHOW_GUI
        self.num_step = 0
        self.minFunds = 5000
        self.initFunds = 10000000
        self.num_tools = self.micro.num_tools
        self.num_zones = self.micro.num_zones
        # res, com, ind pop, demand
        self.num_scalars = 6
        self.num_density_maps = 3
        num_user_features = 1 # static builds
        # traffic, power, density
        self.num_obs_channels = self.micro.map.num_features + self.num_scalars + self.num_density_maps + num_user_features
        #ac_low = np.zeros((3))
       #ac_high = np.array([self.num_tools - 1, self.MAP_X - 1, self.MAP_Y - 1])
       #self.action_space = spaces.Box(low=ac_low, high=ac_high, dtype=int)
        self.action_space = spaces.Discrete(self.num_tools * self.MAP_X * self.MAP_Y)
        self.last_state = None
        self.metadata = {'runtime.vectorized': True}
 
        low_obs = np.full((self.num_obs_channels, self.MAP_X, self.MAP_Y), fill_value=-1)
        high_obs = np.full((self.num_obs_channels, self.MAP_X, self.MAP_Y), fill_value=1)
        # TODO: can/should we use Tuples of MultiBinaries instead, for greater efficiency?
        self.observation_space = spaces.Box(low=low_obs, high=high_obs, dtype = float)
        self.state = None
        self.intsToActions = {}
        self.actionsToInts = np.zeros((self.num_tools, self.MAP_X, self.MAP_Y))
        self.mapIntsToActions()
        self.last_pop = 0
        self.last_num_roads = 0
#       self.past_actions = np.full((self.num_tools, self.MAP_X, self.MAP_Y), False)
        self.print_map = print_map
        self.render_gui = render_gui
        self.mayor_rating = 50
        self.last_mayor_rating = self.mayor_rating
        
        self.last_priority_road_net_size = 0
Esempio n. 3
0
 def setMapSize(self, size, **kwargs):
     '''
     '''
     self.pre_gui(size, **kwargs)
     self.micro = MicropolisControl(self,
                                    self.MAP_X,
                                    self.MAP_Y,
                                    self.PADDING,
                                    rank=self.rank,
                                    power_puzzle=self.power_puzzle,
                                    gui=self.render_gui)
     self.post_gui()
Esempio n. 4
0
 def setMapSize(self, size, **kwargs):
     '''Do most of the actual initialization.
     '''
     self.pre_gui(size, **kwargs)
     #TODO: this better
     if hasattr(self, 'micro'):
         self.micro.reset_params(size)
     else:
         self.micro = MicropolisControl(self,
                                        self.MAP_X,
                                        self.MAP_Y,
                                        self.PADDING,
                                        rank=self.rank,
                                        power_puzzle=self.power_puzzle,
                                        gui=self.render_gui)
     self.city_metrics = self.get_city_metrics()
     self.last_city_metrics = self.city_metrics
     self.post_gui()
Esempio n. 5
0
 def setMapSize(self, size, print_map=False, PADDING=0, static_builds=True):
     self.MAP_X = size
     self.MAP_Y = size
     self.obs_width = self.MAP_X + PADDING * 2
     self.micro = MicropolisControl(self.MAP_X, self.MAP_Y, PADDING)
     self.static_builds = True
     if self.static_builds:
         self.micro.map.initStaticBuilds()
     self.win1 = self.micro.win1
     self.micro.SHOW_GUI = self.SHOW_GUI
     self.num_step = 0
     self.minFunds = 5000
     self.initFunds = 10000000
     self.num_tools = self.micro.num_tools
     self.num_zones = self.micro.num_zones
     self.num_scalars = 1
     # traffic, power, density
     self.num_obs_channels = self.num_zones + self.num_scalars + 3
     if self.static_builds:
         self.num_obs_channels += 1
     ac_low = np.zeros((3))
     ac_high = np.array(
         [self.num_tools - 1, self.MAP_X - 1, self.MAP_Y - 1])
     self.action_space = spaces.Box(low=ac_low, high=ac_high, dtype=int)
     self.last_state = None
     self.metadata = {'runtime.vectorized': True}
     low_obs = np.zeros((self.num_obs_channels, self.MAP_X, self.MAP_Y))
     high_obs = np.full((self.num_obs_channels, self.MAP_X, self.MAP_Y),
                        fill_value=1)
     # TODO: can/should we use Tuples of MultiBinaries instead, for greater efficiency?
     self.observation_space = spaces.Box(low=low_obs,
                                         high=high_obs,
                                         dtype=bool)
     self.state = None
     #       self.intsToActions = {}
     #       self.mapIntsToActions
     #       self.mapIntsToActions()
     self.last_pop = 0
     self.last_num_roads = 0
Esempio n. 6
0
 def setMapSize(self, MAP_X=6, MAP_Y=6):
     self.MAP_X = MAP_X
     self.MAP_Y = MAP_Y
     self.micro = MicropolisControl(MAP_X, MAP_Y)
     self.win1 = self.micro.win1
     self.micro.SHOW_GUI = self.SHOW_GUI
     self.num_step = 0
     self.minFunds = 1000
     self.initFunds = 1000000000
     self.num_tools = self.micro.num_tools
     self.num_zones = self.micro.num_zones
     self.action_space = spaces.Discrete(self.num_tools * self.MAP_X *
                                         self.MAP_Y)
     low_obs = np.zeros((self.num_zones, self.MAP_X, self.MAP_Y))
     high_obs = np.full((self.num_zones, self.MAP_X, self.MAP_Y),
                        fill_value=1)
     # TODO: can/should we use Tuples of MultiBinaries instead, for greater efficiency?
     self.observation_space = spaces.Box(low=low_obs,
                                         high=high_obs,
                                         dtype=bool)
     self.state = None
     self.intsToActions = {}
     self.mapIntsToActions()
     self.last_pop = 0