@@ -76,23 +76,42 @@ class InterfaceState
7676{
7777 friend class SolutionBase ; // addIncoming() / addOutgoing() should be called only by SolutionBase
7878 friend class Interface ; // allow Interface to set owner_ and priority_
79+ friend class StagePrivate ;
80+
7981public:
82+ enum Status
83+ {
84+ ENABLED, // state is actively considered during planning
85+ DISABLED, // state is disabled because a required connected state failed
86+ DISABLED_FAILED, // state that failed, causing the whole partial solution to be disabled
87+ };
8088 /* * InterfaceStates are ordered according to two values:
8189 * Depth of interlinked trajectory parts and accumulated trajectory costs along that path.
8290 * Preference ordering considers high-depth first and within same depth, minimal cost paths.
8391 */
84- struct Priority : public std ::pair< unsigned int , double >
92+ struct Priority : std::tuple<Status, unsigned int , double >
8593 {
86- Priority (unsigned int depth, double cost) : std::pair<unsigned int , double >(depth, cost) {}
94+ Priority (unsigned int depth, double cost, Status status = ENABLED)
95+ : std::tuple<Status, unsigned int , double >(status, depth, cost) {
96+ assert (std::isfinite (cost));
97+ }
98+ // Constructor copying depth and cost, but modifying its status
99+ Priority (const Priority& other, Status status) : Priority(other.depth(), other.cost(), status) {}
87100
88- inline unsigned int depth () const { return this ->first ; }
89- inline double cost () const { return this ->second ; }
101+ inline Status status () const { return std::get<0 >(*this ); }
102+ inline bool enabled () const { return std::get<0 >(*this ) == ENABLED; }
103+ inline unsigned int depth () const { return std::get<1 >(*this ); }
104+ inline double cost () const { return std::get<2 >(*this ); }
90105
91106 // add priorities
92107 Priority operator +(const Priority& other) const {
93- return Priority (this -> depth () + other.depth (), this -> cost () + other.cost ());
108+ return Priority (depth () + other.depth (), cost () + other.cost (), std::min ( status (), other. status () ));
94109 }
95- bool operator <(const Priority& other) const ;
110+ // comparison operators
111+ bool operator <(const Priority& rhs) const ;
112+ inline bool operator >(const Priority& rhs) const { return rhs < *this ; }
113+ inline bool operator <=(const Priority& rhs) const { return !(rhs < *this ); }
114+ inline bool operator >=(const Priority& rhs) const { return !(*this < rhs); }
96115 };
97116 using Solutions = std::deque<SolutionBase*>;
98117
@@ -147,19 +166,20 @@ class Interface : public ordered<InterfaceState*>
147166 class iterator : public base_type ::iterator
148167 {
149168 public:
150- using base_type::iterator::iterator; // inherit base constructors
151169 iterator (base_type::iterator other) : base_type::iterator(other) {}
152170
153171 InterfaceState& operator *() const noexcept { return *base_type::iterator::operator *(); }
172+
154173 InterfaceState* operator ->() const noexcept { return base_type::iterator::operator *(); }
155174 };
156175 class const_iterator : public base_type ::const_iterator
157176 {
158177 public:
159- using base_type::const_iterator::const_iterator; // inherit base constructors
160178 const_iterator (base_type::const_iterator other) : base_type::const_iterator(other) {}
179+ const_iterator (base_type::iterator other) : base_type::const_iterator(other) {}
161180
162181 const InterfaceState& operator *() const noexcept { return *base_type::const_iterator::operator *(); }
182+
163183 const InterfaceState* operator ->() const noexcept { return base_type::const_iterator::operator *(); }
164184 };
165185
@@ -194,6 +214,9 @@ class Interface : public ordered<InterfaceState*>
194214 using base_type::remove_if;
195215};
196216
217+ std::ostream& operator <<(std::ostream& os, const InterfaceState::Priority& prio);
218+ std::ostream& operator <<(std::ostream& os, const Interface& interface);
219+
197220class CostTerm ;
198221class StagePrivate ;
199222class ContainerBasePrivate ;
@@ -370,14 +393,26 @@ inline const InterfaceState* state<Interface::BACKWARD>(const SolutionBase& solu
370393
371394// / Trait to retrieve outgoing (FORWARD) or incoming (BACKWARD) solution segments of a given state
372395template <Interface::Direction dir>
373- const InterfaceState::Solutions& trajectories (const InterfaceState* state);
396+ const InterfaceState::Solutions& trajectories (const InterfaceState& state);
397+ template <>
398+ inline const InterfaceState::Solutions& trajectories<Interface::FORWARD>(const InterfaceState& state) {
399+ return state.outgoingTrajectories ();
400+ }
401+ template <>
402+ inline const InterfaceState::Solutions& trajectories<Interface::BACKWARD>(const InterfaceState& state) {
403+ return state.incomingTrajectories ();
404+ }
405+
406+ // / Trait to retrieve opposite direction (FORWARD <-> BACKWARD)
407+ template <Interface::Direction dir>
408+ constexpr Interface::Direction opposite ();
374409template <>
375- inline const InterfaceState::Solutions& trajectories <Interface::FORWARD>(const InterfaceState* state ) {
376- return state-> outgoingTrajectories () ;
410+ inline constexpr Interface::Direction opposite <Interface::FORWARD>() {
411+ return Interface::BACKWARD ;
377412}
378413template <>
379- inline const InterfaceState::Solutions& trajectories <Interface::BACKWARD>(const InterfaceState* state ) {
380- return state-> incomingTrajectories () ;
414+ inline constexpr Interface::Direction opposite <Interface::BACKWARD>() {
415+ return Interface::FORWARD ;
381416}
382417} // namespace task_constructor
383418} // namespace moveit
0 commit comments