引入:
dijkstra(迪傑斯特拉)演算法是典型的最短路徑路由演算法,用於計算乙個節點到其他所有節點的最短路徑。主要特點是以起始點為中心向外層層擴充套件,直到擴充套件到終點為止。dijkstra演算法能得出最短路徑的最優解,但由於它遍歷計算的節點很多,所以效率低。
**:
package dijkstra;
public class node
public char getid()
public void setid(char id)
public boolean isintree()
public void setintree(boolean isintree)
}
package dijkstra;
public class distpare
public int getparentnode()
public void setparentnode(int parentnode)
public int getdistance()
public void setdistance(int distance)
}
package dijkstra;
public class graph {
private final int maxnum = 20;
private final int maxint = 999999;
private int nodenum; //number of the nodes in graph
private int treenum; //number of the nodes in tree
private int adjmatrix; //distance between two nodes
private node nodelist; //all nodes
private distpare spath; //shortest path between parent node and i
private int currentnode;
private int currentdist;
public graph(){
adjmatrix = new int[maxnum][maxnum];
nodelist = new node[maxnum];
spath = new distpare[maxnum];
nodenum = 0;
treenum = 0;
for(int i=0; i
Dijkstra最短路徑演算法
基本思路是 選擇出發點相鄰的所有節點中,權最小的乙個,將它的路徑設定為確定。其他節點的路徑需要儲存起來。然後從剛剛確認的那個節點的相鄰節點,算得那些節點的路徑長。然後從所有未確定的節點中選擇乙個路徑最短的設定為確定。重複上面步驟即可。void dijkstra graph g,string v fl...
最短路徑 Dijkstra演算法
最短路徑 描述 已知乙個城市的交通路線,經常要求從某一點出發到各地方的最短路徑。例如有如下交通圖 則從a出發到各點的最短路徑分別為 b 0c 10 d 50 e 30 f 60 輸入 輸入只有乙個用例,第一行包括若干個字元,分別表示各頂點的名稱,接下來是乙個非負的整數方陣,方陣維數等於頂點數,其中0...
最短路徑演算法 Dijkstra
dijkstra的最短路徑演算法是基於前驅頂點的最短路徑計算的,整體上來講還是比較簡單的,下面是 include include include void shortestpath const std vector paths,int from,std vector short path flags...