Skip to content

Commit 13ceaa3

Browse files
author
Anton Andreychuk
committed
Input/Output fixes
1 parent b5921ff commit 13ceaa3

11 files changed

Lines changed: 170 additions & 161 deletions

File tree

CBS-SIPP.pro

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ CONFIG += console c++11
33
CONFIG -= app_bundle
44
CONFIG -= qt
55
TARGET = CCBS
6-
INCLUDEPATH += D:/boost_1_73_0
76
win32 {
87
QMAKE_LFLAGS += -static -static-libgcc -static-libstdc++
98
}

Examples/config.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" ?>
2+
<root>
3+
<algorithm>
4+
<use_cardinal>true</use_cardinal>
5+
<use_disjoint_splitting>true</use_disjoint_splitting>
6+
<hlh_type>2</hlh_type>
7+
<connectedness>3</connectedness>
8+
<focal_weight>1.0</focal_weight>
9+
<agent_size>0.353553</agent_size>
10+
<timelimit>30</timelimit>
11+
<precision>0.0000001</precision>
12+
</algorithm>
13+
</root>

Examples/task_log.xml

Lines changed: 83 additions & 103 deletions
Large diffs are not rendered by default.

cbs.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,11 @@ Constraint CBS::get_wait_constraint(int agent, Move move1, Move move2)
134134
return Constraint(agent, interval.first, interval.second, move1.id1, move1.id2);
135135
}
136136

