Questions tagged [dijkstra]

Dijkstra's algorithm, conceived by Dutch computer scientist Edsger Dijkstra is a graph search algorithm that solves the single-source shortest path problem for a connected graph with nonnegative edge path costs, producing a shortest path tree. This algorithm is often used in routing and as a subroutine in other graph algorithms.

For a given source vertex (node) in the connected graph, the algorithm finds the path with lowest cost (i.e. the shortest path) between that vertex and every other vertex. It can also be used for finding costs of shortest paths from a single vertex to a single destination vertex by stopping the algorithm once the shortest path to the destination vertex has been determined. For example, if the vertices of the graph represent cities and edge path costs represent driving distances between pairs of cities connected by a direct road, Dijkstra's algorithm can be used to find the shortest route between one city and all other cities. As a result, the shortest path first is widely used in network routing protocols, most notably IS-IS and OSPF (Open Shortest Path First).

Pseudocode :

function Dijkstra(Graph, source):
   for each vertex v in Graph:            // Initializations
       dist[v] := infinity ;              // Unknown distance function from source to v
       previous[v] := undefined ;         // Previous node in optimal path from source
   end for ;
   dist[source] := 0 ;                    // Distance from source to source
   Q := the set of all nodes in Graph ;   // All nodes in the graph are unoptimized - thus are in Q
   while Q is not empty:                  // The main loop
       u := vertex in Q with smallest distance in dist[] ;
      if dist[u] = infinity:
          break ;                        // all remaining vertices are inaccessible from source
      end if ;
      remove u from Q ;
      for each neighbor v of u:          // where v has not yet been removed from Q.
          alt := dist[u] + dist_between(u, v) ;
          if alt < dist[v]:              // Relax (u,v,a)
              dist[v] := alt ;
              previous[v] := u ;
              decrease-key v in Q;       // Reorder v in the Queue
          end if ;
      end for ;
  end while ;
  return dist[] ;
end Dijkstra.

Reference :

1895 questions
0
votes
2 answers

How to print the path after Dijikstra calculation?

I started to implement Graphs algorithms and I don't know how to print the path from the source to destination for this Dijkstra implementation ? Thank you #define INF 0x3f3f3f3f typedef pair ii; // to vertex, weight typedef vector
0
votes
1 answer

Using dijkstra_path function in networkx library

I'm using networkx library to find shortest path between two nodes using dijkstra algo as follows import networkx as nx A = [[0, 100, 0, 0 , 40, 0], [100, 0, 20, 0, 0, 70], [0, 20, 0, 80, 50, 0], [0, 0, 80, 0, 0, 30], [40, 0,…
user5782275
0
votes
1 answer

Using a fibonacci heap, is it possible/easy to represent neighbors aswell as minimum distance

I am trying to devise an implementation of dijkstras with fibonacci heaps. What I am trying to understand is if it is possible to represent, other than the minimum distance in O(logn) (with delete) but the neighbors of any given node? Or does this…
Max
  • 4,345
  • 8
  • 38
  • 64
0
votes
1 answer

Fibonacci Heap for Dijkstra via Java

I want to implement Fibonacci Heap on Dijkstra Algorithm. I use this code for Fibonacci heap. http://keithschwarz.com/interesting/code/?dir=fibonacci-heap The problem is how to call the method: decreaseKey? It always give me the hint that…
09817167d
  • 3
  • 4
0
votes
0 answers

Visit every node using shortest route algorithm

For my A-level computing project I am coding a route planner in VB. I am planning on implementing Dijkstra's algorithm to do this, but I was wondering if there is a way in which it can find the shortest route, whilst also visiting every node…
0
votes
1 answer

Calculate the shortest path from start to end, if we have the ability to overcome at MOST 1 obstacle

We're given a Maze in the form of a 2D Matrix of integers; where 0's are passible space and 1's are walls. The starting position will always be :array[0][0] and the end will always be :array[HEIGHT -1][WIDTH-1] The only possible moves are up,…
Elroy Jetson
  • 938
  • 11
  • 27
0
votes
1 answer

Cytoscape JS - Different Weights based on Direction for Dijkstra's

Trying to get Cytoscape JS to behave for me but running into some usability issues that I don't know if it's me or a limitation of the library. Primary problem is wanting to use different weights based on direction. A to B should have weight 3,…
imukai
  • 638
  • 1
  • 7
  • 17
0
votes
1 answer

How does PathExpanderBuilder.addNodeFilter work?

I'm working on a procedure that should find the lowest-weighted path between two nodes using Dijkstra's algorithm. The procedure should only return paths whose all nodes match specific criteria (i.e. all nodes should have properties with specific…
Aviran Katz
  • 741
  • 2
  • 8
  • 26
0
votes
1 answer

Shortest path of Dijkstra algorithm

I want to implement an iterator for the shortest path in my edge weighted graph. public class Graph implements GraphADT { protected final int DEFAULT_CAPACITY = 10; protected int numVertices; // number of vertices in the graph …
props
  • 105
  • 1
  • 7
0
votes
0 answers

error: no match for ‘operator==’ In Boost Graph and OMPL

I am trying to use Boost Dijkstra as shown in here. I am using OMPL library and the boost graph declaration can be found here. declaration of ob::Cost can be found here. Write the below code. When I compile it say this error: error: no match for…
Tal
  • 1,145
  • 2
  • 14
  • 32
0
votes
2 answers

C++ Dijkstra Algorithm - print edge name/type

I am currently working on Dijkstra's Shortest Path problem. I have nothing specific in this project, algorithm is standard (implement with set of pairs) except I need to print the types of edges from one vertex to another. Imagine I have 4 vertices…
oneturkmen
  • 1,288
  • 1
  • 11
  • 27
0
votes
1 answer

Find longest path in graph where each node has at most two incoming and two outgoing edges

As the title says I have to find longest path in directed graph where each node has at most two incoming edges and two outgoing edges. I don't know if that fact helps anything.. The graph will have at most 10000 nodes. And I need to find the longest…
someone12321
  • 755
  • 5
  • 24
0
votes
0 answers

Vector size hangs the program?

I have implemented the Dijkstra's algorithm in C++ with the help of vectors. The problem description is available here. This passes all the test cases except one. The test case input causing the failure is available here class CompareDistance{ …
Rohit Walavalkar
  • 790
  • 9
  • 28
0
votes
1 answer

Measure time Dijkstra's algorithm takes between nodes

I'm doing a graph program in C# which uses the Dijkstra algorithm to find the shortest path between nodes but I need to export the time it takes between each node to an excel file. I really haven't been able to come up with something or find any…
0
votes
0 answers

Adjacency list and struct Dijkstra

I must create a Dijkstra algorithm program using an adjacency list. My teacher give me this struct. But I have this error : note: expected 'struct maillon **' but argument is of type 'LISTE' void insere(int som_a, int som_b, int poids,…
user7047949