def _fill(self, fill_config, actor_config): """ Initial filling of lots. First, the configuration files of the simulation scenario are parsed, then every lot is filled to its specified value. The actors' parameters which are used to fill the lot are taken from the config JSOBN via a weighted random choice. """ ''' parse config files ''' fill_file = open(os.path.dirname(__file__) + "/" + fill_config) fill_json = json.load(fill_file) init_attributes = fill_json actor_file = open(os.path.dirname(__file__) + "/" + actor_config) actor_json = json.load(actor_file) actor_attributes = actor_json for i,lot in enumerate(self.lots): self.percent_occupancy = 0 # do until the lot is full while self.percent_occupancy < 70: # get size of actor size_choices = [(ix*0.5, el) for ix, el in enumerate(actor_attributes["residential"]["size_distribution"])] size = wr.choice(size_choices) # get remaining parking time of actor remaining_park_time_choices = [(ix, el) for ix, el in enumerate(init_attributes["remaining_duration"])] # parking_time = wr.choice(remaining_park_time_choices) + random.randint(0,1800) parking_time = wr.choice(remaining_park_time_choices)*3600 + random.randint(-1800,1800) # build actor attributes params = { "size": size, "color": actor_attributes["residential"]["color"], "name": actor_attributes["residential"]["name"], "forbidden_lot_types": actor_attributes["residential"]["forbidden_lot_types"], "pos": lot.geometry.coords[0], "rot": 0, "speed": 0, "target_speed": 0, "target_location": None, "target_node_id": None, "parking_start_time": self.simulation.start_time, "parking_time": parking_time-self.simulation.start_time, "parking_size": size + 2 * random.random(), "search_tolerance": random.gauss(0.6, 0.1), "max_search_time": 0, "init_time": 0, "technology": None } # look for space , occupy and initialize actor there space = lot.look_for_space(params["pos"], params["parking_size"]) if space == False: percent_occupancy = lot.lot_percentage() break else: #create actor actor = Actor(self.simulation.actor_manager, self.simulation.router, params, {"lot": lot, "space":space}) # occupy, place and add actor to lot lot.occupy(space) self.simulation.actor_manager.add(actor) # give current edge parameters to actor: actor.current_route_element = { "eid": lot.edge[2]["eid"], "start_node":lot.edge[2]["start_nid"], "end_node":lot.edge[2]["end_nid"], "start_pos": lot.edge[2]["geom"].coords[0], "end_pos": lot.edge[2]["geom"].coords[-1], "vecs": [] } actor.route = [] self.percent_occupancy = lot.lot_percentage() print "--> filled lots with initial data"