hpp-manipulation 9.3.0
Classes for manipulation planning.
Loading...
Searching...
No Matches
states-path-finder.hh
Go to the documentation of this file.
1// Copyright (c) 2017, Joseph Mirabel
2// Authors: Joseph Mirabel (joseph.mirabel@laas.fr),
3// Florent Lamiraux (florent.lamiraux@laas.fr)
4// Alexandre Thiault (athiault@laas.fr)
5// Le Quang Anh (quang-anh.le@laas.fr)
6//
7// This file is part of hpp-manipulation.
8// hpp-manipulation is free software: you can redistribute it
9// and/or modify it under the terms of the GNU Lesser General Public
10// License as published by the Free Software Foundation, either version
11// 3 of the License, or (at your option) any later version.
12//
13// hpp-manipulation is distributed in the hope that it will be
14// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
15// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16// General Lesser Public License for more details. You should have
17// received a copy of the GNU Lesser General Public License along with
18// hpp-manipulation. If not, see <http://www.gnu.org/licenses/>.
19
20#ifndef HPP_MANIPULATION_PATH_PLANNER_STATES_PATH_FINDER_HH
21#define HPP_MANIPULATION_PATH_PLANNER_STATES_PATH_FINDER_HH
22
23#include <chrono>
26#include <hpp/core/fwd.hh>
28#include <hpp/core/path.hh>
31#include <hpp/manipulation/config.hh>
34#include <unordered_map>
35
36namespace hpp {
37namespace manipulation {
38namespace pathPlanner {
39
42
101class HPP_MANIPULATION_DLLAPI StatesPathFinder : public core::PathPlanner {
102 public:
103 struct OptimizationData;
104
105 virtual ~StatesPathFinder() {};
106
108
110 const problem,
111 const roadmap);
112
114
123
124 // access functions for Python interface
125 std::vector<std::string> constraintNamesFromSolverAtWaypoint(std::size_t wp);
126 std::vector<std::string> lastBuiltTransitions() const;
127 std::string displayConfigsSolved() const;
128 bool buildOptimizationProblemFromNames(std::vector<std::string> names);
129
130 // Substeps of method solveOptimizationProblem
131 void initWPRandom(std::size_t wp);
132 void initWPNear(std::size_t wp);
133 void initWP(std::size_t wp, ConfigurationIn_t q);
145
146 SolveStepStatus solveStep(std::size_t wp);
147
151 void reset();
152
157 virtual void startSolve();
158
163 virtual void oneStep();
164
167 virtual void tryConnectInitAndGoals();
168
169 protected:
171 const core::RoadmapPtr_t&);
173
174 void init(StatesPathFinderWkPtr_t weak) { weak_ = weak; }
175
176 private:
178 struct GraphSearchData;
179
181 void gatherGraphConstraints();
182
184 void checkTimeOut() const;
185
188 bool findTransitions(GraphSearchData& data) const;
189
191 graph::Edges_t getTransitionList(const GraphSearchData& data,
192 const std::size_t& i) const;
193
195
196 // check that the solver either contains exactly same constraint
197 // or a constraint with similar parametrizable form
198 // constraint/both and constraint/complement
199 bool contains(const Solver_t& solver, const ImplicitPtr_t& c) const;
200
201 // check that the solver either contains exactly same constraint
202 // or a stricter version of the constraint
203 // constraint/both stricter than constraint and stricter than
204 // constraint/complement
205 bool containsStricter(const Solver_t& solver, const ImplicitPtr_t& c) const;
206 bool checkConstantRightHandSide(size_type index);
207 bool buildOptimizationProblem(const graph::Edges_t& transitions);
208
210 void preInitializeRHS(std::size_t j, Configuration_t& q);
211 bool analyseOptimizationProblem(const graph::Edges_t& transitions,
213
215 void initializeRHS(std::size_t j);
216 bool solveOptimizationProblem();
217
218 // Data structure used to store a constraint right hand side as value and its
219 // name as key, both in form of hash numbers (so that names and rhs of two
220 // constraints can be easily merge). Exemple : ConstraintMap_t map =
221 // {{nameStringHash, rhsVectorHash}}; With rhsVectorHash the hash of a
222 // vector_t of rights hand side constraints with hashRHS, and nameStringHash
223 // the hash of a std::string - obtained for instance with std::hash.
224 typedef std::unordered_map<size_t, size_t> ConstraintMap_t; // map (name,
225 // rhs)
226
233 Configuration_t getConfigStatus(size_type i, size_type j) const;
234
240 vector_t getConstraintRHS(ImplicitPtr_t constraint, Configuration_t q) const;
241
245 size_t hashRHS(vector_t rhs) const;
246
254 bool checkSolvers(ConstraintMap_t const& pairMap,
255 ConstraintMap_t const& constraintMap) const;
256
265 bool saveIncompatibleRHS(ConstraintMap_t& pairMap,
266 ConstraintMap_t& constraintMap, size_type const wp);
267
268 // For a joint get his most, constrained with it, far parent
270
272 core::Configurations_t getConfigList() const;
273
275 bool checkWaypointRightHandSide(std::size_t ictr, std::size_t jslv) const;
276 bool checkSolverRightHandSide(std::size_t ictr, std::size_t jslv) const;
277 bool checkWaypointRightHandSide(std::size_t jslv) const;
278 bool checkSolverRightHandSide(std::size_t jslv) const;
279
280 void displayRhsMatrix();
281 void displayStatusMatrix(const graph::Edges_t& transitions);
282
284 ProblemConstPtr_t problem_;
286 core::ProblemPtr_t inStateProblem_;
287
289 NumericalConstraints_t constraints_;
291 std::map<std::string, std::size_t> index_;
292
295 std::map<ImplicitPtr_t, ImplicitPtr_t> sameRightHandSide_;
296
300 std::map<ImplicitPtr_t, ImplicitPtr_t> stricterConstraints_;
301
302 mutable OptimizationData* optData_;
303 mutable std::shared_ptr<GraphSearchData> graphData_;
304 graph::Edges_t lastBuiltTransitions_;
305
313 NumericalConstraints_t goalConstraints_;
314 bool goalDefinedByConstraints_;
315 // Variables used across several calls to oneStep
316 Configuration_t q1_, q2_;
317 core::Configurations_t configList_;
318 std::size_t idxConfigList_;
319 size_type nTryConfigList_;
320 bool solved_, interrupt_;
322 std::chrono::steady_clock::time_point start_;
323
325 StatesPathFinderWkPtr_t weak_;
326
327}; // class StatesPathFinder
328
329
330} // namespace pathPlanner
331} // namespace manipulation
332} // namespace hpp
333
334#endif // HPP_MANIPULATION_PATH_PLANNER_STATES_PATH_FINDER_HH
ProblemConstPtr_t problem() const
virtual const RoadmapPtr_t & roadmap() const
static StatesPathFinderPtr_t createWithRoadmap(const core::ProblemConstPtr_t &problem, const core::RoadmapPtr_t &roadmap)
SolveStepStatus solveStep(std::size_t wp)
StatesPathFinder(const StatesPathFinder &other)
virtual ~StatesPathFinder()
Definition states-path-finder.hh:105
core::Configurations_t computeConfigList(ConfigurationIn_t q1, ConfigurationIn_t q2)
StatesPathFinder(const core::ProblemConstPtr_t &problem, const core::RoadmapPtr_t &)
SolveStepStatus
Status of the step to solve for a particular waypoint.
Definition states-path-finder.hh:135
@ VALID_SOLUTION
Valid solution (no collision).
Definition states-path-finder.hh:137
@ NO_SOLUTION
Bad solve status, no solution from the solver.
Definition states-path-finder.hh:139
@ COLLISION_AFTER
Solution has collision in edge going from the waypoint.
Definition states-path-finder.hh:143
@ COLLISION_BEFORE
Solution has collision in edge leading to the waypoint.
Definition states-path-finder.hh:141
static StatesPathFinderPtr_t create(const core::ProblemConstPtr_t &problem)
std::vector< std::string > constraintNamesFromSolverAtWaypoint(std::size_t wp)
void initWP(std::size_t wp, ConfigurationIn_t q)
std::vector< std::string > lastBuiltTransitions() const
bool buildOptimizationProblemFromNames(std::vector< std::string > names)
void init(StatesPathFinderWkPtr_t weak)
Definition states-path-finder.hh:174
shared_ptr< Implicit > ImplicitPtr_t
pinocchio::JointConstPtr_t JointConstPtr_t
shared_ptr< Roadmap > RoadmapPtr_t
shared_ptr< Problem > ProblemPtr_t
shared_ptr< const Problem > ProblemConstPtr_t
std::vector< Configuration_t > Configurations_t
std::vector< EdgePtr_t > Edges_t
Definition fwd.hh:57
Definition fwd.hh:97
shared_ptr< StatesPathFinder > StatesPathFinderPtr_t
Definition fwd.hh:101
Definition connected-component.hh:39
pinocchio::Configuration_t Configuration_t
Definition fwd.hh:48
core::NumericalConstraints_t NumericalConstraints_t
Definition fwd.hh:143
shared_ptr< const Problem > ProblemConstPtr_t
Definition fwd.hh:66
core::size_type size_type
Definition fwd.hh:90
pinocchio::ConfigurationIn_t ConfigurationIn_t
Definition fwd.hh:49
core::vector_t vector_t
Definition fwd.hh:92