コード例 #1
0
 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)
コード例 #2
0
    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)
コード例 #3
0
    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)
コード例 #4
0
    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")
コード例 #5
0
 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")
コード例 #6
0
    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)
コード例 #7
0
    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)
コード例 #8
0
    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")
コード例 #9
0
    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)
コード例 #10
0
    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)
コード例 #11
0
    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)
コード例 #12
0
 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))
コード例 #13
0
    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)
コード例 #14
0
 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))
コード例 #15
0
 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")
コード例 #16
0
    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)
コード例 #17
0
ファイル: bay_gate_solver.py プロジェクト: aarondewindt/ooc
    def __init__(self,
                 airport_data_path,
                 flights_data_path,
                 jid,
                 cplex_command="cplex",
                 buffer_time=None,
                 spare_bays=None,
                 line_width_limit=120):
        self.line_width_limit = line_width_limit

        self.airport = Airport(airport_data_path=airport_data_path)
        """"
        class:`ooc.Airport` object of holding the information of
        the target airport.
        """

        self.flights = Flights(flight_data_path=flights_data_path,
                               airport=self.airport,
                               buffer_time=buffer_time,
                               spare_bays=spare_bays)
        """
        class:`ooc.Flights` object holding the information of all
        flights of the day
        """

        self.jid = jid
        """
        Job id. This is a unique id for a specific run or set of runs. The workspace
        folder will be named after the jid.
        """

        self.workspace_path = abspath("./" + self.jid)
        """
        Path to directory which will hold all of the generated lp files ond solutions.
        """

        self.solutions = []  # List holding the final solution.

        self.init_workspace()  # Initialize workspace.
        self.init_solution_list()

        # Create a few path to relevant paths.
        self.bay_lp_path = normpath(join(self.workspace_path, "bay.lp"))
        self.bay_sol_path = normpath(join(self.workspace_path, "bay.sol"))
        self.gate_lp_path = normpath(join(self.workspace_path, "gate.lp"))
        self.gate_sol_path = normpath(join(self.workspace_path, "gate.sol"))
        self.result_path = normpath(join(self.workspace_path, "result.csv"))

        # Check whether we can access cplex from the command line.
        try:
            # For some reason the 'subprocess.run' function does not work like described in the documentation in
            # linux. So after some trail and error I got it working by giving it a list with
            if sys.platform == "linux":
                args = [cplex_command + " -c help"]
            else:  # This works on Windows. Probably also MAC since this is the behaviour described in the documentation
                args = [cplex_command, "-c", "help"]
            result = subprocess.run(args,
                                    shell=True,
                                    stdout=subprocess.PIPE,
                                    stderr=subprocess.PIPE)

            # We can. Store command for later use.
            if len(result.stderr):
                print_color.pr_r(
                    "Warning: Cplex was not found. Please check whether the cplex command is correct. Otherwise cplex "
                    "will have to be run separately.")
                self.cplex_command = None
            else:
                self.cplex_command = cplex_command
        except OSError:
            # We can't. We'll have to run the solver manually.
            print_color.pr_r(
                "Warning: Cplex was not found. Please check whether the cplex command is correct. Otherwise cplex "
                "will have to be run separately.")
            self.cplex_command = None