⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pilotagent.java.svn-base

📁 這是一個JAVA語言寫的多代理人程式用來模擬飛機起飛或是降落的程式
💻 SVN-BASE
📖 第 1 页 / 共 3 页
字号:
package agents;

import interfaces.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.Semaphore;

import world.Airport;
import world.Gate;
import world.Plane;
import world.RealPlane;
import world.Runway;
import world.TRACON;
import world.Taxiway;
import world.Tower;
import world.Waypoint;
import world.Weather;
import base.Agent;
import base.World;
import base.WorldObject;
import base.WorldObjectState;
import base.WorldVector;

public class PilotAgent extends Agent implements PilotInterface {

	final double departingVelocity = 12;
	final double landingVelocity = 160;
	final double taxiVelocity = 50;
	public static final Double turn_velocity = Math.PI/12;
	
	Semaphore inc_velocity = new Semaphore(1, true);
    //DATA
    String flightNumber;
    public Plane plane;
    Airport airport;
    String approach;
    Weather weather;
    TRACON departureTracon;
    public enum PilotState {NO_ACTION, NEW_ARRIVAL, SENT_CHECKLIST, NEED_TO_ASK_TO_LAND, ASKED_TO_LAND, CLEAR_TO_LAND, NOT_CLEAR_TO_LAND, ECHO_LANDING, 
    						GOT_LANDING_PATH, ECHO_LANDING_PATH, GOT_TAXI_LAND_PATH, ECHO_TAXI_LAND_PATH, LANDING, TAXIING, ARRIVED,
    						NEW_DEPARTURE, SENT_DEPARTURE_CHECKLIST, REQUESTED_DEPARTURE_CLEARANCE, CLEARED_FOR_DEPARTURE, ECHO_CLEARED_FOR_DEPARTURE,
    						GOT_WEATHER, ECHO_WEATHER, DEPARTURE_CHECKLIST_DONE, ASKED_FOR_PUSH_BACK, WAIT_PUSH_BACK, ECHO_PUSH_BACK, PUSH_BACK,
    						READY_FOR_TAXI, GOT_TAXI_PATH, ECHO_TAXI_PATH, DEPARTURE_TAXIING, READY_FOR_TAKEOFF, HOLD_FOR_DEPARTURE, ECHO_HOLD_FOR_DEPARTURE, 
    						GOT_DEPARTURE_TRACON, ECHO_DEPARTURE_TRACON, LC_CLEARED_FOR_DEPARTURE, READY_TO_DEPART, TAKING_OFF, DEAD};
    public PilotState pilotState;
    public Runway landing, departing;
    WorldVector runwayPosition;
    Taxiway taxiway;
    public Gate destinationGate;
    public String destination;//???
    List<Taxiway> landingPath, taxiLandingPath, taxiDepartingPath; //what is landingPath used for?
    List<Waypoint> departureProcedure;
    LocalControllerInterface localController;
    GroundControllerInterface groundController;
    public ClearanceDeliveryInterface clearanceDelivery;

    public static void main(String args[]){
    	Tower tower = new Tower();
    	List<WorldVector> vertices = new ArrayList<WorldVector>();
    	vertices.add(new WorldVector(50,90,0));
    	vertices.add(new WorldVector(50,110,0));
    	vertices.add(new WorldVector(150,90,0));
    	vertices.add(new WorldVector(150,110,0));
    	WorldObjectState runwayState = new WorldObjectState(new WorldVector(100,100,0),vertices);
    	Runway runway = new Runway("Runway2C",runwayState);
    	
    	WorldObjectState planeState = new WorldObjectState(new WorldVector(100, 100, 0));
    	Plane myPlane = new RealPlane("747",planeState);
    	
    	//LocalControllerInterface lc = new LocalController("lc",tower);
    	ClearanceDeliveryInterface cd = new ClearanceDeliveryAgent("cd", tower);
    	
    	PilotAgent myPilot = new PilotAgent("Pilot",myPlane);
    	
    	myPlane.ctrlAssumePilotRole(myPilot);
    	//myPilot.msgNewArrivingFlight("SWA111", runway, new Gate(new Taxiway()), lc);
    	//myPilot.pilotState = PilotState.ECHO_LANDING_PATH;
    	myPilot.msgNewDepartingFlight("SWA111", runway, new Gate(new Taxiway()), "Bora Bora", cd);
    	myPilot.pilotState = PilotAgent.PilotState.ECHO_DEPARTURE_TRACON;
    	World.startWorld();
    	myPilot.startThread();
    }
    
