polishing up mlp version of benchmark
[IRC.git] / Robust / src / Benchmarks / mlp / directto / mlp-java / FlightList.java
1 // This is the class that manages all the flights
2
3 //import java.util.*;
4
5 public class FlightList {
6   private D2 d2;
7
8   public /*static*/ int noFlights;
9   public /*static*/ Vector f;
10
11   public FlightList( D2 d2 ) {
12     this.d2=d2;
13     noFlights=0;
14     f=new Vector(100);
15   }
16
17   /*
18   public void addFlight(int index, Flight flight) {
19     f.addElement(index,flight);
20   }
21   */
22
23   public /*static*/ void addFlightPlan(int time, StringTokenizer st) { 
24     Flight newFlight=new Flight(d2, st.nextToken());
25     noFlights++;
26     f.addElement(newFlight);
27     FlightPlan fAux=new FlightPlan();
28     Aircraft aAux=d2.getAircraftList().getAircraft(st.nextToken());      
29     newFlight.setAircraftType(aAux);
30     newFlight.setFlightType(st.nextToken());
31     Route rAux=new Route(d2, Integer.parseInt(st.nextToken()));
32     for (int i=0;i<rAux.noFixes;i++)
33       rAux.addFix(i,st.nextToken());           
34     fAux.setRoute(rAux);
35     fAux.setCruiseParam(Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()));
36     newFlight.setFlightPlan(fAux);
37   }
38
39   public /*static*/ String getFlightName(int index) {
40     Flight fAux=(Flight) f.elementAt(index);
41     return fAux.flightID;
42   }
43
44   public /*static*/ void amendFlightPlan(int time, StringTokenizer st) {
45     Flight fAux=getFlight(st.nextToken());
46     Route rAux=new Route(d2, Integer.parseInt(st.nextToken()));    
47     for (int i=0;i<rAux.noFixes;i++)
48       rAux.addFix(i,st.nextToken());      
49     fAux.fPlan.setRoute(rAux);
50     fAux.fPlan.setCruiseParam(Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()));
51   }
52
53   public /*static*/ void amendFlightInfo(int time, StringTokenizer st) {
54     Flight fAux=getFlight(st.nextToken());
55     Aircraft aAux=d2.getAircraftList().getAircraft(st.nextToken());      
56     fAux.setAircraftType(aAux);
57     fAux.setFlightType(st.nextToken());
58   }
59
60   public /*static*/ void sendingAircraft(int time, StringTokenizer st) {
61     int noF=Integer.parseInt(st.nextToken());
62     String id;
63     Point4d pos;
64     Velocity vel;
65     Track t;
66     String nameFix;
67     Flight fAux;
68     for (int counter=0; counter<noF; counter++) {
69       id=st.nextToken();
70       pos=new Point4d(time,
71                       Double.valueOf(st.nextToken()).doubleValue(),
72                       Double.valueOf(st.nextToken()).doubleValue(),
73                       Double.valueOf(st.nextToken()).doubleValue());
74       vel=new Velocity(Double.valueOf(st.nextToken()).doubleValue(),
75                        Double.valueOf(st.nextToken()).doubleValue(),
76                        Double.valueOf(st.nextToken()).doubleValue());
77       t=new Track(pos, vel);
78       nameFix=st.nextToken();
79       fAux=getFlight(id);
80       System.out.println(id+" Flight id: "+fAux.flightID);
81       fAux.setTrack(t);
82       System.out.println("Setting current fix ...");
83       fAux.fPlan.setCurrentFix(nameFix);
84       System.out.println("Sent flight "+
85                          fAux.flightID+
86                          "; position: "+
87                          fAux.track.pos);
88       d2.getTrajectorySynthesizer().updateTrajectory(time, fAux);
89       fAux.traject.printInfo();      
90     }
91   }  
92
93   public /*static*/ void removeFlightPlan(int time, StringTokenizer st) {
94     String id=st.nextToken();
95     int i=0;
96     while ((i<noFlights) && (((Flight) f.elementAt(i)).hasID(id))) i++;
97     if (i<noFlights) f.removeElementAt(i);
98   }
99
100   public /*static*/ Flight getFlight(String id) {
101     for( int i = 0; i < f.size(); ++i ) {
102       Flight fAux=(Flight) f.elementAt(i);
103       if (fAux.hasID(id))
104         return fAux;
105     }
106     System.out.println("Flight not found - "+id);
107     System.exit(-1);
108   }
109
110   public /*static*/ boolean anyPlanesAlive() {
111     for( int i = 0; i < f.size(); ++i ) {
112       Flight aAux=(Flight) f.elementAt(i);
113       Vector p1=aAux.traject.p;
114       Point4d pAux= (Point4d) p1.elementAt(0);
115       if (!pAux.outOfRange())
116         return true;
117     }
118     return false;
119   }
120
121   public /*static*/ void printInfo() {
122     System.out.println("\n\nThe number of flights:"+noFlights);
123     System.out.println("The flights are:");
124     for( int i = 0; i < f.size(); ++i ) {
125       Flight fAux=(Flight) f.elementAt(i);
126       System.out.println(fAux);
127     }
128   }
129 }