9 #ifndef WeightedVertexGraph_h
10 #define WeightedVertexGraph_h
18 template <
class state,
class action,
class environment>
38 std::vector<state>
path;
51 printf(
"No necessary expansions\n");
59 auto i2 =
m_f.find(i.g);
79 printf(
"No forward item\n");
87 auto i2 =
m_b.find(i.g);
107 printf(
"No backward item\n");
111 for (
auto i =
m_f.begin(); i !=
m_f.end(); i++)
117 for (
auto i =
m_b.begin(); i !=
m_b.end(); i++)
131 auto fi =
m_f.begin();
132 auto bi =
m_b.rbegin();
146 if (bi ==
m_b.rend())
148 }
while (fi->first+bi->first >
optCost);
149 if (bi ==
m_b.rend())
160 while (bi !=
m_b.rend())
170 if (fi->first+(tmp)->first >=
optCost)
183 if (bi ==
m_b.rend())
205 printf(
"Forward/Backward/Min: %d %d %d %s\n", forwardCopy, backwardCopy,
totalWork,
229 return m_f.rbegin()->first;
240 return m_b.rbegin()->first;
251 const int kLRMargin = 150;
252 const int kTopMargin = 75;
253 const int kBottomMargin = 50;
255 const int kCountTextSize = 25;
256 const int kInstanceTextSize = 20;
257 const int kStatsTextSize = 20;
258 const int kNodeGSize = 30;
260 const int kNodeRadius = 25;
261 const int kNodeGap = 75;
262 const int epsilon = 0;
265 if (eshed)
height += kNodeGap;
272 s =
"<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width = \""+std::to_string(
width)+
"\" height = \""+std::to_string(
height)+
"\" ";
273 s +=
"preserveAspectRatio = \"none\" ";
284 for (
auto i =
m_f.begin(); i !=
m_f.end(); i++)
290 int bcnt =
m_b.size()-1;
291 bool drewBest =
false;
292 for (
auto j =
m_b.rbegin(); j !=
m_b.rend(); j++)
300 if (
fless(i->first + j->first+epsilon,
optCost) && j->second != 0)
338 double p1x, p1y, p2x, p2y;
340 p1y = kTopMargin+kNodeGap*fcnt;
341 p2x =
width-kLRMargin;
345 p2y =
height-kNodeGap*bcnt-kBottomMargin;
348 p2y = kTopMargin+kNodeGap*bcnt;
350 double length = sqrt((p1x-p2x)*(p1x-p2x)+(p1y-p2y)*(p1y-p2y));
351 double scale = (1.5*kNodeRadius)/length;
367 for (
auto i =
m_f.begin(); i !=
m_f.end(); i++)
374 std::string tmp = std::to_string((
int)i->first);
396 for (
auto i =
m_b.begin(); i !=
m_b.end(); i++)
403 std::string tmp = std::to_string((
int)i->first);
405 int loc = kTopMargin+kNodeGap*cnt;
440 std::stringstream tmp;
441 tmp <<
"Start: " <<
start;
444 tmp <<
"Goal: " <<
goal;
447 s +=
SVGDrawText(kLRMargin, kTopMargin-2*kNodeRadius,
"g<tspan dy =\"15\">F</tspan>",
Colors::black, kCountTextSize);
452 std::fstream svgFile;
453 svgFile.open(filename, std::fstream::out | std::fstream::trunc);
457 printf(
"Generated SVG '%s'\n", filename);
461 void SaveSVG(
const char *filename,
int groupSize)
465 int localHeight = 75*(
std::max(
m_f.size(),
m_b.size())+groupSize-1)/groupSize+50;
466 int localWidth = localHeight*0.5;
469 s =
"<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width = \""+std::to_string(localWidth)+
"\" height = \""+std::to_string(localHeight)+
"\" ";
470 s +=
"preserveAspectRatio = \"none\" ";
474 int lastF = -1, lastB = -1;
475 for (
auto i =
m_f.begin(); i !=
m_f.end(); i++)
479 int bcnt =
m_b.size()-1;
480 for (
auto j =
m_b.rbegin(); j !=
m_b.rend(); j++)
486 if (
fless(i->first + j->first,
optCost) && j->second != 0)
488 if (fcnt/groupSize != lastF && bcnt/groupSize != lastB)
491 lastF = fcnt/groupSize;
492 lastB = bcnt/groupSize;
501 if (fcnt/groupSize != lastF && bcnt/groupSize != lastB)
504 lastF = fcnt/groupSize;
505 lastB = bcnt/groupSize;
518 for (
auto i =
m_f.begin(); i !=
m_f.end(); i++)
520 if (cnt%groupSize == 0)
529 std::string tmp = std::to_string((
int)i->first);
534 if (cnt%groupSize == groupSize-1)
536 std::string tmp = std::to_string((
int)nodes);
541 if (cnt%groupSize != 0)
543 std::string tmp = std::to_string((
int)nodes);
548 for (
auto i =
m_b.begin(); i !=
m_b.end(); i++)
550 if (cnt%groupSize == 0)
559 std::string tmp = std::to_string((
int)i->first);
564 if (cnt%groupSize == groupSize-1)
566 std::string tmp = std::to_string((
int)nodes);
571 if (cnt%groupSize != 0)
573 std::string tmp = std::to_string((
int)nodes);
591 std::stringstream tmp;
592 tmp <<
"Start: " <<
start;
595 tmp <<
"Goal: " <<
goal;
603 std::fstream svgFile;
604 svgFile.open(filename, std::fstream::out | std::fstream::trunc);
608 printf(
"Generated SVG '%s'\n", filename);