dijkstra

Dijkstra's algorithm to find all the shortest paths possible

我们两清 提交于 2019-11-30 12:29:17
问题 I'm working on Dijkstra's algorithm, and I really need to find all the possible shortest paths, not just one. I'm using an adjacency matrix and I applied Dijkstra's algorithm, and I can find the shortest path. But I need to find all the paths with that minimum cost, I mean all the possible solutions, if they exist. This is how my algorithm works, for a single solution: public void dijkstra( int graph[][] ) { int d[] = new int[ graph.length ]; int dC[] = new int[ graph.length ]; int p[] = new

There's an easy way to apply a shortest path alghoritm in objective c?

我的梦境 提交于 2019-11-30 10:26:40
I have a series of point (x,y) linked by a path. There's an easy way in objective c to apply something like a Dijkstra shortest path alghoritm in order to know the shortest path among two variable points of these? The real problem is i have an image with a series of locations on it and the coordinate of all these location. Now i need the user to choose two of this location and getting the shortest path between the location choosen. I found a way to do this. Here there is a perfect implementation of the algorithm. Hope it helps someone. https://github.com/snyderp/PESGraph You may be able to

Understanding Time complexity calculation for Dijkstra Algorithm

杀马特。学长 韩版系。学妹 提交于 2019-11-30 10:25:33
问题 As per my understanding, I have calculated time complexity of Dijkstra Algorithm as big-O notation using adjacency list given below. It didn't come out as it was supposed to and that led me to understand it step by step. Each vertex can be connected to (V-1) vertices, hence the number of adjacent edges to each vertex is V - 1. Let us say E represents V-1 edges connected to each vertex. Finding & Updating each adjacent vertex's weight in min heap is O(log(V)) + O(1) or O(log(V)) . Hence from

how to save shortest path in dijkstra algorithm

风流意气都作罢 提交于 2019-11-30 08:26:41
问题 So first let's define Dijkstra algorithm: Dijkstra's algorithm finds single-source shortest paths in a directed graph with non-negative edge weights. I want to know how can I save the shortest path form s to t with Dijkstra algorithm. I searched on google, but I couldn't find anything particular; I also changed Dijkstra algorithm, but I could't get any answer. How can I save the shortest path from s to t with Dijkstra ? I know my question is basic and unprofessional, but any help would be

Dijkstra's algorithm with 'must-pass' nodes

南楼画角 提交于 2019-11-30 07:39:25
问题 I am trying to implement Dijkstra's algorithm which can find the shortest path between the start node and the end node. Before reach the end node there are some 'must-pass' intermediate nodes (more than one) for example 2 or 3 must pass nodes which must pass before reach the end node. If i have one must pass node the solution i found is find two different paths from the must pass node to destination and from must pass node to start node. I am out of ideas how i can implement such an algorithm

Find distance of route from get.shortest.paths()

有些话、适合烂在心里 提交于 2019-11-30 07:35:55
I'm using the igraph package in R to do something rather simple: Calculate the shortest distance between two nodes in my network. Is there a straightforward way to extract the distance of a path calculated via get.shortest.paths() ? Here is some reproducible code that exemplifies my problem: ## reproducible code: df2 = rbind(c(234,235,21.6), c(234,326,11.0), c(235,241,14.5), c(326,241,8.2), c(241,245,15.3), c(234,245,38.46)) df2 = as.data.frame(df2) names(df2) = c("start_id","end_id","newcost") require(igraph) g2 <- graph.data.frame(df2, directed=FALSE) class(g2) print(g2, e=TRUE, v=TRUE) ##

P1342 请柬 建反图+dijkstra

人走茶凉 提交于 2019-11-30 04:36:01
题目链接 一句话题意:喊你求出从1出发到所有点的最短路以及所有点的最短路到1的最短路之和。 从1开始跑最短路很容易,直接一遍堆优化dijkstra就完了。 对于其他点到1的最短路又怎么求,不可能一个一个的求,所以想到之前暑假讲关于图论的技巧——建反图。 这样的话问题就迎刃而解了,再在反图上从1开始跑一遍最短路就完了。 代码如下: #include<bits/stdc++.h> using namespace std; const int maxn=2e6+7; const int inf=0x7fffffff; struct node1{ int nxt,to,val; }edge1[maxn*3]; struct node2{ int nxt,to,val; }edge2[maxn*3]; priority_queue<pair<long long ,int > >q1; priority_queue<pair<long long ,int > >q2; long long dis1[maxn],dis2[maxn]; int cnt1,cnt2; int n,m; int x,y,v; int head1[maxn],head2[maxn]; void add1(int x,int y,int v){ edge1[++cnt1].nxt=head1[x]; edge1[cnt1

BZOJ 2834: 回家的路 Dijkstra

 ̄綄美尐妖づ 提交于 2019-11-30 03:04:58
Code: #include <bits/stdc++.h> #define N 200005 #define E 2000000 #define setIO(s) freopen(s".in","r",stdin) using namespace std; int n,m,tot,edges,s,T; int hd[E],to[E],nex[E],val[E],d[E],done[E],id[E][2]; void addedge(int u,int v,int c) { nex[++edges]=hd[u],hd[u]=edges,to[edges]=v,val[edges]=c; } struct Point { int x,y,id; Point(int x=0,int y=0):x(x),y(y){} }t[N]; struct Node { int u,dis; Node(int u=0,int dis=0): u(u),dis(dis){} bool operator<(Node b) const { return b.dis<dis; } }; priority_queue<Node>q; bool cmpx(Point a,Point b) { return a.x==b.x?a.y<b.y:a.x<b.x; } bool cmpy(Point a,Point b

Finding the shortest route using Dijkstra algorithm

China☆狼群 提交于 2019-11-30 02:30:59
问题 I need to find the shortest route between 2 vertices of a graph. I have a matrix, which contains all the weights. How can I do it? Currently, I have the following code: private int[] Dijkstra(int start, int end) { bool[] done = new bool[8]; int[] parent = new int[8]; for (int i = 0; i < parent.Length; i++) parent[i] = -1; int[] distances = new int[8]; for (int i = 0; i < distances.Length; i++) distances[i] = int.MaxValue; distances[start] = 0; int current = start; while (!done[current]) {

Dijkstra algorithm with min-priority queue

寵の児 提交于 2019-11-30 01:12:08
问题 I'm trying to implement the dijkstra algorithm with priority queue, but I can't understand how it works. I read many guide on the web but I can't understand this algorithm at all. My question are: what is the priority for each node? I think that it is the weight of the incoming edge with minimun value, but I'm not sure. Is this true? Second question, when I extract the root of the queue, how works if this node is not adjacency with no one of the visited nodes? 回答1: You should use priority