-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDijkstr.cpp
59 lines (45 loc) · 1.38 KB
/
Dijkstr.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include"Dijkstra.h"
#define _CRT_SECURE_NO_WARNINGS
#include"dijkstra_test.h"
Dijkstra::~Dijkstra()
{
//cout <<endl<< "Dijkstraクラスのデストラクタ" << endl;
}
int Dijkstra::serachRun()
{
int min, target;
cout << "スタート地点: " << start;
cout << " ゴール地点: " << goal << endl;
//*(cost + start) = 0;
cost.at(start) = 0;
while (1) {
min = MAX_VALUE;
//要素の個数分
/* 未確定の中から距離が最も小さい地点(a)を選んで、その距離を その地点の最小距離として確定します */
for (int i = 0; i < N; i++) {
if ((min > cost.at(i)) && (alused.at(i) == FALSE)) {
min = cost.at(i);
target = i;
cout << endl << "min: " << min << " target: " << target;
}
}
if (target == goal) {
//printf("\n%d", *(cost + goal));
cout << endl << cost.at(goal)<<endl;
cout << "探索を終了します" << endl;
//return *(cost + goal);
return cost.at(goal);
}/* 全ての地点の最短経路が確定 */
/*コストの処理*/
for (int root = 0; root < N; root++) {
//uniquearray仕様
if ((cost.at(root) > (distance[target][root]) + cost.at(target))) {
cost.at(root) = distance[target][root] + cost.at(target);
rooter.at(root) = target;
cout << endl << "rooter: " << rooter.at(root);
}
}//for (int rootおわり
//*(alused + target) = TRUE; //最短コストでた
alused.at(target) = TRUE;
}//while(1)おわり
}