forked from justinhj/astar-algorithm-cpp
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain_single_path.cpp
More file actions
68 lines (57 loc) · 2.34 KB
/
main_single_path.cpp
File metadata and controls
68 lines (57 loc) · 2.34 KB
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
60
61
62
63
64
65
66
67
68
#include <iostream>
#include <vector>
#include <chrono>
#include "MapInfo.h"
#include "find_path.h"
#include "smooth_path.h"
// Main
int main()
{
std::vector<int> world_map =
{
// 0001020304050607080910111213141516171819
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 00
1,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,1, // 01
1,9,9,1,1,9,9,9,1,9,1,9,1,9,1,9,9,9,1,1, // 02
1,9,9,1,1,9,9,9,1,9,1,9,1,9,1,9,9,9,1,1, // 03
1,9,1,1,1,1,9,9,1,9,1,9,1,1,1,1,9,9,1,1, // 04
1,9,1,1,9,1,1,1,1,9,1,1,1,1,9,1,1,1,1,1, // 05
1,9,9,9,9,1,1,1,1,1,1,9,9,9,9,1,1,1,1,1, // 06
1,9,9,9,9,9,9,9,9,1,1,1,9,9,9,9,9,9,9,1, // 07
1,9,1,1,1,1,1,1,1,1,1,9,1,1,1,1,1,1,1,1, // 08
1,9,1,9,9,9,9,9,9,9,1,1,9,9,9,9,9,9,9,1, // 09
1,9,1,1,1,1,9,1,1,9,1,1,1,1,1,1,1,1,1,1, // 10
1,9,9,9,9,9,1,9,1,9,1,9,9,9,9,9,1,1,1,1, // 11
1,9,1,9,1,9,9,9,1,9,1,9,1,9,1,9,9,9,1,1, // 12
1,9,1,9,1,9,9,9,1,9,1,9,1,9,1,9,9,9,1,1, // 13
1,9,1,1,1,1,9,9,1,9,1,9,1,1,1,1,9,9,1,1, // 14
1,9,1,1,9,1,1,1,1,9,1,1,1,1,9,1,1,1,1,1, // 15
1,9,9,9,9,1,1,1,1,1,1,9,9,9,9,1,1,1,1,1, // 16
1,1,9,9,9,9,9,9,9,1,1,1,9,9,9,1,9,9,9,9, // 17
1,9,1,1,1,1,1,1,1,1,1,9,1,1,1,1,1,1,1,1, // 18
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 19
};
for (size_t idx = 0; idx < world_map.size(); ++idx) {
if (world_map[idx] == 9)
world_map[idx] = 255;
else
world_map[idx] = 0;
}
int map_width = 20;
int map_height = 20;
struct MapInfo Map;
Map.world_map = world_map;
Map.map_width = map_width;
Map.map_height = map_height;
int start[2] = {0, 0}; // Create a start state
int end[2] = {18, 14}; // Define the goal state
auto start_time = std::chrono::high_resolution_clock::now();
auto [path, distance] = find_path(start, end, Map);
auto stop_time = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(stop_time - start_time);
std::cout << "Time used [microseconds]:" << duration.count() << std::endl;
std::cout << "This is the path. Distance used:" << distance << std::endl;
for(size_t i=0; i<path.size(); i=i+2)
std::cout << path[i] << "," << path[i+1] << std::endl;
return 0;
}