.. _program_listing_file__tmp_ws_src_rmf_traffic_rmf_traffic_include_rmf_traffic_schedule_Negotiation.hpp: Program Listing for File Negotiation.hpp ======================================== |exhale_lsh| :ref:`Return to documentation for file ` (``/tmp/ws/src/rmf_traffic/rmf_traffic/include/rmf_traffic/schedule/Negotiation.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp /* * Copyright (C) 2020 Open Source Robotics Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ #ifndef RMF_TRAFFIC__SCHEDULE__NEGOTIATION_HPP #define RMF_TRAFFIC__SCHEDULE__NEGOTIATION_HPP #include #include #include namespace rmf_traffic { namespace schedule { //============================================================================== class Negotiation { public: // TODO(MXG): Add an API that allows a multi-participant planner to propose // globally optimal itineraries. static rmf_utils::optional make( std::shared_ptr schedule_viewer, std::vector participants); static std::shared_ptr make_shared( std::shared_ptr schedule_viewer, std::vector participants); const std::unordered_set& participants() const; void add_participant(ParticipantId p); bool ready() const; bool complete() const; struct VersionedKey { ParticipantId participant; Version version; inline bool operator==(const VersionedKey& other) const { return participant == other.participant && version == other.version; } inline bool operator!=(const VersionedKey& other) const { return !(*this == other); } }; using VersionedKeySequence = std::vector; struct Submission { ParticipantId participant; PlanId plan; Itinerary itinerary; }; using Proposal = std::vector; using Alternatives = std::vector; class Table; using TablePtr = std::shared_ptr; using ConstTablePtr = std::shared_ptr; class Table : public std::enable_shared_from_this
{ public: class Viewer { public: using View = schedule::Viewer::View; View query( const Query::Spacetime& parameters, const VersionedKeySequence& alternatives) const; class Endpoint { public: ParticipantId participant() const; PlanId plan_id() const; RouteId route_id() const; const rmf_traffic::Trajectory::Waypoint& waypoint() const; const std::string& map() const; const ParticipantDescription& description() const; class Implementation; private: Endpoint(); rmf_utils::impl_ptr _pimpl; }; std::unordered_map initial_endpoints( const VersionedKeySequence& alternatives) const; std::unordered_map final_endpoints( const VersionedKeySequence& alterantives) const; using AlternativeMap = std::unordered_map>; const AlternativeMap& alternatives() const; const Proposal& base_proposals() const; std::shared_ptr get_description( ParticipantId participant_id) const; ParticipantId participant_id() const; rmf_utils::optional parent_id() const; const VersionedKeySequence& sequence() const; bool defunct() const; bool rejected() const; bool forfeited() const; const Itinerary* submission() const; std::optional earliest_base_proposal_time() const; std::optional latest_base_proposal_time() const; class Implementation; private: Viewer(); rmf_utils::impl_ptr _pimpl; }; using ViewerPtr = std::shared_ptr; ViewerPtr viewer() const; const Itinerary* submission() const; Version version() const; const Proposal& proposal() const; ParticipantId participant() const; const VersionedKeySequence& sequence() const; std::vector unversioned_sequence() const; bool submit( PlanId plan_id, std::vector itinerary, Version version); bool reject( Version version, ParticipantId rejected_by, Alternatives alternatives); bool rejected() const; void forfeit(Version version); bool forfeited() const; bool defunct() const; TablePtr respond(ParticipantId by_participant); // const-qualified respond() ConstTablePtr respond(ParticipantId by_participant) const; TablePtr parent(); // const-qualified parent() ConstTablePtr parent() const; std::vector children(); // const-qualified children() std::vector children() const; bool ongoing() const; class Implementation; private: Table(); rmf_utils::unique_impl_ptr _pimpl; }; TablePtr table( ParticipantId for_participant, const std::vector& to_accommodate); // const-qualified table() ConstTablePtr table( ParticipantId for_participant, const std::vector& to_accommodate) const; TablePtr table(const std::vector& sequence); // const-qualified table() ConstTablePtr table(const std::vector& sequence) const; enum class SearchStatus { Deprecated = 0, Absent, Found }; template struct SearchResult { SearchStatus status; Ptr table; inline bool deprecated() const { return SearchStatus::Deprecated == status; } inline bool absent() const { return SearchStatus::Absent == status; } inline bool found() const { return SearchStatus::Found == status; } inline operator bool() const { return found(); } }; SearchResult find( ParticipantId for_participant, const VersionedKeySequence& to_accommodate); SearchResult find( ParticipantId for_participant, const VersionedKeySequence& to_accommodate) const; SearchResult find(const VersionedKeySequence& sequence); SearchResult find(const VersionedKeySequence& sequence) const; class Evaluator { public: virtual std::size_t choose( const std::vector& proposals) const = 0; virtual ~Evaluator() = default; }; ConstTablePtr evaluate(const Evaluator& evaluator) const; class Implementation; private: Negotiation(); rmf_utils::unique_impl_ptr _pimpl; }; //============================================================================== class QuickestFinishEvaluator : public Negotiation::Evaluator { public: // Documentation inherited std::size_t choose( const std::vector& proposals) const final; }; } // namespace schedule } // namespace rmf_traffic #endif // RMF_TRAFFIC__SCHEDULE__NEGOTIATION_HPP