forked from PathPlanning/AStar-JPS-ThetaStar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mission.cpp
125 lines (112 loc) · 3.57 KB
/
mission.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
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
120
121
122
123
124
125
#include "mission.h"
#include "astar.h"
#include "bfs.h"
#include "dijkstra.h"
#include "theta.h"
#include "xmllogger.h"
#include "gl_const.h"
Mission::Mission()
{
logger = nullptr;
search = nullptr;
fileName = nullptr;
}
Mission::Mission(const char *FileName)
{
fileName = FileName;
logger = nullptr;
search = nullptr;
}
Mission::~Mission()
{
if (logger)
delete logger;
if (search)
delete search;
}
bool Mission::getMap()
{
return map.getMap(fileName);
}
bool Mission::getConfig()
{
return config.getConfig(fileName);
}
bool Mission::createLog()
{
if (logger != NULL) delete logger;
logger = new XmlLogger(config.LogParams[CN_LP_LEVEL]);
return logger->getLog(fileName, config.LogParams);
}
void Mission::createEnvironmentOptions()
{
if (config.SearchParams[CN_SP_ST] == CN_SP_ST_BFS || config.SearchParams[CN_SP_ST] == CN_SP_ST_DIJK)
options = EnvironmentOptions(config.SearchParams[CN_SP_AS], config.SearchParams[CN_SP_AD],
config.SearchParams[CN_SP_CC]);
else
options = EnvironmentOptions(config.SearchParams[CN_SP_AS], config.SearchParams[CN_SP_AD],
config.SearchParams[CN_SP_CC], config.SearchParams[CN_SP_MT]);
}
void Mission::createSearch()
{
if (search)
delete search;
if (config.SearchParams[CN_SP_ST] == CN_SP_ST_BFS)
search = new BFS();
else if (config.SearchParams[CN_SP_ST] == CN_SP_ST_DIJK)
search = new Dijkstra();
else if (config.SearchParams[CN_SP_ST] == CN_SP_ST_ASTAR)
search = new Astar(config.SearchParams[CN_SP_HW], config.SearchParams[CN_SP_BT]);
else if (config.SearchParams[CN_SP_ST] == CN_SP_ST_JP_SEARCH)
search = new JP_Search(config.SearchParams[CN_SP_HW], config.SearchParams[CN_SP_BT]);
else if (config.SearchParams[CN_SP_ST] == CN_SP_ST_TH)
search = new Theta(config.SearchParams[CN_SP_HW], config.SearchParams[CN_SP_BT]);
}
void Mission::startSearch()
{
sr = search->startSearch(logger, map, options);
if (config.SearchParams[CN_SP_PS])
{
smooth_search_result(sr, map, options.cutcorners);
}
}
void Mission::printSearchResultsToConsole()
{
std::cout << "Path ";
if (!sr.pathfound)
std::cout << "NOT ";
std::cout << "found!" << std::endl;
std::cout << "numberofsteps=" << sr.numberofsteps << std::endl;
std::cout << "nodescreated=" << sr.nodescreated << std::endl;
if (sr.pathfound) {
std::cout << "pathlength=" << sr.pathlength << std::endl;
std::cout << "pathlength_scaled=" << sr.pathlength * map.cellSize << std::endl;
}
std::cout << "time=" << sr.time << std::endl;
}
void Mission::saveSearchResultsToLog()
{
logger->writeToLogSummary(sr.numberofsteps, sr.nodescreated, sr.pathlength, sr.time, map.cellSize);
if (sr.pathfound) {
logger->writeToLogPath(*sr.lppath);
logger->writeToLogHPpath(*sr.hppath);
logger->writeToLogMap(map, *sr.lppath);
} else
logger->writeToLogNotFound();
logger->saveLog();
}
const char *Mission::getAlgorithmName()
{
if (config.SearchParams[CN_SP_ST] == CN_SP_ST_ASTAR)
return CNS_SP_ST_ASTAR;
else if (config.SearchParams[CN_SP_ST] == CN_SP_ST_DIJK)
return CNS_SP_ST_DIJK;
else if (config.SearchParams[CN_SP_ST] == CN_SP_ST_BFS)
return CNS_SP_ST_BFS;
else if (config.SearchParams[CN_SP_ST] == CN_SP_ST_JP_SEARCH)
return CNS_SP_ST_JP_SEARCH;
else if (config.SearchParams[CN_SP_ST] == CN_SP_ST_TH)
return CNS_SP_ST_TH;
else
return "";
}