|
| 1 | +#%% |
| 2 | +from hyplan.aircraft import DynamicAviation_B200 |
| 3 | +from hyplan.airports import Airport |
| 4 | +from hyplan.flight_line import FlightLine |
| 5 | +from hyplan.flight_plan import compute_flight_plan, plot_flight_plan, plot_altitude_trajectory |
| 6 | +from hyplan.flight_optimizer import build_graph, greedy_optimize |
| 7 | +from hyplan.units import ureg |
| 8 | +import logging |
| 9 | + |
| 10 | +logging.basicConfig(level=logging.INFO) |
| 11 | + |
| 12 | +# Define aircraft |
| 13 | +aircraft = DynamicAviation_B200() |
| 14 | + |
| 15 | +# Define airports |
| 16 | +departure_airport = Airport("KSBA") |
| 17 | +return_airport = Airport("KBUR") |
| 18 | + |
| 19 | +# Define several flight lines in the LA basin area |
| 20 | +flight_line_1 = FlightLine.start_length_azimuth( |
| 21 | + lat1=34.50, lon1=-118.20, |
| 22 | + length=ureg.Quantity(50000, "meter"), |
| 23 | + az=90.0, |
| 24 | + altitude=ureg.Quantity(15000, "feet"), |
| 25 | + site_name="Line_A" |
| 26 | +) |
| 27 | + |
| 28 | +flight_line_2 = FlightLine.start_length_azimuth( |
| 29 | + lat1=34.65, lon1=-118.10, |
| 30 | + length=ureg.Quantity(70000, "meter"), |
| 31 | + az=125.0, |
| 32 | + altitude=ureg.Quantity(18000, "feet"), |
| 33 | + site_name="Line_B" |
| 34 | +) |
| 35 | + |
| 36 | +flight_line_3 = FlightLine.start_length_azimuth( |
| 37 | + lat1=34.30, lon1=-117.80, |
| 38 | + length=ureg.Quantity(40000, "meter"), |
| 39 | + az=45.0, |
| 40 | + altitude=ureg.Quantity(15000, "feet"), |
| 41 | + site_name="Line_C" |
| 42 | +) |
| 43 | + |
| 44 | +flight_lines = [flight_line_1, flight_line_2, flight_line_3] |
| 45 | +airports = [departure_airport, return_airport] |
| 46 | + |
| 47 | +#%% Build graph and inspect |
| 48 | +print("Building graph...") |
| 49 | +G = build_graph(aircraft, flight_lines, airports) |
| 50 | +print(f"Graph: {G.number_of_nodes()} nodes, {G.number_of_edges()} edges") |
| 51 | +print(f"Nodes: {list(G.nodes)}") |
| 52 | +print() |
| 53 | + |
| 54 | +# Show edge types |
| 55 | +from collections import Counter |
| 56 | +edge_types = Counter(d["edgetype"] for _, _, d in G.edges(data=True)) |
| 57 | +print(f"Edge types: {dict(edge_types)}") |
| 58 | + |
| 59 | +#%% Run greedy optimization |
| 60 | +print("\nRunning greedy optimization...") |
| 61 | +result = greedy_optimize( |
| 62 | + aircraft=aircraft, |
| 63 | + flight_lines=flight_lines, |
| 64 | + airports=airports, |
| 65 | + takeoff_airport=departure_airport, |
| 66 | + return_airport=return_airport, |
| 67 | +) |
| 68 | + |
| 69 | +print(f"\nRoute: {result['route']}") |
| 70 | +print(f"Total time: {result['total_time']:.2f} hours") |
| 71 | +print(f"Lines covered: {result['lines_covered']}/{len(flight_lines)}") |
| 72 | +print(f"Refuel stops: {result['refuel_stops']}") |
| 73 | + |
| 74 | +#%% Feed optimized sequence into compute_flight_plan |
| 75 | +print("\nComputing flight plan from optimized sequence...") |
| 76 | +flight_plan_df = compute_flight_plan( |
| 77 | + aircraft, |
| 78 | + result["flight_sequence"], |
| 79 | + departure_airport, |
| 80 | + return_airport, |
| 81 | +) |
| 82 | +print(flight_plan_df[["segment_type", "segment_name", "distance", "time_to_segment"]]) |
| 83 | + |
| 84 | +#%% Plot |
| 85 | +plot_flight_plan(flight_plan_df, departure_airport, return_airport, result["flight_sequence"]) |
| 86 | +plot_altitude_trajectory(flight_plan_df) |
| 87 | + |
| 88 | +# %% |
0 commit comments