    public PilotAgent(Plane myPlane, Airport myAirport){
    	super();
		plane = myPlane;
		airport = myAirport;
		pilotState = PilotState.NO_ACTION;
    	plane.ctrlAssumePilotRole(this);
		
    }
    
    public PilotAgent(String name, Plane plane) {
    	super();
    	this.plane = plane;
    	flightNumber = name;
    	plane.ctrlAssumePilotRole(this);
    }
    
    public PilotAgent(Plane myPlane, Airport myAirport, LocalControllerInterface lc, 
    		GroundControllerInterface gc, ClearanceDeliveryInterface cd, String fn){
    	super();
		plane = myPlane;
		airport = myAirport;
		pilotState = PilotState.NO_ACTION;
		localController = lc; groundController = gc;
		clearanceDelivery = cd;
		flightNumber = fn;
		plane.ctrlAssumePilotRole(this);
    }  
    
    // Pilot
	public boolean heartBeat(){return true;}
	
	// Non normative scenario
	public void msgPilotIsDead() {
		//print("Pilot is now dead");
		pilotState = PilotState.DEAD;
	}
	
	// Landing
	public void msgNewArrivingFlight(String callNumber, Runway runway, Gate gate, LocalControllerInterface lc){
		//print("Received msgNewArrivingFlight");
		flightNumber = callNumber;
		landing = runway;
		destinationGate = gate;
		localController = lc;
		pilotState = PilotState.NEED_TO_ASK_TO_LAND;
		stateChanged();
	}
	public void msgArrivalChecklistSuccessful(){
		//print("Received msgArrivalChecklistSuccessful");
		pilotState = PilotState.NEED_TO_ASK_TO_LAND;
		stateChanged();
	}
	public void msgClearanceToLand(Runway runway){
		//print("Received msgClearanceToLand");

		//landing = runway;

		pilotState = PilotState.CLEAR_TO_LAND;
		stateChanged();
	}
	public void msgNotClearedToLand(){
		//print("Received msgNotClearedToLand");
		pilotState = PilotState.NOT_CLEAR_TO_LAND;
		stateChanged();
	}
	public void msgLandingPath(List<Taxiway> path, GroundControllerInterface gc){
		//print("Received msgLandingPath");
		landingPath = path;
		groundController = gc;
		pilotState = PilotState.GOT_LANDING_PATH;
		stateChanged();
	}
	public void msgTaxiLandingPath(List<Taxiway> taxiInstruction){
		//print("Received msgTaxiLandingPath " + taxiInstruction);
		taxiLandingPath = taxiInstruction;
		pilotState = PilotState.GOT_TAXI_LAND_PATH;
		stateChanged();
	}
	
	// Takeoff
	public void msgNewDepartingFlight(String callNumber, Runway runway, Gate gate, String myDestination, ClearanceDeliveryInterface cd){
		print("Received msgNewDepartingFlight");
		flightNumber = callNumber;
		runway.get_world_object_state();
		departing = runway;
		destinationGate = gate;
		destination = myDestination;
		clearanceDelivery = cd;
		pilotState = PilotState.NEW_DEPARTURE;
		//pilotState = PilotState.GOT_TAXI_PATH;
		stateChanged();
	}
	public void msgClearanceGranted(List<Waypoint> procedure, GroundControllerInterface gc){
		print("Received msgClearanceGranted");
		departureProcedure = procedure;
		groundController = gc;
		pilotState = PilotState.CLEARED_FOR_DEPARTURE;
		stateChanged();
	}
	public void msgSendWeather(Weather report){
		print("Received msgSendWeather");
		weather = report;
		pilotState = PilotState.GOT_WEATHER;
		stateChanged();
	}
	public void msgDepartureChecklistSuccessful(){
		print("Received msgDepartureChecklistSuccessful");
		pilotState = PilotState.DEPARTURE_CHECKLIST_DONE;
		stateChanged();
	}
	public void msgGivePushBack(Runway takeoffRunway, Gate gate){
		print("Received msgGivePushBack");
		//departing = takeoffRunway;
		destinationGate = gate;
		pilotState = PilotState.WAIT_PUSH_BACK;
		stateChanged();
	}
	
