dijkstra

Is Dijkstra's algorithm for directed or undirected graphs?

笑着哭i 提交于 2019-12-02 20:41:51
I keep trying to google this, but the results I'm finding are just adding to my confusion. It seems that it can be possibly used for both? If so, which is it designed for by default and what needs to change to make it work the non-default way (whether that be directed or undirected)? Edit: for reference, I had a problem last semester where I was given a list like this (airports): AER,KZN,1.8835 ASF,KZN,1.3005 ASF,MRV,1.1204 CEK,KZN,1.9263 CEK,OVB,1.6733 DME,KZN,1.7892 DME,NBC,2.2319 DME,UUA,2.3786 EGO,KGD,1.4649 EGO,KZN,1.2603 GYD,NBC,2.0755 I was told it was directed, and asked to find the

Dijkstra

匿名 (未验证) 提交于 2019-12-02 20:37:20
原创 1 import java.util.*; 2 3 public class Dijkstra { 4 5 static int v; //顶点 6 static int e; //边 7 static int aim; //aim与其余顶点的最短路径 8 static int matrix[][]; //邻接矩阵 9 static int book[]; //标记数组 10 static int dis[]; //存储与其他顶点的距离 11 static int min=99999; 12 static int inf=99999; 13 14 public static void main(String[] args) { 15 Scanner reader=new Scanner(System.in); 16 v=reader.nextInt(); 17 e=reader.nextInt(); 18 aim=reader.nextInt(); 19 matrix=new int[v+1][v+1]; //从1开始编号 20 book=new int[v+1]; 21 dis=new int[v+1]; 22 //矩阵初始化 23 for(int i=1;i<=v;i++) { 24 book[i]=0; 25 for(int j=1;j<=v;j++) { 26 if

What is the point of adding and removing the element from Priority Queue in the given dijkstra code?

风格不统一 提交于 2019-12-02 18:03:33
问题 I was studying Dijkstra algorithm code given at this link -> https://java2blog.com/dijkstra-java/ Can someone explain the following 2 parts of the code? 1) Why are we adding and removing the element from Priority queue when calculate distance is less? if( newDistance < v.getDistance() ) { priorityQueue.remove(v); v.setDistance(newDistance); v.setPredecessor(actualVertex); priorityQueue.add(v); } 2) What are we doing in compareTo method and why? @Override public int compareTo(Vertex

Dijkstra on “Software Engineering” [closed]

左心房为你撑大大i 提交于 2019-12-02 17:10:53
Edsger Dijkstra, who could be somewhat abrasive at times (he called "Carl Friedrich Gauss, the Prince of Mathematicians but also somewhat of a coward") said in his essay "On the cruelty of really teaching computing science" ( EWD1036 ): A number of these phenomena have been bundled under the name "Software Engineering". As economics is known as "The Miserable Science", software engineering should be known as "The Doomed Discipline", doomed because it cannot even approach its goal since its goal is self-contradictory. Software engineering, of course, presents itself as another worthy cause, but

2019ICPC南京自我反省

烂漫一生 提交于 2019-12-02 16:51:10
  第一场ICPC,跟第一场CCPC一样,可惜真的可惜。   打完比赛就感觉难受,难受不在于又抱了块铜牌,而是那种能出的题没出的可惜感非常浓重。   开场还是可以的,通过一阵讨论,就大胆猜测了A的规律,然后一发过,接着鲲鲲看出K是计算几何题,就去搞K,我读了一会H没搞懂就跟榜去读C,一开始看C有好几个图片,还以为是难题,不过读完之后感觉能做,便跟+1交换了下思路。然后鲲鲲wrong了一发K,有些焦急,不过等+1一发A了C题之后,鲲鲲也找到了错误,然后K题跟着过了。一直到这个时候,大概过了1小时40多分钟,还是挺顺利的。接着+1跟我说了一个J题她的推论,然后我觉得能够建出图来,然后就是一个费用流,果断去尝试,而+1跟鲲鲲一起去搞H题。这时就出现了个错误的想法,觉得再出J跟H就差不多了,所以思想便松懈了。   接下来便出问题了,J题敲完一交结果T了,然后我脑子里瞬间就想dijkstra优化,还有zwk费用流,然后dijkstra优化的没用过直接抄板子,样例都跑不过,不知道为什么,然后浪费了一堆时间,最后试了一发zwk费用流,结果又T了,然后便觉得这不是网络流的题。而在此途中+1和鲲鲲H题推出了个结论,但是一交wrong了。然后就是陷入了卡题中,周围各种吐槽H题的,我们心态也逐渐受到了影响,而还有40分钟左右时,我突然想到,而鲲鲲也刚好对我说了个二分图,我便立马确定了下n 3 的复杂度

Correct formulation of the A* algorithm

寵の児 提交于 2019-12-02 16:50:18
I'm looking at definitions of the A* path-finding algorithm, and it seems to be defined somewhat differently in different places. The difference is in the action performed when going through the successors of a node, and finding that a successor is on the closed list. One approach (suggested by Wikipedia , and this article ) says: if the successor is on the closed list, just ignore it Another approach (suggested here and here , for example) says: if the successor is on the closed list, examine its cost. If it's higher than the currently computed score, remove the item from the closed list for

Bus public transport algorithm

最后都变了- 提交于 2019-12-02 15:39:07
I am working on an offline C# application that can find bus routes. I can extract the timetable/bus/route data. I am searching for the most simple solution that will work with basic data. What algorithm can be used to find a route from bus stop "A" to bus stop "B"? Is there a open-source solution ready for C#/Java? Is the google GTFS format for database good for a simple solution? http://code.google.com/transit/spec/transit_feed_specification.html Thanks for any help. I am stuck with this. I don't know where to start - how to store the data and how to find routes. I know about Dijkstra/A* but

Understanding Dijkstra's Mozart programming style

无人久伴 提交于 2019-12-02 14:10:53
I came across this article about programming styles, seen by Edsger Dijsktra. To quickly paraphrase, the main difference is Mozart, when the analogy is made to programming, fully understood (debatable) the problem before writing anything, while Beethoven made his decisions as he wrote the notes out on paper, creating many revisions along the way. With Mozart programming, version 1.0 would be the only version for software that should aim to work with no errors and maximum efficiency. Also, Dijkstra says software not at that level of refinement and stability should not be released to the public.

MongoDB + Neo4J vs OrientDB vs ArangoDB [closed]

时光总嘲笑我的痴心妄想 提交于 2019-12-02 14:04:31
I am currently on design phase of a MMO browser game, game will include tilemaps for some real time locations (so tile data for each cell) and a general world map. Game engine I prefer uses MongoDB for persistent data world. I will also implement a shipping simulation (which I will explain more below) which is basically a Dijkstra module, I had decided to use a graph database hoping it will make things easier, found Neo4j as it is quite popular. I was happy with MongoDB + Neo4J setup but then noticed OrientDB , which apparently acts like both MongoDB and Neo4J (best of both worlds?), they even

850. Dijkstra求最短路 II

自作多情 提交于 2019-12-02 11:41:31
给定一个n个点m条边的有向图,图中可能存在重边和自环,所有边权均为正值。 请你求出1号点到n号点的最短距离,如果无法从1号点走到n号点,则输出-1。 输入格式 第一行包含整数n和m。 接下来m行每行包含三个整数x,y,z,表示存在一条从点x到点y的有向边,边长为z。 输出格式 输出一个整数,表示1号点到n号点的最短距离。 如果路径不存在,则输出-1。 数据范围 1 ≤ n , m ≤ 10 5 1≤n,m≤105, 图中涉及边长均不超过10000。 输入样例: 3 3 1 2 2 2 3 1 1 3 4 输出样例: 3 代码实现: //堆优化版本的dijkstra() #include<iostream> #include<cstring> #include<queue> using namespace std; //我们需要用堆来维护所有的点的距离,维护距离的时候我们需要知道结点编号是多少 //所以堆里边存的其实是一个pair typedef pair<int,int> PII; const int N = 1e5 + 10; //n,m都是1e5,属于稀疏图用邻接表 int d[N]; int h[N],ne[N],e[N],idx; bool st[N]; //权重 int w[N]; int n,m; void add(int a,int b,int c){ e[idx]