Skip to content

Commit 5979a27

Browse files
committedSep 21, 2020
added tests for pq_dj
1 parent 0aa6515 commit 5979a27

File tree

15 files changed

+157593
-207
lines changed

15 files changed

+157593
-207
lines changed
 

‎app

-4.34 KB
Binary file not shown.

‎arena/arena.hpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,27 @@
77

88
using namespace std;
99

10+
// arena_type represents different types of datasets
11+
// that the algorithm will be tested on.
1012
enum arena_type {
1113
ARENA_CUSTOM,
1214
ARENA_MOVING_AI
1315
};
1416

17+
// arena is a a simple parser for different dataset types.
18+
// it is the outside world for a robot for simulation.
1519
class arena {
1620
private:
1721
cell_type** graph;
1822
void parse_custom(string& filepath);
1923
void parse_movingai(string& scenepath, string& root, int test_index);
2024

2125
public:
26+
int bucket; // bucket is a group of tests for the same map
2227
cell start;
2328
cell destination;
2429
int width;
2530
int height;
26-
int bucket;
2731

2832
arena();
2933
arena(string& filepath, arena_type map_type);

‎cell/cell.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ enum cell_type {
88
BLOCK
99
};
1010

11+
// cell is a single point in the grid environment
1112
class cell {
1213
public:
1314
int row;

‎documentation/arena.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
11
# Arena
22

3-
#### arena_custom
3+
### enum arena_type
4+
This is for identifying format of dataset. `arena` uses it to handle various parsing functions.
5+
6+
#### class arena
7+
This class represents the environment robot is moving it.
8+
Robot is supposed to read environment and update its own memory and
9+
not change arena's values. It uses `string_tokenizer` to parse map dataset files.
410

511
**Properties**
612
| Name | Data Type | Description |
713
| ------------- | ------------- | ------------- |
14+
| bucket | int | group index of tests. a group represent tests for the same map |
815
| graph | cell_type** | store grid cells as 2d array |
916
| start | cell | start point of robot for testing |
1017
| destination | cell | goal of robot for testing |
1118
| width | int | no. of columns in graph |
1219
| height | int | no. of rows in graph |
20+
21+
**Methods**
22+
| Name | Return | Params | Description |
23+
| ------------- | ------------- | ------------- | ------------- |
24+
| parse_custom | void | filepath | filepath is the map file to parse and it must be relative to root of this repository |
25+
| parse_movingai | void | scenepath | test |

‎main/main_custom.cpp

+60-53
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ const int ALPHA = 10;
1616
const string TEST_PATH_PREFIX = "tests/grids/custom_random/maps_250x250/alpha10/";
1717
const string MAP_PATH_PREFIX = "datasets/grids/custom_random/maps_250x250/sample";
1818

19-
// void print_path(int &path_length, vector<cell> &path) {
20-
// cout << path_length << '\n';
21-
// for(int i=path.size()-1;i>=0;i--)
22-
// cout << path[i].col << " " << path[i].row << '\n';
23-
// }
19+
void print_path(int &path_length, vector<cell> &path) {
20+
cout << path_length << '\n';
21+
for(int i=path.size()-1;i>=0;i--)
22+
cout << path[i].col << " " << path[i].row << '\n';
23+
}
2424

2525
void solve_map_dijkstra(string input_path, ofstream &output_file) {
2626
arena env = arena(input_path, ARENA_CUSTOM);
@@ -147,6 +147,7 @@ int main() {
147147
string output_path;
148148
ofstream output_file;
149149

150+
// A*
150151
output_path = TEST_PATH_PREFIX + "a_star.csv";
151152
output_file.open(output_path);
152153
output_file << "Map Label, Path Length, Time (ms)\n";
@@ -157,55 +158,61 @@ int main() {
157158
output_file.flush();
158159
output_file.close();
159160

160-
// output_path = TEST_PATH_PREFIX + "a_star_segmented.csv";
161-
// output_file.open(output_path);
162-
// output_file << "Map Label, Path Length, Time (ms)\n";
163-
// for(int i=0;i<1000;i++) {
164-
// string input_path = MAP_PATH_PREFIX + to_string(i);
165-
// solve_map_astar_segmented(input_path, output_file);
166-
// }
167-
// output_file.flush();
168-
// output_file.close();
169-
170-
// output_path = "tests/dijkstra.csv";
171-
// output_file.open(output_path);
172-
// output_file << "Map Label, Path Length, Time (ms)\n";
173-
// for(int i=0;i<1000;i++) {
174-
// string input_path = MAP_PATH_PREFIX + to_string(i);
175-
// solve_map_dijkstra(input_path, output_file);
176-
// }
177-
// output_file.flush();
178-
// output_file.close();
161+
// A* Segmented
162+
output_path = TEST_PATH_PREFIX + "a_star_segmented.csv";
163+
output_file.open(output_path);
164+
output_file << "Map Label, Path Length, Time (ms)\n";
165+
for(int i=0;i<1000;i++) {
166+
string input_path = MAP_PATH_PREFIX + to_string(i);
167+
solve_map_astar_segmented(input_path, output_file);
168+
}
169+
output_file.flush();
170+
output_file.close();
171+
172+
173+
// Dijkstra
174+
output_path = TEST_PATH_PREFIX + "dijkstra.csv";
175+
output_file.open(output_path);
176+
output_file << "Map Label, Path Length, Time (ms)\n";
177+
for(int i=0;i<1000;i++) {
178+
string input_path = MAP_PATH_PREFIX + to_string(i);
179+
solve_map_dijkstra(input_path, output_file);
180+
}
181+
output_file.flush();
182+
output_file.close();
179183

180-
// output_path = TEST_PATH_PREFIX + "dijkstra_segmented.csv";
181-
// output_file.open(output_path);
182-
// output_file << "Map Label, Path Length, Time (ms)\n";
183-
// for(int i=0;i<1000;i++) {
184-
// string input_path = MAP_PATH_PREFIX + to_string(i);
185-
// solve_map_dijkstra_segmented(input_path, output_file);
186-
// }
187-
// output_file.flush();
188-
// output_file.close();
189-
190-
// output_path = TEST_PATH_PREFIX + "pq_dijkstra.csv";
191-
// output_file.open(output_path);
192-
// output_file << "Map Label, Path Length, Time (ms)\n";
193-
// for(int i=0;i<1000;i++) {
194-
// string input_path = MAP_PATH_PREFIX + to_string(i);
195-
// solve_map_pqdj(input_path, output_file);
196-
// }
197-
// output_file.flush();
198-
// output_file.close();
199-
200-
// output_path = TEST_PATH_PREFIX + "pq_dijkstra_segmented.csv";
201-
// output_file.open(output_path);
202-
// output_file << "Map Label, Path Length, Time (ms)\n";
203-
// for(int i=0;i<1000;i++) {
204-
// string input_path = MAP_PATH_PREFIX + to_string(i);
205-
// solve_map_pqdj_segmented(input_path, output_file);
206-
// }
207-
// output_file.flush();
208-
// output_file.close();
184+
// Dijkstra Segmented
185+
output_path = TEST_PATH_PREFIX + "dijkstra_segmented.csv";
186+
output_file.open(output_path);
187+
output_file << "Map Label, Path Length, Time (ms)\n";
188+
for(int i=0;i<1000;i++) {
189+
string input_path = MAP_PATH_PREFIX + to_string(i);
190+
solve_map_dijkstra_segmented(input_path, output_file);
191+
}
192+
output_file.flush();
193+
output_file.close();
194+
195+
// Priority Queue based Dijkstra
196+
output_path = TEST_PATH_PREFIX + "pq_dijkstra.csv";
197+
output_file.open(output_path);
198+
output_file << "Map Label, Path Length, Time (ms)\n";
199+
for(int i=0;i<1000;i++) {
200+
string input_path = MAP_PATH_PREFIX + to_string(i);
201+
solve_map_pqdj(input_path, output_file);
202+
}
203+
output_file.flush();
204+
output_file.close();
205+
206+
// Priority Queue Based Dijkstra Segmented
207+
output_path = TEST_PATH_PREFIX + "pq_dijkstra_segmented.csv";
208+
output_file.open(output_path);
209+
output_file << "Map Label, Path Length, Time (ms)\n";
210+
for(int i=0;i<1000;i++) {
211+
string input_path = MAP_PATH_PREFIX + to_string(i);
212+
solve_map_pqdj_segmented(input_path, output_file);
213+
}
214+
output_file.flush();
215+
output_file.close();
209216

210217
return 0;
211218
}

‎main/main_moving_ai.cpp

+55-55
Original file line numberDiff line numberDiff line change
@@ -338,43 +338,55 @@ int main(int argc, char *argv[]) {
338338
string output_path;
339339
ofstream output_file;
340340

341-
// // A Star
342-
// output_path = TEST_PATH_PREFIX + "a_star.csv";
343-
// output_file.open(output_path);
344-
// output_file << "Bucket, Map Name, Path Length, Time(ms)" << endl;
345-
// for(int i=0;i<156;i++) {
346-
// string map = scene_list[i];
347-
// string scenepath = SCENE_PATH_PREFIX + map;
348-
// solve_map_astar(scenepath, application, map, output_file);
349-
// }
350-
// output_file.flush();
351-
// output_file.close();
341+
// A Star
342+
output_path = TEST_PATH_PREFIX + "a_star.csv";
343+
output_file.open(output_path);
344+
output_file << "Bucket, Map Name, Path Length, Time(ms)" << endl;
345+
for(int i=0;i<156;i++) {
346+
string map = scene_list[i];
347+
string scenepath = SCENE_PATH_PREFIX + map;
348+
solve_map_astar(scenepath, application, map, output_file);
349+
}
350+
output_file.flush();
351+
output_file.close();
352352

353353
// A Star Segmented
354-
// output_path = TEST_PATH_PREFIX + "a_star_segmented.csv";
355-
// output_file.open(output_path);
356-
// output_file << "Bucket, Map Name, Path Length, Time(ms)" << endl;
357-
// for(int i=0;i<156;i++) {
358-
// string map = scene_list[i];
359-
// string scenepath = SCENE_PATH_PREFIX + map;
360-
// solve_map_astar_segmented(scenepath, application, map, output_file);
361-
// }
362-
// output_file.flush();
363-
// output_file.close();
354+
output_path = TEST_PATH_PREFIX + "a_star_segmented.csv";
355+
output_file.open(output_path);
356+
output_file << "Bucket, Map Name, Path Length, Time(ms)" << endl;
357+
for(int i=0;i<156;i++) {
358+
string map = scene_list[i];
359+
string scenepath = SCENE_PATH_PREFIX + map;
360+
solve_map_astar_segmented(scenepath, application, map, output_file);
361+
}
362+
output_file.flush();
363+
output_file.close();
364+
365+
// Dijkstra
366+
output_path = TEST_PATH_PREFIX + "dijkstra.csv";
367+
output_file.open(output_path);
368+
output_file << "Bucket, Map Name, Path Length, Time(ms)" << endl;
369+
for(int i=0;i<156;i++) {
370+
string map = scene_list[i];
371+
string scenepath = SCENE_PATH_PREFIX + map;
372+
solve_map_dijkstra(scenepath, application, map, output_file);
373+
}
374+
output_file.flush();
375+
output_file.close();
364376

365377
// Dijkstra Segmented
366-
// output_path = TEST_PATH_PREFIX + "dijkstra_segmented.csv";
367-
// output_file.open(output_path);
368-
// output_file << "Bucket, Map Name, Path Length, Time(ms)" << endl;
369-
// for(int i=0;i<156;i++) {
370-
// string map = scene_list[i];
371-
// string scenepath = SCENE_PATH_PREFIX + map;
372-
// solve_map_dijkstra_segmented(scenepath, application, map, output_file);
373-
// }
374-
// output_file.flush();
375-
// output_file.close();
376-
377-
// // Priority Queue based Dijkstra
378+
output_path = TEST_PATH_PREFIX + "dijkstra_segmented.csv";
379+
output_file.open(output_path);
380+
output_file << "Bucket, Map Name, Path Length, Time(ms)" << endl;
381+
for(int i=0;i<156;i++) {
382+
string map = scene_list[i];
383+
string scenepath = SCENE_PATH_PREFIX + map;
384+
solve_map_dijkstra_segmented(scenepath, application, map, output_file);
385+
}
386+
output_file.flush();
387+
output_file.close();
388+
389+
// Priority Queue based Dijkstra
378390
output_path = TEST_PATH_PREFIX + "pq_dijkstra.csv";
379391
output_file.open(output_path);
380392
output_file << "Bucket, Map Name, Path Length, Time(ms)" << endl;
@@ -387,28 +399,16 @@ int main(int argc, char *argv[]) {
387399
output_file.close();
388400

389401
// Priority Queue based Dijkstra Segmented
390-
// output_path = TEST_PATH_PREFIX + "pq_dijkstra_segmented_0.csv";
391-
// output_file.open(output_path);
392-
// output_file << "Bucket, Map Name, Path Length, Time(ms)" << endl;
393-
// for(int i=0;i<156;i++) {
394-
// string map = scene_list[i];
395-
// string scenepath = SCENE_PATH_PREFIX + map;
396-
// solve_map_pqdj_segmented(scenepath, application, map, output_file);
397-
// }
398-
// output_file.flush();
399-
// output_file.close();
400-
401-
// Dijkstra
402-
// output_path = TEST_PATH_PREFIX + "dijkstra.csv";
403-
// output_file.open(output_path);
404-
// output_file << "Bucket, Map Name, Path Length, Time(ms)" << endl;
405-
// for(int i=0;i<156;i++) {
406-
// string map = scene_list[i];
407-
// string scenepath = SCENE_PATH_PREFIX + map;
408-
// solve_map_dijkstra(scenepath, application, map, output_file);
409-
// }
410-
// output_file.flush();
411-
// output_file.close();
402+
output_path = TEST_PATH_PREFIX + "pq_dijkstra_segmented_0.csv";
403+
output_file.open(output_path);
404+
output_file << "Bucket, Map Name, Path Length, Time(ms)" << endl;
405+
for(int i=0;i<156;i++) {
406+
string map = scene_list[i];
407+
string scenepath = SCENE_PATH_PREFIX + map;
408+
solve_map_pqdj_segmented(scenepath, application, map, output_file);
409+
}
410+
output_file.flush();
411+
output_file.close();
412412

413413
return 0;
414414
}

0 commit comments

Comments
 (0)
Please sign in to comment.