137-
double CBS::get_hl_heuristic(const std::list<Conflict> &conflicts, bool simplex)
137+
double CBS::get_hl_heuristic(const std::list<Conflict> &conflicts)
138138
{
139-
if(conflicts.empty() || CN_HLH_TYPE == 0)
139+
if(conflicts.empty() || config.hlh_type == 0)
140140
return 0;
141-
else if (CN_HLH_TYPE == 1 || simplex)
141+
else if (config.hlh_type == 1)
142142
{
143143
optimization::Simplex simplex("simplex");
144144
std::map<int, int> colliding_agents;
@@ -265,8 +265,6 @@ Solution CBS::find_solution(const Map &map, const Task &task, const Config &cfg)
265265
int low_level_searches(0);
266266
int low_level_expanded(0);
267267
int id = 2;
268-
double lp_h(0), dac_h(0);
269-
int equal_h, total_h;
270268
do
271269
{
272270
auto parent = tree.get_front();
@@ -332,7 +330,7 @@ Solution CBS::find_solution(const Map &map, const Task &task, const Config &cfg)
332330
Constraint positive;
333331
bool inserted = false;
334332
bool left_ok = true, right_ok = true;
335-
if(CN_USE_DS)
333+
if(config.use_disjoint_splitting)
336334
{
337335
int agent1positives(0), agent2positives(0);
338336
for(auto c: constraintsA)

cbs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class CBS
2222
bool check_positive_constraints(std::list<Constraint> constraints, Constraint constraint);
2323
Conflict check_paths(const sPath &pathA, const sPath &pathB);
2424
bool check_conflict(Move move1, Move move2);
25-
double get_hl_heuristic(const std::list<Conflict> &conflicts, bool simplex = false);
25+
double get_hl_heuristic(const std::list<Conflict> &conflicts);
2626
std::vector<Conflict> get_all_conflicts(const std::vector<sPath> &paths, int id);
2727
Constraint get_constraint(int agent, Move move1, Move move2);
2828
Constraint get_wait_constraint(int agent, Move move1, Move move2);

config.cpp

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void Config::getConfig(const char *fileName)
6868
{
6969
use_cardinal = true;
7070
}
71-
if(value.compare("false") == 0 || value.compare("0") == 0)
71+
else if(value.compare("false") == 0 || value.compare("0") == 0)
7272
{
7373
use_cardinal = false;
7474
}
@@ -78,30 +78,28 @@ void Config::getConfig(const char *fileName)
7878
use_cardinal = CN_USE_CARDINAL;
7979
}
8080
}
81-
if(use_cardinal == true)
81+
82+
element = algorithm->FirstChildElement("use_disjoint_splitting");
83+
if (!element)
84+
{
85+
std::cout << "Error! No 'use_disjoint_splitting' element found inside '"<<CNS_TAG_ALGORITHM<<"' section. It's compared to '"<<CN_USE_DS<<"'."<<std::endl;
86+
use_disjoint_splitting = CN_USE_DS;
87+
}
88+
else
8289
{
83-
element = algorithm->FirstChildElement("cache_paths");
84-
if (!element)
90+
std::string value = element->GetText();
91+
if(value.compare("true") == 0 || value.compare("1") == 0)
92+
{
93+
use_disjoint_splitting = true;
94+
}
95+
else if(value.compare("false") == 0 || value.compare("0") == 0)
8596
{
86-
std::cout << "Error! No 'cache_paths' element found inside '"<<CNS_TAG_ALGORITHM<<"' section. It's compared to '"<<CN_CACHE_PATHS<<"'."<<std::endl;
87-
use_cardinal = CN_CACHE_PATHS;
97+
use_disjoint_splitting = false;
8898
}
8999
else
90100
{
91-
std::string value = element->GetText();
92-
if(value.compare("true") == 0 || value.compare("1") == 0)
93-
{
94-
cache_paths = true;
95-
}
96-
if(value.compare("false") == 0 || value.compare("0") == 0)
97-
{
98-
cache_paths = false;
99-
}
100-
else
101-
{
102-
std::cout << "Error! Wrong 'cache_paths' value found inside '"<<CNS_TAG_ALGORITHM<<"' section. It's compared to '"<<CN_CACHE_PATHS<<"'."<<std::endl;
103-
cache_paths = CN_CACHE_PATHS;
104-
}
101+
std::cout << "Error! Wrong 'use_disjoint_splitting' element found inside '"<<CNS_TAG_ALGORITHM<<"' section. It's compared to '"<<CN_USE_DS<<"'."<<std::endl;
102+
use_disjoint_splitting = CN_USE_DS;
105103
}
106104
}
107105

@@ -139,7 +137,7 @@ void Config::getConfig(const char *fileName)
139137
if(focal_weight < 1.0)
140138
{
141139
std::cout << "Error! Wrong 'focal_weight' value found inside '"<<CNS_TAG_ALGORITHM<<"' section. It's compared to '"<<CN_FOCAL_WEIGHT<<"'."<<std::endl;
142-
connectdness = CN_CONNECTEDNESS;
140+
focal_weight = CN_FOCAL_WEIGHT;
143141
}
144142
stream.clear();
145143
stream.str("");
@@ -165,6 +163,26 @@ void Config::getConfig(const char *fileName)
165163
stream.str("");
166164
}
167165

166+
element = algorithm->FirstChildElement("hlh_type");
167+
if (!element)
168+
{
169+
std::cout << "Error! No 'hlh_type' element found inside '"<<CNS_TAG_ALGORITHM<<"' section. It's compared to '"<<CN_HLH_TYPE<<"'."<<std::endl;
170+
hlh_type = CN_HLH_TYPE;
171+
}
172+
else
173+
{
174+
auto value = element->GetText();
175+
stream<<value;
176+
stream>>hlh_type;
177+
if(hlh_type < 0 || hlh_type > 2)
178+
{
179+
std::cout << "Error! Wrong 'hlh_type' value found inside '"<<CNS_TAG_ALGORITHM<<"' section. It's compared to '"<<CN_HLH_TYPE<<"'."<<std::endl;
180+
hlh_type = CN_HLH_TYPE;
181+
}
182+
stream.clear();
183+
stream.str("");
184+
}
185+
168186
element = algorithm->FirstChildElement("timelimit");
169187
if (!element)
170188
{

config.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ class Config
1515
double precision;
1616
double focal_weight;
1717
bool use_cardinal;
18-
bool cache_paths;
18+
bool use_disjoint_splitting;
19+
int hlh_type;
1920
int connectdness;
2021
double agent_size;
2122
double timelimit;

const.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
#ifndef CONST_H
22
#define CONST_H
33

4-
#define CN_USE_CARDINAL 1
5-
#define CN_CACHE_PATHS 0
6-
#define CN_HLH_TYPE 0
7-
#define CN_USE_DS 0
4+
#define CN_USE_CARDINAL 0 //1 - true, 0 - false
5+
#define CN_HLH_TYPE 0 // 0 - no hlh, 1 - solve lpp by simplex, 2 - greedly take disjoint conflicts
6+
#define CN_USE_DS 0 //1 - true, 0 - false
87
#define CN_TIMELIMIT 30 // in seconds
98
#define CN_AGENT_SIZE sqrt(2.0)/4.0 //radius; only values in range (0; 0.5] are supported
10-
#define CN_CONNECTEDNESS 2
11-
#define CN_PRECISION 0.00001
12-
#define CN_FOCAL_WEIGHT 1.0
9+
#define CN_CONNECTEDNESS 2 // possible variants 2,3,4,5
10+
#define CN_PRECISION 1e-6
11+
#define CN_FOCAL_WEIGHT 1.0 // experimental function, focal is supported only on the high-level
1312
#define CN_OBSTL 1
1413
#define CN_EPSILON 1e-8
1514
#define CN_INFINITY 1e+8
@@ -50,6 +49,7 @@
5049
#define CNS_TAG_ATTR_NUMOFSTEPS "numberofsteps"
5150
#define CNS_TAG_ATTR_NODESCREATED "totalnodescreated"
5251
#define CNS_TAG_ATTR_LENGTH "length"
52+
#define CNS_TAG_ATTR_DURATION "duration"
5353
#define CNS_TAG_ATTR_PATHLENGTH "pathlength"
5454
#define CNS_TAG_ATTR_TIME "time"
5555
#define CNS_TAG_ATTR_X "x"

main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ int main(int argc, const char *argv[])
2323
CBS cbs;
2424
Solution solution = cbs.find_solution(map, task, config);
2525
XML_logger logger;
26-
std::cout<< "Runtime: "<<solution.time.count() << "\nMakespan: " << solution.makespan << "\nFlowtime:" << solution.flowtime<< "\nInitial Cost: "<<solution.init_cost<< "\nCollision Checking Time: " << solution.check_time
26+
std::cout<< "Runtime: "<<solution.time.count() << "\nMakespan: " << solution.makespan << "\nFlowtime: " << solution.flowtime<< "\nInitial Cost: "<<solution.init_cost<< "\nCollision Checking Time: " << solution.check_time
2727
<< "\nHL expanded: " << solution.high_level_expanded << "\nLL searches: " << solution.low_level_expansions << "\nLL expanded(avg): " << solution.low_level_expanded << std::endl;
2828

2929
logger.get_log(argv[2]);
3030
logger.write_to_log_summary(solution);
31-
logger.write_to_log_path(solution);
31+
logger.write_to_log_path(solution, map);
3232
logger.save_log();
3333
}
3434
else

xml_logger.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ void XML_logger::write_to_log_summary(const Solution &solution)
5959
element->SetAttribute(CNS_TAG_ATTR_MAKESPAN, solution.makespan);
6060
}
6161

