| Line |
Branch |
Exec |
Source |
| 1 |
|
|
// |
| 2 |
|
|
// Copyright (c) 2014 CNRS |
| 3 |
|
|
// Authors: Florent Lamiraux, Joseph Mirabel |
| 4 |
|
|
// |
| 5 |
|
|
|
| 6 |
|
|
// Redistribution and use in source and binary forms, with or without |
| 7 |
|
|
// modification, are permitted provided that the following conditions are |
| 8 |
|
|
// met: |
| 9 |
|
|
// |
| 10 |
|
|
// 1. Redistributions of source code must retain the above copyright |
| 11 |
|
|
// notice, this list of conditions and the following disclaimer. |
| 12 |
|
|
// |
| 13 |
|
|
// 2. Redistributions in binary form must reproduce the above copyright |
| 14 |
|
|
// notice, this list of conditions and the following disclaimer in the |
| 15 |
|
|
// documentation and/or other materials provided with the distribution. |
| 16 |
|
|
// |
| 17 |
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 18 |
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 19 |
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 20 |
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 21 |
|
|
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 22 |
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 23 |
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 24 |
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 25 |
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 |
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 27 |
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
| 28 |
|
|
// DAMAGE. |
| 29 |
|
|
|
| 30 |
|
|
#include <hpp/core/path-optimization/simple-shortcut.hh> |
| 31 |
|
|
#include <hpp/core/path-projector.hh> |
| 32 |
|
|
#include <hpp/core/path-validation.hh> |
| 33 |
|
|
#include <hpp/core/path-vector.hh> |
| 34 |
|
|
#include <hpp/core/problem-target.hh> |
| 35 |
|
|
#include <hpp/core/problem.hh> |
| 36 |
|
|
#include <hpp/core/roadmap.hh> |
| 37 |
|
|
#include <hpp/util/assertion.hh> |
| 38 |
|
|
#include <hpp/util/debug.hh> |
| 39 |
|
|
|
| 40 |
|
|
namespace hpp { |
| 41 |
|
|
namespace core { |
| 42 |
|
|
namespace pathOptimization { |
| 43 |
|
✗ |
SimpleShortcutPtr_t SimpleShortcut::create(const ProblemConstPtr_t& problem) { |
| 44 |
|
✗ |
SimpleShortcut* ptr = new SimpleShortcut(problem); |
| 45 |
|
✗ |
return SimpleShortcutPtr_t(ptr); |
| 46 |
|
|
} |
| 47 |
|
|
|
| 48 |
|
✗ |
SimpleShortcut::SimpleShortcut(const ProblemConstPtr_t& problem) |
| 49 |
|
✗ |
: PathOptimizer(problem) {} |
| 50 |
|
|
|
| 51 |
|
✗ |
PathVectorPtr_t SimpleShortcut::optimize(const PathVectorPtr_t& path) { |
| 52 |
|
|
RoadmapPtr_t roadmap( |
| 53 |
|
✗ |
Roadmap::create(problem()->distance(), problem()->robot())); |
| 54 |
|
✗ |
std::vector<NodePtr_t> nodes; |
| 55 |
|
✗ |
Configuration_t qPtr(path->initial()); |
| 56 |
|
✗ |
roadmap->initNode(qPtr); |
| 57 |
|
✗ |
NodePtr_t node(roadmap->initNode()); |
| 58 |
|
✗ |
nodes.push_back(node); |
| 59 |
|
✗ |
for (std::size_t i = 0; i < path->numberPaths(); ++i) { |
| 60 |
|
✗ |
PathPtr_t p(path->pathAtRank(i)); |
| 61 |
|
✗ |
qPtr = Configuration_t(p->end()); |
| 62 |
|
✗ |
node = roadmap->addNodeAndEdge(node, qPtr, p); |
| 63 |
|
✗ |
nodes.push_back(node); |
| 64 |
|
|
} |
| 65 |
|
✗ |
roadmap->addGoalNode(node->configuration()); |
| 66 |
|
✗ |
PathValidationPtr_t pv(problem()->pathValidation()); |
| 67 |
|
✗ |
for (std::size_t i = 0; i < nodes.size() - 1; ++i) { |
| 68 |
|
✗ |
for (std::size_t j = i + 2; j < nodes.size(); ++j) { |
| 69 |
|
|
PathPtr_t path( |
| 70 |
|
✗ |
steer(nodes[i]->configuration(), nodes[j]->configuration())); |
| 71 |
|
✗ |
PathValidationReportPtr_t report; |
| 72 |
|
✗ |
PathPtr_t unused; |
| 73 |
|
✗ |
if ((path) && (pv->validate(path, false, unused, report))) { |
| 74 |
|
✗ |
roadmap->addEdge(nodes[i], nodes[j], path); |
| 75 |
|
|
} |
| 76 |
|
|
} |
| 77 |
|
|
} |
| 78 |
|
✗ |
PathVectorPtr_t result(problem()->target()->computePath(roadmap)); |
| 79 |
|
✗ |
assert(result); |
| 80 |
|
✗ |
return result; |
| 81 |
|
|
} |
| 82 |
|
|
} // namespace pathOptimization |
| 83 |
|
|
} // namespace core |
| 84 |
|
|
} // namespace hpp |
| 85 |
|
|
|