-
Notifications
You must be signed in to change notification settings - Fork 40
/
mission.cpp
92 lines (79 loc) · 2.11 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
#include"mission.h"
Mission::Mission()
{
m_pSearch = nullptr;
m_pLogger = nullptr;
}
Mission::~Mission()
{
delete m_pSearch;
delete m_pLogger;
}
void Mission::setFileNames(const char *taskName, const char *mapName, const char *configName, const char *obstaclesName)
{
this->mapName = mapName;
this->taskName = taskName;
this->configName = configName;
this->obstaclesName = obstaclesName;
}
bool Mission::getMap()
{
return m_map.getMap(mapName);
}
bool Mission::getTask()
{
return (m_task.getTask(taskName) && m_task.validateTask(m_map));
}
bool Mission::getConfig()
{
return m_config.getConfig(configName);
}
bool Mission::getObstacles()
{
if(obstaclesName)
return m_obstacles.getObstacles(obstaclesName);
else
return false;
}
void Mission::createSearch()
{
if(m_pSearch)
{
delete m_pSearch;
delete m_pLogger;
}
m_pSearch = new AA_SIPP(m_config);
}
void Mission::createLog()
{
if(m_config.loglevel != CN_LOGLVL_NO)
{
m_pLogger = new XmlLogger(m_config.loglevel);
m_pLogger->createLog(taskName);
}
}
void Mission::startSearch()
{
//std::cout<<"SEARCH STARTED\n";
sr = m_pSearch->startSearch(m_map, m_task, m_obstacles);
}
void Mission::printSearchResultsToConsole()
{
//std::cout<<bool(sr.agentsSolved/sr.agents)<<" "<<sr.time<<" "<<sr.makespan<<" "<<sr.pathlength<<" "<<sr.flowlength<<"\n";
std::cout<<"Results:\nTask solved: "<<bool(sr.agentsSolved/sr.agents)<<"\nTries: "<<sr.tries<<"\nRuntime: "<<sr.runtime<<"\nAgents solved: "<<sr.agentsSolved<<" ("<<(float)sr.agentsSolved*100/sr.agents<<"%)\nFlowtime: "<<sr.flowtime<<"\nMakespan: "<<sr.makespan<<"\n";
}
void Mission::saveSearchResultsToLog()
{
if(m_config.loglevel == CN_LOGLVL_NO)
return;
std::cout<<"LOG STARTED\n";
m_pLogger->writeToLogInput(taskName, mapName, configName, obstaclesName);
m_pLogger->writeToLogSummary(sr);
if(sr.pathfound)
{
m_pLogger->writeToLogMap(m_map, sr);
m_pLogger->writeToLogPath(sr, m_task, m_config);
}
m_pLogger->saveLog();
std::cout<<"LOG SAVED\n";
}