Exemple #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
max_payload = 0.58  # tonnes
weight = 1.52  # tonnes
max_tour_duration = 7 * 60.

# %% Instance fleet
if stochastic:
    ev = Fleet.EV.GaussianElectricVehicle(ev_id, weight, battery_capacity,
                                          battery_capacity_nominal, alpha_upp,
                                          alpha_down, max_tour_duration,
                                          max_payload)
else:
    ev = Fleet.EV.ElectricVehicle(ev_id, weight, battery_capacity,
                                  battery_capacity_nominal, alpha_upp,
                                  alpha_down, max_tour_duration, max_payload)

if stochastic:
    fleet = Fleet.GaussianFleet({0: ev}, network)
else:
    fleet = Fleet.Fleet({0: ev}, network)

fleet.hard_penalization = hard_penalization
fleet.resize_fleet(fleet_size)
# %% Save fleet
fleet.write_xml(f'{main_folder}fleet.xml',
                network_in_file=True,
                assign_customers=False,
                with_routes=False,
                print_pretty=print_pretty)

fleet2 = Fleet.from_xml(f'{main_folder}fleet.xml')
Exemple #3
0
 def update_fleet(self):
     self.fleet = Fleet.from_xml(self.fleet_path, assign_customers=False, with_routes=False, instance=False,
                                 from_online=False)
                                           MUTPB=0.85,
                                           hard_penalization=200000,
                                           elite_individuals=1,
                                           tournament_size=5,
                                           r=3)
hp_beta = GATools.BetaGA_HyperParameters(weights,
                                         CXPB=0.6,
                                         MUTPB=0.8,
                                         hard_penalization=200000,
                                         elite_individuals=1,
                                         tournament_size=5)

if __name__ == '__main__':
    for i in range(3):
        # %% Read instance data
        fleet = Fleet.from_xml(folder + instance_name + '.xml')
        soc_policy = (fleet.vehicles[0].alpha_down, fleet.vehicles[0].alpha_up)

        # %% Initial population and fleet size
        N = int(
            sum([fleet.network.demand(i) for i in fleet.network.customers]) /
            fleet.vehicles[0].max_payload) + 1
        fill_up_to = N / (
            N + additional_vehicles) if additional_vehicles else fill_up_to
        init_pop, m = alphaGA.heuristic_population_1(hp_alpha.r, fleet,
                                                     fill_up_to)
        fleet.resize_fleet(m)
        hp_alpha.num_individuals = 10 * len(fleet) + 5 * len(
            fleet.network) + 10
        hp_alpha.max_generations = 3 * hp_alpha.num_individuals + 15
        hp_alpha.alpha_up = fleet.vehicles[0].alpha_up