62-
void XML_logger::write_to_log_path(const Solution &solution)
62+
void XML_logger::write_to_log_path(const Solution &solution, const Map &map)
6363
{
6464
tinyxml2::XMLElement *element=doc->FirstChildElement(CNS_TAG_ROOT);
6565
element = element->FirstChildElement(CNS_TAG_LOG);
6666

67-
tinyxml2::XMLElement *agent, *path, *hplevel;
67+
tinyxml2::XMLElement *agent, *path;
6868

6969
for(int i = 0; i < int(solution.paths.size()); i++)
7070
{
@@ -73,36 +73,36 @@ void XML_logger::write_to_log_path(const Solution &solution)
7373
element->LinkEndChild(agent);
7474

7575
path = doc->NewElement(CNS_TAG_PATH);
76-
path->SetAttribute(CNS_TAG_ATTR_NUM, i);
77-
path->SetAttribute(CNS_TAG_ATTR_LENGTH, solution.paths[i].cost);
76+
//path->SetAttribute(CNS_TAG_ATTR_NUM, i);
77+
path->SetAttribute(CNS_TAG_ATTR_DURATION, solution.paths[i].cost);
7878
agent->LinkEndChild(path);
7979

80-
hplevel = doc->NewElement(CNS_TAG_HPLEVEL);
81-
path->LinkEndChild(hplevel);
80+
//hplevel = doc->NewElement(CNS_TAG_HPLEVEL);
81+
//path->LinkEndChild(hplevel);
8282
auto iter = solution.paths[i].nodes.begin();
8383
auto it = solution.paths[i].nodes.begin();
8484
int partnumber(0);
8585
tinyxml2::XMLElement *part;
86-
part = doc->NewElement(CNS_TAG_SECTION);
86+
/*part = doc->NewElement(CNS_TAG_SECTION);
8787
part->SetAttribute(CNS_TAG_ATTR_NUM, partnumber);
88-
//part->SetAttribute(CNS_TAG_ATTR_SX, it->j);
89-
//part->SetAttribute(CNS_TAG_ATTR_SY, it->i);
90-
//part->SetAttribute(CNS_TAG_ATTR_FX, iter->j);
91-
//part->SetAttribute(CNS_TAG_ATTR_FY, iter->i);
88+
part->SetAttribute(CNS_TAG_START_I, map.get_i(it->id));
89+
part->SetAttribute(CNS_TAG_START_J, map.get_j(it->id));
90+
part->SetAttribute(CNS_TAG_GOAL_I, map.get_i(iter->id));
91+
part->SetAttribute(CNS_TAG_GOAL_J, map.get_j(iter->id));
9292
part->SetAttribute(CNS_TAG_ATTR_LENGTH, iter->g);
9393
hplevel->LinkEndChild(part);
94-
partnumber++;
94+
partnumber++;*/
9595
while(iter != std::prev(solution.paths[i].nodes.end()))
9696
{
9797
part = doc->NewElement(CNS_TAG_SECTION);
9898
part->SetAttribute(CNS_TAG_ATTR_NUM, partnumber);
99-
// part->SetAttribute(CNS_TAG_ATTR_SX, it->j);
100-
// part->SetAttribute(CNS_TAG_ATTR_SY, it->i);
99+
part->SetAttribute(CNS_TAG_START_I, map.get_i(it->id));
100+
part->SetAttribute(CNS_TAG_START_J, map.get_j(it->id));
101101
iter++;
102-
// part->SetAttribute(CNS_TAG_ATTR_FX, iter->j);
103-
// part->SetAttribute(CNS_TAG_ATTR_FY, iter->i);
104-
part->SetAttribute(CNS_TAG_ATTR_LENGTH, iter->g - it->g);
105-
hplevel->LinkEndChild(part);
102+
part->SetAttribute(CNS_TAG_GOAL_I, map.get_i(iter->id));
103+
part->SetAttribute(CNS_TAG_GOAL_J, map.get_j(iter->id));
104+
part->SetAttribute(CNS_TAG_ATTR_DURATION, iter->g - it->g);
105+
path->LinkEndChild(part);
106106
it++;
107107
partnumber++;
108108
}

0 commit comments

Comments
 (0)