--- /dev/null
+// class that implements types of aircrafts
+
+class Aircraft {
+ String type;
+ double maxLift, maxThrust;
+
+ public Aircraft(String t, double maxL, double maxT) {
+ type=t;
+ maxLift=maxL;
+ maxThrust=maxT;
+ }
+
+ boolean hasType(String type0) {
+ return (type.compareTo(type0)==0);
+ }
+
+ public String toString() {
+ return new String("Airplane: "+type+" "+maxLift+" "+maxThrust);
+ }
+}
--- /dev/null
+// This class memorizes all the existing aircrafts
+
+//import java.util.*;
+
+class AircraftList {
+ public int noAircrafts;
+ private Vector aircrafts;
+
+ public AircraftList() {
+ noAircrafts=0; // the number of aircrafts
+ aircrafts=new Vector(100); // the aircrafts
+ }
+
+ // sets the parameters of the aircraft number "pos": its name, its lift and its thrust
+ public void setAircraft(String name,double lift,double thrust) {
+ aircrafts.addElement(new Aircraft(name,lift,thrust));
+ }
+
+ public Aircraft getAircraft(String name) {
+ for( int i = 0; i < aircrafts.size(); ++i ) {
+ Aircraft aAux=(Aircraft) aircrafts.elementAt(i);
+ if (aAux.hasType(name))
+ return aAux;
+ }
+
+ System.out.println("Aircraft not found - "+name);
+ System.exit(-1);
+ }
+
+ public int getAircraftIndex(String name) {
+ for( int i = 0; i < aircrafts.size(); ++i ) {
+ Aircraft aAux=(Aircraft) aircrafts.elementAt(i);
+ if (aAux.hasType(name))
+ return i;
+ }
+
+ System.out.println("Aircraft not found - "+name);
+ System.exit(-1);
+ }
+
+ public void printInfo() {
+ System.out.println("\n\nThe number of aircrafts:"+noAircrafts);
+ System.out.println("The aircrafts are:");
+ for( int i = 0; i < aircrafts.size(); ++i ) {
+ Aircraft aAux=(Aircraft) aircrafts.elementAt(i);
+ System.out.println(aAux);
+ }
+ }
+
+ public void addAircraft(StringTokenizer parameters) {
+ setAircraft(parameters.nextToken(), Integer.parseInt(parameters.nextToken()), Integer.parseInt(parameters.nextToken()));
+ noAircrafts++;
+ }
+
+ public void removeAircraft(StringTokenizer parameters) {
+ noAircrafts--;
+ int aAuxIndex=getAircraftIndex(parameters.nextToken());
+ aircrafts.removeElementAt(aAuxIndex);
+ }
+}
--- /dev/null
+//import java.util.*;
+//import java.io.*;
+
+class Algorithm {
+ private D2 d2;
+
+ public /*static*/ double initialTime,time;
+ public /*static*/ double currIteration;
+ public /*static*/ ConflictList cList;
+
+ public Algorithm( D2 d2 ) {
+ this.d2 = d2;
+ ConflictList cList=new ConflictList();
+ }
+
+ public /*static*/ void setInitialTime(double time) {
+ initialTime=time;
+ currIteration=0;
+ }
+
+ public /*static*/ boolean isConflict(Point4d p1, Point4d p2) {
+ Point2d pAux1=new Point2d(p1.x,p1.y);
+ Point2d pAux2=new Point2d(p2.x,p2.y);
+ if ( (Point2d.squaredDistance(pAux1,pAux2) <=
+ Math.pow(d2.getStatic().radius(),2))
+
+ && Math.abs(p1.z-p2.z) <= d2.getStatic().distance()
+ )
+ return true;
+
+ return false;
+ }
+
+ public /*static*/ Point4d findConflict(Flight a, Flight b) {
+ Point4d conflictPoint=new Point4d(Point4d.outOfRangeTime(),0,0,0);
+ if (a.flightID!=b.flightID) {
+ Vector p1=a.traject.p;
+ Vector p2=b.traject.p;
+
+ int pos=0;
+ boolean found=false;
+
+ while ( (pos<p1.size()) && (pos<p2.size()) && (!found) ) {
+ Point4d point1=(Point4d) p1.elementAt(pos);
+ Point4d point2=(Point4d) p2.elementAt(pos);
+ if (isConflict(point1,point2)) {
+ System.out.println(point1+" "+point2);
+ found=true;
+ conflictPoint=point1;
+ }
+ pos++;
+ }
+ }
+ return conflictPoint;
+ }
+
+ public /*static*/ ConflictList getConflictsWith(double time, Flight flight) {
+ ConflictList conflicts=new ConflictList();
+
+ Vector flights=d2.getFlightList().f;
+ int n,i,j;
+ n=d2.getFlightList().noFlights;
+
+ d2.getTrajectorySynthesizer().updateTrajectory(time, flight);
+ for (i=0; i<n; i++) {
+ Flight aAux=(Flight) flights.elementAt(i);
+ d2.getTrajectorySynthesizer().updateTrajectory(time, aAux);
+ }
+
+ Flight aux1=flight;
+ for (i=0; i<n; i++) {
+ Flight aux2=(Flight) flights.elementAt(i);
+ Point4d conflictPoint=findConflict(aux1,aux2);
+ if (!(conflictPoint.outOfRange())) {
+ conflicts.newConflict(conflictPoint,aux1,aux2);
+ }
+ }
+ return conflicts;
+ }
+
+ public /*static*/ void doIteration() {
+ time=initialTime+currIteration*d2.getStatic().iterationStep();
+ currIteration++;
+ System.out.println("In doIteration!");
+ System.out.println("Time:"+time);
+
+ cList.clear();
+ Vector flights=d2.getFlightList().f;
+ int n=d2.getFlightList().noFlights;
+ int i,j;
+
+ for (i=0;i<n;i++) {
+ Flight aAux=(Flight) flights.elementAt(i);
+ d2.getTrajectorySynthesizer().updateTrajectory(time,aAux);
+ }
+
+ System.out.println("Does it get here? (after the trajectory update)");
+
+ for (i=0;i<n;i++)
+ for (j=i+1;j<n;j++) {
+ Flight aux1=(Flight) flights.elementAt(i);
+ Flight aux2=(Flight) flights.elementAt(j);
+ Point4d conflictPoint=findConflict(aux1,aux2);
+ if (!(conflictPoint.outOfRange())) {
+ cList.newConflict(conflictPoint,aux1,aux2);
+ }
+ }
+ }
+}
--- /dev/null
+// This class memorizes a conflict
+
+class Conflict {
+ public Point4d coordinates; // its position
+ public Flight flight1, flight2; // the two flights involved in the conflict
+
+ public Conflict(Point4d coord, Flight f1, Flight f2) {
+ coordinates=coord;
+ flight1=f1;
+ flight2=f2;
+ }
+
+ public boolean hasFlights(Flight f1, Flight f2) {
+ if ( ((flight1.flightID==f1.flightID)&&(flight2.flightID==f2.flightID))||
+ ((flight1.flightID==f2.flightID)&&(flight2.flightID==f1.flightID)) )
+ return true;
+ return false;
+ }
+
+ public String toString() {
+ return ("Conflict at time "+coordinates.time+" position "+coordinates+" between "+
+ flight1.flightID+" and "+flight2.flightID+".");
+ }
+}
--- /dev/null
+// This class keeps a list of conflicts.
+// The conflicts are updated at every moment of time
+// We detect only the first conflict between every pair of flights
+
+//import java.util.*;
+
+/*final*/ class ConflictList
+{
+ public int noConflicts; // the number of conflicts
+ private Vector conflicts; // the conflicts
+
+ public ConflictList() {
+ noConflicts=0;
+ conflicts=new Vector(100);
+ }
+
+ public void clear() {
+ noConflicts=0;
+ conflicts.clear();
+ }
+
+ public Conflict conflictAt(int index) {
+ return (Conflict) conflicts.elementAt(index);
+ }
+
+ public String printInfo() {
+ String st;
+ if (noConflicts==0)
+ st="No conflicts!";
+ else {
+ st=""+noConflicts+" conflicts\n";
+ for( int i = 0; i < conflicts.size(); ++i ) {
+ Conflict cAux=(Conflict) conflicts.elementAt(i);
+ st=st+"\n"+cAux;
+ }
+ }
+ return st;
+ }
+
+ public void newConflict(Point4d coord, Flight f1, Flight f2) {
+ noConflicts++;
+ conflicts.addElement(new Conflict(coord,f1,f2));
+ }
+
+ public Conflict findConflict(Flight f1, Flight f2) {
+ for( int i = 0; i < conflicts.size(); ++i ) {
+ Conflict cAux=(Conflict) conflicts.elementAt(i);
+ if (cAux.hasFlights(f1,f2))
+ return cAux;
+ }
+ return null;
+ }
+
+ public int findConflictIndex(Flight f1, Flight f2) {
+ for( int i = 0; i < conflicts.size(); ++i ) {
+ Conflict cAux=(Conflict) conflicts.elementAt(i);
+ if (cAux.hasFlights(f1,f2))
+ return i;
+ }
+ return -1;
+ }
+
+ public void removeConflict(Flight f1, Flight f2) {
+ noConflicts--;
+ int cAuxIndex=findConflictIndex(f1,f2);
+ conflicts.removeElementAt(cAuxIndex);
+ }
+}
--- /dev/null
+// This class contains the the main method of this project.
+// All it does is to initialize the input and output threads
+// and kick off the algorithm
+
+//import java.io.*;
+
+class D2 {
+ public ReadWrite rw;
+
+ private Static singletonStatic ; public Static getStatic () { return singletonStatic ; }
+ private AircraftList singletonAircraftList ; public AircraftList getAircraftList () { return singletonAircraftList ; }
+ private Algorithm singletonAlgorithm ; public Algorithm getAlgorithm () { return singletonAlgorithm ; }
+ private FixList singletonFixList ; public FixList getFixList () { return singletonFixList ; }
+ private Flight singletonFlight ; public Flight getFlight () { return singletonFlight ; }
+ private FlightList singletonFlightList ; public FlightList getFlightList () { return singletonFlightList ; }
+ private MessageList singletonMessageList ; public MessageList getMessageList () { return singletonMessageList ; }
+ private TrajectorySynthesizer singletonTrajectorySynthesizer; public TrajectorySynthesizer getTrajectorySynthesizer() { return singletonTrajectorySynthesizer; }
+
+ public D2() {
+ singletonStatic = new Static ();
+ singletonAircraftList = new AircraftList ();
+ singletonFixList = new FixList ();
+ singletonAlgorithm = new Algorithm ( this );
+ singletonFlight = new Flight ( this, "" );
+ singletonFlightList = new FlightList ( this );
+ singletonMessageList = new MessageList ( this );
+ singletonTrajectorySynthesizer = new TrajectorySynthesizer( this );
+ }
+
+ public static void main(String arg[]) {
+ System.out.println("D2 - Application started");
+
+ D2 d2 = new D2();
+
+ d2.rw=new ReadWrite( d2 );
+ d2.rw.read();
+
+ d2.getMessageList().executeAll();
+
+ while( d2.getFlightList().anyPlanesAlive() ) {
+ d2.getAlgorithm().doIteration();
+ }
+
+ d2.rw.write();
+ }
+}
--- /dev/null
+// this class stores the properties of a fix
+
+class Fix {
+ private String name;
+ private Point2d p;
+
+ public Fix(String name0,Point2d p0) {
+ name=name0;
+ p=p0;
+ }
+
+ public Point2d getFixCoord() {
+ return p;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ boolean hasName(String name0) {
+ return (name.compareTo(name0)==0);
+ }
+
+ public String toString() {
+ return new String("Fix: "+name+" "+p);
+ }
+}
--- /dev/null
+// This class memorizes all the fixes in the area.
+// There are methods for setting the properties of a fix and
+// for getting a fix by a given name
+
+//import java.util.*;
+
+class FixList {
+
+ public /*static*/ int noFixes() { return _noFixes; }
+ public /*static*/ Vector fixes() { return _fixes; }
+
+ private int _noFixes;
+ private Vector _fixes;
+
+ public FixList() {
+ _noFixes=0;
+ _fixes=new Vector(100);
+ }
+
+ // sets the parameters of the fix number "pos": its name
+ // and its coordinates
+ public /*static*/ void setFix(String name,float x,float y)
+ {
+ _fixes.addElement(new Fix(name,(Point2d) new Point2d(x,y)));
+ }
+
+ public /*static*/ String getFix(int index)
+ {
+ Fix fAux=(Fix) _fixes.elementAt(index);
+ return (String) fAux.getName();
+ }
+
+ public /*static*/ int getIndex(String name) {
+ for( int i = 0; i < _fixes.size(); ++i ) {
+ Fix fAux=(Fix) _fixes.elementAt( i );
+ if (fAux.hasName(name))
+ return i;
+ }
+ System.out.println("Fix not found - "+name);
+ System.exit(-1);
+ }
+
+ public /*static*/ Fix getFix(String name) {
+ for( int i = 0; i < _fixes.size(); ++i ) {
+ Fix fAux=(Fix) _fixes.elementAt( i );
+ if (fAux.hasName(name))
+ return fAux;
+ }
+ System.out.println("Fix not found - "+name);
+ System.exit(-1);
+ }
+
+ public /*static*/ void printInfo() {
+ System.out.println("\n\nThe number of fixes:"+_noFixes);
+ System.out.println("The fixes are:");
+ for( int i = 0; i < _fixes.size(); ++i ) {
+ Fix bAux=(Fix) _fixes.elementAt( i );
+ System.out.println(bAux);
+ }
+ }
+
+ public /*static*/ void addFix(StringTokenizer parameters)
+ {
+ setFix(parameters.nextToken(), Integer.parseInt(parameters.nextToken()), Integer.parseInt(parameters.nextToken()));
+ _noFixes++;
+ }
+
+ public /*static*/ void removeFix(StringTokenizer parameters)
+ {
+ _noFixes--;
+ //Fix fAux=getFix(parameters.nextToken());
+ int fixIndex=getIndex(parameters.nextToken());
+ //_fixes.remove(fAux);
+ _fixes.removeElementAt(fixIndex);
+ }
+}
--- /dev/null
+// the class that describes a flight
+
+public class Flight /*implements Cloneable*/ {
+
+ private D2 d2;
+
+ public String flightID; // the flight id
+ public int trialStatus; //
+ public Aircraft aircraftType; // the type of aircraft
+ public Track track; // data from radar
+ public Trajectory traject; // the estimated trajectory
+ public FlightPlan fPlan; // the associated flight plan
+ public String flightType; // the type of flight
+ private float horizAcc, vertAcc; // data used for estimating trajectory
+
+ public static int realFlightStatus(){ return -1;}
+ public static int trialFlightStatus(){ return 1;}
+
+ public Flight(D2 d2, String id) {
+ this.d2=d2;
+ this.flightID=id;
+ this.trialStatus=realFlightStatus();
+ }
+
+ public void setAircraftType (Aircraft ac) {
+ this.aircraftType=ac;
+ }
+
+ public void setFlightType(String flightType) {
+ this.flightType=flightType;
+ }
+
+ public void setTrack(Track newTrack) {
+ this.track=newTrack;
+ }
+
+ public void setFlightPlan(FlightPlan fp) {
+ fPlan=fp;
+ }
+
+ public void updateTrajectory(double time) {
+ d2.getTrajectorySynthesizer().updateTrajectory(time, this);
+ }
+
+ public boolean hasID (String id) {
+ return (flightID.compareTo(id)==0);
+ }
+
+ public boolean isFlying (String flType) {
+ return (flightType.compareTo(flType)==0);
+ }
+
+ public static Flight copyOf( D2 d2, Flight f) {
+ Flight fNew = new Flight(d2, f.flightID);
+ fNew.trialStatus = f.trialStatus;
+ fNew.aircraftType = f.aircraftType;
+ fNew.track = f.track;
+ fNew.traject = f.traject;
+ fNew.fPlan = f.fPlan;
+ fNew.flightType = f.flightType;
+ fNew.horizAcc = f.horizAcc;
+ fNew.vertAcc = f.vertAcc;
+ return fNew;
+ }
+
+ public String toString() {
+ return new String("Flight "+flightID+" Aircraft:"+aircraftType.type+
+ " Flight type:"+flightType+
+ " Cruise Altitude:"+fPlan.cruiseAlt+
+ " Cruise Speed:"+fPlan.cruiseSpeed+"\n"+fPlan.r);
+ }
+}
--- /dev/null
+// This is the class that manages all the flights
+
+//import java.util.*;
+
+class FlightList {
+ private D2 d2;
+
+ public /*static*/ int noFlights;
+ public /*static*/ Vector f;
+
+ public FlightList( D2 d2 ) {
+ this.d2=d2;
+ noFlights=0;
+ f=new Vector(100);
+ }
+
+ /*
+ public void addFlight(int index, Flight flight) {
+ f.addElement(index,flight);
+ }
+ */
+
+ public /*static*/ void addFlightPlan(int time, StringTokenizer st) {
+ Flight newFlight=new Flight(d2, st.nextToken());
+ noFlights++;
+ f.addElement(newFlight);
+ FlightPlan fAux=new FlightPlan();
+ Aircraft aAux=d2.getAircraftList().getAircraft(st.nextToken());
+ newFlight.setAircraftType(aAux);
+ newFlight.setFlightType(st.nextToken());
+ Route rAux=new Route(d2, Integer.parseInt(st.nextToken()));
+ for (int i=0;i<rAux.noFixes;i++)
+ rAux.addFix(i,st.nextToken());
+ fAux.setRoute(rAux);
+ fAux.setCruiseParam(Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()));
+ newFlight.setFlightPlan(fAux);
+ }
+
+ public /*static*/ String getFlightName(int index) {
+ Flight fAux=(Flight) f.elementAt(index);
+ return fAux.flightID;
+ }
+
+ public /*static*/ void amendFlightPlan(int time, StringTokenizer st) {
+ Flight fAux=getFlight(st.nextToken());
+ Route rAux=new Route(d2, Integer.parseInt(st.nextToken()));
+ for (int i=0;i<rAux.noFixes;i++)
+ rAux.addFix(i,st.nextToken());
+ fAux.fPlan.setRoute(rAux);
+ fAux.fPlan.setCruiseParam(Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()));
+ }
+
+ public /*static*/ void amendFlightInfo(int time, StringTokenizer st) {
+ Flight fAux=getFlight(st.nextToken());
+ Aircraft aAux=d2.getAircraftList().getAircraft(st.nextToken());
+ fAux.setAircraftType(aAux);
+ fAux.setFlightType(st.nextToken());
+ }
+
+ public /*static*/ void sendingAircraft(int time, StringTokenizer st) {
+ int noF=Integer.parseInt(st.nextToken());
+ String id;
+ Point4d pos;
+ Velocity vel;
+ Track t;
+ String nameFix;
+ Flight fAux;
+ for (int counter=0; counter<noF; counter++) {
+ id=st.nextToken();
+ pos=new Point4d(time,
+ Double.valueOf(st.nextToken()).doubleValue(),
+ Double.valueOf(st.nextToken()).doubleValue(),
+ Double.valueOf(st.nextToken()).doubleValue());
+ vel=new Velocity(Double.valueOf(st.nextToken()).doubleValue(),
+ Double.valueOf(st.nextToken()).doubleValue(),
+ Double.valueOf(st.nextToken()).doubleValue());
+ t=new Track(pos, vel);
+ nameFix=st.nextToken();
+ fAux=getFlight(id);
+ System.out.println(id+" Flight id: "+fAux.flightID);
+ fAux.setTrack(t);
+ System.out.println("Setting current fix ...");
+ fAux.fPlan.setCurrentFix(nameFix);
+ System.out.println("Sent flight "+
+ fAux.flightID+
+ "; position: "+
+ fAux.track.pos);
+ d2.getTrajectorySynthesizer().updateTrajectory(time, fAux);
+ fAux.traject.printInfo();
+ }
+ }
+
+ public /*static*/ void removeFlightPlan(int time, StringTokenizer st) {
+ String id=st.nextToken();
+ int i=0;
+ while ((i<noFlights) && (((Flight) f.elementAt(i)).hasID(id))) i++;
+ if (i<noFlights) f.removeElementAt(i);
+ }
+
+ public /*static*/ Flight getFlight(String id) {
+ for( int i = 0; i < f.size(); ++i ) {
+ Flight fAux=(Flight) f.elementAt(i);
+ if (fAux.hasID(id))
+ return fAux;
+ }
+ System.out.println("Flight not found - "+id);
+ System.exit(-1);
+ }
+
+ public /*static*/ boolean anyPlanesAlive() {
+ for( int i = 0; i < f.size(); ++i ) {
+ Flight aAux=(Flight) f.elementAt(i);
+ Vector p1=aAux.traject.p;
+ Point4d pAux= (Point4d) p1.elementAt(0);
+ if (!pAux.outOfRange())
+ return true;
+ }
+ return false;
+ }
+
+ public /*static*/ void printInfo() {
+ System.out.println("\n\nThe number of flights:"+noFlights);
+ System.out.println("The flights are:");
+ for( int i = 0; i < f.size(); ++i ) {
+ Flight fAux=(Flight) f.elementAt(i);
+ System.out.println(fAux);
+ }
+ }
+}
--- /dev/null
+// this class implements a flight plan
+
+class FlightPlan {
+ public double cruiseAlt, cruiseSpeed; // cruising altitude and speed
+
+ public Route r; // the route (given by fixes)
+
+ public FlightPlan() {
+ cruiseAlt=0;
+ cruiseSpeed=0;
+ }
+
+ public FlightPlan (FlightPlan fp) {
+ cruiseAlt=fp.cruiseAlt;
+ cruiseSpeed=fp.cruiseSpeed;
+ }
+
+ public void setCruiseParam(double crAlt, double crSp) {
+ cruiseAlt=crAlt;cruiseSpeed=crSp;
+ }
+
+ public void setRoute(Route route) {
+ this.r=route;
+ }
+
+ public void setCurrentFix(String nameFix) {
+ int i=r.getIndexOf(nameFix);
+ System.out.println("name of the fix: "+nameFix+" index:"+i);
+ r.setCurrent(i);
+ }
+}
--- /dev/null
+//import java.util.*;
+
+class Message {
+
+ D2 d2;
+ int time;
+ String type;
+ StringTokenizer parameters;
+
+ public Message(D2 d2, int time, String type, StringTokenizer parameters) {
+ this.d2=d2;
+ this.time=time;
+ this.type=type;
+ this.parameters=parameters;
+ }
+
+ public Message(Message m) {
+ this.d2=m.d2;
+ this.time=m.time;
+ this.type=m.type;
+ this.parameters=m.parameters;
+ }
+
+ public void executeMessage() {
+ System.out.println("Executing message of type "+type);
+ //static messages
+ if (type.compareTo("SET_MAP_SIZE")==0) {
+ System.out.println("Setting the map size...");
+ d2.getStatic().setMapSize(parameters);
+ }
+ else if (type.compareTo("SET_ITERATION_STEP")==0) {
+ System.out.println("Setting the iteration step...");
+ d2.getStatic().setIterationStep(parameters);
+ }
+ else if (type.compareTo("SET_NO_OF_ITERATIONS")==0) {
+ System.out.println("Setting the no. of iterations...");
+ d2.getStatic().setNumberOfIterations(parameters);
+ }
+ else if (type.compareTo("SET_CYLINDER")==0) {
+ System.out.println("Setting the cylinder of safety/unsafety...");
+ d2.getStatic().setCylinder(parameters);
+ }
+ else if (type.compareTo("ADD_FIX")==0) {
+ System.out.println("Adding a new fix...");
+ d2.getFixList().addFix(parameters);
+ }
+ else if (type.compareTo("REMOVE_FIX")==0) {
+ System.out.println("Removing a fix...");
+ d2.getFixList().removeFix(parameters);
+ }
+ else if (type.compareTo("ADD_AIRCRAFT")==0) {
+ System.out.println("Adding an aircraft...");
+ d2.getAircraftList().addAircraft(parameters);
+ }
+ else if (type.compareTo("REMOVE_AIRCRAFT")==0) {
+ System.out.println("Removing an aircraft...");
+ d2.getAircraftList().removeAircraft(parameters);
+ }
+
+ //dynamic messages
+ if (type.compareTo("DO_WORK")==0)
+ d2.getAlgorithm().setInitialTime(time);
+
+ if (type.compareTo("ADD_FLIGHT_PLAN")==0) {
+ System.out.println("Adding flight plan...");
+ d2.getFlightList().addFlightPlan(time,parameters);
+ }
+ else if (type.compareTo("REMOVE_FLIGHT_PLAN")==0) {
+ System.out.println("Removing flight plan...");
+ d2.getFlightList().removeFlightPlan(time,parameters);
+ }
+ else if (type.compareTo("AMEND_FLIGHT_INFO")==0) {
+ System.out.println("Amending flight info...");
+ d2.getFlightList().amendFlightInfo(time,parameters);
+ }
+ else if (type.compareTo("AMEND_FLIGHT_PLAN")==0) {
+ System.out.println("Amending flight plan...");
+ d2.getFlightList().amendFlightPlan(time,parameters);
+ }
+ else if (type.compareTo("SENDING_AIRCRAFT")==0) {
+ System.out.println("Sending aircraft data...");
+ d2.getFlightList().sendingAircraft(time,parameters);
+ }
+ }
+}
--- /dev/null
+//import java.io.*;
+//import java.util.*;
+
+class MessageList {
+ private D2 d2;
+ private Vector messages;
+
+ public MessageList( D2 d2 ) {
+ this.d2 = d2;
+ messages=new Vector();
+ }
+
+ public Message data() {
+ Message m = (Message) messages.elementAt(0);
+ messages.removeElementAt(0);
+ return m;
+ }
+
+ public Message next() {
+ return data();
+ }
+
+ public boolean hasNext() {
+ return messages.size() != 0;
+ }
+
+ //is true for DO_WORK
+ public boolean setMessage(String line) {
+ if (line.equals(""))
+ return false;
+
+ System.out.println("I'm reading line "+line);
+
+ // treating comments
+ if ((line.charAt(0)=='/')&&(line.charAt(1)=='/'))
+ return false;
+
+ StringTokenizer st=new StringTokenizer(line);
+ int time=Integer.parseInt(st.nextToken());
+ String type=st.nextToken();
+ Message newMessage=new Message(d2,time,type,st);
+ messages.addElement(newMessage);
+ if (type.equals("DO_WORK"))
+ return true;
+
+ return false;
+ }
+
+ public void executeAll() {
+ System.out.println("executeAll: we have "+messages.size()+" messages.");
+ while(hasNext())
+ next().executeMessage();
+ d2.getStatic().printInfo();
+ d2.getFixList().printInfo();
+ d2.getAircraftList().printInfo();
+ d2.getFlightList().printInfo();
+ System.out.println("Messages executed\n\n\n\n\n");
+ }
+}
--- /dev/null
+// a 2d point - used for fixes
+
+class Point2d {
+ public double x,y;
+
+ public Point2d () {
+ x=0;
+ y=0;
+ }
+
+ public Point2d (double xcoord , double ycoord) {
+ this.x=xcoord;
+ this.y=ycoord;
+ }
+
+ public static double horizDistance(Point2d p1, Point2d p2) {
+ return (Math.sqrt(squaredDistance(p1,p2)));
+ }
+
+ public static double squaredDistance(Point2d p1, Point2d p2) {
+ return (Math.pow(p1.x-p2.x,2)+Math.pow(p1.y-p2.y,2));
+ }
+
+ public String toString() {
+ return new String("("+x+","+y+")");
+ }
+}
--- /dev/null
+// point with 3 space coordinates and time label
+
+//import java.text.*;
+
+class Point4d extends Point2d {
+ public double x,y,z,time;
+
+ public static int outOfRangeTime() { return -1; }
+
+ public Point4d () {
+ x=0;y=0;z=0;
+ time=0;
+ }
+
+ public Point4d(Point2d p) {
+ x=p.x;
+ y=p.y;
+ time=z=0;
+ }
+
+ public Point4d (double t, double xcoord, double ycoord, double zcoord) {
+ x=xcoord; y=ycoord; z=zcoord;
+ time=t;
+ }
+
+ public Point4d (double xcoord, double ycoord, double zcoord) {
+ x=xcoord; y=ycoord; z=zcoord;
+ time=0;
+ }
+
+ public Point4d (Point4d p) {
+ x=p.x;
+ y=p.y;
+ z=p.z;
+ time=p.time;
+ }
+
+ public void setTime (double t) {
+ time=t;
+ }
+
+ public static double squaredDistance(Point4d p1,Point4d p2) {
+ return (Math.pow(p1.x-p2.x,2)+Math.pow(p1.y-p2.y,2)+Math.pow(p1.z-p2.z,2));
+ }
+
+ public static double horizDistance(Point4d p1, Point4d p2) {
+ return (Math.sqrt(Math.pow(p1.x-p2.x,2)+Math.pow(p1.y-p2.y,2)));
+ }
+
+ public int compareX(Point4d p) {
+ if (this.x==p.x)
+ return 0;
+ else
+ if (this.x<p.x)
+ return -1;
+ else return 1;
+ }
+
+ public int compareY(Point4d p) {
+ if (this.y==p.y)
+ return 0;
+ else
+ if (this.y<p.y)
+ return -1;
+ else return 1;
+ }
+
+ public int compareZ(Point4d p) {
+ if (this.z==p.z)
+ return 0;
+ else
+ if (this.z<p.z)
+ return -1;
+ else return 1;
+ }
+
+ public boolean outOfRange() {
+ return (this.time<0);
+ }
+
+ public Point2d toPoint2d() {
+ return (new Point2d(this.x, this.y));
+ }
+
+ /*
+ static public String decimalFormat(double n) {
+ NumberFormat nf=NumberFormat.getNumberInstance();
+ nf.setMaximumFractionDigits(2);
+ return nf.format(n);
+ }
+ */
+
+ public String toString() {
+ String st="("+/*decimalFormat*/(x)+";"+/*decimalFormat*/(y)+";"+/*decimalFormat*/(z)+")";
+ return st;
+ }
+}
--- /dev/null
+// This class is the connection between the input and the output threads,
+// synchronizing the two threads
+
+//import java.io.*;
+//import java.util.*;
+
+class ReadWrite {
+ D2 d2;
+
+ public ReadWrite( D2 d2 ) {
+ this.d2 = d2;
+ }
+
+ public void read() {
+ FileInputStream in = new FileInputStream( "input.txt" );
+
+ while(true) {
+ String line=in.readLine();
+
+ if(line==null)
+ System.exit(0);
+
+ if(d2.getMessageList().setMessage(line))
+ break;
+ }
+
+ System.out.println("Input data read.");
+ }
+
+ public void write() {
+ d2.getStatic().printInfo();
+ d2.getFixList().printInfo();
+ d2.getAircraftList().printInfo();
+ d2.getFlightList().printInfo();
+ }
+}
--- /dev/null
+// describes a route - number of beacons, the current position on the
+// route, and the beacons.
+
+//import java.util.*;
+
+class Route {
+
+ D2 d2;
+ public int noFixes,current;
+ public Vector fixes;
+
+ Route(D2 d2, int no) {
+ this.d2=d2;
+ noFixes=no;
+ current=0;
+ fixes=new Vector(noFixes);
+ }
+
+ Route(D2 d2, int no, int cur) {
+ this.d2=d2;
+ noFixes=no;
+ current=cur;
+ fixes=new Vector(noFixes);
+ }
+
+ public void addFix (int pos, Fix f) {
+ fixes.insertElementAt(f, pos);
+ }
+
+ public void addFix (int pos, String name) {
+ addFix(pos, (Fix) d2.getFixList().getFix(name) );
+ }
+
+ public Fix getFixAt(int pos) {
+ if ((pos>-1) && (pos<noFixes)) {
+ return (Fix) fixes.elementAt(pos);
+ }
+ return null;
+ }
+
+ public void setCurrent(int c) {
+ current=c;
+ }
+
+ public Fix getCurrent() {
+ return (Fix) fixes.elementAt(current);
+ }
+
+ public Point2d getCoordsOf (int i) {
+ if ((i>-1) && (i<noFixes)) {
+ Fix tmpFix=(Fix) fixes.elementAt(i);
+ return (tmpFix.getFixCoord());
+ }
+ return null;
+ }
+
+ public int getIndexOf (String nameFix) {
+ int index=-1;
+ for (int i=0 ; i<noFixes ; i++) {
+ if (((Fix) fixes.elementAt(i)).hasName(nameFix)) {
+ index=i;
+ i=noFixes;
+ }
+ }
+ return index;
+ }
+
+ public int getIndexOf (Fix f) {
+ Fix tmp;
+ int index=-1;
+ for (int i=0 ; i<noFixes ; i++) {
+ tmp=(Fix) fixes.elementAt(i);
+ if (tmp==f) {
+ index=i;
+ break;
+ }
+ }
+ return index;
+ }
+
+ public boolean hasFix (Fix f) {
+ int index=-1;
+ for (int i=0 ; i<noFixes; i++) {
+ if (((Fix) fixes.elementAt(i))==f) {
+ index=i;
+ break;
+ }
+ }
+ return (index>-1);
+ }
+
+ public String toString() {
+ return new String("No. Fixes:"+noFixes+": "+fixes);
+ }
+}
--- /dev/null
+
+// This class memorizes the static data (besides fixes)
+
+
+//import java.util.*;
+
+class Static {
+
+ public /*static*/ double _width, _height; // the dimensions of the given area
+ public /*static*/ double _iterationStep, _noIterations;
+ public /*static*/ double _radius, _distance;
+
+ public double width() { return _width; }
+ public double height() { return _height; }
+ public double iterationStep(){ return _iterationStep; }
+ public double noIterations() { return _noIterations; }
+ public double radius() { return _radius; }
+ public double distance() { return _distance; }
+
+ public Static() {}
+
+ public /*static*/ void setMapSize(StringTokenizer st) {
+ _width=Double.parseDouble(st.nextToken());
+ _height=Double.parseDouble(st.nextToken());
+ }
+
+ public /*static*/ void setCylinder(StringTokenizer st) {
+ _radius=Double.parseDouble(st.nextToken());
+ _distance=Double.parseDouble(st.nextToken());
+ }
+
+ public /*static*/ void setIterationStep(StringTokenizer st) {
+ _iterationStep=Double.parseDouble(st.nextToken());
+ }
+
+ public /*static*/ void setNumberOfIterations(StringTokenizer st) {
+ _noIterations=Integer.parseInt(st.nextToken());
+ }
+
+ // this is a test procedure
+ public /*static*/ void printInfo() {
+ System.out.println("\n\nStatic Data:");
+ System.out.println("Width:"+_width+" Height:"+_height);
+ System.out.println("Radius of safety/unsafety:"+_radius);
+ System.out.println("Distance of safety/unsafety:"+_distance);
+ System.out.println("Iteration step:"+_iterationStep+" No. of Iterations:"+_noIterations);
+ }
+}
--- /dev/null
+// the data about a plane - current position and velocity
+
+class Track {
+ Point4d pos;
+ Velocity vel;
+
+ public Track(Point4d p, Velocity v) {
+ pos=p;
+ vel=v;
+ }
+
+ public void setPosition (Point4d p) {
+ pos=p;
+ }
+
+ public void setVelocity (Velocity v) {
+ vel=v;
+ }
+
+ public void printInfo() {
+ System.out.println("track: "+pos+"||"+vel);
+ }
+}
--- /dev/null
+// class that implements the trajectory and some methods of access
+
+//import java.util.*;
+
+class Trajectory {
+
+ public int noPoints; // the number of points in the trajectory
+ private int current;
+ public double distToDest, timeToDest; // estimated time&distance to end fix
+ public int nextFixIndex; // index of the next fix in the trajectory of the flight;
+ public Fix nextFix; // the next fix in the trajectory of the flight
+ public Velocity startVelocity; // velocity at the first point in the trajectory;
+ public Vector p; // the points in the trajectory
+
+ public Trajectory(int np) {
+ noPoints=np;
+ p=new Vector(noPoints);
+ current=0;
+ }
+
+ // adds a point to the trajectory at the position "pos"
+ public void setPoint (int pos, Point4d point) {
+ p.insertElementAt((Point4d) point, pos);
+ }
+
+ public void setNoPoints (int noP) {
+ noPoints=noP;
+ }
+
+ public Point4d getCurrent () {
+ return (Point4d) p.elementAt(current);
+ }
+
+ public Point4d getPointAt (int index) {
+ return (Point4d) p.elementAt(index);
+ }
+
+ public double distanceToDestination() {
+ return distToDest;
+ }
+
+ public double timeToDestination(double time) {
+ return (timeToDest-time);
+ }
+
+ public double timeToDestination(int time) {
+ return (timeToDest-time);
+ }
+
+ public Velocity getVelocity() {
+ return startVelocity;
+ }
+
+ public void printInfo() {
+ System.out.println("New trajectory: ");
+ for (int i=0 ; i<noPoints ; i++) {
+ System.out.println(getPointAt(i));
+ }
+ }
+}
--- /dev/null
+/*
+ The class that estimates the trajectory of a plane, given its
+ current position, velocity and flight plan
+*/
+
+//import java.util.*;
+//import java.lang.*;
+
+public class TrajectorySynthesizer {
+
+ D2 d2;
+
+ private /*static*/ double horizTotalDist, currentDist;
+ private /*static*/ Velocity currentVelocity;
+ private /*static*/ Point4d currentPos;
+ private /*static*/ int nextFix, noFixes;
+ private /*static*/ int iterations;
+ private /*static*/ double thrust, lift, targetSpeed, targetAlt, timeF;
+ /*static*/ Trajectory traject;
+
+ private /*static*/ double bigUglyConstant() { return 1000000; }
+ private /*static*/ int limit() { return 200; }
+
+
+ public TrajectorySynthesizer( D2 d2 ) {
+ this.d2 = d2;
+ timeF=0;
+ }
+
+ public /*static*/ Trajectory updateTrajectory (int time, Flight flight) {
+ Integer nTime=new Integer(time);
+ return updateTrajectory (nTime.doubleValue(), flight);
+ }
+
+ public /*static*/ Trajectory updateTrajectory (double time, Flight flight) {
+ System.out.println("Updating trajectory for "+flight.flightID);
+ int i;
+ setInitialParameters(flight);
+ System.out.println("Starting position: "+currentPos);
+ if (currentPos.outOfRange()) {
+ traject.setNoPoints(1);
+ traject.setPoint(0, currentPos);
+ traject.distToDest=0;
+ traject.timeToDest=0;
+
+ } else {
+ for (i=0 ; (!currentPos.outOfRange()) && (i<limit()) ; i++) {
+ getTrajectoryPoint(flight, time+i*d2.getStatic().iterationStep());
+ if (i==0) {
+ System.out.println("current position: "+currentPos);
+ traject.distToDest=horizTotalDist;
+ traject.nextFixIndex=nextFix;
+ traject.nextFix=(currentPos.outOfRange())? null : flight.fPlan.r.getFixAt(nextFix);
+ }
+ if (i==1) {
+ traject.startVelocity=new Velocity(currentVelocity);
+ }
+ traject.setPoint(i, (Point4d) currentPos);
+ }
+ traject.setNoPoints(--i);
+ System.out.println(traject.noPoints);
+ traject.timeToDest=(i>0)? traject.getPointAt(i-1).time+timeF:time+timeF;
+ }
+
+ flight.traject=traject;
+ System.out.println("Finished updating trajectory ...");
+ return traject;
+ }
+
+ private /*static*/ void setInitialParameters(Flight flight) {
+ int i;
+ Point2d p1, p2;
+
+ traject=new Trajectory(10);
+ currentPos=new Point4d(flight.track.pos.time, flight.track.pos.x,
+ flight.track.pos.y, flight.track.pos.z);
+ currentVelocity=new Velocity(flight.track.vel);
+ horizTotalDist=0;
+ p1=new Point2d(currentPos.x, currentPos.y);
+ for (i=flight.fPlan.r.current; i<flight.fPlan.r.noFixes; i++) {
+ p2=flight.fPlan.r.getCoordsOf (i);
+ horizTotalDist+=Point2d.horizDistance(p1,p2);
+ p1=p2;
+ }
+ nextFix=flight.fPlan.r.current;
+ noFixes=flight.fPlan.r.noFixes;
+ thrust=flight.aircraftType.maxThrust;
+ lift=flight.aircraftType.maxLift;
+ targetSpeed=flight.fPlan.cruiseSpeed;
+ targetAlt=flight.fPlan.cruiseAlt;
+ }
+
+ private /*static*/ void getTrajectoryPoint(Flight flight, double time) {
+ if (currentPos.time<time) {
+ double z=newVerticalCoord(flight, time);
+ Point2d pXY=newHorizCoords (flight, time);
+ if (pXY.x<bigUglyConstant()-1) {
+ currentPos=new Point4d(time, pXY.x, pXY.y, z);
+ } else {
+ currentPos=new Point4d (Point4d.outOfRangeTime(),0,0,0);
+ }
+ }
+ }
+
+ private /*static*/ double newVerticalCoord (Flight flight, double time) {
+ double newZ;
+ double acc;
+
+ if (currentPos.z>=targetAlt) {
+ newZ=currentPos.z;
+ currentVelocity.vector.z=0;
+ } else {
+ acc=neededAcceleration(currentPos.z, targetAlt, lift);
+ newZ=currentPos.z+currentVelocity.vector.z*(time-currentPos.time)+
+ acc*Math.pow(time-currentPos.time,2)/2;
+ newZ=(newZ>=targetAlt)? targetAlt:newZ;
+ currentVelocity.vector.z=(newZ>=targetAlt)?
+ 0:(currentVelocity.vector.z+acc*(time-currentPos.time));
+ }
+ return newZ;
+ }
+
+ private /*static*/ double neededAcceleration(double speed, double nSpeed,
+ double thrust) {
+ double accel=(speed<nSpeed)? thrust: (speed>nSpeed)? -thrust:0;
+ return accel;
+ }
+
+ private /*static*/ Point2d decompose (double scalar,
+ Point2d p1, Point2d p2) {
+ double angle;
+ if (p1.x==p2.x) {
+ angle=(p1.y<p2.y)? Math.PI()/2.0 : -Math.PI()/2.0;
+ } else {
+ angle=(p1.x<p2.x)?
+ Math.atan((p1.y-p2.y)/(p1.x-p2.x)):
+ Math.PI()+Math.atan((p1.y-p2.y)/(p1.x-p2.x));
+ }
+ return (new Point2d (scalar*Math.cos(angle),
+ scalar*Math.sin(angle)));
+ }
+
+ private /*static*/ Point2d newHorizCoords (Flight flight, double time) {
+ double dt=time-currentPos.time;
+ double hSpeed=currentVelocity.horizSpeed();
+ double accel=neededAcceleration(hSpeed, targetSpeed, thrust);
+ double accelTime=(accel==0)? 0:(targetSpeed-hSpeed)/accel;
+ double distance, speed;
+ Point2d current, temp, temp2;
+
+ if (accelTime<dt) {
+ speed=targetSpeed;
+ distance=hSpeed*accelTime+accel*Math.pow(accelTime,2)/2+
+ speed*(dt-accelTime);
+ } else {
+ speed=hSpeed+accel*dt;
+ distance=hSpeed*dt+accel*Math.pow(dt,2)/2;
+ }
+
+ if ((distance>horizTotalDist)&&(horizTotalDist>0)) {
+ timeF=(accel<=0)?(horizTotalDist/hSpeed):
+ (-hSpeed+Math.sqrt(hSpeed*hSpeed+2*accel*horizTotalDist))/accel;
+ System.out.println("TIMEF= "+timeF);
+ }
+
+ horizTotalDist-=distance;
+
+ for (current=currentPos.toPoint2d();
+ (nextFix<noFixes) &&
+ (distance>Point2d.horizDistance(current,
+ flight.fPlan.r.getCoordsOf(nextFix)));
+ nextFix++) {
+ distance-=Point2d.horizDistance(current,
+ flight.fPlan.r.getCoordsOf(nextFix));
+ current=flight.fPlan.r.getCoordsOf(nextFix);
+ }
+
+ if (nextFix<noFixes) {
+ temp2=decompose(distance,
+ current, flight.fPlan.r.getCoordsOf(nextFix));
+ temp=decompose(speed,
+ current, flight.fPlan.r.getCoordsOf(nextFix));
+
+ current=new Point2d(temp2.x+current.x, temp2.y+current.y);
+
+ currentVelocity.vector.x=temp.x;
+ currentVelocity.vector.y=temp.y;
+ } else {
+ current=new Point2d(bigUglyConstant(),bigUglyConstant());
+ }
+ return current;
+ }
+}
--- /dev/null
+// trial flight class with trial planning-related methods
+
+public class TrialFlight {
+ D2 d2;
+
+ Flight oldFlight, trialFlight;
+ Route trialRoute;
+ Trajectory trialTrajectory;
+ double time;
+ Fix fix1, fix2;
+ int fixIndex;
+ // differences between the old flight and the trial flight follow:
+ double timeDiff, distDiff; // time and distance difference
+ ConflictList oldConflicts, newConflicts; // the lists of conflicts
+ int noNew, noRemoved; // the number of new and removed conflicts, respectively
+
+ // constructor of a trial flight using a shortcut between two fixes.
+ public TrialFlight(D2 d2, Flight flight, Fix fix1, Fix fix2) {
+ this.d2=d2;
+ int aux, fixIndex1, fixIndex2;
+ oldFlight=flight;
+ fixIndex1=oldFlight.fPlan.r.getIndexOf(fix1);
+ fixIndex2=oldFlight.fPlan.r.getIndexOf(fix2);
+ if (fixIndex1>fixIndex2) {
+ aux=fixIndex1;
+ fixIndex1=fixIndex2;
+ fixIndex2=aux;
+ }
+ trialFlight=Flight.copyOf(d2, oldFlight);
+ trialFlight.trialStatus=Flight.trialFlightStatus();
+ this.changeToTrialRoute(fixIndex1, fixIndex2);
+ }
+
+ // constructor for a trial flight using the current position of a plane
+ public TrialFlight(D2 d2, Flight flight, String fixName) {
+ this.d2=d2;
+ oldFlight=flight;
+ }
+
+ // constructor that uses an estimated position and a fix
+ public TrialFlight(D2 d2, Flight flight, Point4d position, Fix fix) {
+ this.d2=d2;
+ int aux;
+ oldFlight=flight;
+ fixIndex=oldFlight.fPlan.r.getIndexOf(fix);
+ trialFlight=Flight.copyOf(d2, oldFlight);
+ trialFlight.trialStatus=Flight.trialFlightStatus();
+ oldFlight.updateTrajectory(position.time);
+ // assuming that the position given as parameter is the same as the first point in the trajectory
+ trialFlight.track=new Track(new Point4d(position), new Velocity(oldFlight.track.vel));
+ trialFlight.fPlan=new FlightPlan(oldFlight.fPlan);
+ changeToTrialRoute(position, fixIndex);
+ trajectoryDiff(position.time);
+ conflictsDiff(position.time);
+ System.out.println("old route:"+oldFlight.fPlan.r);
+ System.out.println("new route:"+trialFlight.fPlan.r);
+ trialFlight.trialStatus=-1;
+ }
+
+ public void trajectoryDiff (double time) {
+ trialFlight.updateTrajectory(time);
+ oldFlight.updateTrajectory(time);
+ System.out.println("Flight "+trialFlight.flightID+":");
+ distDiff=oldFlight.traject.distanceToDestination()-
+ trialFlight.traject.distanceToDestination();
+ timeDiff=oldFlight.traject.timeToDestination(time)-
+ trialFlight.traject.timeToDestination(time);
+ if (timeDiff<0) { timeDiff=0; }
+ System.out.println("Time difference: "+timeDiff);
+ System.out.println("Distance difference: "+distDiff);
+ }
+
+ public void conflictsDiff(double time) {
+ int i, j;
+ oldConflicts=d2.getAlgorithm().getConflictsWith(time,oldFlight);
+ newConflicts=d2.getAlgorithm().getConflictsWith(time,trialFlight);
+ System.out.println("Flight "+trialFlight.flightID+":");
+ System.out.println("Conflicts for the old flight:");
+ System.out.println(oldConflicts);
+ System.out.println("Conflicts for the trial flight:");
+ System.out.println(newConflicts);
+ noNew=0;
+ for (i=0 ; i<newConflicts.noConflicts ; i++) {
+ Conflict conflict=newConflicts.conflictAt(i);
+ if (oldConflicts.findConflict(conflict.flight1, conflict.flight2)==null) {
+ noNew++;
+ }
+ }
+ noRemoved=oldConflicts.noConflicts-(newConflicts.noConflicts-noNew);
+ }
+
+ public void changeToTrialRoute (Point4d pos, int index) {
+ int i,count, index1=0;
+ if (index>-1) {
+ trialRoute=new Route(d2, oldFlight.fPlan.r.noFixes-index);
+ trialRoute.current=0;
+ for (i=index; i<oldFlight.fPlan.r.noFixes ; i++) {
+ trialRoute.addFix(i-index, oldFlight.fPlan.r.getFixAt(i));
+ }
+ trialFlight.fPlan.r=trialRoute;
+ }
+ }
+
+ public void changeToTrialRoute (int index1, int index2) {
+ int i,count;
+ if ((index1>-1) && (index2>-1) && (index2-index1>1)) {
+ trialRoute=new Route(d2, oldFlight.fPlan.r.noFixes-
+ (index2-index1-1));
+ trialRoute.current=index1+1;
+ for (i=0 ; i<=index1 ; i++) {
+ trialRoute.addFix(i, oldFlight.fPlan.r.getFixAt(i));
+ if (oldFlight.fPlan.r.current==i) {
+ trialRoute.current=i;
+ }
+ }
+
+ for (i=index2; i<oldFlight.fPlan.r.noFixes ; i++) {
+ trialRoute.addFix(i-index2+index1+1,
+ oldFlight.fPlan.r.getFixAt(i));
+ if (oldFlight.fPlan.r.current==i) {
+ trialRoute.current=i-index2+index1+1;
+ }
+ }
+ trialFlight.fPlan.r=trialRoute;
+ }
+ }
+}
--- /dev/null
+// the class that describes coordinates the velocity of a plane
+
+//import java.lang.*;
+
+class Velocity {
+
+ public Point4d vector;
+ public double speed;
+
+ Velocity() {
+ Velocity(0,0,0);
+ }
+
+ Velocity(double newX, double newY, double newZ) {
+ this.vector=new Point4d(newX, newY, newZ);
+ this.speed=this.horizSpeed();
+ }
+
+ public static Velocity copyOf(Velocity v) {
+ return new Velocity( v );
+ }
+
+ Velocity (Velocity v) {
+ this.vector=new Point4d (v.vector);
+ this.speed=this.horizSpeed();
+ }
+
+ public double horizSpeed() {
+ return Math.sqrt(Math.pow(vector.x,2.0)+Math.pow(vector.y,2.0));
+ }
+
+ public String toString() {
+ return vector.toString();
+ }
+}
--- /dev/null
+10 ADD_PLANE Boeing 747
+20 ADD_PLANE AirBus 300
+30 AMEND_ROUTE Boeing 0 0 0 1 1 0 1 B B 1 0
+30 AMEND_ROUTE AirBus 10 10 0 -1 -1 0 1 A A 1 0
+30 DO_WORK
\ No newline at end of file
--- /dev/null
+Aircraft.java
+AircraftList.java
+Algorithm.java
+CanvasImage.java
+CanvasMap.java
+Conflict.java
+ConflictList.java
+D2.java
+Fix.java
+FixList.java
+Flight.java
+FlightList.java
+FlightPlan.java
+Graphic.java
+Message.java
+MessageList.java
+Perform.java
+Point2d.java
+Point4d.java
+Read.java
+ReadMessages.java
+ReadWrite.java
+Route.java
+Static.java
+Track.java
+Trajectory.java
+TrajectorySynthesizer.java
+TrialFlight.java
+TrialPlanning.java
+Velocity.java
+Write.java
--- /dev/null
+0 SET_ITERATION_STEP 1
+0 SET_NO_OF_ITERATIONS 50
+0 SET_CYLINDER 20 501
+0 SET_MAP_SIZE 600 400
+
+0 ADD_FIX A 50 50
+0 ADD_FIX B 50 150
+0 ADD_FIX C 100 200
+0 ADD_FIX D 150 100
+0 ADD_FIX E 250 0
+0 ADD_FIX F 200 200
+0 ADD_FIX G 200 50
+0 ADD_FIX H 150 300
+0 ADD_FIX I 300 150
+0 ADD_FIX J 350 50
+0 ADD_FIX K 300 350
+0 ADD_FIX L 350 250
+0 ADD_FIX M 400 200
+0 ADD_FIX N 450 100
+0 ADD_FIX O 100 250
+0 ADD_FIX P 500 300
+0 ADD_FIX Q 250 250
+0 ADD_FIX R 300 100
+0 ADD_FIX S 100 0
+0 ADD_FIX T 450 0
+0 ADD_FIX U 0 300
+0 ADD_FIX V 200 350
+0 ADD_FIX W 500 150
+
+0 ADD_AIRCRAFT Boeing737 60 5
+0 ADD_AIRCRAFT AirBus310 70 5
+0 ADD_AIRCRAFT DC80 80 6
+0 ADD_AIRCRAFT Boeing747 75 4
+
+20 ADD_FLIGHT_PLAN RO0001 Boeing737 OVER 6 O Q L M N T 10000 5
+20 ADD_FLIGHT_PLAN LH3473 AirBus310 OVER 4 K F G E 10000 5
+20 ADD_FLIGHT_PLAN AF2809 Boeing747 OVER 5 B D R J T 10500 5
+
+
+30 ADD_FLIGHT_PLAN DL8201 DC80 OVER 1 A 9800 7
+30 ADD_FLIGHT_PLAN RO1313 Boeing737 OVER 5 S G I L K 9900 6
+
+35 ADD_FLIGHT_PLAN UA0802 DC80 OVER 4 H Q M T 10000 5
+
+// changing route
+50 AMEND_FLIGHT_PLAN DL8201 5 P M R G A 9800 7
+
+
+// sending positions
+55 SENDING_AIRCRAFT 1 LH3473 300 360 10500 0 -5 0 K
+62 SENDING_AIRCRAFT 1 RO0001 50 300 9000 2 0 0 O
+65 SENDING_AIRCRAFT 1 AF2809 0 150 8000 3 0 100 B
+65 SENDING_AIRCRAFT 1 DL8201 500 320 0 0 -2 400 P
+65 SENDING_AIRCRAFT 1 RO1313 90 0 9000 1 1 0 S
+70 SENDING_AIRCRAFT 1 UA0802 120 330 9800 1.7 0 -200 H
+
+// 70 DO_WORK
+
+
+200 ADD_FLIGHT_PLAN AA3323 DC80 OVER 6 U B D R J T 10000 10
+200 ADD_FLIGHT_PLAN BA1234 Boeing747 OVER 6 S G R I L P 10000 12
+200 ADD_FLIGHT_PLAN RO0023 Boeing737 OVER 6 S A C O H V 9800 10
+200 ADD_FLIGHT_PLAN LH9898 AirBus310 OVER 5 K Q F G E 10100 12
+
+
+220 SENDING_AIRCRAFT 2 AA3323 0 310 0 0 -2 300 U LH9898 380 350 10000 -1 0 0 K
+225 SENDING_AIRCRAFT 2 RO0023 110 0 10000 -2 0 0 S BA1234 150 20 9000 2 2 0 G
+
+225 DO_WORK
--- /dev/null
+0 SET_ITERATION_STEP 1
+0 SET_NO_OF_ITERATIONS 50
+0 SET_CYLINDER 20 501
+0 SET_MAP_SIZE 600 400
+
+0 ADD_FIX A 50 50
+0 ADD_FIX B 50 150
+0 ADD_FIX C 100 200
+0 ADD_FIX D 150 100
+0 ADD_FIX E 250 0
+0 ADD_FIX F 200 200
+0 ADD_FIX G 200 50
+0 ADD_FIX H 150 300
+0 ADD_FIX I 300 150
+0 ADD_FIX J 350 50
+0 ADD_FIX K 300 350
+0 ADD_FIX L 350 250
+0 ADD_FIX M 400 200
+0 ADD_FIX N 450 100
+0 ADD_FIX O 100 250
+0 ADD_FIX P 500 300
+0 ADD_FIX Q 250 250
+0 ADD_FIX R 300 100
+0 ADD_FIX S 100 0
+0 ADD_FIX T 450 0
+
+
+0 ADD_AIRCRAFT Boeing737 60 5
+0 ADD_AIRCRAFT AirBus310 70 5
+0 ADD_AIRCRAFT DC80 80 6
+0 ADD_AIRCRAFT Boeing747 75 6
+
+20 ADD_FLIGHT_PLAN Ro0001 Boeing737 OVER 6 O Q L M N T 10000 5
+20 ADD_FLIGHT_PLAN LH3473 AirBus310 OVER 4 K F G E 10000 5
+20 ADD_FLIGHT_PLAN af280 Boeing747 OVER 5 B D R J T 10500 5
+
+
+30 ADD_FLIGHT_PLAN DL8201 DC80 OVER 1 A 9800 7
+30 ADD_FLIGHT_PLAN RO1313 Boeing737 OVER 5 S G I L K 9900 6
+
+35 ADD_FLIGHT_PLAN UA0802 DC80 OVER 4 H Q M T 10000 5
+
+// changing route
+50 AMEND_FLIGHT_PLAN DL8201 5 P M R G A 9800 7
+
+
+// sending positions
+55 SENDING_AIRCRAFT 1 LH3473 300 360 10500 0 -5 0 K
+62 SENDING_AIRCRAFT 1 Ro0001 50 300 9000 2 0 0 O
+65 SENDING_AIRCRAFT 1 af280 0 150 8000 3 0 100 B
+65 SENDING_AIRCRAFT 1 DL8201 500 320 0 0 -2 400 P
+65 SENDING_AIRCRAFT 1 RO1313 90 0 9000 1 1 0 S
+70 SENDING_AIRCRAFT 1 UA0802 120 330 9800 1.7 0 -200 H
+
+70 DO_WORK
+
+
--- /dev/null
+0 SET_ITERATION_STEP 1
+0 SET_NO_OF_ITERATIONS 50
+0 SET_CYLINDER 20 501
+0 SET_MAP_SIZE 600 400
+
+0 ADD_FIX A 50 50
+0 ADD_FIX B 50 150
+0 ADD_FIX C 100 200
+0 ADD_FIX D 150 100
+0 ADD_FIX E 250 0
+0 ADD_FIX F 200 200
+0 ADD_FIX G 200 50
+0 ADD_FIX H 150 300
+0 ADD_FIX I 300 150
+0 ADD_FIX J 350 50
+0 ADD_FIX K 300 350
+0 ADD_FIX L 350 250
+0 ADD_FIX M 400 200
+0 ADD_FIX N 450 100
+0 ADD_FIX O 100 250
+0 ADD_FIX P 500 300
+0 ADD_FIX Q 250 250
+0 ADD_FIX R 300 100
+0 ADD_FIX S 100 0
+0 ADD_FIX T 450 0
+0 ADD_FIX U 0 300
+0 ADD_FIX V 200 350
+0 ADD_FIX W 500 150
+
+0 ADD_AIRCRAFT Boeing737 60 5
+0 ADD_AIRCRAFT AirBus310 70 5
+0 ADD_AIRCRAFT DC80 80 6
+0 ADD_AIRCRAFT Boeing747 75 4
+
+20 ADD_FLIGHT_PLAN RO0001 Boeing737 OVER 6 O Q L M N T 10000 5
+20 ADD_FLIGHT_PLAN LH3473 AirBus310 OVER 4 K F G E 10000 5
+20 ADD_FLIGHT_PLAN AF2809 Boeing747 OVER 5 B D R J T 10500 5
+
+
+30 ADD_FLIGHT_PLAN DL8201 DC80 OVER 1 A 9800 7
+30 ADD_FLIGHT_PLAN RO1313 Boeing737 OVER 5 S G I L K 9900 6
+
+35 ADD_FLIGHT_PLAN UA0802 DC80 OVER 4 H Q M T 10000 5
+
+// changing route
+50 AMEND_FLIGHT_PLAN DL8201 5 P M R G A 9800 7
+
+
+// sending positions
+55 SENDING_AIRCRAFT 1 LH3473 300 360 10500 0 -5 0 K
+62 SENDING_AIRCRAFT 1 RO0001 50 300 9000 2 0 0 O
+65 SENDING_AIRCRAFT 1 AF2809 0 150 8000 3 0 100 B
+65 SENDING_AIRCRAFT 1 DL8201 500 320 0 0 -2 400 P
+65 SENDING_AIRCRAFT 1 RO1313 90 0 9000 1 1 0 S
+70 SENDING_AIRCRAFT 1 UA0802 120 330 9800 1.7 0 -200 H
+
+// 70 DO_WORK
+
+
+200 ADD_FLIGHT_PLAN AA3323 DC80 OVER 6 U B D R J T 10000 10
+200 ADD_FLIGHT_PLAN BA1234 Boeing747 OVER 6 S G R I L P 10000 12
+200 ADD_FLIGHT_PLAN RO0023 Boeing737 OVER 6 S A C O H V 9800 10
+200 ADD_FLIGHT_PLAN LH9898 AirBus310 OVER 5 K Q F G E 10100 12
+
+
+220 SENDING_AIRCRAFT 2 AA3323 0 310 0 0 -2 300 U LH9898 380 350 10000 -1 0 0 K
+225 SENDING_AIRCRAFT 2 RO0023 110 0 10000 -2 0 0 S BA1234 150 20 9000 2 2 0 G
+
+225 DO_WORK
--- /dev/null
+MAIN_CLASS=D2
+
+PROGRAM=test
+SOURCE_FILES=*.java
+
+BUILDSCRIPT=~/research/Robust/src/buildscript
+BSFLAGS= -debug -nooptimize -mainclass $(MAIN_CLASS) #-justanalyze -ownership -ownallocdepth 1 -ownwritedots final -enable-assertions
+
+all: $(PROGRAM).bin
+
+view: PNGs
+ eog *.png &
+
+PNGs: DOTs
+ d2p *COMPLETE*.dot
+
+DOTs: $(PROGRAM).bin
+
+$(PROGRAM).bin: $(SOURCE_FILES)
+ $(BUILDSCRIPT) $(BSFLAGS) -o $(PROGRAM) $(SOURCE_FILES)
+
+clean:
+ rm -f $(PROGRAM).bin
+ rm -fr tmpbuilddirectory
+ rm -f *~
+ rm -f *.dot
+ rm -f *.png
+ rm -f aliases.txt
--- /dev/null
+// class that implements types of aircrafts
+
+class Aircraft
+{
+ String type;
+ double maxLift, maxThrust;
+
+ public Aircraft(String t, double maxL, double maxT)
+ {
+ type=t;
+ maxLift=maxL;
+ maxThrust=maxT;
+ }
+
+ boolean hasType(String type0)
+ {
+ return (type.compareTo(type0)==0);
+ }
+
+ public String toString()
+ {
+ return new String("Airplane: "+type+" "+maxLift+" "+maxThrust);
+ }
+
+}
+
--- /dev/null
+// This class memorizes all the existing aircrafts
+
+
+import java.util.*;
+
+final class AircraftList
+{
+ public static int noAircrafts=0; // the number of aircrafts
+ private static ArrayList aircrafts=new ArrayList(100); // the aircrafts
+
+ public static void setAircraft(String name,double lift,double thrust)
+ // sets the parameters of the aircraft number "pos": its name, its lift and its thrust
+ {
+ aircrafts.add(new Aircraft(name,lift,thrust));
+ }
+
+ public static Aircraft getAircraft(String name)
+ // returns the fix with the given name
+ {
+ Iterator it=aircrafts.iterator();
+ while (it.hasNext())
+ {
+ Aircraft aAux=(Aircraft) it.next();
+ if (aAux.hasType(name))
+ return aAux;
+ }
+ throw new RuntimeException("Aircraft not found - "+name);
+ }
+
+ public static Iterator getAircrafts()
+ {
+ return aircrafts.iterator();
+ }
+
+ public static void printInfo()
+ // this is a test procedure
+ {
+ System.out.println("\n\nThe number of aircrafts:"+noAircrafts);
+ System.out.println("The aircrafts are:");
+ Iterator it=aircrafts.iterator();
+ while (it.hasNext())
+ {
+ Aircraft aAux=(Aircraft) it.next();
+ System.out.println(aAux);
+ }
+ }
+
+ public static void addAircraft(StringTokenizer parameters)
+ {
+ setAircraft(parameters.nextToken(), Integer.parseInt(parameters.nextToken()), Integer.parseInt(parameters.nextToken()));
+ noAircrafts++;
+ }
+
+ public static void removeAircraft(StringTokenizer parameters)
+ {
+ noAircrafts--;
+ Aircraft aAux=getAircraft(parameters.nextToken());
+ aircrafts.remove(aAux);
+ }
+
+}
+
+
+
+
--- /dev/null
+import java.util.*;
+import java.io.*;
+
+class Algorithm
+{
+ public static double initialTime,time;
+ public static double currIteration;
+ public static ConflictList cList=new ConflictList();
+
+ public static void setInitialTime(double time)
+ {
+ initialTime=time;
+ currIteration=0;
+ }
+
+ public static boolean isConflict(Point4d p1, Point4d p2)
+ {
+ Point2d pAux1=new Point2d(p1.x,p1.y);
+ Point2d pAux2=new Point2d(p2.x,p2.y);
+ if ( (Point2d.squaredDistance(pAux1,pAux2)<=Math.pow(Static.radius,2)) && (Math.abs(p1.z-p2.z)<=Static.distance) )
+ return true;
+ else return false;
+ }
+
+ public static Point4d findConflict(Flight a, Flight b)
+ {
+ Point4d conflictPoint=new Point4d(Point4d.outOfRangeTime,0,0,0);
+ if (a.flightID!=b.flightID) {
+ ArrayList p1=a.traject.p;
+ ArrayList p2=b.traject.p;
+
+ int pos=0;
+ boolean found=false;
+
+ while ( (pos<p1.size()) && (pos<p2.size()) && (!found) )
+ {
+ Point4d point1=(Point4d) p1.get(pos);
+ Point4d point2=(Point4d) p2.get(pos);
+ if (isConflict(point1,point2))
+ {
+ // System.out.println("CONFLICT at position "+point1);
+
+ System.out.println(point1+" "+point2);
+ found=true;
+ conflictPoint=point1;
+ // cList.newConflict(time+pos*Static.iterationStep,point1,a,b);
+ }
+ pos++;
+ }
+ }
+ return conflictPoint;
+ }
+
+
+
+ public static ConflictList getConflictsWith(double time, Flight flight)
+ {
+ ConflictList conflicts=new ConflictList();
+
+ ArrayList flights=FlightList.f;
+ int n=FlightList.noFlights,i,j;
+
+ TrajectorySynthesizer.updateTrajectory(time, flight);
+ for (i=0; i<n; i++) {
+ Flight aAux=(Flight) flights.get(i);
+ TrajectorySynthesizer.updateTrajectory(time, aAux);
+ }
+
+ Flight aux1=flight;
+ for (i=0; i<n; i++) {
+ Flight aux2=(Flight) flights.get(i);
+ Point4d conflictPoint=findConflict(aux1,aux2);
+ if (!(conflictPoint.outOfRange())) {
+ conflicts.newConflict(conflictPoint,aux1,aux2);
+ }
+ }
+ return conflicts;
+ }
+
+
+ static public void doIteration() throws IOException
+ {
+ time=initialTime+currIteration*Static.iterationStep;
+ currIteration++;
+ System.out.println("In doIteration!");
+ System.out.println("Time:"+time);
+
+
+ cList.clear();
+ ArrayList flights=FlightList.f;
+ int n=FlightList.noFlights,i,j;
+
+ for (i=0;i<n;i++)
+ {
+ Flight aAux=(Flight) flights.get(i);
+ TrajectorySynthesizer.updateTrajectory(time,aAux);
+ }
+
+ System.out.println("Does it get here? (after the trajectory update)");
+
+ for (i=0;i<n;i++)
+ for (j=i+1;j<n;j++)
+ {
+ Flight aux1=(Flight) flights.get(i);
+ Flight aux2=(Flight) flights.get(j);
+ Point4d conflictPoint=findConflict(aux1,aux2);
+ if (!(conflictPoint.outOfRange())) {
+ cList.newConflict(conflictPoint,aux1,aux2);
+ }
+ }
+ }
+
+}
+
+
+
+
+
+
+
+
+
+
--- /dev/null
+// This class memorizes a conflict
+
+class Conflict
+{
+ public Point4d coordinates; // its position
+ public Flight flight1, flight2; // the two flights involved in the conflict
+
+ public Conflict(Point4d coord, Flight f1, Flight f2)
+ {
+ coordinates=coord;
+ flight1=f1;
+ flight2=f2;
+ }
+
+ public boolean hasFlights(Flight f1, Flight f2)
+ {
+ if ( ((flight1.flightID==f1.flightID)&&(flight2.flightID==f2.flightID))||
+ ((flight1.flightID==f2.flightID)&&(flight2.flightID==f1.flightID)) )
+ return true;
+ else return false;
+ }
+
+ public String toString()
+ {
+ return ("Conflict at time "+coordinates.time+" position "+coordinates+" between "+
+ flight1.flightID+" and "+flight2.flightID+".");
+ }
+
+}
--- /dev/null
+// This class keeps a list of conflicts.
+// The conflicts are updated at every moment of time
+// We detect only the first conflict between every pair of flights
+
+import java.util.*;
+
+final class ConflictList
+{
+ public int noConflicts; // the number of conflicts
+ private ArrayList conflicts; // the conflicts
+
+
+ public ConflictList()
+ {
+ noConflicts=0;
+ conflicts=new ArrayList(100);
+ }
+
+ public void clear()
+ {
+ noConflicts=0;
+ conflicts.clear();
+ }
+
+ public Conflict conflictAt(int index)
+ {
+ return (Conflict) conflicts.get(index);
+ }
+
+ public Iterator getConflicts()
+ {
+ return conflicts.iterator();
+ }
+
+ public String printInfo()
+ // this is a test procedure
+ {
+ String st;
+ if (noConflicts==0)
+ st="No conflicts!";
+ else
+ {
+ st=""+noConflicts+" conflicts\n";
+ Iterator iter=getConflicts();
+ while (iter.hasNext())
+ {
+ Conflict cAux=(Conflict) iter.next();
+ st=st+"\n"+cAux;
+ }
+ }
+ return st;
+ }
+
+ public void newConflict(Point4d coord, Flight f1, Flight f2)
+ {
+ noConflicts++;
+ conflicts.add(new Conflict(coord,f1,f2));
+ }
+
+
+ public Conflict findConflict(Flight f1, Flight f2)
+ {
+ Iterator iter=getConflicts();
+ while (iter.hasNext())
+ {
+ Conflict cAux=(Conflict) iter.next();
+ if (cAux.hasFlights(f1,f2))
+ return cAux;
+ }
+ return null;
+ }
+
+
+ public void removeConflict(Flight f1, Flight f2)
+ {
+ noConflicts--;
+ Conflict cAux=findConflict(f1,f2);
+ conflicts.remove(cAux);
+ }
+
+}
+
+
+
+
+
+
+
+
+
+
--- /dev/null
+
+// This class contains the the main method of this project.
+// All it does is to initialize the input and output threads and
+// to launch the graphical interface
+
+import java.io.*;
+
+class D2
+{
+ public static ReadWrite rw;
+ public static Read threadRead;
+
+ public static void main(String arg[]) throws Exception
+ {
+ System.out.println("D2 - Application started");
+
+ rw=new ReadWrite();
+ threadRead=new Read(rw);
+ // Write threadWrite=new Write(rw);
+
+ // Graphic mainGraphic=new Graphic();
+ // mainGraphic.display();
+
+ threadRead.run();
+ //System.out.println("Hey!!!");
+ MessageList.executeAll();
+
+ while (FlightList.anyPlanesAlive())
+ Algorithm.doIteration();
+ // threadWrite.start();
+ }
+
+}
+
+
+
+
--- /dev/null
+// this class stores the properties of a fix
+
+class Fix
+{
+ private String name; // its name
+ private Point2d p; // its coordinates
+
+ public Fix(String name0,Point2d p0)
+ {
+ name=name0;
+ p=p0;
+ }
+
+ public Point2d getFixCoord()
+ {
+ return p;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ boolean hasName(String name0)
+ {
+ return (name.compareTo(name0)==0);
+ }
+
+ public String toString()
+ // for testing purposes
+ {
+ return new String("Fix: "+name+" "+p);
+ }
+
+}
+
+
+
+
--- /dev/null
+// This class memorizes all the fixes in the area.
+// There are methods for setting the properties of a fix and
+// for getting a fix by a given name
+
+
+import java.util.*;
+
+final class FixList
+{
+ public static int noFixes=0; // the number of fixes
+ public static ArrayList fixes=new ArrayList (100); // the fixes
+
+ public static void setFix(String name,float x,float y)
+ // sets the parameters of the fix number "pos": its name
+ // and its coordinates
+ {
+ fixes.add(new Fix(name,(Point2d) new Point2d(x,y)));
+ }
+
+
+ public static String getFix(int index)
+ {
+ Fix fAux=(Fix) fixes.get(index);
+ return (String) fAux.getName();
+ }
+
+ public static int getIndex(String name)
+ // returns the index of the fix with the given name
+ {
+ int index=0;
+ Iterator it=getFixes();
+ while (it.hasNext())
+ {
+ Fix fAux=(Fix) it.next();
+ if (fAux.hasName(name))
+ return index;
+ index++;
+ }
+ throw new RuntimeException("Fix not found - "+name);
+ }
+
+ public static Fix getFix(String name)
+ // returns the fix with the given name
+ {
+ Iterator it=getFixes();
+ while (it.hasNext())
+ {
+ Fix fAux=(Fix) it.next();
+ if (fAux.hasName(name))
+ return fAux;
+ }
+ throw new RuntimeException("Fix not found - "+name);
+ }
+
+ public static Iterator getFixes()
+ {
+ return fixes.iterator();
+ }
+
+ public static void printInfo()
+ // this is a test procedure
+ {
+ System.out.println("\n\nThe number of fixes:"+noFixes);
+ System.out.println("The fixes are:");
+ Iterator it=getFixes();
+ while (it.hasNext())
+ {
+ Fix bAux=(Fix) it.next();
+ System.out.println(bAux);
+ }
+ }
+
+ public static void addFix(StringTokenizer parameters)
+ {
+ setFix(parameters.nextToken(), Integer.parseInt(parameters.nextToken()), Integer.parseInt(parameters.nextToken()));
+ noFixes++;
+ }
+
+ public static void removeFix(StringTokenizer parameters)
+ {
+ noFixes--;
+ Fix fAux=getFix(parameters.nextToken());
+ fixes.remove(fAux);
+ }
+
+}
+
+
+
+
+
+
--- /dev/null
+// the class that describes a flight
+
+class Flight implements Cloneable
+{
+ public String flightID; // the flight id
+ public int trialStatus; //
+ public Aircraft aircraftType; // the type of aircraft
+ public Track track; // data from radar
+ public Trajectory traject; // the estimated trajectory
+ public FlightPlan fPlan; // the associated flight plan
+ public String flightType; // the type of flight
+ private float horizAcc, vertAcc; // data used for estimating trajectory
+ static int realFlightStatus=-1;
+ static int trialFlightStatus=1;
+
+
+ public Flight(String id)
+ {
+ this.flightID=id;
+ this.trialStatus=realFlightStatus;
+ }
+
+
+ public void setAircraftType (Aircraft ac)
+ {
+ this.aircraftType=ac;
+ }
+
+ public void setFlightType(String flightType)
+ {
+ this.flightType=flightType;
+ }
+
+
+ public void setTrack(Track newTrack)
+ {
+ this.track=newTrack;
+ }
+
+ public void setFlightPlan(FlightPlan fp)
+ {
+ fPlan=fp;
+ }
+
+ public void updateTrajectory(double time)
+ {
+ TrajectorySynthesizer.updateTrajectory(time, this);
+ }
+
+ // public Trajectory getTrajectory (int time)
+ //{
+ //boolean condition=false;
+ //if (condition) traject=computeTrajectory(time);
+
+ // return traject;
+ // }
+
+ public boolean hasID (String id)
+ {
+ return (flightID.compareTo(id)==0);
+ }
+
+ public boolean isFlying (String flType)
+ {
+ return (flightType.compareTo(flType)==0);
+ }
+
+ public static Flight copyOf(Flight f)
+ {
+ try {
+ return (Flight) f.clone();
+ } catch (Exception e) { System.out.println("Copying error !"); }
+ return null;
+ }
+
+ public String toString()
+ {
+ return new String("Flight "+flightID+" Aircraft:"+aircraftType.type+
+ " Flight type:"+flightType+
+ " Cruise Altitude:"+fPlan.cruiseAlt+
+ " Cruise Speed:"+fPlan.cruiseSpeed+"\n"+fPlan.r);
+ }
+
+}
+
+
+
+
+
+
+
+
+
--- /dev/null
+// This is the class that manages all the flights
+
+import java.util.*;
+
+class FlightList
+{
+ public static int noFlights=0;
+ public static ArrayList f=new ArrayList(100);
+
+
+ public void addFlight(int index, Flight flight)
+ {
+ f.add(index,flight);
+ }
+
+ public static void addFlightPlan(int time, StringTokenizer st)
+ {
+ Flight newFlight= new Flight(st.nextToken());
+ noFlights++;
+ f.add(newFlight);
+ FlightPlan fAux=new FlightPlan();
+ Aircraft aAux=AircraftList.getAircraft(st.nextToken());
+ newFlight.setAircraftType(aAux);
+ newFlight.setFlightType(st.nextToken());
+ Route rAux=new Route(Integer.parseInt(st.nextToken()));
+ for (int i=0;i<rAux.noFixes;i++)
+ rAux.addFix(i,st.nextToken());
+ fAux.setRoute(rAux);
+ fAux.setCruiseParam(Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()));
+ newFlight.setFlightPlan(fAux);
+ }
+
+ public static String getFlightName(int index)
+ {
+ Flight fAux=(Flight) f.get(index);
+ return fAux.flightID;
+ }
+
+ public static void amendFlightPlan(int time, StringTokenizer st)
+ {
+ Flight fAux=getFlight(st.nextToken());
+ Route rAux=new Route(Integer.parseInt(st.nextToken()));
+ for (int i=0;i<rAux.noFixes;i++)
+ rAux.addFix(i,st.nextToken());
+ fAux.fPlan.setRoute(rAux);
+ fAux.fPlan.setCruiseParam(Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()));
+ }
+
+ public static void amendFlightInfo(int time, StringTokenizer st)
+ {
+ Flight fAux=getFlight(st.nextToken());
+ Aircraft aAux=AircraftList.getAircraft(st.nextToken());
+ fAux.setAircraftType(aAux);
+ fAux.setFlightType(st.nextToken());
+ }
+
+ public static void sendingAircraft(int time, StringTokenizer st)
+ {
+ int noF=Integer.parseInt(st.nextToken());
+ String id;
+ Point4d pos;
+ Velocity vel;
+ Track t;
+ String nameFix;
+ Flight fAux;
+ for (int counter=0 ; counter<noF ;counter ++) {
+ id=st.nextToken();
+ pos=new Point4d(time,
+ Double.valueOf(st.nextToken()).doubleValue(),
+ Double.valueOf(st.nextToken()).doubleValue(),
+ Double.valueOf(st.nextToken()).doubleValue());
+ vel=new Velocity(Double.valueOf(st.nextToken()).doubleValue(),
+ Double.valueOf(st.nextToken()).doubleValue(),
+ Double.valueOf(st.nextToken()).doubleValue());
+ t=new Track(pos, vel);
+ nameFix=st.nextToken();
+ // int i=0;
+ // while ((i<noFlights) && (((Flight) f.get(i)).hasID(id))) i++;
+ fAux=getFlight(id);
+ System.out.println(id+" Flight id: "+fAux.flightID);
+ // if (i<noFlights) {
+ fAux.setTrack(t);
+ System.out.println("Setting current fix ...");
+ fAux.fPlan.setCurrentFix(nameFix);
+ // System.exit(0);
+ System.out.println("Sent flight "+
+ fAux.flightID+
+ "; position: "+
+ fAux.track.pos);
+ TrajectorySynthesizer.updateTrajectory(time,
+ fAux);
+ fAux.traject.printInfo();
+ // }
+ }
+ // You don't read this !!!
+ // String currentFix=st.nextToken();
+ }
+
+
+ public static void removeFlightPlan(int time, StringTokenizer st)
+ {
+ String id=st.nextToken();
+ int i=0;
+ while ((i<noFlights) && (((Flight) f.get(i)).hasID(id))) i++;
+ if (i<noFlights) f.remove(i);
+ }
+
+
+ public static Flight getFlight(String id)
+ {
+ Iterator iter=f.iterator();
+ while (iter.hasNext())
+ {
+ Flight fAux=(Flight) iter.next();
+ if (fAux.hasID(id))
+ return fAux;
+ }
+ throw new RuntimeException("Flight not found - "+id);
+ }
+
+
+ // only for th version w/o GUI
+ public static boolean anyPlanesAlive()
+ {
+ boolean aux=false;
+ ArrayList flights=FlightList.f;
+
+ for (int i=0;i<FlightList.noFlights;i++)
+ {
+ Flight aAux=(Flight) flights.get(i);
+ ArrayList p1=aAux.traject.p;
+ Point4d pAux= (Point4d) p1.get(0);
+ if (!pAux.outOfRange())
+ aux=true;
+ }
+ return aux;
+ }
+
+
+ public static void printInfo()
+ // this is a test procedure
+ {
+ System.out.println("\n\nThe number of flights:"+noFlights);
+ System.out.println("The flights are:");
+ Iterator iter=f.iterator();
+ while (iter.hasNext())
+ {
+ Flight fAux=(Flight) iter.next();
+ System.out.println(fAux);
+ }
+ }
+
+}
+
+
+
--- /dev/null
+// this class implements a flight plan
+
+class FlightPlan
+{
+ public double cruiseAlt, cruiseSpeed; // cruising altitude and speed
+
+ public Route r; // the route (given by fixes)
+
+
+ public FlightPlan()
+ {
+ cruiseAlt=0;
+ cruiseSpeed=0;
+ }
+
+ public FlightPlan (FlightPlan fp)
+ {
+ cruiseAlt=fp.cruiseAlt;
+ cruiseSpeed=fp.cruiseSpeed;
+ }
+
+ public void setCruiseParam(double crAlt, double crSp)
+ {
+ cruiseAlt=crAlt;cruiseSpeed=crSp;
+
+ }
+
+ public void setRoute(Route route)
+ {
+ this.r=route;
+ }
+
+ public void setCurrentFix(String nameFix)
+ {
+ int i=r.getIndexOf(nameFix);
+ //int i=FixList.getIndex(nameFix);
+ System.out.println("name of the fix: "+nameFix+" index:"+i);
+ r.setCurrent(i);
+ }
+
+}
+
+
--- /dev/null
+import java.util.*;
+
+class Message
+{
+ int time;
+ String type;
+ StringTokenizer parameters;
+
+ public Message(int time, String type, StringTokenizer parameters)
+ {
+ this.time=time;
+ this.type=type;
+ this.parameters=parameters;
+ }
+
+ public Message(Message m)
+ {
+ this.time=m.time;
+ this.type=m.type;
+ this.parameters=m.parameters;
+ }
+
+ public void executeMessage()
+ {
+ System.out.println("Executing message of type "+type);
+ //static messages
+ if (type.compareTo("SET_MAP_SIZE")==0)
+ {
+ System.out.println("Setting the map size...");
+ Static.setMapSize(parameters);
+ }
+ if (type.compareTo("SET_ITERATION_STEP")==0)
+ {
+ System.out.println("Setting the iteration step...");
+ Static.setIterationStep(parameters);
+ }
+ if (type.compareTo("SET_NO_OF_ITERATIONS")==0)
+ {
+ System.out.println("Setting the no. of iterations...");
+ Static.setNumberOfIterations(parameters);
+ }
+ if (type.compareTo("SET_CYLINDER")==0)
+ {
+ System.out.println("Setting the cylinder of safety/unsafety...");
+ Static.setCylinder(parameters);
+ }
+ if (type.compareTo("ADD_FIX")==0)
+ {
+ System.out.println("Adding a new fix...");
+ FixList.addFix(parameters);
+ }
+ if (type.compareTo("REMOVE_FIX")==0)
+ {
+ System.out.println("Removing a fix...");
+ FixList.removeFix(parameters);
+ }
+ if (type.compareTo("ADD_AIRCRAFT")==0)
+ {
+ System.out.println("Adding an aircraft...");
+ AircraftList.addAircraft(parameters);
+ }
+ if (type.compareTo("REMOVE_AIRCRAFT")==0)
+ {
+ System.out.println("Removing an aircraft...");
+ AircraftList.removeAircraft(parameters);
+ }
+
+ //dynamic messages
+ if (type.compareTo("DO_WORK")==0)
+ Algorithm.setInitialTime(time);
+
+ if (type.compareTo("ADD_FLIGHT_PLAN")==0)
+ {
+ System.out.println("Adding flight plane...");
+ FlightList.addFlightPlan(time,parameters);
+ }
+ if (type.compareTo("REMOVE_FLIGHT_PLAN")==0)
+ {
+ System.out.println("Removing flight plan...");
+ FlightList.removeFlightPlan(time,parameters);
+ }
+ if (type.compareTo("AMEND_FLIGHT_INFO")==0)
+ {
+ System.out.println("Amending flight info...");
+ FlightList.amendFlightInfo(time,parameters);
+ }
+ if (type.compareTo("AMEND_FLIGHT_PLAN")==0)
+ {
+ System.out.println("Amending flight plan...");
+ FlightList.amendFlightPlan(time,parameters);
+ }
+ if (type.compareTo("SENDING_AIRCRAFT")==0)
+ {
+ System.out.println("Sending aircraft data...");
+ FlightList.sendingAircraft(time,parameters);
+ }
+ }
+}
+
+
--- /dev/null
+import java.io.*;
+import java.util.*;
+
+
+
+class MessageList
+{
+ private static LinkedList messages=new LinkedList();
+
+ public static Message data()
+ {
+ return (Message) messages.getFirst();
+ }
+
+ public static Message next()
+ {
+ Message mAux=new Message((Message) messages.getFirst());
+ messages.removeFirst();
+ return (Message) mAux;
+ }
+
+ public static boolean hasNext()
+ {
+ return (messages.size()!=0);
+ }
+
+ public static boolean setMessage(String line) //is true for DO_WORK
+ {
+ if (line.equals(""))
+ return false;
+ System.out.println("I'm reading line "+line);
+ // treating comments
+ if ((line.charAt(0)=='/')&&(line.charAt(1)=='/'))
+ return false;
+ StringTokenizer st=new StringTokenizer(line);
+ int time=Integer.parseInt(st.nextToken());
+ String type=st.nextToken();
+ Message newMessage=new Message(time,type,st);
+ //System.out.println("???"+newMessage);
+ messages.add(newMessage);
+ if (type.equals("DO_WORK"))
+ return true;
+ else return false;
+ }
+
+
+ public static void executeAll()
+ {
+ System.out.println("executeAll: we have "+messages.size()+" messages.");
+ while (hasNext())
+ next().executeMessage();
+ Static.printInfo();
+ FixList.printInfo();
+ AircraftList.printInfo();
+ FlightList.printInfo();
+ System.out.println("Messages executed\n\n\n\n\n");
+ }
+
+}
+
+
+
+
--- /dev/null
+// a 2d point - used for fixes
+
+class Point2d
+
+{
+ public double x,y;
+
+ public Point2d ()
+ {
+ x=0;
+ y=0;
+ }
+
+ public Point2d (double xcoord , double ycoord)
+ {
+ this.x=xcoord;
+ this.y=ycoord;
+ }
+
+ public static double horizDistance(Point2d p1, Point2d p2)
+ {
+ return (Math.sqrt(squaredDistance(p1,p2)));
+ }
+
+ public static double squaredDistance(Point2d p1, Point2d p2)
+ {
+ return (Math.pow(p1.x-p2.x,2)+Math.pow(p1.y-p2.y,2));
+ }
+
+ public String toString()
+ {
+ return new String("("+x+","+y+")");
+ }
+
+}
+
+
+
+
+
+
+
+
+
--- /dev/null
+// point with 3 space coordinates and time label
+import java.text.*;
+
+class Point4d extends Point2d
+{
+ public double x,y,z,time;
+
+ public static int outOfRangeTime=-1;
+
+
+ public Point4d ()
+ {
+ x=0;y=0;z=0;
+ time=0;
+ }
+
+ public Point4d(Point2d p)
+ {
+ x=p.x;
+ y=p.y;
+ time=z=0;
+ }
+
+ public Point4d (double t, double xcoord, double ycoord, double zcoord)
+ {
+ x=xcoord; y=ycoord; z=zcoord;
+ time=t;
+ }
+
+ public Point4d (double xcoord, double ycoord, double zcoord)
+ {
+ x=xcoord; y=ycoord; z=zcoord;
+ time=0;
+ }
+
+ public Point4d (Point4d p)
+ {
+ x=p.x;
+ y=p.y;
+ z=p.z;
+ time=p.time;
+ }
+
+ public void setTime (double t)
+ {
+ time=t;
+ }
+
+ public static double squaredDistance(Point4d p1,Point4d p2)
+ {
+ return (Math.pow(p1.x-p2.x,2)+Math.pow(p1.y-p2.y,2)+Math.pow(p1.z-p2.z,2));
+ }
+
+ public static double horizDistance(Point4d p1, Point4d p2)
+ {
+ return (Math.sqrt(Math.pow(p1.x-p2.x,2)+Math.pow(p1.y-p2.y,2)));
+ }
+
+ public int compareX(Point4d p)
+ {
+ if (this.x==p.x)
+ return 0;
+ else
+ if (this.x<p.x)
+ return -1;
+ else return 1;
+ }
+
+ public int compareY(Point4d p)
+ {
+ if (this.y==p.y)
+ return 0;
+ else
+ if (this.y<p.y)
+ return -1;
+ else return 1;
+ }
+
+ public int compareZ(Point4d p)
+ {
+ if (this.z==p.z)
+ return 0;
+ else
+ if (this.z<p.z)
+ return -1;
+ else return 1;
+ }
+
+ public boolean outOfRange()
+ {
+ return (this.time<0);
+ }
+
+ public Point2d toPoint2d()
+ {
+ return (new Point2d(this.x, this.y));
+ }
+
+ static public String decimalFormat(double n)
+ {
+ NumberFormat nf=NumberFormat.getNumberInstance();
+ nf.setMaximumFractionDigits(2);
+ return nf.format(n);
+ }
+
+ public String toString()
+ {
+ String st="("+decimalFormat(x)+";"+decimalFormat(y)+";"+decimalFormat(z)+")";
+ return st;
+ }
+
+}
+
+
+
+
--- /dev/null
+// class Read - reads the input from local file/network
+
+import java.io.*;
+
+class Read extends Thread
+{
+ private ReadWrite buffer;
+ private RandomAccessFile f;
+
+ public Read(ReadWrite b) throws IOException
+ {
+ buffer=b;
+ try{
+ f=new RandomAccessFile("input.txt","r");
+ } catch (FileNotFoundException e) {System.out.println("File Open Error");return;}
+
+ }
+
+ public void run()
+ {
+ try {
+ // while(true)
+ buffer.read(f);
+ } catch(IOException e) {System.out.println("Invalid Input Data");System.exit(0);}
+ System.out.println("Data set read");
+ }
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
--- /dev/null
+// This class is the connection between the input and the output threads,
+// synchronizing the two threads
+// It reads effectively reads the input and writes the output and
+
+
+import java.io.*;
+import java.util.*;
+
+class ReadWrite
+{
+
+ private boolean readAccess=true;
+ private static boolean readDone = false;
+
+ public synchronized void read(RandomAccessFile f) throws IOException
+ {
+ // reads a data set
+ if (!readAccess)
+ {
+ try{
+ wait();
+ } catch (InterruptedException e){}
+ }
+
+ // read operations
+
+ try{
+ while (true)
+ {
+ String line=f.readLine();
+ if (line==null)
+ System.exit(0);
+ if (MessageList.setMessage(line))
+ break;
+ }
+ } catch (EOFException e) {};
+
+ System.out.println("Input data read.");
+
+ // D2.threadRead.stop();
+ // just temporarly
+ // MessageList.executeAll();
+
+ /*Algorithm.doIteration();
+ Static.printInfo();
+ FixList.printInfo();
+ AircraftList.printInfo();
+ FlightList.printInfo();
+
+ ConflictList.printInfo();
+ System.out.println("Connflicts List OVER");*/
+
+ readAccess=false;
+ }
+
+
+ public synchronized void write(RandomAccessFile f) throws IOException
+ {
+ //System.out.println("Does it reach 'write'?");
+ // writes a data set
+ if (readAccess)
+ {
+ try{
+ wait();
+ } catch (InterruptedException e){}
+
+ }
+
+ // write operations
+
+ Static.printInfo();
+ FixList.printInfo();
+ AircraftList.printInfo();
+ FlightList.printInfo();
+ // Algorithm.doWork(f);
+ readAccess=true;
+ notify();
+
+ }
+
+}
--- /dev/null
+// describes a route - number of beacons, the current position on the
+// route, and the beacons.
+
+import java.util.*;
+
+class Route {
+
+ public int noFixes,current;
+ public ArrayList fixes;
+
+ Route(int no) {
+ noFixes=no;
+ current=0;
+ fixes=new ArrayList(noFixes);
+ }
+
+ Route(int no, int cur) {
+ noFixes=no;
+ current=cur;
+ fixes=new ArrayList(noFixes);
+ }
+
+ public void addFix (int pos, Fix f)
+ {
+ fixes.add(pos, f);
+ }
+
+ public void addFix (int pos, String name) {
+ addFix(pos, (Fix) FixList.getFix(name) );
+ }
+
+ public Fix getFixAt(int pos)
+ {
+ if ((pos>-1) && (pos<noFixes)) {
+ return (Fix) fixes.get(pos);
+ }
+ else return null;
+ }
+
+ public void setCurrent(int c) {
+ current=c;
+ }
+
+ public Fix getCurrent()
+ {
+ return (Fix) fixes.get(current);
+ }
+
+ public Point2d getCoordsOf (int i)
+ {
+ if ((i>-1) && (i<noFixes)) {
+ Fix tmpFix=(Fix) fixes.get(i);
+ return (tmpFix.getFixCoord());
+ }
+ else return null;
+ }
+
+ public int getIndexOf (String nameFix)
+ {
+ int index=-1;
+ for (int i=0 ; i<noFixes ; i++) {
+ // System.out.println((Fix) fixes.get(i));
+ if (((Fix) fixes.get(i)).hasName(nameFix)) {
+ index=i;
+ i=noFixes;
+ }
+ }
+ return index;
+ }
+
+ public int getIndexOf (Fix f)
+ {
+ Fix tmp;
+ int index=-1;
+ for (int i=0 ; i<noFixes ; i++) {
+ // System.out.println((Fix) fix.get(i));
+ tmp=(Fix) fixes.get(i);
+ if (tmp==f) {
+ index=i;
+ i=noFixes;
+ }
+ }
+ return index;
+ }
+
+
+ public boolean hasFix (Fix f)
+ {
+ int index=-1;
+ for (int i=0 ; i<noFixes; i++) {
+ if (((Fix) fixes.get(i))==f) {
+ index=i;
+ i=noFixes;
+ }
+ }
+ return (index>-1);
+ }
+
+ public String toString()
+ {
+ return new String("No. Fixes:"+noFixes+": "+fixes);
+ }
+
+}
+
+
+
--- /dev/null
+
+// This class memorizes the static data (besides fixes)
+
+
+import java.util.*;
+
+class Static
+{
+ public static double width, height; // the dimensions of the given area
+ public static double iterationStep, noIterations;
+ public static double radius, distance;
+
+ public static void setMapSize(StringTokenizer st)
+ {
+ width=Double.parseDouble(st.nextToken());
+ height=Double.parseDouble(st.nextToken());
+ }
+
+ public static void setCylinder(StringTokenizer st)
+ {
+ radius=Double.parseDouble(st.nextToken());
+ distance=Double.parseDouble(st.nextToken());
+ }
+
+ public static void setIterationStep(StringTokenizer st)
+ {
+ iterationStep=Double.parseDouble(st.nextToken());
+ }
+
+ public static void setNumberOfIterations(StringTokenizer st)
+ {
+ noIterations=Integer.parseInt(st.nextToken());
+ }
+
+ public static void printInfo()
+ // this is a test procedure
+ {
+ System.out.println("\n\nStatic Data:");
+ System.out.println("Width:"+width+" Height:"+height);
+ System.out.println("Radius of safety/unsafety:"+radius);
+ System.out.println("Distance of safety/unsafety:"+distance);
+ System.out.println("Iteration step:"+iterationStep+" No. of Iterations:"+noIterations);
+
+
+ }
+
+}
+
+
+
+
+
--- /dev/null
+// the data about a plane - current position and velocity
+
+class Track
+{
+
+ Point4d pos;
+ Velocity vel;
+
+ public Track(Point4d p, Velocity v)
+ {
+ pos=p;
+ vel=v;
+ }
+
+ public void setPosition (Point4d p)
+ {
+ pos=p;
+ }
+
+ public void setVelocity (Velocity v)
+ {
+ vel=v;
+ }
+
+ public void printInfo()
+ {
+ System.out.println("track: "+pos+"||"+vel);
+ }
+
+}
--- /dev/null
+// class that implements the trajectory and some methods of access
+
+import java.util.*;
+
+class Trajectory
+
+{
+
+ public int noPoints; // the number of points in the trajectory
+ private int current;
+ public double distToDest, timeToDest; // estimated time&distance to end fix
+ public int nextFixIndex; // index of the next fix in the trajectory of the flight;
+ public Fix nextFix; // the next fix in the trajectory of the flight
+ public Velocity startVelocity; // velocity at the first point in the trajectory;
+ ArrayList p; // the points in the trajectory
+
+ public Trajectory(int np)
+ {
+ noPoints=np;
+ p=new ArrayList(noPoints);
+ current=0;
+ }
+
+ public void setPoint (int pos, Point4d point)
+ // adds a point to the trajectory at the position "pos"
+ {
+ p.add(pos, (Point4d) point);
+ }
+
+ public void setNoPoints (int noP)
+ {
+ noPoints=noP;
+ }
+
+ public Point4d getCurrent ()
+ {
+ return (Point4d) p.get(current);
+ }
+
+ public Point4d getPointAt (int index)
+ {
+ return (Point4d) p.get(index);
+ }
+
+ public double distanceToDestination()
+ {
+ return distToDest;
+ }
+
+ public double timeToDestination(double time)
+ {
+ return (timeToDest-time);
+ }
+
+ public double timeToDestination(int time)
+ {
+ return (timeToDest-time);
+ }
+
+ public Velocity getVelocity()
+ {
+ return startVelocity;
+ }
+
+ public void printInfo()
+ {
+ System.out.println("New trajectory: ");
+ for (int i=0 ; i<noPoints ; i++) {
+ System.out.println(getPointAt(i));
+ }
+
+ }
+
+}
+
+
+
--- /dev/null
+/*
+ The class that estimates the trajectory of a plane, given its
+ current position, velocity and flight plan
+*/
+
+import java.util.*;
+import java.lang.*;
+
+public class TrajectorySynthesizer
+
+{
+ private static double horizTotalDist, currentDist;
+ private static Velocity currentVelocity;
+ private static Point4d currentPos;
+ private static int nextFix, noFixes;
+ private static int iterations;
+ private static double thrust, lift, targetSpeed, targetAlt, timeF=0;
+ static Trajectory traject;
+
+ private static double bigUglyConstant=1000000;
+ // private static double outOfRangeTime=-1;
+ private static int limit=200;
+
+ public static Trajectory updateTrajectory (int time, Flight flight)
+ {
+ Integer nTime=new Integer(time);
+ return updateTrajectory (nTime.doubleValue(), flight);
+ }
+
+ public static Trajectory updateTrajectory (double time, Flight flight)
+ /*
+ the method that updates the estimated trajectory for a flight
+ */
+ {
+ System.out.println("Updating trajectory for "+flight.flightID);
+ int i;
+ setInitialParameters(flight);
+ System.out.println("Starting position: "+currentPos);
+ if (currentPos.outOfRange()) {
+ traject.setNoPoints(1);
+ traject.setPoint(0, currentPos);
+ traject.distToDest=0;
+ traject.timeToDest=0;
+ }
+ else {
+ for (i=0 ; (!currentPos.outOfRange()) && (i<limit) ; i++)
+ {
+ // if (currentPos.outOfRange()) {
+ // traject.setPoint(i, (Point4d) currentPos);
+ //}
+ // else {
+ // System.out.println(i+"current position" +currentPos);
+ getTrajectoryPoint(flight, time+i*Static.iterationStep);
+ // System.out.println(currentVelocity);
+ // System.out.println(currentPos);
+ if (i==0) {
+ System.out.println("current position: "+currentPos);
+ traject.distToDest=horizTotalDist;
+ traject.nextFixIndex=nextFix;
+ traject.nextFix=(currentPos.outOfRange())? null : flight.fPlan.r.getFixAt(nextFix);
+ }
+ if (i==1) {
+ traject.startVelocity=new Velocity(currentVelocity);
+ // System.out.println(currentVelocity+" "+traject.startVelocity);
+
+ }
+ traject.setPoint(i, (Point4d) currentPos);
+ // }
+
+ }
+ traject.setNoPoints(--i);
+ System.out.println(traject.noPoints);
+ traject.timeToDest=(i>0)? traject.getPointAt(i-1).time+timeF:time+timeF;
+ // System.out.println(currentVelocity+" "+traject.startVelocity);
+ }
+ flight.traject=traject;
+ System.out.println("Finished updating trajectory ...");
+ return traject;
+ }
+
+ private static void setInitialParameters(Flight flight)
+ /*
+ initialization & initial computation part
+ */
+ {
+ // System.out.println("Initial parameters ...");
+ int i;
+ Point2d p1, p2;
+ // Double temp=new Double(Static.noIterations);
+ // iterations=temp.intValue();
+ traject=new Trajectory(10);
+ currentPos=new Point4d(flight.track.pos.time, flight.track.pos.x,
+ flight.track.pos.y, flight.track.pos.z);
+ currentVelocity=new Velocity(flight.track.vel);
+ horizTotalDist=0;
+ p1=new Point2d(currentPos.x, currentPos.y);
+ for (i=flight.fPlan.r.current; i<flight.fPlan.r.noFixes; i++)
+ {
+ p2=flight.fPlan.r.getCoordsOf (i);
+ horizTotalDist+=Point2d.horizDistance(p1,p2);
+ p1=p2;
+ }
+ // System.out.println("horiz total distance: "+horizTotalDist);
+
+ // traject.distToDestination=horizTotalDist;
+ nextFix=flight.fPlan.r.current;
+ noFixes=flight.fPlan.r.noFixes;
+ thrust=flight.aircraftType.maxThrust;
+ lift=flight.aircraftType.maxLift;
+ targetSpeed=flight.fPlan.cruiseSpeed;
+ targetAlt=flight.fPlan.cruiseAlt;
+ // System.out.println("thrust= "+thrust+" lift= "+lift+
+ // System.out.println( " speed= "+targetSpeed+" alt= "+targetAlt);
+ // System.out.println("current velocity: "+currentVelocity);
+ }
+
+ private static void getTrajectoryPoint(Flight flight, double time)
+ /*
+ estimates the position at time given, using data computed so far
+ */
+ {
+ if (currentPos.time<time) {
+ double z=newVerticalCoord(flight, time);
+ Point2d pXY=newHorizCoords (flight, time);
+ //System.out.println ("XY : "+pXY);
+ if (pXY.x<bigUglyConstant-1) {
+ currentPos=new Point4d(time, pXY.x, pXY.y, z);
+ // System.out.println("currentPos="+currentPos+" currentvel= "+currentVelocity+" next fix: "+nextFix);
+ }
+ else { currentPos=new Point4d (Point4d.outOfRangeTime,0,0,0); }
+ }
+ }
+
+ private static double newVerticalCoord (Flight flight, double time)
+ /*
+ - estimates the new vertical coordinate at the time given
+ - also, updates current vertical velocity & acceleration
+ */
+ {
+ double newZ;
+ double acc;
+
+ if (currentPos.z>=targetAlt) {
+ newZ=currentPos.z;
+ currentVelocity.vector.z=0;
+ }
+ else {
+ acc=neededAcceleration(currentPos.z, targetAlt, lift);
+ newZ=currentPos.z+currentVelocity.vector.z*(time-currentPos.time)+
+ acc*Math.pow(time-currentPos.time,2)/2;
+ newZ=(newZ>=targetAlt)? targetAlt:newZ;
+ currentVelocity.vector.z=(newZ>=targetAlt)?
+ 0:(currentVelocity.vector.z+acc*(time-currentPos.time));
+ }
+ return newZ; // to be completed
+ }
+
+ private static double neededAcceleration(double speed, double nSpeed,
+ double thrust)
+ {
+ double accel=(speed<nSpeed)? thrust: (speed>nSpeed)? -thrust:0;
+ return accel;
+ }
+
+ private static Point2d decompose (double scalar,
+ Point2d p1, Point2d p2)
+ {
+ double angle;
+ if (p1.x==p2.x) {
+ angle=(p1.y<p2.y)? Math.PI/2 : -Math.PI/2;
+ }
+ else {
+ angle=(p1.x<p2.x)?
+ Math.atan((p1.y-p2.y)/(p1.x-p2.x)):
+ Math.PI+Math.atan((p1.y-p2.y)/(p1.x-p2.x));
+ }
+ // System.out.println("scalar= "+scalar+" angle="+angle);
+ return (new Point2d (scalar*Math.cos(angle),
+ scalar*Math.sin(angle)));
+ }
+
+ private static Point2d newHorizCoords (Flight flight, double time)
+ /*
+ - estimates the new horizontal coordinates at the time given
+ - updates the horizontal velocity & acceleration
+ */
+ {
+ double dt=time-currentPos.time;
+ // System.out.println("dt="+dt);
+ // System.out.println("time="+time);
+ double hSpeed=currentVelocity.horizSpeed();
+ double accel=neededAcceleration(hSpeed, targetSpeed, thrust);
+ double accelTime=(accel==0)? 0:(targetSpeed-hSpeed)/accel;
+ double distance, speed;
+ Point2d current, temp, temp2;
+ // System.out.println("current:"+hSpeed+" accel="+accel+" time:"+accelTime);
+ if (accelTime<dt) {
+ speed=targetSpeed;
+ distance=hSpeed*accelTime+accel*Math.pow(accelTime,2)/2+
+ speed*(dt-accelTime);
+ }
+ else {
+ speed=hSpeed+accel*dt;
+ distance=hSpeed*dt+accel*Math.pow(dt,2)/2;
+ }
+
+ // if ((horizTotalDist<0) || (hSpeed<0)) { hSpeed=0; }
+
+ if ((distance>horizTotalDist)&&(horizTotalDist>0)) {
+ timeF=(accel<=0)?(horizTotalDist/hSpeed):
+ (-hSpeed+Math.sqrt(hSpeed*hSpeed+2*accel*horizTotalDist))/accel;
+ System.out.println("TIMEF= "+timeF);
+ }
+ horizTotalDist-=distance;
+ for (current=currentPos.toPoint2d();
+ (nextFix<noFixes) &&
+ (distance>Point2d.horizDistance(current,
+ flight.fPlan.r.getCoordsOf(nextFix)));
+ nextFix++) {
+ distance-=Point2d.horizDistance(current,
+ flight.fPlan.r.getCoordsOf(nextFix));
+ current=flight.fPlan.r.getCoordsOf(nextFix);
+ }
+ // System.out.println("speed= "+speed+ " distance: "+distance+" fix: "+
+ // flight.fPlan.r.getCoordsOf(nextFix)+
+ // " current: "+current);
+ if (nextFix<noFixes) {
+ temp2=decompose(distance,
+ current, flight.fPlan.r.getCoordsOf(nextFix));
+ temp=decompose(speed,
+ current, flight.fPlan.r.getCoordsOf(nextFix));
+
+ current=new Point2d(temp2.x+current.x, temp2.y+current.y);
+
+ currentVelocity.vector.x=temp.x;
+ currentVelocity.vector.y=temp.y;
+ }
+ else {
+ current=new Point2d(bigUglyConstant,bigUglyConstant);
+ }
+ return current;
+ }
+
+}
--- /dev/null
+// trial flight class with trial planning-related methods
+
+class TrialFlight {
+
+ Flight oldFlight, trialFlight;
+ Route trialRoute;
+ Trajectory trialTrajectory;
+ double time;
+ Fix fix1, fix2;
+ int fixIndex;
+ // differences between the old flight and the trial flight follow:
+ double timeDiff, distDiff; // time and distance difference
+ ConflictList oldConflicts, newConflicts; // the lists of conflicts
+ int noNew, noRemoved; // the number of new and removed conflicts, respectively
+
+ public TrialFlight(Flight flight, Fix fix1, Fix fix2)
+ // constructor of a trial flight using a shortcut between two fixes.
+ {
+ int aux, fixIndex1, fixIndex2;
+ oldFlight=flight;
+ fixIndex1=oldFlight.fPlan.r.getIndexOf(fix1);
+ fixIndex2=oldFlight.fPlan.r.getIndexOf(fix2);
+ if (fixIndex1>fixIndex2) {
+ aux=fixIndex1;
+ fixIndex1=fixIndex2;
+ fixIndex2=aux;
+ }
+ trialFlight=Flight.copyOf(oldFlight);
+ trialFlight.trialStatus=Flight.trialFlightStatus;
+ this.changeToTrialRoute(fixIndex1, fixIndex2);
+ }
+
+ public TrialFlight(Flight flight, String fixName)
+ // constructor for a trial flight using the current position of a plane
+ {
+ oldFlight=flight;
+
+ }
+
+ public TrialFlight(Flight flight, Point4d position, Fix fix)
+ // constructor that uses an estimated position and a fix
+ {
+ int aux;
+ oldFlight=flight;
+ // fixIndex1=oldFlight.fPlan.r.getIndexOf(fixName1);
+ fixIndex=oldFlight.fPlan.r.getIndexOf(fix);
+
+ // System.out.println(oldFlight);
+ trialFlight=Flight.copyOf(oldFlight);
+
+ trialFlight.trialStatus=Flight.trialFlightStatus;
+
+ oldFlight.updateTrajectory(position.time);
+ trialFlight.track=new Track(new Point4d(position), new Velocity(oldFlight.track.vel)); // assuming that the position given as parameter is the same as the first point in the trajectory
+ // trialFlight.track.vel=oldFlight.traject.getVelocity();
+ trialFlight.fPlan=new FlightPlan(oldFlight.fPlan);
+
+ // System.out.println("old route:"+oldFlight.fPlan.r);
+ // System.out.println("new route:"+trialFlight.fPlan.r);
+
+
+
+ changeToTrialRoute(position, fixIndex);
+
+
+ // System.out.println("old route:"+oldFlight.fPlan.r);
+ // System.out.println("new route:"+trialFlight.fPlan.r);
+
+
+
+ trajectoryDiff(position.time);
+ conflictsDiff(position.time);
+ System.out.println("old route:"+oldFlight.fPlan.r);
+ System.out.println("new route:"+trialFlight.fPlan.r);
+ // System.out.println("old: "+oldFlight.trialStatus);
+ trialFlight.trialStatus=-1;
+ // System.out.println("old: "+oldFlight.trialStatus);
+ }
+
+ public void trajectoryDiff (double time)
+ {
+ trialFlight.updateTrajectory(time);
+ oldFlight.updateTrajectory(time);
+
+
+ System.out.println("Flight "+trialFlight.flightID+":");
+ distDiff=oldFlight.traject.distanceToDestination()-
+ trialFlight.traject.distanceToDestination();
+ timeDiff=oldFlight.traject.timeToDestination(time)-
+ trialFlight.traject.timeToDestination(time);
+ if (timeDiff<0) { timeDiff=0; }
+ System.out.println("Time difference: "+timeDiff);
+ System.out.println("Distance difference: "+distDiff);
+ }
+
+ public void conflictsDiff(double time)
+ {
+ int i, j;
+ oldConflicts=Algorithm.getConflictsWith(time,oldFlight);
+ newConflicts=Algorithm.getConflictsWith(time,trialFlight);
+ System.out.println("Flight "+trialFlight.flightID+":");
+ System.out.println("Conflicts for the old flight:");
+ System.out.println(oldConflicts);
+ System.out.println("Conflicts for the trial flight:");
+ System.out.println(newConflicts);
+ noNew=0;
+ for (i=0 ; i<newConflicts.noConflicts ; i++) {
+ Conflict conflict=newConflicts.conflictAt(i);
+ if (oldConflicts.findConflict(conflict.flight1, conflict.flight2)==null) {
+ noNew++;
+ }
+ }
+ noRemoved=oldConflicts.noConflicts-
+ (newConflicts.noConflicts-noNew);
+ // System.out.println("No. of new conflicts: "+noNew);
+ // System.out.println("No. of removed conflicts: "+noRemoved);
+ }
+
+ public void changeToTrialRoute (Point4d pos, int index)
+ {
+ int i,count, index1=0;
+ if (index>-1) {
+ trialRoute=new Route(oldFlight.fPlan.r.noFixes-index);
+ trialRoute.current=0;
+ for (i=index; i<oldFlight.fPlan.r.noFixes ; i++) {
+ trialRoute.addFix(i-index, oldFlight.fPlan.r.getFixAt(i));
+ }
+ trialFlight.fPlan.r=trialRoute;
+ }
+ }
+
+
+ public void changeToTrialRoute (int index1, int index2)
+ {
+ int i,count;
+ if ((index1>-1) && (index2>-1) && (index2-index1>1)) {
+ trialRoute=new Route(oldFlight.fPlan.r.noFixes-
+ (index2-index1-1));
+ trialRoute.current=index1+1;
+ for (i=0 ; i<=index1 ; i++) {
+ trialRoute.addFix(i, oldFlight.fPlan.r.getFixAt(i));
+ if (oldFlight.fPlan.r.current==i) {
+ trialRoute.current=i;
+ }
+ }
+
+ for (i=index2; i<oldFlight.fPlan.r.noFixes ; i++) {
+ trialRoute.addFix(i-index2+index1+1,
+ oldFlight.fPlan.r.getFixAt(i));
+ if (oldFlight.fPlan.r.current==i) {
+ trialRoute.current=i-index2+index1+1;
+ }
+ }
+ trialFlight.fPlan.r=trialRoute;
+ }
+ }
+}
+
+
--- /dev/null
+// the class that describes coordinates the velocity of aplane
+
+
+import java.lang.*;
+
+class Velocity {
+
+ Point4d vector;
+ double speed;
+
+ Velocity() {
+ this(0,0,0);
+ }
+
+ Velocity(double newX, double newY, double newZ) {
+ this.vector=new Point4d(newX, newY, newZ);
+ this.speed=this.horizSpeed();
+ }
+
+ static Velocity copyOf(Velocity v)
+ {
+ try{
+ return (Velocity) v.clone();
+ } catch (Exception e) {System.out.println("Esti bou!");}
+ return null;
+ }
+
+ Velocity (Velocity v)
+ {
+ this.vector=new Point4d (v.vector);
+ this.speed=this.horizSpeed();
+ }
+
+ public double horizSpeed()
+ {
+ return Math.sqrt(Math.pow(vector.x,2)+Math.pow(vector.y,2));
+ }
+
+ public String toString()
+ {
+ // Point4d pAux=new Point4d(0,x,y,z);
+ return ""+vector;
+ }
+
+}
+
+
+
+
--- /dev/null
+// class Write - writes the output to local file/network
+
+import java.io.*;
+
+class Write extends Thread
+{
+ private ReadWrite buffer;
+ private RandomAccessFile f;
+
+ public Write(ReadWrite b) throws IOException
+ {
+ buffer=b;
+ try{
+ f=new RandomAccessFile("results.out","rw");
+ } catch (FileNotFoundException e) {System.out.println("File Open Error");return;}
+ }
+
+
+ public void run()
+ {
+ try {
+ while (true)
+ buffer.write(f);
+ } catch(IOException e) {System.out.println("Invalid Output Data");System.exit(0);}
+ System.out.println("Data set written");
+ }
+}
--- /dev/null
+10 ADD_PLANE Boeing 747
+20 ADD_PLANE AirBus 300
+30 AMEND_ROUTE Boeing 0 0 0 1 1 0 1 B B 1 0
+30 AMEND_ROUTE AirBus 10 10 0 -1 -1 0 1 A A 1 0
+30 DO_WORK
\ No newline at end of file
--- /dev/null
+Aircraft.java
+AircraftList.java
+Algorithm.java
+CanvasImage.java
+CanvasMap.java
+Conflict.java
+ConflictList.java
+D2.java
+Fix.java
+FixList.java
+Flight.java
+FlightList.java
+FlightPlan.java
+Graphic.java
+Message.java
+MessageList.java
+Perform.java
+Point2d.java
+Point4d.java
+Read.java
+ReadMessages.java
+ReadWrite.java
+Route.java
+Static.java
+Track.java
+Trajectory.java
+TrajectorySynthesizer.java
+TrialFlight.java
+TrialPlanning.java
+Velocity.java
+Write.java
--- /dev/null
+0 SET_ITERATION_STEP 1
+0 SET_NO_OF_ITERATIONS 50
+0 SET_CYLINDER 20 501
+0 SET_MAP_SIZE 600 400
+
+0 ADD_FIX A 50 50
+0 ADD_FIX B 50 150
+0 ADD_FIX C 100 200
+0 ADD_FIX D 150 100
+0 ADD_FIX E 250 0
+0 ADD_FIX F 200 200
+0 ADD_FIX G 200 50
+0 ADD_FIX H 150 300
+0 ADD_FIX I 300 150
+0 ADD_FIX J 350 50
+0 ADD_FIX K 300 350
+0 ADD_FIX L 350 250
+0 ADD_FIX M 400 200
+0 ADD_FIX N 450 100
+0 ADD_FIX O 100 250
+0 ADD_FIX P 500 300
+0 ADD_FIX Q 250 250
+0 ADD_FIX R 300 100
+0 ADD_FIX S 100 0
+0 ADD_FIX T 450 0
+0 ADD_FIX U 0 300
+0 ADD_FIX V 200 350
+0 ADD_FIX W 500 150
+
+0 ADD_AIRCRAFT Boeing737 60 5
+0 ADD_AIRCRAFT AirBus310 70 5
+0 ADD_AIRCRAFT DC80 80 6
+0 ADD_AIRCRAFT Boeing747 75 4
+
+20 ADD_FLIGHT_PLAN RO0001 Boeing737 OVER 6 O Q L M N T 10000 5
+20 ADD_FLIGHT_PLAN LH3473 AirBus310 OVER 4 K F G E 10000 5
+20 ADD_FLIGHT_PLAN AF2809 Boeing747 OVER 5 B D R J T 10500 5
+
+
+30 ADD_FLIGHT_PLAN DL8201 DC80 OVER 1 A 9800 7
+30 ADD_FLIGHT_PLAN RO1313 Boeing737 OVER 5 S G I L K 9900 6
+
+35 ADD_FLIGHT_PLAN UA0802 DC80 OVER 4 H Q M T 10000 5
+
+// changing route
+50 AMEND_FLIGHT_PLAN DL8201 5 P M R G A 9800 7
+
+
+// sending positions
+55 SENDING_AIRCRAFT 1 LH3473 300 360 10500 0 -5 0 K
+62 SENDING_AIRCRAFT 1 RO0001 50 300 9000 2 0 0 O
+65 SENDING_AIRCRAFT 1 AF2809 0 150 8000 3 0 100 B
+65 SENDING_AIRCRAFT 1 DL8201 500 320 0 0 -2 400 P
+65 SENDING_AIRCRAFT 1 RO1313 90 0 9000 1 1 0 S
+70 SENDING_AIRCRAFT 1 UA0802 120 330 9800 1.7 0 -200 H
+
+// 70 DO_WORK
+
+
+200 ADD_FLIGHT_PLAN AA3323 DC80 OVER 6 U B D R J T 10000 10
+200 ADD_FLIGHT_PLAN BA1234 Boeing747 OVER 6 S G R I L P 10000 12
+200 ADD_FLIGHT_PLAN RO0023 Boeing737 OVER 6 S A C O H V 9800 10
+200 ADD_FLIGHT_PLAN LH9898 AirBus310 OVER 5 K Q F G E 10100 12
+
+
+220 SENDING_AIRCRAFT 2 AA3323 0 310 0 0 -2 300 U LH9898 380 350 10000 -1 0 0 K
+225 SENDING_AIRCRAFT 2 RO0023 110 0 10000 -2 0 0 S BA1234 150 20 9000 2 2 0 G
+
+225 DO_WORK
--- /dev/null
+0 SET_ITERATION_STEP 1
+0 SET_NO_OF_ITERATIONS 50
+0 SET_CYLINDER 20 501
+0 SET_MAP_SIZE 600 400
+
+0 ADD_FIX A 50 50
+0 ADD_FIX B 50 150
+0 ADD_FIX C 100 200
+0 ADD_FIX D 150 100
+0 ADD_FIX E 250 0
+0 ADD_FIX F 200 200
+0 ADD_FIX G 200 50
+0 ADD_FIX H 150 300
+0 ADD_FIX I 300 150
+0 ADD_FIX J 350 50
+0 ADD_FIX K 300 350
+0 ADD_FIX L 350 250
+0 ADD_FIX M 400 200
+0 ADD_FIX N 450 100
+0 ADD_FIX O 100 250
+0 ADD_FIX P 500 300
+0 ADD_FIX Q 250 250
+0 ADD_FIX R 300 100
+0 ADD_FIX S 100 0
+0 ADD_FIX T 450 0
+
+
+0 ADD_AIRCRAFT Boeing737 60 5
+0 ADD_AIRCRAFT AirBus310 70 5
+0 ADD_AIRCRAFT DC80 80 6
+0 ADD_AIRCRAFT Boeing747 75 6
+
+20 ADD_FLIGHT_PLAN Ro0001 Boeing737 OVER 6 O Q L M N T 10000 5
+20 ADD_FLIGHT_PLAN LH3473 AirBus310 OVER 4 K F G E 10000 5
+20 ADD_FLIGHT_PLAN af280 Boeing747 OVER 5 B D R J T 10500 5
+
+
+30 ADD_FLIGHT_PLAN DL8201 DC80 OVER 1 A 9800 7
+30 ADD_FLIGHT_PLAN RO1313 Boeing737 OVER 5 S G I L K 9900 6
+
+35 ADD_FLIGHT_PLAN UA0802 DC80 OVER 4 H Q M T 10000 5
+
+// changing route
+50 AMEND_FLIGHT_PLAN DL8201 5 P M R G A 9800 7
+
+
+// sending positions
+55 SENDING_AIRCRAFT 1 LH3473 300 360 10500 0 -5 0 K
+62 SENDING_AIRCRAFT 1 Ro0001 50 300 9000 2 0 0 O
+65 SENDING_AIRCRAFT 1 af280 0 150 8000 3 0 100 B
+65 SENDING_AIRCRAFT 1 DL8201 500 320 0 0 -2 400 P
+65 SENDING_AIRCRAFT 1 RO1313 90 0 9000 1 1 0 S
+70 SENDING_AIRCRAFT 1 UA0802 120 330 9800 1.7 0 -200 H
+
+70 DO_WORK
+
+
--- /dev/null
+0 SET_ITERATION_STEP 1
+0 SET_NO_OF_ITERATIONS 50
+0 SET_CYLINDER 20 501
+0 SET_MAP_SIZE 600 400
+
+0 ADD_FIX A 50 50
+0 ADD_FIX B 50 150
+0 ADD_FIX C 100 200
+0 ADD_FIX D 150 100
+0 ADD_FIX E 250 0
+0 ADD_FIX F 200 200
+0 ADD_FIX G 200 50
+0 ADD_FIX H 150 300
+0 ADD_FIX I 300 150
+0 ADD_FIX J 350 50
+0 ADD_FIX K 300 350
+0 ADD_FIX L 350 250
+0 ADD_FIX M 400 200
+0 ADD_FIX N 450 100
+0 ADD_FIX O 100 250
+0 ADD_FIX P 500 300
+0 ADD_FIX Q 250 250
+0 ADD_FIX R 300 100
+0 ADD_FIX S 100 0
+0 ADD_FIX T 450 0
+0 ADD_FIX U 0 300
+0 ADD_FIX V 200 350
+0 ADD_FIX W 500 150
+
+0 ADD_AIRCRAFT Boeing737 60 5
+0 ADD_AIRCRAFT AirBus310 70 5
+0 ADD_AIRCRAFT DC80 80 6
+0 ADD_AIRCRAFT Boeing747 75 4
+
+20 ADD_FLIGHT_PLAN RO0001 Boeing737 OVER 6 O Q L M N T 10000 5
+20 ADD_FLIGHT_PLAN LH3473 AirBus310 OVER 4 K F G E 10000 5
+20 ADD_FLIGHT_PLAN AF2809 Boeing747 OVER 5 B D R J T 10500 5
+
+
+30 ADD_FLIGHT_PLAN DL8201 DC80 OVER 1 A 9800 7
+30 ADD_FLIGHT_PLAN RO1313 Boeing737 OVER 5 S G I L K 9900 6
+
+35 ADD_FLIGHT_PLAN UA0802 DC80 OVER 4 H Q M T 10000 5
+
+// changing route
+50 AMEND_FLIGHT_PLAN DL8201 5 P M R G A 9800 7
+
+
+// sending positions
+55 SENDING_AIRCRAFT 1 LH3473 300 360 10500 0 -5 0 K
+62 SENDING_AIRCRAFT 1 RO0001 50 300 9000 2 0 0 O
+65 SENDING_AIRCRAFT 1 AF2809 0 150 8000 3 0 100 B
+65 SENDING_AIRCRAFT 1 DL8201 500 320 0 0 -2 400 P
+65 SENDING_AIRCRAFT 1 RO1313 90 0 9000 1 1 0 S
+70 SENDING_AIRCRAFT 1 UA0802 120 330 9800 1.7 0 -200 H
+
+// 70 DO_WORK
+
+
+200 ADD_FLIGHT_PLAN AA3323 DC80 OVER 6 U B D R J T 10000 10
+200 ADD_FLIGHT_PLAN BA1234 Boeing747 OVER 6 S G R I L P 10000 12
+200 ADD_FLIGHT_PLAN RO0023 Boeing737 OVER 6 S A C O H V 9800 10
+200 ADD_FLIGHT_PLAN LH9898 AirBus310 OVER 5 K Q F G E 10100 12
+
+
+220 SENDING_AIRCRAFT 2 AA3323 0 310 0 0 -2 300 U LH9898 380 350 10000 -1 0 0 K
+225 SENDING_AIRCRAFT 2 RO0023 110 0 10000 -2 0 0 S BA1234 150 20 9000 2 2 0 G
+
+225 DO_WORK