dijkstra

Suitable data structure for large graphs

前提是你 提交于 2019-12-06 07:59:36
问题 I have a large graph, is there any other data structure other than adjacency list and "adjacency matrix" in c++ stl or some other data structure which I can employ for such a large graph, actually the adjacency matrix of my graph does not fit in the main memory. My graph is directed and I am implementing dijkstra algorithm in C++. I have seen the previous posts...but I am searching for a suitable data structure with respect to dijkstra. By large I mean a graph containing more than 100 million

最短路--Dijkstra

纵然是瞬间 提交于 2019-12-06 07:56:39
Dijkstra--单源最短路 算法思想 每次选择没有被访问过的,并且dis最小的点,加入集合,更新dis 模板 int dis[maxn],vis[maxn]; //距离,标记 void dijkstra() { int k = 1,mi; vis[k] = 1; //初始化 mem(dis,inf); //wa for(int i = 1; i <= n; i++) dis[i] = a[k][i]; for(int i = 1; i < n; i++) //共选n-1次 { mi = inf; for(int j = 1; j <= n; j++) //每次选dis最小的点,加入集合 { if(!vis[j] && mi > dis[j]) { mi = dis[j]; k = j; } } if(mi == inf) break; vis[k] = 1; for(int j = 1; j <= n; j++) //再根据选的点,更新其他点 { if(!vis[j] && dis[j] > dis[k]+a[k][j]) dis[j] = dis[k]+a[k][j]; } } } 例题 参考博客 https://blog.csdn.net/kprogram/article/details/81225176 来源: https://www.cnblogs.com

More than 640 000 elements in the array - memory problem [Dijkstra]

丶灬走出姿态 提交于 2019-12-06 05:58:36
I have a script which puts 803*803 (644 809) graph with 1 000 000 value inside each. With ~500*500 everything works fine - but now it crashes - it tries to allocate more than 64MB of memory (which I haven't). What's the solution? Somehow "split" it or...? $result=mysql_query("SELECT * FROM some_table", $connection); confirm($result); while($rows = mysql_fetch_array($result)){ $result2=mysql_query("SELECT * FROM some_table", $connection); confirm($result2); while($rows2 = mysql_fetch_array($result2)){ $first = $rows["something"]; $second = $rows2["something2"]; $graph[$first][$second] = 1000000

PAT甲级【2019年9月考题】——A1164 DijkstraSequence【30】

淺唱寂寞╮ 提交于 2019-12-06 05:41:09
7-4 Dijkstra Sequence (30 分) Dijkstra's algorithm is one of the very famous greedy algorithms. It is used for solving the single source shortest path problem which gives the shortest paths from one particular source vertex to all the other vertices of the given graph. It was conceived by computer scientist Edsger W. Dijkstra in 1956 and published three years later. In this algorithm, a set contains vertices included in shortest path tree is maintained. During each step, we find one vertex which is not yet included and has a minimum distance from the source, and collect it into the set. Hence

Shortest path between raw geo coordinates and a node of a graph

喜夏-厌秋 提交于 2019-12-06 03:11:02
问题 I have implemented a simple Dijkstra's algorithm for finding the shortest path on an .osm map with Java. The pathfinding in a graph which is created from an .osm file works pretty well. But in case the user's current location and/or destination is not a node of this graph (just raw coordinates) how do we 'link' those coordinates to the graph to make pathfinding work? The simple straightforward solution "find the nearest to the current location node and draw a straight line" doesn't seem to be

Go, Dijkstra : print out the path, not just calculate the shortest distance

可紊 提交于 2019-12-06 02:40:38
问题 Go, Dijkstra : print out the path, not just calculate the shortest distance. http://play.golang.org/p/A2jnzKcbWD I was able to find the shortest distance using Dijkstra algorithm, maybe not. The code can be found here. But it would be useless if I can't print out the path. With a lot of pointers going on, I can't figure out how to print out the final path that takes the least amount of weights. In short, how do I not only find the shortest distance, but also print out the shortest path on

Modified Dijkstra to find most optimized shortest path given extra properties

人盡茶涼 提交于 2019-12-06 01:24:07
This is a follow-up question for a question I asked at here . The problem is mapped to a graph with say non-negative weights on edges (no preference if it can be directed or not). However, along with a weight which is actually distance, we also have another property which is data coverage of the edge which can be important factor which route to select given how severe I need internet on my phone (for real-time gaming for example I need good bandwidth). So overall, we want to somehow find a trade-off between the length of the path and network bandwidth to solve the problem of finding most

Dijkstra's algorithm on directed acyclic graph with negative edges

不问归期 提交于 2019-12-05 16:00:21
Will Dijkstra's algorithm work on a graph with negative edges if it is acyclic (DAG)? I think it would because since there are no cycles there cannot be a negative loop. Is there any other reason why this algorithm would fail? Thanks [midterm tomorrow] Consider the graph (directed 1 -> 2, 2-> 4, 4 -> 3, 1 -> 3, 3 -> 5 ): 1---(2)---3--(2)--5 | | (3) (2) | | 2--(-10)--4 The minimum path is 1 - 2 - 4 - 3 - 5 , with cost -3 . However, Dijkstra will set d[3] = 2, d[2] = 3 in the first step, then extract node 3 from its priority queue and set d[5] = 4 . Since node 3 was extracted from the priority

Dijkstras Algorithm doesn't appear to work, my understanding must be flawed

岁酱吖の 提交于 2019-12-05 10:50:14
Here's my interpretation of how Dijkstra's algorithm as described by wikipedia would deal with the below graph. First it marks the shortest distance to all neighbouring nodes, so A gets 1 and C gets 7. Then it picks the neighbour with the current shortest path. This is A. The origin is marked as visited and will not be considered again. The shortest (and only) path from the origin to B through A is now 12. A is marked as visited. The shortest path from the origin to the Destination through B is 13. B is marked as visited. The shortest path from the Origin to C through the destination is 14,

Make Boost Dijkstra algorithm stop when it reaches a destination node

元气小坏坏 提交于 2019-12-05 10:34:27
I'm using boost::graph and its Dijkstra implementation. When someone is using the Dijkstra algorithm, it may be to know the shortest path between 2 nodes in a graph. But as you need to check all nodes in the graph to find the shortest path, usually (like the boost algorithm) Dijkstra gives you back all the distances between one origin point, and all the other nodes of the graph. One easy improvement of this algorithm when you only want the path between 2 nodes is to stop it when the algorithm reach the destination node. Then, you are sure that the distance that you have for this final