コード例 #1
0
 /**
  * Dijkstra doesn't allow negative edge weights so throw an exception if one was found.
  *
  * @throws IllegalArgumentException if the graph contains negative weights
  */
 private void checkForNegativeWeights() {
   for (Edge e : graph.getEdges()) {
     if (e.getWeight() < 0) {
       throw new IllegalArgumentException("graph contains negative weights!");
     }
   }
 }
コード例 #2
0
  private void executeDijkstra() {
    // determine minimum distance vertex and add it to the path.
    while (!this.priorityQueue.isEmpty()) {
      Vertex vertex = this.priorityQueue.extractMin();

      for (Edge e : graph.getIncidentEdgesOf(vertex)) {
        relax(vertex, e.getVertexB(), e.getWeight(), dist, pred);
      }
    }
  }