예제 #1
0
  @Override
  public void run() {
    try {

      System.out.println("Processing current input status message");
      StatusInputMsg receivedNewMsg = queue.take();
      // -------------------------------------------------------------------------
      ArrayList<Path> currPathList = new ArrayList<Path>(receivedNewMsg.getCurrEdge());
      Map<String, Gate> currGateStatus = new HashMap<String, Gate>();
      Map<String, Gate> finalCurrGateStatus = new HashMap<String, Gate>();

      Map<Gate, ArrayList<Edge>> adjacencyStatus = getCurrentAdjacencyStatus(currPathList);

      for (Path path : currPathList) {
        Gate tempGate = new Gate(path.getStartNode());
        currGateStatus.put(tempGate.toString(), tempGate);
      }

      // At this instant, form the graph and find the shorted path with the current edges
      for (Map.Entry<String, Gate> e1 : currGateStatus.entrySet()) {

        String key = e1.getKey();
        Gate gate = e1.getValue();

        ArrayList<Edge> a = adjacencyStatus.get(gate);
        Edge[] b = new Edge[a.size()];

        // Update the adjecencies with current input.
        for (int i = 0; i < a.size(); i++) {
          Edge e = new Edge(gate, a.get(i).travelTime);
          b[i] = e;
        }
        gate.adjacencies = (Edge[]) b.clone();
        finalCurrGateStatus.put(key, gate);
      }

      System.out.println("Succcessfully processed current Input Status");

      /*
      for(Map.Entry<String, Gate> entry : finalCurrGateStatus.entrySet()){
      	System.out.println("key "+entry.getKey());
      	System.out.println("value "+entry.getValue().shortestTime);

      }
       */
      // -------------------------------------------------------------------------

      ArrayList<DepartureFlight> currDeptFlightList =
          new ArrayList<DepartureFlight>(receivedNewMsg.getCurrFlightStatus());
      Map<String, String> currFlightIdGateNameStatus = new HashMap<String, String>();

      for (DepartureFlight deptFlight : currDeptFlightList) {

        currFlightIdGateNameStatus.put(deptFlight.getFlightId(), deptFlight.getFlightGate());
      }
      currFlightIdGateNameStatus.put("ARRIVAL", "BaggageClaim");

      System.out.println("Succcessfully processed current flight Status");

      // -------------------------------------------------------------------------

      ArrayList<Baggage> currBaggageList = new ArrayList<Baggage>(receivedNewMsg.getCurrBaggage());

      for (Baggage bg : currBaggageList) {

        String currBagNumber = bg.getBagNumber();
        String currStartNode = bg.getEntryPoint();
        String currEndNode = currFlightIdGateNameStatus.get(bg.getFlightId());

        // This sleep can be varied to see the effect of processing time on the input buffer
        // management.
        sleep(1);

        Dijkstra.computeShortestPath(finalCurrGateStatus.get(currStartNode)); // run Dijkstra
        System.out.println(
            "For bag "
                + currBagNumber
                + " Time to reach "
                + currEndNode
                + ": "
                + finalCurrGateStatus.get(currEndNode).shortestTime);

        List<Gate> path = Dijkstra.getShortestPathTo(finalCurrGateStatus.get(currEndNode));
        System.out.println("Path: " + path.toString());
      }

      System.out.println(
          "Succcessfully generated shortest duration paths to each baggage in input message");

    } catch (InterruptedException e) {
      e.printStackTrace();
    }
  }
예제 #2
0
  /*Test function for algorithm*/
  public static void main(String[] args) {
    // mark all the vertices
    Gate A = new Gate("A");
    Gate B = new Gate("B");
    Gate D = new Gate("D");
    Gate F = new Gate("F");
    Gate K = new Gate("K");
    Gate J = new Gate("J");
    Gate M = new Gate("M");
    Gate O = new Gate("O");
    Gate P = new Gate("P");
    Gate R = new Gate("R");
    Gate Z = new Gate("Z");

    // set the edges and weight

    // set the edges and weight
    A.adjacencies = new Edge[] {new Edge(M, 8)};
    B.adjacencies = new Edge[] {new Edge(D, 11)};
    D.adjacencies = new Edge[] {new Edge(B, 11)};
    F.adjacencies = new Edge[] {new Edge(K, 23)};
    K.adjacencies = new Edge[] {new Edge(O, 40)};
    J.adjacencies = new Edge[] {new Edge(K, 25)};
    M.adjacencies = new Edge[] {new Edge(R, 8)};
    O.adjacencies = new Edge[] {new Edge(K, 40)};
    P.adjacencies = new Edge[] {new Edge(Z, 18)};
    R.adjacencies = new Edge[] {new Edge(P, 15)};
    Z.adjacencies = new Edge[] {new Edge(P, 18)};

    computeShortestPath(J); // run Dijkstra
    System.out.println("Distance to " + O + ": " + O.shortestTime);
    List<Gate> path = getShortestPathTo(O);
    System.out.println("Path: " + path);
  }