def __init__(self, num_flights=50, num_airlines=5, triples=True, reduction_factor=100, discretisation_size=50, custom_schedule=None, df=None, xp_problem=None): scheduleTypes = scheduleMaker.schedule_types(show=False) # init variables, schedule and cost function if custom_schedule is None and df is None: schedule_df = scheduleMaker.df_maker(num_flights, num_airlines, distribution=scheduleTypes[0]) else: if df is None: schedule_df = scheduleMaker.df_maker(custom=custom_schedule) else: schedule_df = df self.reductionFactor = reduction_factor self.costFun = CostFuns().costFun["realistic"] self.flightTypeDict = CostFuns().flightTypeDict self.discretisationSize = discretisation_size if xp_problem is None: self.xp_problem = xp.problem() else: self.xp_problem = xp_problem with HiddenPrints(): self.xp_problem.reset() # internal optimisation step udpp_model_xp = udppModel.UDPPmodel(schedule_df, self.costFun, self.xp_problem) udpp_model_xp.run() with HiddenPrints(): self.xp_problem.reset() super().__init__(udpp_model_xp.get_new_df(), self.costFun, triples=triples, xp_problem=self.xp_problem) flights = [flight for flight in self.flights] for flight in self.flights: flights[flight.slot.index] = flight self.flights = flights self.set_flights_input_net(self.discretisationSize) self.offerChecker = checkOffer.OfferChecker(self.scheduleMatrix) _, self.matches_vect = self.offerChecker.all_couples_check( self.airlines_pairs) self.reverseAirDict = dict( zip(list(self.airDict.keys()), list(self.airDict.values())))
def make_batch(batchSize): inputs = [] outputs = [] initialCosts = [] airlines = [] UDPPmodels = [] for run in range(batchSize): df = df_maker(custom=[6, 4, 3, 7, 2, 8]) df["margins"] = [ random.choice(range(10, 50)) for i in range(df.shape[0]) ] costFun = CostFuns().costFun["linear"] udMod = udppModel.UDPPmodel(df, costFun) UDPPmodels.append(udMod) airline = [air for air in udMod.airlines if air.name == "A"][0] airlines.append(airline) initialCosts.append(udMod.compute_costs(airline.flights, "initial")) with HiddenPrints(): UDPPlocalOpt(airline, udMod.slots) inputVect = make_network_input(airline) outputVect = make_network_output(airline) inputs.append(inputVect) outputs.append(outputVect) return inputs, outputs, airlines, UDPPmodels
import numpy as np import time import pandas as pd airline: IstopAirline flight: IstopFlight np.random.seed(0) scheduleTypes = scheduleMaker.schedule_types(show=True) # init variables, chedule and cost function num_flights = 3 num_airlines = 4 # schedule_df = scheduleMaker.df_maker(num_flights, num_airlines, distribution=scheduleTypes[0]) schedule_df = scheduleMaker.df_maker( custom=[num_flights for _ in range(num_airlines)]) schedule_df.to_csv("custom_" + str(num_airlines) + "_" + str(num_flights) + ".csv") # schedule_df_1 = pd.read_csv("custom_5_5.csv") # print(schedule_df["type"]==schedule_df_1["type"]) cost_fun = CostFuns().costFun["realistic"] # create model # rl_model = old_rl.Rl(schedule_df, cost_fun, triples=True, parallel=False) # # # t = time.perf_counter() # couple_matches = rl_model.all_couples_matches() # print("time to get all couple matches: ", time.perf_counter() - t) # print(len(couple_matches), " convenient pairs found", "\n") #
This model optimise the total cost constraining all airline to don't have negative impact UDPP = full udpp internal (not exactly) optimisation ISTOP = offer provider """ np.random.seed(0) scheduleType = scheduleMaker.schedule_types(show=True) num_flights = 50 num_airlines = 9 for i in range(0, 1): df = scheduleMaker.df_maker(num_flights, num_airlines, distribution=scheduleType[3]) df_NNB = df.copy(deep=True) df_UDPP = df_NNB.copy(deep=True) costFun = CostFuns().costFun["realistic"] print("max from FPFS") max_model = nnBound.NNBoundModel(df_NNB, costFun) max_model.run() max_model.print_performance() max_model.m.write("problem", "lp") print("UDPP Opt from FPFS") udpp_model_xp = udppModel.UDPPmodel(df_UDPP, costFun) udpp_model_xp.run()
from ModelStructure.ScheduleMaker import scheduleMaker from UDPP.udppModel import UDPPmodel from ModelStructure.Costs.costFunctionDict import CostFuns import pandas as pd final_df: pd.DataFrame costFun = CostFuns().costFun["step"] final_df = pd.DataFrame(columns=["instance", "airline", "margins", "priority", "eta", "slot", "new slot"]) scheduleType = scheduleMaker.schedule_types(show=False) for i in range(5000): df = scheduleMaker.df_maker(50, 4, distribution=scheduleType[0]) udMod = UDPPmodel(df, costFun) udMod.run(optimised=True) for airline in udMod.airlines: for flight in airline.flights: to_append = [i, flight.airline, flight.margin, flight.priority, flight.eta, flight.slot.time, flight.newSlot.time] a_series = pd.Series(to_append, index=final_df.columns) final_df = final_df.append(a_series, ignore_index=True) if i % 50 ==0: print(i) # standardisation for col in final_df.columns[2:-1]: final_df[col] = (final_df[col] - final_df[col].mean()) / final_df[col].std() final_df.to_csv("50_4_increase.csv")
instance = instanceMaker.Instance(num_flights=num_flights, num_airlines=num_airlines) mat = instance.get_schedule_tensor() print(instance.airDict) print(instance.flightTypeDict) # for i in range(mat.shape[0]): # flight = instance.flights[i] # print(flight.airline, flight.type, instance.flightDict[flight.type], flight, flight.slot.time - flight.eta) # print(mat[i]) from Old_RL import old_rl import pandas as pd df = scheduleMaker.df_maker(custom=[5, 5, 5, 5]) mod = old_rl.Rl(df, CostFuns().costFun["realistic"]) dfSchedules = mod.udppDf dfSchedules["instance"] = [0 for _ in range(20)] dfSchedMat = pd.DataFrame(mod.scheduleMatrix.T) dfSchedMat["instance"] = [0 for _ in range(22)] for i in range(1, 201): df = scheduleMaker.df_maker(custom=[5, 5, 5, 5]) mod = old_rl.Rl(df, CostFuns().costFun["realistic"]) dfS = mod.udppDf dfS["instance"] = [i for _ in range(20)] dfSM = pd.DataFrame(mod.scheduleMatrix.T) dfSM["instance"] = [i for _ in range(22)] dfSchedules = dfSchedules.append(dfS, ignore_index=True)
# udMod.run(optimised=True) # udMod.print_performance() # # # output = net.prioritisation(make_network_input(airline)) # prValues, times = make_prioritisation(output) # i = 0 # for f in airline.flights: # print(f.slot, f.priorityValue, f.newSlot.time, prValues[i], times[i]) # i += 1 net.load_weights("netWeights.pt") for i in range(10): print("\n\n\n", "run ", i) df = scheduleMaker.df_maker(custom=[6, 4, 3, 7, 2, 8]) df["margins"] = [random.choice(range(10, 50)) for i in range(df.shape[0])] df1 = df.copy(deep=True) udMod = UDPPmodel(df, costFun) udMod.run(optimised=True) udMod.print_performance() print(udMod.solution[udMod.solution["airline"] == "A"]) airline_opt = [air for air in udMod.airlines if air.name == "A"][0] udMod = UDPPmodel(df1, costFun) airline = [air for air in udMod.airlines if air.name == "A"][0] output = net.prioritisation(make_network_input(airline)) prValues, times = make_prioritisation(output) print(airline_opt.numFlights, airline.numFlights, len(prValues)) j = 0 k = 0