System.out.println("Aircraft not found - "+name);
System.exit(-1);
+ return null;
}
public int getAircraftIndex(String name) {
System.out.println("Aircraft not found - "+name);
System.exit(-1);
+ return 0;
}
public void printInfo() {
//import java.io.*;
public class Algorithm {
- private D2 d2;
-
public double initialTime,time;
public double currIteration;
public ConflictList cList;
- public Algorithm( D2 d2 ) {
- this.d2 = d2;
+ public Algorithm() {
cList=new ConflictList();
}
currIteration=0;
}
- public /*static*/ boolean isConflict(Point4d p1, Point4d p2) {
+ public /*static*/ boolean isConflict(D2 d2, 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) <=
return false;
}
- public /*static*/ Point4d findConflict(Flight a, Flight b) {
+ public /*static*/ Point4d findConflict(D2 d2, Flight a, Flight b) {
Point4d conflictPoint=new Point4d(Point4d.outOfRangeTime(),0,0,0);
if (a.flightID!=b.flightID) {
Vector p1=a.traject.p;
while ( (pos<p1.size()) && (pos<p2.size()) && (!found) ) {
Point4d point1=(Point4d) p1.elementAt(pos);
Point4d point2=(Point4d) p2.elementAt(pos);
- if (isConflict(point1,point2)) {
+ if (isConflict(d2, point1,point2)) {
System.out.println(point1+" "+point2);
found=true;
conflictPoint=point1;
return conflictPoint;
}
- public /*static*/ ConflictList getConflictsWith(double time, Flight flight) {
+ public /*static*/ ConflictList getConflictsWith(D2 d2, 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);
+ d2.getTrajectorySynthesizer().updateTrajectory(d2, time, flight);
for (i=0; i<n; i++) {
Flight aAux=(Flight) flights.elementAt(i);
- d2.getTrajectorySynthesizer().updateTrajectory(time, aAux);
+ d2.getTrajectorySynthesizer().updateTrajectory(d2, time, aAux);
}
Flight aux1=flight;
for (i=0; i<n; i++) {
Flight aux2=(Flight) flights.elementAt(i);
- Point4d conflictPoint=findConflict(aux1,aux2);
+ Point4d conflictPoint=findConflict(d2, aux1,aux2);
if (!(conflictPoint.outOfRange())) {
conflicts.newConflict(conflictPoint,aux1,aux2);
}
return conflicts;
}
- public /*static*/ void doIteration() {
+ public /*static*/ void doIteration(D2 d2) {
time=initialTime+currIteration*d2.getStatic().iterationStep();
currIteration++;
System.out.println("In doIteration!");
for (i=0;i<n;i++) {
Flight aAux=(Flight) flights.elementAt(i);
- d2.getTrajectorySynthesizer().updateTrajectory(time,aAux);
+ d2.getTrajectorySynthesizer().updateTrajectory(d2, time,aAux);
}
System.out.println("Does it get here? (after the trajectory update)");
for (j=i+1;j<n;j++) {
Flight aux1=(Flight) flights.elementAt(i);
Flight aux2=(Flight) flights.elementAt(j);
- Point4d conflictPoint=findConflict(aux1,aux2);
+ Point4d conflictPoint=findConflict(d2, aux1,aux2);
if (!(conflictPoint.outOfRange())) {
cList.newConflict(conflictPoint,aux1,aux2);
}
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 );
+ singletonAlgorithm = new Algorithm ();
+ singletonFlight = new Flight ( "" );
+ singletonFlightList = new FlightList ();
+ singletonMessageList = new MessageList ();
+ singletonTrajectorySynthesizer = new TrajectorySynthesizer();
}
public static void main(String arg[]) {
D2 d2 = new D2();
- d2.rw=new ReadWrite( d2 );
- d2.rw.read();
+ d2.rw=new ReadWrite();
+ d2.rw.read(d2);
- d2.getMessageList().executeAll();
+ d2.getMessageList().executeAll(d2);
int count = 0;
while( d2.getFlightList().anyPlanesAlive() ) {
- d2.getAlgorithm().doIteration();
+ d2.getAlgorithm().doIteration(d2);
count++;
if( count % 10000 == 0 ) {
}
}
- d2.rw.write();
+ d2.rw.write(d2);
}
}
}
System.out.println("Fix not found - "+name);
System.exit(-1);
+ return 0;
}
public /*static*/ Fix getFix(String name) {
}
System.out.println("Fix not found - "+name);
System.exit(-1);
+ return null;
}
public /*static*/ void printInfo() {
// the class that describes a flight
public class Flight /*implements Cloneable*/ {
-
- private D2 d2;
public String flightID; // the flight id
public int trialStatus; //
public static int realFlightStatus(){ return -1;}
public static int trialFlightStatus(){ return 1;}
- public Flight(D2 d2, String id) {
- this.d2=d2;
+ public Flight(String id) {
this.flightID=id;
this.trialStatus=realFlightStatus();
}
fPlan=fp;
}
- public void updateTrajectory(double time) {
- d2.getTrajectorySynthesizer().updateTrajectory(time, this);
+ public void updateTrajectory(D2 d2, double time) {
+ d2.getTrajectorySynthesizer().updateTrajectory(d2, time, this);
}
public boolean hasID (String id) {
return (flightType.compareTo(flType)==0);
}
- public static Flight copyOf( D2 d2, Flight f) {
- Flight fNew = disjoint flightCopy new Flight(d2, f.flightID);
+ public static Flight copyOf(Flight f) {
+ Flight fNew = disjoint flightCopy new Flight(f.flightID);
fNew.trialStatus = f.trialStatus;
fNew.aircraftType = f.aircraftType;
fNew.track = f.track;
//import java.util.*;
public class FlightList {
- private D2 d2;
-
public /*static*/ int noFlights;
public /*static*/ Vector f;
- public FlightList( D2 d2 ) {
- this.d2=d2;
+ public FlightList() {
noFlights=0;
f=new Vector(100);
}
}
*/
- public /*static*/ void addFlightPlan(int time, StringTokenizer st) {
- Flight newFlight=disjoint flightAdd new Flight(d2, st.nextToken());
+ public /*static*/ void addFlightPlan(D2 d2, int time, StringTokenizer st) {
+ Flight newFlight=disjoint flightAdd new Flight(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()));
+ Route rAux=new Route(Integer.parseInt(st.nextToken()));
for (int i=0;i<rAux.noFixes;i++)
- rAux.addFix(i,st.nextToken());
+ rAux.addFix(d2,i,st.nextToken());
fAux.setRoute(rAux);
fAux.setCruiseParam(Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()));
newFlight.setFlightPlan(fAux);
return fAux.flightID;
}
- public /*static*/ void amendFlightPlan(int time, StringTokenizer st) {
+ public /*static*/ void amendFlightPlan(D2 d2, int time, StringTokenizer st) {
Flight fAux=getFlight(st.nextToken());
- Route rAux=new Route(d2, Integer.parseInt(st.nextToken()));
+ Route rAux=new Route(Integer.parseInt(st.nextToken()));
for (int i=0;i<rAux.noFixes;i++)
- rAux.addFix(i,st.nextToken());
+ rAux.addFix(d2,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) {
+ public /*static*/ void amendFlightInfo(D2 d2, 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) {
+ public /*static*/ void sendingAircraft(D2 d2, int time, StringTokenizer st) {
int noF=Integer.parseInt(st.nextToken());
String id;
Point4d pos;
fAux.flightID+
"; position: "+
fAux.track.pos);
- d2.getTrajectorySynthesizer().updateTrajectory(time, fAux);
+ d2.getTrajectorySynthesizer().updateTrajectory(d2, time, fAux);
fAux.traject.printInfo();
}
}
}
System.out.println("Flight not found - "+id);
System.exit(-1);
+ return null;
}
public /*static*/ boolean anyPlanesAlive() {
//import java.util.*;
public class Message {
-
- D2 d2;
int time;
String type;
StringTokenizer parameters;
- public Message(D2 d2, int time, String type, StringTokenizer parameters) {
- this.d2=d2;
+ public Message(int time, String type, StringTokenizer parameters) {
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() {
+ public void executeMessage(D2 d2) {
System.out.println("Executing message of type "+type);
//static messages
if (type.compareTo("ADD_FLIGHT_PLAN")==0) {
System.out.println("Adding flight plan...");
- d2.getFlightList().addFlightPlan(time,parameters);
+ d2.getFlightList().addFlightPlan(d2,time,parameters);
}
else if (type.compareTo("REMOVE_FLIGHT_PLAN")==0) {
System.out.println("Removing flight plan...");
}
else if (type.compareTo("AMEND_FLIGHT_INFO")==0) {
System.out.println("Amending flight info...");
- d2.getFlightList().amendFlightInfo(time,parameters);
+ d2.getFlightList().amendFlightInfo(d2, time,parameters);
}
else if (type.compareTo("AMEND_FLIGHT_PLAN")==0) {
System.out.println("Amending flight plan...");
- d2.getFlightList().amendFlightPlan(time,parameters);
+ d2.getFlightList().amendFlightPlan(d2, time,parameters);
}
else if (type.compareTo("SENDING_AIRCRAFT")==0) {
System.out.println("Sending aircraft data...");
- d2.getFlightList().sendingAircraft(time,parameters);
+ d2.getFlightList().sendingAircraft(d2, time,parameters);
}
}
}
//import java.util.*;
public class MessageList {
- private D2 d2;
private Vector messages;
- public MessageList( D2 d2 ) {
- this.d2 = d2;
+ public MessageList() {
messages=new Vector();
}
}
//is true for DO_WORK
- public boolean setMessage(String line) {
+ public boolean setMessage(String line) {
if (line.equals(""))
return false;
StringTokenizer st=new StringTokenizer(line);
int time=Integer.parseInt(st.nextToken());
String type=st.nextToken();
- Message newMessage=disjoint msgs new Message(d2,time,type,st);
+ Message newMessage=disjoint msgs new Message(time,type,st);
messages.addElement(newMessage);
if (type.equals("DO_WORK"))
return true;
return false;
}
- public void executeAll() {
+ public void executeAll(D2 d2) {
System.out.println("executeAll: we have "+messages.size()+" messages.");
while(hasNext())
- next().executeMessage();
+ next().executeMessage(d2);
d2.getStatic().printInfo();
d2.getFixList().printInfo();
d2.getAircraftList().printInfo();
//import java.util.*;
public class ReadWrite {
- D2 d2;
- public ReadWrite( D2 d2 ) {
- this.d2 = d2;
- }
+ public ReadWrite() {}
- public void read() {
+ public void read(D2 d2) {
FileInputStream in = new FileInputStream( "input4.txt" );
while(true) {
System.out.println("Data set read");
}
- public void write() {
+ public void write(D2 d2) {
d2.getStatic().printInfo();
d2.getFixList().printInfo();
d2.getAircraftList().printInfo();
public class Route {
- D2 d2;
public int noFixes,current;
public Vector fixes;
- Route(D2 d2, int no) {
- this.d2=d2;
+ Route(int no) {
noFixes=no;
current=0;
fixes=new Vector(noFixes);
}
- Route(D2 d2, int no, int cur) {
- this.d2=d2;
+ Route(int no, int cur) {
noFixes=no;
current=cur;
fixes=new Vector(noFixes);
fixes.insertElementAt(f, pos);
}
- public void addFix (int pos, String name) {
+ public void addFix (D2 d2, int pos, String name) {
addFix(pos, (Fix) d2.getFixList().getFix(name) );
}
public class TrajectorySynthesizer {
- D2 d2;
-
private /*static*/ double horizTotalDist, currentDist;
private /*static*/ Velocity currentVelocity;
private /*static*/ Point4d currentPos;
private /*static*/ int limit() { return 200; }
- public TrajectorySynthesizer( D2 d2 ) {
- this.d2 = d2;
+ public TrajectorySynthesizer() {
timeF=0;
}
- public /*static*/ Trajectory updateTrajectory (int time, Flight flight) {
+ public /*static*/ Trajectory updateTrajectory (D2 d2, int time, Flight flight) {
Integer nTime=new Integer(time);
- return updateTrajectory (nTime.doubleValue(), flight);
+ return updateTrajectory (d2, nTime.doubleValue(), flight);
}
- public /*static*/ Trajectory updateTrajectory (double time, Flight flight) {
+ public /*static*/ Trajectory updateTrajectory (D2 d2, double time, Flight flight) {
System.out.println("Updating trajectory for "+flight.flightID);
int i;
setInitialParameters(flight);
+++ /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;
- }
- }
-}
-MAIN_CLASS=D2
+MAIN_CLASS=D2 #smalltest
PROGRAM=test
-SOURCE_FILES=*.java
+SOURCE_FILES=D2.java #smalltest.java
BUILDSCRIPT=~/research/Robust/src/buildscript
BSFLAGS= -debug -nooptimize -mainclass $(MAIN_CLASS) -justanalyze -ownership -ownallocdepth 1 -ownwritedots final -ownaliasfile aliases.txt -enable-assertions