1 // trial flight class with trial planning-related methods
3 public class TrialFlight {
6 Flight oldFlight, trialFlight;
8 Trajectory trialTrajectory;
12 // differences between the old flight and the trial flight follow:
13 double timeDiff, distDiff; // time and distance difference
14 ConflictList oldConflicts, newConflicts; // the lists of conflicts
15 int noNew, noRemoved; // the number of new and removed conflicts, respectively
17 // constructor of a trial flight using a shortcut between two fixes.
18 public TrialFlight(D2 d2, Flight flight, Fix fix1, Fix fix2) {
20 int aux, fixIndex1, fixIndex2;
22 fixIndex1=oldFlight.fPlan.r.getIndexOf(fix1);
23 fixIndex2=oldFlight.fPlan.r.getIndexOf(fix2);
24 if (fixIndex1>fixIndex2) {
29 trialFlight=Flight.copyOf(d2, oldFlight);
30 trialFlight.trialStatus=Flight.trialFlightStatus();
31 this.changeToTrialRoute(fixIndex1, fixIndex2);
34 // constructor for a trial flight using the current position of a plane
35 public TrialFlight(D2 d2, Flight flight, String fixName) {
40 // constructor that uses an estimated position and a fix
41 public TrialFlight(D2 d2, Flight flight, Point4d position, Fix fix) {
45 fixIndex=oldFlight.fPlan.r.getIndexOf(fix);
46 trialFlight=Flight.copyOf(d2, oldFlight);
47 trialFlight.trialStatus=Flight.trialFlightStatus();
48 oldFlight.updateTrajectory(position.time);
49 // assuming that the position given as parameter is the same as the first point in the trajectory
50 trialFlight.track=new Track(new Point4d(position), new Velocity(oldFlight.track.vel));
51 trialFlight.fPlan=new FlightPlan(oldFlight.fPlan);
52 changeToTrialRoute(position, fixIndex);
53 trajectoryDiff(position.time);
54 conflictsDiff(position.time);
55 System.out.println("old route:"+oldFlight.fPlan.r);
56 System.out.println("new route:"+trialFlight.fPlan.r);
57 trialFlight.trialStatus=-1;
60 public void trajectoryDiff (double time) {
61 trialFlight.updateTrajectory(time);
62 oldFlight.updateTrajectory(time);
63 System.out.println("Flight "+trialFlight.flightID+":");
64 distDiff=oldFlight.traject.distanceToDestination()-
65 trialFlight.traject.distanceToDestination();
66 timeDiff=oldFlight.traject.timeToDestination(time)-
67 trialFlight.traject.timeToDestination(time);
68 if (timeDiff<0) { timeDiff=0; }
69 System.out.println("Time difference: "+timeDiff);
70 System.out.println("Distance difference: "+distDiff);
73 public void conflictsDiff(double time) {
75 oldConflicts=d2.getAlgorithm().getConflictsWith(time,oldFlight);
76 newConflicts=d2.getAlgorithm().getConflictsWith(time,trialFlight);
77 System.out.println("Flight "+trialFlight.flightID+":");
78 System.out.println("Conflicts for the old flight:");
79 System.out.println(oldConflicts);
80 System.out.println("Conflicts for the trial flight:");
81 System.out.println(newConflicts);
83 for (i=0 ; i<newConflicts.noConflicts ; i++) {
84 Conflict conflict=newConflicts.conflictAt(i);
85 if (oldConflicts.findConflict(conflict.flight1, conflict.flight2)==null) {
89 noRemoved=oldConflicts.noConflicts-(newConflicts.noConflicts-noNew);
92 public void changeToTrialRoute (Point4d pos, int index) {
93 int i,count, index1=0;
95 trialRoute=new Route(d2, oldFlight.fPlan.r.noFixes-index);
97 for (i=index; i<oldFlight.fPlan.r.noFixes ; i++) {
98 trialRoute.addFix(i-index, oldFlight.fPlan.r.getFixAt(i));
100 trialFlight.fPlan.r=trialRoute;
104 public void changeToTrialRoute (int index1, int index2) {
106 if ((index1>-1) && (index2>-1) && (index2-index1>1)) {
107 trialRoute=new Route(d2, oldFlight.fPlan.r.noFixes-
109 trialRoute.current=index1+1;
110 for (i=0 ; i<=index1 ; i++) {
111 trialRoute.addFix(i, oldFlight.fPlan.r.getFixAt(i));
112 if (oldFlight.fPlan.r.current==i) {
113 trialRoute.current=i;
117 for (i=index2; i<oldFlight.fPlan.r.noFixes ; i++) {
118 trialRoute.addFix(i-index2+index1+1,
119 oldFlight.fPlan.r.getFixAt(i));
120 if (oldFlight.fPlan.r.current==i) {
121 trialRoute.current=i-index2+index1+1;
124 trialFlight.fPlan.r=trialRoute;