38 #include "MultiLevelPlanningCommon.h"
39 #include "../KinematicChain.h"
40 #include <ompl/base/SpaceInformation.h>
41 #include <ompl/tools/benchmark/Benchmark.h>
42 #include <boost/range/irange.hpp>
43 #include <boost/range/algorithm_ext/push_back.hpp>
45 const unsigned int numLinks = 15;
46 const double runtime_limit = 5;
47 const double memory_limit = 4096;
48 const int run_count = 2;
50 const double linkLength = 1.0 / numLinks;
53 std::vector<Environment> envs;
55 Environment createCustomHornEnvironment(
unsigned int d)
57 double narrowPassageWidth =
log((
double)d) / (double)d;
58 return createHornEnvironment(d, narrowPassageWidth);
63 std::vector<SpaceInformationPtr> si_vec;
65 for (
unsigned int k = 0; k < sequenceLinks.size(); k++)
67 auto links = sequenceLinks.at(k);
68 assert(links < numLinks);
70 OMPL_INFORM(
"Create MultiLevel Chain with %d links.", links);
71 auto spaceK(std::make_shared<KinematicChainSpace>(links, linkLength, &envs.at(links)));
73 auto siK = std::make_shared<SpaceInformation>(spaceK);
74 siK->setStateValidityChecker(std::make_shared<KinematicChainValidityChecker>(siK));
76 si_vec.push_back(siK);
79 OMPL_INFORM(
"Add Original Chain with %d links.", numLinks);
82 auto planner = std::make_shared<ompl::multilevel::QRRT>(si_vec);
84 std::string qName =
"QRRT[";
85 for (
unsigned int k = 0; k < sequenceLinks.size(); k++)
87 int links = sequenceLinks.at(k);
88 qName += std::to_string(links) +
",";
90 qName += std::to_string(numLinks);
92 planner->setName(qName);
96 std::vector<std::vector<int>> getAdmissibleProjections(
int dim)
98 std::vector<std::vector<int>> projections;
99 std::vector<int> discrete;
100 boost::push_back(discrete, boost::irange(2, dim + 1));
102 std::vector<int> twoStep;
103 boost::push_back(twoStep, boost::irange(2, dim + 1, 2));
105 if (twoStep.back() != dim)
106 twoStep.push_back(dim);
108 projections.push_back(twoStep);
109 projections.push_back(discrete);
111 auto last = std::unique(projections.begin(), projections.end());
112 projections.erase(last, projections.end());
114 std::cout <<
"Projections for dim " << dim << std::endl;
115 for (
unsigned int k = 0; k < projections.size(); k++)
117 std::vector<int> pk = projections.at(k);
118 std::cout << k <<
": ";
119 for (
unsigned int j = 0; j < pk.size(); j++)
121 std::cout << pk.at(j) << (j < pk.size() - 1 ?
"," :
"");
123 std::cout << std::endl;
131 Environment env = createCustomHornEnvironment(numLinks);
132 OMPL_INFORM(
"Original Chain has %d links", numLinks);
133 for (
unsigned int k = 0; k < numLinks; k++)
135 envs.push_back(createCustomHornEnvironment((k > 0 ? k : 1)));
138 auto chain(std::make_shared<KinematicChainSpace>(numLinks, linkLength, &env));
141 ss.setStateValidityChecker(std::make_shared<KinematicChainValidityChecker>(ss.getSpaceInformation()));
144 std::vector<double> startVec(numLinks, boost::math::constants::pi<double>() / (
double)numLinks);
145 std::vector<double> goalVec(numLinks, 0);
147 goalVec[0] = boost::math::constants::pi<double>() - .001;
149 chain->copyFromReals(start.get(), startVec);
150 chain->copyFromReals(goal.get(), goalVec);
151 ss.setStartAndGoalStates(start, goal);
154 benchmark.addExperimentParameter(
"num_links",
"INTEGER", std::to_string(numLinks));
162 addPlanner(benchmark, std::make_shared<ompl::geometric::STRIDE>(si));
163 addPlanner(benchmark, std::make_shared<ompl::geometric::KPIECE1>(si));
164 addPlanner(benchmark, std::make_shared<ompl::geometric::EST>(si));
165 addPlanner(benchmark, std::make_shared<ompl::geometric::PRM>(si));
167 std::vector<std::vector<int>> admissibleProjections = getAdmissibleProjections(numLinks - 1);
168 for (
unsigned int k = 0; k < admissibleProjections.size(); k++)
170 std::vector<int> proj = admissibleProjections.at(k);
172 addPlanner(benchmark, plannerK);
175 printEstimatedTimeToCompletion(numberPlanners, run_count, runtime_limit);
178 request.
maxTime = runtime_limit;
179 request.
maxMem = memory_limit;
183 numberRuns = numberPlanners * run_count;
185 benchmark.setPostRunEvent(std::bind(&PostRunEvent, std::placeholders::_1, std::placeholders::_2));
187 benchmark.benchmark(request);
188 benchmark.saveResultsToFile(boost::str(boost::format(
"kinematic_%i.log") % numLinks).c_str());
190 printBenchmarkResults(benchmark);