added smaller version of directo for something in between tiny and full tests of...
[IRC.git] / Robust / src / Benchmarks / mlp / directto / mlp-small-for-testing / FlightList.java
1 // This is the class that manages all the flights
2
3 //import java.util.*;
4
5 public class FlightList {
6   public  int noFlights;
7   public  Vector f;
8
9   public FlightList() {
10     noFlights=0;
11     f=new Vector(100);
12   }
13
14   /*
15   public void addFlight(int index, Flight flight) {
16     f.addElement(index,flight);
17   }
18   */
19
20   public  void addFlightPlan(D2 d2, int time, StringTokenizer st) { 
21     Flight newFlight=disjoint flightAdd new Flight(st.nextToken());
22     noFlights++;
23     f.addElement(newFlight);
24
25     FlightPlan fAux=new FlightPlan();
26     Aircraft aAux=d2.getAircraftList().getAircraft(st.nextToken());      
27     newFlight.setAircraftType(aAux);
28   
29     newFlight.setFlightType(st.nextToken());
30     Route rAux=new Route(Integer.parseInt(st.nextToken()));
31     for (int i=0;i<rAux.noFixes;i++)
32       rAux.addFix(d2,i,st.nextToken());           
33     fAux.setRoute(rAux);
34     fAux.setCruiseParam(Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()));
35     newFlight.setFlightPlan(fAux);
36   }
37
38   public  String getFlightName(int index) {
39     Flight fAux=(Flight) f.elementAt(index);
40     return fAux.flightID;
41   }
42
43   public  void amendFlightPlan(D2 d2, int time, StringTokenizer st) {
44     Flight fAux=getFlight(st.nextToken());
45     Route rAux=new Route(Integer.parseInt(st.nextToken()));    
46     for (int i=0;i<rAux.noFixes;i++)
47       rAux.addFix(d2,i,st.nextToken());      
48     fAux.fPlan.setRoute(rAux);
49     fAux.fPlan.setCruiseParam(Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()));
50   }
51
52     public  void amendFlightInfo(D2 d2, int time, StringTokenizer st) {
53     Flight fAux=getFlight(st.nextToken());
54     Aircraft aAux=d2.getAircraftList().getAircraft(st.nextToken());      
55     fAux.setAircraftType(aAux);
56     fAux.setFlightType(st.nextToken());
57   }
58
59     public  void sendingAircraft(D2 d2, int time, StringTokenizer st) {
60     int noF=Integer.parseInt(st.nextToken());
61     String id;
62     Point4d pos;
63     Velocity vel;
64     Track t;
65     String nameFix;
66     Flight fAux;
67     for (int counter=0; counter<noF; counter++) {
68       id=st.nextToken();
69       pos=new Point4d(time,
70                       Double.valueOf(st.nextToken()).doubleValue(),
71                       Double.valueOf(st.nextToken()).doubleValue(),
72                       Double.valueOf(st.nextToken()).doubleValue());
73       vel=new Velocity(Double.valueOf(st.nextToken()).doubleValue(),
74                        Double.valueOf(st.nextToken()).doubleValue(),
75                        Double.valueOf(st.nextToken()).doubleValue());
76       t=new Track(pos, vel);
77       nameFix=st.nextToken();
78       fAux=getFlight(id);
79       System.out.println(id+" Flight id: "+fAux.flightID);
80       fAux.setTrack(t);
81       System.out.println("Setting current fix ...");
82       fAux.fPlan.setCurrentFix(nameFix);
83       System.out.println("Sent flight "+
84                          fAux.flightID+
85                          "; position: "+
86                          fAux.track.pos);
87       d2.getTrajectorySynthesizer().updateTrajectory(d2, time, fAux);
88       fAux.traject.printInfo();      
89     }
90   }  
91
92   public  void removeFlightPlan(int time, StringTokenizer st) {
93     String id=st.nextToken();
94     int i=0;
95     while ((i<noFlights) && (((Flight) f.elementAt(i)).hasID(id))) i++;
96     if (i<noFlights) f.removeElementAt(i);
97   }
98
99   public  Flight getFlight(String id) {
100     for( int i = 0; i < f.size(); ++i ) {
101       Flight fAux=(Flight) f.elementAt(i);
102       if (fAux.hasID(id))
103         return fAux;
104     }
105     System.out.println("Flight not found - "+id);
106     System.exit(-1);
107     return null;
108   }
109
110   public  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  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 }