66#include "KoulesConfig.h"
67#include "KoulesSetup.h"
68#include "KoulesStateSpace.h"
69#include <ompl/tools/benchmark/Benchmark.h>
70#include <ompl/config.h>
71#include <boost/program_options.hpp>
72#include <boost/format.hpp>
78namespace po = boost::program_options;
80void writeParams(std::ostream &out)
82 out << sideLength <<
' ' << shipRadius <<
' ' << kouleRadius <<
' ' <<
' ' << propagationStepSize <<
' '
83 << shipAcceleration <<
' ' << shipRotVel <<
' ' << shipDelta <<
' ' << shipEps << std::endl;
86void plan(KoulesSetup &ks,
double maxTime,
const std::string &outputFile)
88 if (ks.solve(maxTime))
90 std::ofstream out(outputFile.c_str());
96 path.printAsMatrix(out);
97 if (!ks.haveExactSolutionPath())
98 OMPL_INFORM(
"Solution is approximate. Distance to actual goal is %g",
99 ks.getProblemDefinition()->getSolutionDifference());
100 OMPL_INFORM(
"Output saved in %s", outputFile.c_str());
109 ks.getPlannerData(pd);
110 std::ofstream vertexFile((outputFile +
"-vertices").c_str()), edgeFile((outputFile +
"-edges").c_str());
112 unsigned numVerts = pd.numVertices();
113 std::vector<unsigned int> edgeList;
115 for (
unsigned int i = 0; i < numVerts; ++i)
117 coords = pd.getVertex(i).getState()->as<KoulesStateSpace::StateType>()->values;
118 vertexFile << coords[0] <<
' ' << coords[1] <<
'\n';
120 pd.getEdges(i, edgeList);
121 for (
unsigned int j = 0; j < edgeList.size(); ++j)
122 edgeFile << i <<
' ' << edgeList[j] <<
'\n';
128 const std::string &outputFile)
132 b.addExperimentParameter(
"num_koules",
"INTEGER", std::to_string((ks.getStateSpace()->getDimension() - 5) / 4));
134 b.addPlanner(ks.getConfiguredPlannerInstance(plannerName));
136 b.benchmark(request);
138 b.saveResultsToFile(outputFile.c_str());
139 OMPL_INFORM(
"Output saved in %s", outputFile.c_str());
142int main(
int argc,
char **argv)
146 unsigned int numKoules, numRuns;
147 double maxTime, kouleVel;
148 std::string plannerName, outputFile;
149 po::options_description desc(
"Options");
150 desc.add_options()(
"help",
"show help message")(
"plan",
"solve the game of koules")(
151 "benchmark",
"benchmark the game of koules")(
152 "numkoules", po::value<unsigned int>(&numKoules)->default_value(3),
"start from <numkoules> koules")(
153 "maxtime", po::value<double>(&maxTime)->default_value(10.),
154 "time limit in seconds")(
"output", po::value<std::string>(&outputFile),
"output file name")(
155 "numruns", po::value<unsigned int>(&numRuns)->default_value(10),
156 "number of runs for each planner in benchmarking mode")(
157 "planner", po::value<std::string>(&plannerName)->default_value(
"kpiece"),
158 "planning algorithm to use (pdst, kpiece, sst, rrt, est, sycloprrt, or syclopest)")(
159 "velocity", po::value<double>(&kouleVel)->default_value(0.),
"initial velocity of each koule");
161 po::variables_map vm;
162 po::store(po::parse_command_line(argc, argv, desc,
163 po::command_line_style::unix_style ^ po::command_line_style::allow_short),
167 KoulesSetup ks(numKoules, plannerName, kouleVel);
168 if ((vm.count(
"help") != 0u) || argc == 1)
170 std::cout <<
"Solve the games of Koules.\nSelect one of these two options:\n"
171 <<
"\"--plan\", or \"--benchmark\"\n\n"
176 if (outputFile.empty())
178 std::string prefix(vm.count(
"plan") != 0u ?
"koules_" :
"koulesBenchmark_");
179 outputFile = boost::str(boost::format(
"%1%%2%_%3%_%4%.dat") % prefix % numKoules % plannerName % maxTime);
181 if (vm.count(
"plan") != 0u)
182 plan(ks, maxTime, outputFile);
183 else if (vm.count(
"benchmark") != 0u)
186 catch (std::exception &e)
188 std::cerr <<
"Error: " << e.what() <<
"\n";
193 std::cerr <<
"Exception of unknown type!\n";
Object containing planner generated vertex and edge data. It is assumed that all vertices are unique,...
Definition of a control path.
#define OMPL_INFORM(fmt,...)
Log a formatted information string.
#define OMPL_ERROR(fmt,...)
Log a formatted error string.
This namespace contains sampling based planning routines shared by both planning under geometric cons...
This namespace contains sampling based planning routines used by planning under differential constrai...