polishing up mlp version of benchmark
[IRC.git] / Robust / src / Benchmarks / mlp / directto / mlp-java / TrialFlight.java
1 // trial flight class with trial planning-related methods
2
3 public class TrialFlight {
4   D2 d2;
5
6   Flight oldFlight, trialFlight;
7   Route trialRoute;
8   Trajectory trialTrajectory;
9   double time;
10   Fix fix1, fix2;
11   int fixIndex;
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
16   
17   // constructor of a trial flight using a shortcut between two fixes.    
18   public TrialFlight(D2 d2, Flight flight, Fix fix1, Fix fix2) {
19     this.d2=d2;
20     int aux, fixIndex1, fixIndex2;
21     oldFlight=flight;
22     fixIndex1=oldFlight.fPlan.r.getIndexOf(fix1);
23     fixIndex2=oldFlight.fPlan.r.getIndexOf(fix2);
24     if (fixIndex1>fixIndex2) {
25       aux=fixIndex1;
26       fixIndex1=fixIndex2;
27       fixIndex2=aux;
28     }
29     trialFlight=Flight.copyOf(d2, oldFlight);
30     trialFlight.trialStatus=Flight.trialFlightStatus();
31     this.changeToTrialRoute(fixIndex1, fixIndex2);
32   }
33
34   // constructor for a trial flight using the current position of a plane
35   public TrialFlight(D2 d2, Flight flight, String fixName) {
36     this.d2=d2;
37     oldFlight=flight;    
38   }
39
40   // constructor that uses an estimated position and a fix
41   public TrialFlight(D2 d2, Flight flight, Point4d position, Fix fix) {
42     this.d2=d2;
43     int aux;
44     oldFlight=flight;
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;        
58   }
59
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);
71   }
72     
73   public void conflictsDiff(double time) {
74     int i, j;
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);
82     noNew=0;
83     for (i=0 ; i<newConflicts.noConflicts ; i++) {
84       Conflict conflict=newConflicts.conflictAt(i);
85       if (oldConflicts.findConflict(conflict.flight1, conflict.flight2)==null) {
86         noNew++;
87       }
88     }
89     noRemoved=oldConflicts.noConflicts-(newConflicts.noConflicts-noNew);
90   }
91   
92   public void changeToTrialRoute (Point4d pos, int index) {
93     int i,count, index1=0;
94     if (index>-1) {
95       trialRoute=new Route(d2, oldFlight.fPlan.r.noFixes-index);
96       trialRoute.current=0;
97       for (i=index; i<oldFlight.fPlan.r.noFixes ; i++) {
98         trialRoute.addFix(i-index, oldFlight.fPlan.r.getFixAt(i));
99       }
100       trialFlight.fPlan.r=trialRoute;
101     }
102   }
103
104   public void changeToTrialRoute (int index1, int index2) {
105     int i,count;
106     if ((index1>-1) && (index2>-1) && (index2-index1>1)) {
107       trialRoute=new Route(d2, oldFlight.fPlan.r.noFixes-
108                            (index2-index1-1));
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;
114         }
115       }
116       
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;
122         }
123       }
124       trialFlight.fPlan.r=trialRoute;
125     }
126   }
127 }