Beispiel #1
0
    def get_cheapest_route(self):
        # calculates the cost of each possible route and returns the cheapest route (and its cost)
        if self.__error is not None:                                  # if there are no valid routes for this itinerary
            return None, 10 ** 10
        lowest_cost = 10 ** 10                        # method will return this number if itinerary cannot be completed
        self.route_list = self.build_route_list()
        self.cheapest_route = None

        for route in self.route_list:
            total_cost_of_stopovers = self.__stopover_cost * (len(route) - len(self.__airport_list))
            try:
                current_route = Route(route,
                                      self.__aircraft_range,
                                      self.__airport_atlas,
                                      self.__currency_table,
                                      self.__empty_tank,
                                      total_cost_of_stopovers)
            except ImpossibleRouteError:
                continue                                              # this route has a leg that cannot be completed
            else:
                current_route_cost = current_route.get_cost_of_route()
                if current_route_cost < lowest_cost:
                    self.cheapest_route = current_route
                    lowest_cost = current_route_cost
        if lowest_cost == 10 ** 10:                                   # if itinerary cannot be completed
            print("Aircraft has insufficient range to complete this itinerary.")
            print("Consider using a larger aircraft or adding a fuel stop to the list of hubs.")
            self.__error = "Aircraft has insufficient range to complete this itinerary." \
                           "\nConsider using a larger aircraft or adding a fuel stop to the list of hubs."
            self.cheapest_route = None
        else:
            print()
            print(self.cheapest_route)
            self.cheapest_route.print_costs()
            print()
        self.lowest_cost = lowest_cost
        return self.cheapest_route, lowest_cost