Example #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
Example #2
0
    def update_routes(self):
        self.routes, self.depart_info = Dispatcher.read_routes(
            self.routes_path, read_depart_info=True)

        for id_ev, m in self.measurements.items():
            if m.stopped_at_node_from and m.node_from == 0:
                m.time_finishing_service = self.depart_info[id_ev][0]
Example #3
0
        log_routes_folder = main_folder + 'logs/routes/'
        log_histories_folder = main_folder + 'logs/histories/'

        makedirs(log_measurements_folder, exist_ok=True)
        makedirs(log_routes_folder, exist_ok=True)
        makedirs(log_histories_folder, exist_ok=True)

        # Simulation object
        sim = Simulator(net_path, fleet_path, measurements_path, routes_path, history_path, mat_path, 5.,
                        main_folder=main_folder, std_factor=std_factor)

        # Drop time windows and save
        sim.network.drop_time_windows(filepath=sim.network_path)

        # Dispatcher to optimize
        dispatcher = Dispatcher.Dispatcher(sim.network_path, sim.fleet_path, sim.measurements_path, sim.routes_path,
                                           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')
Example #4
0
 def write_routes(self):
     Dispatcher.write_routes(self.routes_path,
                             self.routes,
                             depart_info=None,
                             write_pretty=False)
Example #5
0
 def write_measurements(self):
     Dispatcher.write_measurements(self.measurements_path,
                                   self.measurements,
                                   write_pretty=False)
Example #6
0
 def create_measurements_file(self):
     return Dispatcher.create_measurements_file(self.measurements_path,
                                                self.routes_path)
Example #7
0
                                            MUTPB=0.6,
                                            weights=(0.1 / 2.218, 1. / 0.4364,
                                                     1. / 100, 1. / 500, 1.),
                                            K1=100000,
                                            K2=200000,
                                            keep_best=1,
                                            tournament_size=3,
                                            r=2,
                                            alpha_up=soc_policy[1],
                                            algorithm_name='onGA',
                                            crossover_repeat=1,
                                            mutation_repeat=1)

    dispatcher = Dispatcher.Dispatcher(
        net_path,
        fleet_path,
        measurements_path,
        routes_path,
        onGA_hyper_parameters=onGA_hyper_parameters)

    dispatcher.update()
    cp_info = dispatcher.synchronization()
    routes_from_critical_points = {}

    for id_ev in cp_info.keys():
        r = dispatcher.routes[id_ev]
        j_critical = cp_info[id_ev][0]
        x1_0 = cp_info[id_ev][1]
        x2_0 = cp_info[id_ev][2]
        x3_0 = cp_info[id_ev][3]
        ev = dispatcher.fleet.vehicles[id_ev]
        ev.current_max_tour_duration = ev.max_tour_duration + dispatcher.depart_info[