	public void msgWaitForTaxiway() {
		print("Received msgWaitForTaxiway");
		pilotState = PilotState.WAIT_PUSH_BACK;
		stateChanged();
	}
	
	public void msgTaxiTakeoffPath(List<Taxiway> path, LocalControllerInterface lc){

		print("Received msgTaxiTakeoffPath: " + path);
		taxiDepartingPath = path;
		localController = lc;
		pilotState = PilotState.GOT_TAXI_PATH;
		stateChanged();
	}
	public void msgPositionAndHold(){
		// print("Received msgPositionAndHold");
		pilotState = PilotState.HOLD_FOR_DEPARTURE;
		stateChanged();
	}
	public void msgClearedForTakeoff(Runway takeoffRunway){
		print("Received msgClearedForTakeoff");
		//if(takeoffRunway != null)
		//	departing = takeoffRunway;
		pilotState = PilotState.LC_CLEARED_FOR_DEPARTURE;
		stateChanged();
	}
	public void msgContactDepartureControl(TRACON departureControl){
		print("Received msgContactDepartureControl");
		departureTracon = departureControl;
		pilotState = PilotState.GOT_DEPARTURE_TRACON;
		stateChanged();
	}
	

	@Override
	public boolean pickAndExecuteAnAction() {
	    //LANDING ARRIVAL
		if(pilotState == PilotState.NEW_ARRIVAL){
			DoSendArrivalChecklist();
			return true;
		}
		else if(pilotState == PilotState.NEED_TO_ASK_TO_LAND){
			DoAskToLand();
			return true;
		}
		else if(pilotState == PilotState.CLEAR_TO_LAND){
			DoEchoClearToLand();
			return true;
		}
		else if(pilotState == PilotState.NOT_CLEAR_TO_LAND){
			DoWaitToLand();
			return true;
		}
		else if(pilotState==PilotState.GOT_LANDING_PATH){
		    DoEchoLandingPath();
		    return true;
		}
		else if(pilotState==PilotState.ECHO_LANDING_PATH){
		    DoLanding();
		    return true;
		}
		else if(pilotState==PilotState.GOT_TAXI_LAND_PATH){
		    DoEchoLandTaxiPath();
		    return true;
		}
		else if(pilotState==PilotState.ECHO_TAXI_LAND_PATH){
			DoTaxiToGate();
			return true;
		}
		
		//DEPARTING TAKE OFF
		else if(pilotState==PilotState.NEW_DEPARTURE){
			//print("Sending clearance delivery msgNewDepartingFlight scheduler");
			DoSendDepartureChecklist();
			return true;
		}
		else if(pilotState==PilotState.SENT_DEPARTURE_CHECKLIST){
			DoRequestClearanceForDeparture();
			return true;
		}
		else if(pilotState==PilotState.CLEARED_FOR_DEPARTURE){
			DoEchoDepartureClearance();
			return true;
		}
		else if(pilotState==PilotState.GOT_WEATHER){
			DoEchoWeather();
			return true;
		}
		else if(pilotState==PilotState.DEPARTURE_CHECKLIST_DONE){
			DoRequestPushBack();
			return true;
		}
		else if(pilotState==PilotState.WAIT_PUSH_BACK){
			DoEchoPushBack();
			return true;
		}
		else if(pilotState==PilotState.ECHO_PUSH_BACK){
			DoWaitForPushBack();
			return true;
		}
		else if(pilotState==PilotState.GOT_TAXI_PATH){
			DoEchoTaxiPath();
			return true;
		}
		else if(pilotState==PilotState.ECHO_TAXI_PATH){
			DoDepartureTaxiing();
			return true;
		}
		else if(pilotState==PilotState.HOLD_FOR_DEPARTURE){
			DoEchoHoldForDeparture();
			return true;
		}
		else if(pilotState==PilotState.LC_CLEARED_FOR_DEPARTURE){
			DoEchoClearedForLCDeparture();
			return true;
		}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -