-
Notifications
You must be signed in to change notification settings - Fork 1
/
mission.cpp
137 lines (123 loc) · 3.6 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
126
127
128
129
130
131
132
133
134
135
136
137
#include "mission.h"
#include "astar.h"
#include "dijkstra.h"
#include "xmllogger.h"
#include "gl_const.h"
#include <iostream>
#include "FakeMap.h"
Mission::Mission()
{
logger = nullptr;
search = nullptr;
fileName = nullptr;
map = nullptr;
maptype = 0;
}
Mission::Mission(const char *FileName, int maptype)
{
fileName = FileName;
logger = nullptr;
search = nullptr;
map = nullptr;
this->maptype = maptype;
}
Mission::~Mission()
{
if (logger)
delete logger;
if (search)
delete search;
if(map)
delete map;
}
bool Mission::getMap()
{
if(maptype == 0)
{
map = new Map();
}
else if(maptype == 1)
{
map = new FakeMap();
}
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;
}
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]);
}
search->CreateOpen(config.OpenStructure[CN_OS_OT], config.OpenStructure[CN_OS_OD], *map);
}
void Mission::startSearch()
{
sr = search->startSearch(logger, *map, options);
}
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->getCellSize() << std::endl;
}
std::cout << "time=" << sr.time << std::endl;
}
void Mission::saveSearchResultsToLog()
{
logger->writeToLogSummary(sr.numberofsteps, sr.nodescreated, sr.pathlength, sr.time, map->getCellSize());
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 "";
}