-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.cpp
70 lines (61 loc) · 1.87 KB
/
Main.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
60
61
62
63
64
65
66
67
68
#include <iostream>
#include <stdlib.h>
#include <vector>
#include <deque>
#include <math.h>
#include <unordered_set>
#include <algorithm>
#include "headers/ManhattanDistance.h"
#include "headers/StateManager.h"
#include "headers/Node.h"
#include "headers/Result.h"
#include "headers/Input.h"
#include "headers/Input.h"
#include "headers/algorithms/BFS.h"
#include "headers/algorithms/GreedyBestFirstSearch.h"
#include "headers/algorithms/AStar.h"
#include "headers/algorithms/IDFS.h"
#include "headers/algorithms/IDAStar.h"
#include <ctime>
using namespace std;
Result processAlgorithm(int algorithmId, PackedState initialState) {
switch (algorithmId) {
case InputReader::BFS_ID:
return BFS().execute(initialState);
case InputReader::GREEDY_ID:
return GreedyBestFirstSearch().execute(initialState);
case InputReader::ASTAR_ID:
return AStar().execute(initialState);
case InputReader::IDFS_ID:
return IDFS().execute(initialState);
case InputReader::IDASTAR_ID:
return IDAStar().execute(initialState);
}
}
string currentTime(){
time_t now = time(0);
struct tm tstruct;
char buf[80];
tstruct = *localtime(&now);
strftime(buf, sizeof(buf), "%d-%m-%Y-%H", &tstruct);
string str(buf);
for(int i = 0; i < str.length(); i++){
if(str.at(i) == ':')
str.at(i) = '_';
}
return str;
}
int main(int argc, char** argv)
{
StateManager manager;
InputReader reader;
Input input = reader.parseInput(argc, argv);
string fileName = currentTime() + argv[1] + ".csv";
for (auto unpackedState : input.states) {
PackedState state = manager.pack(unpackedState);
Result result = processAlgorithm(input.algorithm, state);
result.printResult();
result.writeResult(fileName);
}
return 0;
}