-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
119 lines (111 loc) · 4.56 KB
/
Copy pathmain.cpp
File metadata and controls
119 lines (111 loc) · 4.56 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include "sliding_puzzle.hpp"
#include "path_finding.hpp"
#include "astar.hpp"
#include "cafe.hpp"
#include "kbfs.hpp"
#include "spastar.hpp"
#include <iostream>
#include <getopt.h>
template <typename State>
void print_path(const std::vector<State>& path) {
for (const auto& state : path) {
std::clog << state << std::endl;
}
}
int main(int argc, char* argv[]) {
int c;
std::string algorithmChoice = "astar"; // Default algorithm
std::string problem = "tiles"; // Default problem
size_t extraExpansionTime = 0; // Default extra expansion time
size_t threadCount = 1; // Default thread count
static struct option long_options[] =
{
{"algorithm", required_argument, 0, 'a'},
{"problem", required_argument, 0, 'p'},
{"extra-expansion-time", required_argument, 0, 'e'},
{"threads", required_argument, 0, 't'},
{0, 0, 0, 0}
};
int option_index = 0;
while ((c = getopt_long(argc, argv, "a:p:e:t:", long_options, &option_index)) != -1) {
switch (c) {
case 'a':
algorithmChoice = optarg;
break;
case 'p':
problem = optarg;
break;
case 'e':
extraExpansionTime = std::stoi(optarg); // Convert string to int
break;
case 't':
threadCount = std::stoi(optarg); // Convert string to int
break;
default:
std::cerr << "Usage: " << argv[0] << " [-a <algorithm>] [-p <problem>] [-e <extra-expansion-time>] [-t <threads>]" << std::endl;
return 1;
}
}
// std::clog << "Algorithm: " << algorithmChoice << std::endl;
std::clog << "Problem: " << problem << std::endl;
// std::clog << "Extra expansion time: " << extraExpansionTime << std::endl;
// std::clog << "Thread count: " << threadCount << std::endl;
if (algorithmChoice == "astar") {
if (problem == "tiles") {
using namespace SlidingPuzzle;
auto instance = SlidingTileInstance<State>::parseInput(std::cin);
AStar<State> searcher(&instance, extraExpansionTime);
auto path = searcher.findPath();
// print_path(path);
} else if (problem == "path") {
using namespace Pathfinding;
auto instance = PathfindingInstance<State>::parseInput(std::cin);
AStar<State> searcher(&instance, extraExpansionTime);
auto path = searcher.findPath();
// print_path(path);
}
} else if (algorithmChoice == "cafe") {
if (problem == "tiles") {
using namespace SlidingPuzzle;
auto instance = SlidingTileInstance<State>::parseInput(std::cin);
CAFE<State> searcher(&instance, extraExpansionTime, threadCount);
auto path = searcher.findPath();
// print_path(path);
} else if (problem == "path") {
using namespace Pathfinding;
auto instance = PathfindingInstance<State>::parseInput(std::cin);
CAFE<State> searcher(&instance, extraExpansionTime, threadCount);
auto path = searcher.findPath();
// print_path(path);
}
} else if (algorithmChoice == "kbfs") {
if (problem == "tiles") {
using namespace SlidingPuzzle;
auto instance = SlidingTileInstance<State>::parseInput(std::cin);
KBFS<State> searcher(&instance, extraExpansionTime, threadCount);
auto path = searcher.findPath();
// print_path(path);
} else if (problem == "path") {
using namespace Pathfinding;
auto instance = PathfindingInstance<State>::parseInput(std::cin);
KBFS<State> searcher(&instance, extraExpansionTime, threadCount);
auto path = searcher.findPath();
// print_path(path);
}
} else if (algorithmChoice == "spastar") {
if (problem == "tiles") {
using namespace SlidingPuzzle;
auto instance = SlidingTileInstance<State>::parseInput(std::cin);
SPAStar<State> searcher(&instance, extraExpansionTime, threadCount);
auto path = searcher.findPath();
// print_path(path);
} else if (problem == "path") {
using namespace Pathfinding;
auto instance = PathfindingInstance<State>::parseInput(std::cin);
SPAStar<State> searcher(&instance, extraExpansionTime, threadCount);
auto path = searcher.findPath();
// print_path(path);
}
}
return 0;
}