Ejemplo n.º 1
0
    def __init__(self,
                 network_path: str,
                 fleet_path: str,
                 measurements_path: str,
                 routes_path: str,
                 history_path: str,
                 mat_path: str,
                 sample_time: float,
                 main_folder: str = None,
                 std_factor: Tuple = (1., 1.),
                 create_routes_xml: bool = True,
                 create_measurements_xml: bool = True,
                 create_history_xml: bool = True):
        if main_folder:
            self.network_path = f'{main_folder}{network_path.split("/")[-1][:-4]}_temp.xml'
            self.fleet_path = f'{main_folder}{fleet_path.split("/")[-1][:-4]}_temp.xml'
        else:
            self.network_path = net_path
            self.fleet_path = fleet_path

        self.measurements_path = measurements_path
        self.history_path = history_path
        self.mat_path = mat_path
        self.sample_time = sample_time

        self.network = Network.from_xml(network_path, instance=False)
        self.fleet = Fleet.from_xml(fleet_path,
                                    assign_customers=False,
                                    with_routes=False,
                                    instance=False)

        self.network.write_xml(self.network_path, print_pretty=False)
        self.fleet.write_xml(self.fleet_path,
                             network_in_file=False,
                             assign_customers=False,
                             with_routes=False,
                             print_pretty=False)

        self.day_points = int(1440 / self.network.edges[0][0].sample_time)

        self.data = self.data_from_mat_file()

        if main_folder:
            self.routes_path = f'{main_folder}{routes_path.split("/")[-1]}'
        else:
            self.routes_path = routes_path

        self.routes, self.depart_info = Dispatcher.read_routes(
            routes_path, read_depart_info=True)
        Dispatcher.write_routes(self.routes_path,
                                self.routes,
                                self.depart_info,
                                write_pretty=False)

        self.measurements, _ = self.create_measurements_file()
        self.history = FleetHistory().create_from_routes(self.routes)
        self.save_history()

        self.std_factor = std_factor
Ejemplo n.º 2
0
                                           onGA_hyper_parameters=onGA_hyper_parameters)

        # Start loop
        non_altered = 0
        while not sim.done():
            if non_altered < keep:
                non_altered += 1
            else:
                sim.disturb_network()
                non_altered = 0

            sim.forward_fleet()
            sim.save_history()

            # Time when everything occurs
            log_time = datetime.today().strftime('%Y_%m_%d-%H_%M_%S')

            # Log measurements
            if log_online:
                log_measurements_path = log_measurements_folder + log_time + '.xml'
                Dispatcher.write_measurements(log_measurements_path, sim.measurements)

            # Optimize
            dispatcher.update()
            dispatcher.optimize_online(exec_time_filepath=exec_time_path)

            # Log routes after optimization
            if log_online:
                log_routes_path = log_routes_folder + log_time + '.xml'
                Dispatcher.write_routes(log_routes_path, dispatcher.routes, dispatcher.depart_info)
Ejemplo n.º 3
0
 def write_routes(self):
     Dispatcher.write_routes(self.routes_path,
                             self.routes,
                             depart_info=None,
                             write_pretty=False)