Esempio n. 1
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")
Esempio n. 2
0
    def solve_bay_assignment(self):
        """
        Generates the lp code needed to solve the bay assignment,
        solves it using cplex and loads in the solution.
        """
        t0 = perf_counter()
        bay_assignment = BayAssignment(self.flights,
                                       line_width_limit=self.line_width_limit)

        # Generate and save lp code.
        with open(self.bay_lp_path, "w") as f:
            f.write(bay_assignment.lp_code())
        dt_code_generation = perf_counter() - t0
        dt_solving = 0

        if self.cplex_command is not None:
            print("Solving bay assignment with cplex...")
            # Remove old solution file
            if isfile(self.bay_sol_path):
                remove(self.bay_sol_path)

            # Try to solve it.
            # 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 = [
                    self.cplex_command +
                    " -c 'read {}' optimize 'write {}'".format(
                        self.bay_lp_path, self.bay_sol_path)
                ]
            else:  # This works on Windows. Probably also MAC since this is the behaviour described in the documentation
                args = [
                    self.cplex_command, "-c",
                    "read {}".format(self.bay_lp_path, ), "optimize",
                    "write {}".format(self.bay_sol_path)
                ]
            t0 = perf_counter()
            subprocess.run(
                args,
                shell=True,
            )
            dt_solving = perf_counter() - t0

            if not isfile(self.bay_sol_path):
                raise Exception(
                    "No solution file was generated for the bay assignment.")

            print("Bay assignment solved\n")
        else:
            print(
                "Cplex is not available in the command line.\n"
                "The bay assignment lp code was generated and saved at\n{}\n".
                format(self.bay_lp_path) +
                "Please solve it in cplex and save the resulting .sol (xml) file at\n{}\n"
                .format(self.bay_sol_path))

        return dt_code_generation, dt_solving
Esempio n. 3
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)
Esempio n. 4
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)
Esempio n. 5
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)
Esempio n. 6
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)