Пример #1
0
    def generate_evacuation_taz_demands(self, residential_car_density,
                                        serving_car_density, demand_mean_hours,
                                        demand_stddev_hours,
                                        population_portion):
        """Generates evacuation TAZ demands."""

        # TODO(yusef): Fix map + total number of cars.
        # To make the demands consistent, use the default map, paradise_type.net.xml
        # as the input map instead of the reversed. For Paradise map, an easy way to
        # check is that the total number of cars is 11072.
        net = sumolib.net.readNet(self._sumo_net_file)
        traffic_generator = random_traffic_generator.RandomTrafficGenerator(
            net)
        visualizer = map_visualizer.MapVisualizer(net)

        print('Generating TAZ demands with STD: ', demand_stddev_hours,
              ' Portion: ', population_portion)

        # Demands from residential roads.
        residential_edge_type = ['highway.residential']
        residential_edges = net.filterEdges(residential_edge_type)
        demand_mean_seconds = demand_mean_hours * 60 * 60
        demand_stddev_seconds = demand_stddev_hours * 60 * 60
        time_sampler_parameters = random_traffic_generator.TimeSamplerGammaMeanStd(
            demand_mean_seconds, demand_stddev_seconds)
        car_per_meter_residential = residential_car_density * population_portion

        np.random.seed(FLAGS.random_seed)
        residential = traffic_generator.create_evacuation_auto_routing_demands(
            residential_edges, time_sampler_parameters,
            car_per_meter_residential)

        # Demands from parking roads.
        parking_edge_type = ['highway.service']
        parking_edges = net.filterEdges(parking_edge_type)
        time_sampler_parameters = random_traffic_generator.TimeSamplerGammaMeanStd(
            demand_mean_seconds, demand_stddev_seconds)
        car_per_meter_parking = serving_car_density * population_portion

        parking = traffic_generator.create_evacuation_auto_routing_demands(
            parking_edges, time_sampler_parameters, car_per_meter_parking)

        all_demands = residential + parking
        departure_time_points = [x.time for x in all_demands]
        cars_per_time_point = [x.num_cars for x in all_demands]
        departure_time_points = np.array(departure_time_points) / 3600
        print('TAZ demands. Total vehicles: ', sum(cars_per_time_point))

        # TODO(yusef): reconcile.
        demands_dir = os.path.join(self._output_dir, _DEMANDS)
        file_util.f_makedirs(demands_dir)
        output_hist_figure_path = os.path.join(
            demands_dir, 'departure_time_histogram_taz_std_%s_portion_%s.pdf' %
            (demand_stddev_hours, population_portion))
        output_cumulative_figure_path = os.path.join(
            demands_dir,
            'departure_time_cumulative_taz_std_%s_portion_%s.pdf' %
            (demand_stddev_hours, population_portion))
        pkl_file = os.path.join(
            demands_dir, 'demands_taz_tuple_std_%s_portion_%s.pkl' %
            (demand_stddev_hours, population_portion))
        routes_file = os.path.join(
            demands_dir, 'demands_taz_std_%s_portion_%s.rou.xml' %
            (demand_stddev_hours, population_portion))

        # Output the demand xml file.
        visualizer.plot_demands_departure_time(
            departure_time_points,
            cars_per_time_point,
            output_hist_figure_path=output_hist_figure_path,
            output_cumulative_figure_path=output_cumulative_figure_path)
        file_util.save_variable(pkl_file, all_demands)
        exit_taz = 'exit_taz'
        traffic_generator.write_evacuation_vehicle_auto_routing_demands(
            all_demands, exit_taz, routes_file)
Пример #2
0
    def generate_evacuation_shortest_path_demands(
            self, residential_car_density, serving_car_density,
            evacuation_edges, demand_mean_hours, demand_stddev_hours,
            population_portion):
        """Generates evacuation demands."""
        net = sumolib.net.readNet(self._sumo_net_file)
        traffic_generator = random_traffic_generator.RandomTrafficGenerator(
            net)
        visualizer = map_visualizer.MapVisualizer(net)

        print('Generating TAZ demands with STD: ', demand_stddev_hours,
              ' Portion: ', population_portion)

        # Calculate the distance to the evacuation exits.
        evacuation_path_trees = {}
        evacuation_path_length = {}
        for exit_edge in evacuation_edges:
            evacuation_path_trees[exit_edge], evacuation_path_length[
                exit_edge] = (
                    net.getRestrictedShortestPathsTreeToEdge(exit_edge))

        # Demands from residential roads.
        residential_edge_type = ['highway.residential']
        residential_edges = net.filterEdges(residential_edge_type)
        demand_mean_seconds = demand_mean_hours * 60 * 60
        demand_stddev_seconds = demand_stddev_hours * 60 * 60
        time_sampler_parameters = random_traffic_generator.TimeSamplerGammaMeanStd(
            demand_mean_seconds, demand_stddev_seconds)
        car_per_meter_residential = residential_car_density * population_portion

        np.random.seed(FLAGS.random_seed)
        residential = traffic_generator.create_evacuation_shortest_path_demands(
            residential_edges, time_sampler_parameters,
            car_per_meter_residential, evacuation_edges, evacuation_path_trees,
            evacuation_path_length)

        # Demands from parking roads.
        parking_edge_type = ['highway.service']
        parking_edges = net.filterEdges(parking_edge_type)
        time_sampler_parameters = random_traffic_generator.TimeSamplerGammaMeanStd(
            demand_mean_seconds, demand_stddev_seconds)
        car_per_meter_parking = serving_car_density * population_portion

        parking = traffic_generator.create_evacuation_shortest_path_demands(
            parking_edges, time_sampler_parameters, car_per_meter_parking,
            evacuation_edges, evacuation_path_trees, evacuation_path_length)

        all_demands = residential + parking
        departure_time_points = [x.time for x in all_demands]
        cars_per_time_point = [x.num_cars for x in all_demands]
        departure_time_points = np.array(departure_time_points) / 3600
        print('Shortest path demands. Total vehicles: ',
              sum(cars_per_time_point))

        # Output the demand xml file.
        demands_dir = os.path.join(self._output_dir, _DEMANDS)
        file_util.f_makedirs(demands_dir)
        output_hist_figure_path = os.path.join(
            demands_dir,
            'departure_time_histogram_shortest_path_std_%s_portion_%s.pdf' %
            (demand_stddev_hours, population_portion))
        output_cumulative_figure_path = os.path.join(
            demands_dir,
            'departure_time_cumulative_shortest_path_std_%s_portion_%s.pdf' %
            (demand_stddev_hours, population_portion))
        pkl_file = os.path.join(
            demands_dir, 'demands_shortest_path_tuple_std_%s_portion_%s.pkl' %
            (demand_stddev_hours, population_portion))
        routes_file = os.path.join(
            demands_dir, 'demands_shortest_path_std_%s_portion_%s.rou.xml' %
            (demand_stddev_hours, population_portion))

        visualizer.plot_demands_departure_time(
            departure_time_points,
            cars_per_time_point,
            output_hist_figure_path=output_hist_figure_path,
            output_cumulative_figure_path=output_cumulative_figure_path)
        file_util.save_variable(pkl_file, all_demands)
        traffic_generator.write_evacuation_vehicle_path_demands(
            all_demands, routes_file)