コード例 #1
0
 /**
  * Function for Dijkstra's algorithm. TODO:: describe this
  *
  * @param node The node to get the neighbors of.
  * @return A list of the neighbors of the given node.
  */
 private List<LotNode> getNeighbors(LotNode node) {
   List<LotNode> neighbors = new ArrayList<LotNode>();
   for (LotEdge edge : this.getGraph().getEdgeList(this.getEdgesToAvoid())) {
     try {
       if (this.getGraph().getNode(edge) == node && !isSettled(edge.getEndNode())) {
         neighbors.add(edge.getEndNode());
       }
     } catch (LotGraphException e) {
       e.printStackTrace();
       System.out.println("FATAL ERROR- this should not happen. Error: " + e.getMessage());
       System.exit(1);
     }
   }
   return neighbors;
 } // getNeighbors(LotNode)
コード例 #2
0
  /**
   * Function for Dijktra's algorithm. TODO:: describe this
   *
   * @param node The starting node.
   * @param target The node we are trying to get to.
   * @return The distance from the first node to the second node.
   */
  private double getDistance(LotNode node, LotNode target) {
    for (LotEdge edge : this.getGraph().getEdgeList(this.getEdgesToAvoid())) {

      try {
        if (this.getGraph().getNode(edge) == node && edge.getEndNode().equals(target)) {
          return edge.getMetric();
        }
      } catch (LotGraphException e) {
        e.printStackTrace();
        System.out.println("FATAL ERROR- Should not happen. Error: " + e.getMessage());
        System.exit(1);
      }
    }
    throw new RuntimeException("Should not happen");
  } // getDistance(LotNode, LotNode)