def test_bay_gate_distance(self): airport = Airport(abs_path("./airport_data")) self.assertEquals(airport.n_gates, 23) k, l = 14, 22 print(airport.bay_names[k], airport.gate_names[l], airport.bay_gate_distance[k][l]) self.assertAlmostEquals(airport.bay_gate_distance[26][13], 742.0) self.assertAlmostEquals(airport.bay_gate_distance[14][22], 279.0)
def test_load_remote_bays(self): airport = Airport(abs_path("./airport_data")) self.assertIn(24, airport.remote_bays) self.assertIn(25, airport.remote_bays) self.assertIn(26, airport.remote_bays) self.assertIn(33, airport.remote_bays) self.assertIn(35, airport.remote_bays)
def test_load_adjacency(self): """ Checks whether the adjacency matrix has been loaded correctly. """ airport = Airport(abs_path("./airport_data")) self.assertEquals(airport.adjacency[0], (8, 9)) self.assertEquals(airport.adjacency[1], (13, 14))
def test_weights(self): airport = Airport(abs_path("./airport_data")) flights = Flights(abs_path("./flight_data_small"), airport) bay_assignment = BayAssignment(flights) weights = (bay_assignment.alpha, bay_assignment.beta, bay_assignment.gamma) print(weights) set_correct("test_weights", weights) self.assertEqual(get_correct("test_weights"), weights)
def test_is_overnight(self): airport = Airport(abs_path("./airport_data")) flights = Flights(abs_path("./flight_data_small"), airport) self.assertIs(flights.is_overnight(0), False) self.assertIs(flights.is_overnight(4), True) self.assertIs(flights.is_overnight(5), True) self.assertIs(flights.is_overnight(6), True) self.assertIs(flights.is_overnight(2), False)
def test_n_flights(self): """ Check if the number of flights loaded in is correct. :return: """ airport = Airport(abs_path("./airport_data")) flights = Flights(abs_path("./flight_data_small"), airport) self.assertEquals(flights.n_flights, 13)
def test_terminal(self): """ Checks whether the correct terminal has been found for the flights. :return: """ airport = Airport(abs_path("./airport_data")) flights = Flights(abs_path("./flight_data_small"), airport) self.assertEquals(flights.terminal(0), "C") self.assertEquals(flights.terminal(3), "C")
def test_lp_code(self): airport = Airport(abs_path("./airport_data")) flights = Flights(abs_path("./flight_data_small"), airport) bay_assignment = BayAssignment(flights) code = bay_assignment.lp_code() # print(code) bay_assignment.save_lp_file("ba.lp")
def test_domestic(self): """ Checks whether domestic flights are detected correctly. """ airport = Airport(abs_path("./airport_data")) flights = Flights(abs_path("./flight_data_small"), airport) self.assertIs(flights.domestic(0), False) self.assertIs(flights.domestic(6), True)
def test_load_bay_terminal_distance(self): airport = Airport(abs_path("./airport_data")) # Same as in test_load_bay_compliance_matrix, I'll just test a few cases. self.assertEquals(airport.terminal_names[0], "A") self.assertEquals(airport.terminal_names[-1], "D") self.assertAlmostEqual(airport._bay_terminal_distance[0]["A"], 19) self.assertAlmostEqual(airport._bay_terminal_distance[22]["C"], 18) self.assertAlmostEqual(airport._bay_terminal_distance[-1]["B"], 100)
def test_n_passengers(self): """ Checks whether the number of passengers for each flight is correct. """ airport = Airport(abs_path("./airport_data")) flights = Flights(abs_path("./flight_data_small"), airport) self.assertEquals(flights.n_passengers(0), 440) self.assertEquals(flights.n_passengers(3), 189) self.assertEquals(flights.n_passengers(7), 114)
def test_airline(self): """ Checks whether the airline detection code is working. :return: """ airport = Airport(abs_path("./airport_data")) flights = Flights(abs_path("./flight_data_small"), airport) self.assertEquals(flights.airline(0), "BA") self.assertEquals(flights.airline(5), "KQ")
def test_constraint_fueling(self): airport = Airport(abs_path("./airport_data")) flights = Flights(abs_path("./flight_data_small"), airport) bay_assignment = BayAssignment(flights) bay_assignment.constraint_single_bay_compliance() code = bay_assignment.constraint_fueling() print(code) set_correct("test_constraint_fueling", code) self.assertEqual(get_correct("test_constraint_fueling"), code)
def test_penalty_values(self): airport = Airport(abs_path("./airport_data")) flights = Flights(abs_path("./flight_data_small"), airport) bay_assignment = BayAssignment(flights) bay_assignment.constraint_single_bay_compliance() bay_assignment.constraint_adjacency() bay_assignment.constraint_splitted_flight() code = bay_assignment.of_penalty_values() print(code) set_correct("test_penalty_values", code) self.assertEqual(get_correct("test_penalty_values"), code)
def test_of_max_airline_preference(self): airport = Airport(abs_path("./airport_data")) flights = Flights(abs_path("./flight_data_small"), airport) bay_assignment = BayAssignment(flights) # This is the only function allowed to create new decision variables, so it has to be called first. bay_assignment.constraint_single_bay_compliance() code = bay_assignment.of_max_airline_preference() # print(code) set_correct("test_of_max_airline_preference", code) self.assertEqual(get_correct("test_of_max_airline_preference"), code)
def test_preference(self): """ Checks whether the preference table has been loaded in correctly. """ # The preference function has to be implemented first. airport = Airport(abs_path("./airport_data")) flights = Flights(abs_path("./flight_data_small"), airport) self.assertEquals(flights.preferences_table["KQ210"].dest, "BOM") self.assertEquals(flights.preferences_table["KQ210"].bays, (21, )) self.assertEquals(flights.preferences_table["KQ210"].gates, (15, )) self.assertEquals(flights.preferences_table["ET"].dest, "ADD") self.assertEquals(flights.preferences_table["ET"].bays, (11, 12)) self.assertEquals(flights.preferences_table["ET"].gates, (6, 7))
def test_time_conflict(self): """ Checks whether the time conflict function works correctly. """ airport = Airport(abs_path("./airport_data")) flights = Flights(abs_path("./flight_data_small"), airport) self.assertIs(flights.time_conflict(6, 7), True) self.assertIs(flights.time_conflict(8, 9), True) self.assertIs(flights.time_conflict(0, 4), False) self.assertIs(flights.time_conflict(0, 2), False) self.assertIs(flights.time_conflict(7, 8), False)
def test_process_overnight_flights(self): airport = Airport(abs_path("./airport_data")) flights = Flights(abs_path("./flight_data_small"), airport) self.assertEquals(flights.flight_schedule[4].eta, datetime.datetime(2015, 6, 1, 21, 15)) self.assertEquals(flights.flight_schedule[4].etd, datetime.datetime(2015, 6, 1, 22, 39)) self.assertEquals(flights.flight_schedule[5].eta, datetime.datetime(2015, 6, 1, 22, 45)) self.assertEquals(flights.flight_schedule[5].etd, datetime.datetime(2015, 6, 2, 5, 14)) self.assertEquals(flights.flight_schedule[6].eta, datetime.datetime(2015, 6, 2, 5, 20)) self.assertEquals(flights.flight_schedule[6].etd, datetime.datetime(2015, 6, 2, 6, 50))
def test_load_bay_compliance_matrix(self): airport = Airport(abs_path("./airport_data")) # There is no lazy way to generate a large list of asserts. So # I'll just a few random ones. # Test bay list self.assertEquals(airport.bay_names[0], "2A") self.assertEquals(airport.bay_names[-1], "SPV2") self.assertEquals(airport.bay_names[18], "15") self.assertIs(airport.bay_compliance_matrix[0]["H"], False) self.assertIs(airport.bay_compliance_matrix[0]["A"], True) self.assertIs(airport.bay_compliance_matrix[-1]["H"], False) self.assertIs(airport.bay_compliance_matrix[-1]["A"], True) self.assertIs(airport.bay_compliance_matrix[22]["H"], True) self.assertIs(airport.bay_compliance_matrix[22]["A"], False)
def test_load_flight_data(self): """ Checks whether the flight schedule data is loaded in properly. It Tests a few random data point in the table to see if those where loaded in correctly. """ airport = Airport(abs_path("./airport_data")) flights = Flights(abs_path("./flight_data_small"), airport) self.assertEquals(flights.flight_schedule[0].flight_type, ft.Full) self.assertEquals(flights.flight_schedule[0][0], ft.Full) self.assertEquals(flights.flight_schedule[0].eta, datetime.datetime(2015, 6, 2, 20, 30)) self.assertEquals(flights.flight_schedule[6].flight_type, ft.Dep) self.assertEquals(flights.flight_schedule[6].ac_type, "E90") self.assertIsNone(flights.flight_schedule[5].in_flight_no) self.assertEquals(flights.flight_schedule[0].in_flight_no, "BA065") self.assertEquals(flights.flight_schedule[7].in_flight_no, "KQ419")
def load_small_case(): """ This is not a unit test. This function is used to load in the small flight schedule case. :return: """ airport = Airport(abs_path("./airport_data")) flights = Flights(abs_path("./flight_data_small"), airport) bay_solution = [ "11", "8", "8", "8", "14", "14", "14", "16", "2B", "4L", "3B", "3C", "16" ] for i, bay_name in enumerate(bay_solution): if bay_name in airport.bay_names: bay_solution[i] = airport.bay_names.index(bay_name) return GateAssignment(flights, bay_solution)
def test_load_aircraft(self): airport = Airport(abs_path("./airport_data")) self.assertEquals(airport.aircraft["B747"], ("H", 660)) self.assertEquals(airport.aircraft["B772"], ("G", 440)) self.assertEquals(airport.aircraft["B773"], ("G", 550)) self.assertEquals(airport.aircraft["B787"], ("F", 250)) self.assertEquals(airport.aircraft["B788"], ("F", 290)) self.assertEquals(airport.aircraft["A330"], ("F", 335)) self.assertEquals(airport.aircraft["A332"], ("F", 253)) self.assertEquals(airport.aircraft["B767"], ("F", 375)) self.assertEquals(airport.aircraft["B73J"], ("E", 132)) self.assertEquals(airport.aircraft["B737"], ("D", 132)) self.assertEquals(airport.aircraft["B738"], ("D", 189)) self.assertEquals(airport.aircraft["A320"], ("D", 180)) self.assertEquals(airport.aircraft["E90"], ("C", 114)) self.assertEquals(airport.aircraft["CRJ9"], ("B", 90)) self.assertEquals(airport.aircraft["B733"], ("B", 137)) self.assertEquals(airport.aircraft["E70"], ("B", 78)) self.assertEquals(airport.aircraft["Q400"], ("B", 78)) self.assertEquals(airport.aircraft["AT4"], ("A", 52)) self.assertEquals(airport.aircraft["AT7"], ("A", 72))
def test_load_domestic_airports(self): airport = Airport(abs_path("./airport_data")) self.assertIn("HOA", airport.domestic_airports) self.assertIn("GGM", airport.domestic_airports) self.assertIn("KLK", airport.domestic_airports) self.assertIn("KEY", airport.domestic_airports) self.assertIn("ILU", airport.domestic_airports) self.assertIn("KRV", airport.domestic_airports) self.assertIn("KIS", airport.domestic_airports) self.assertIn("KTL", airport.domestic_airports) self.assertIn("KWY", airport.domestic_airports) self.assertIn("LBN", airport.domestic_airports) self.assertIn("LAU", airport.domestic_airports) self.assertIn("LBK", airport.domestic_airports) self.assertIn("LOK", airport.domestic_airports) self.assertIn("LOY", airport.domestic_airports) self.assertIn("LKG", airport.domestic_airports) self.assertIn("MYD", airport.domestic_airports) self.assertIn("NDE", airport.domestic_airports) self.assertIn("RBT", airport.domestic_airports) self.assertIn("MRE", airport.domestic_airports)
def test_load_gates(self): airport = Airport(abs_path("./airport_data")) self.assertIn("18", airport.gate_names)
def test_max_distance(self): airport = Airport(abs_path("./airport_data")) print(airport.max_distance)
def test_terminal_bay_distance(self): airport = Airport(abs_path("./airport_data")) self.assertAlmostEqual(airport.terminal_bay_distance("A", 0), 19)
def test_n_bays(self): airport = Airport(abs_path("./airport_data")) self.assertEquals(airport.n_bays, 48)
def test_n_gates(self): airport = Airport(abs_path("./airport_data")) self.assertEquals(airport.n_gates, 23)
def test_load_airlines(self): airport = Airport(abs_path("./airport_data")) self.assertEquals(airport.airlines["KQ"], (999, "A")) self.assertEquals(airport.airlines["G9"], (999, "B")) self.assertEquals(airport.airlines["EY"], (999, "C")) self.assertEquals(airport.airlines["SA"], (999, "B"))
def test_load_fueling(self): airport = Airport(abs_path("./airport_data")) self.assertIs(airport.fueling[0], True) self.assertIs(airport.fueling[33], False)