Program Listing for File LTLPlanner.h

Return to documentation for file (src/ompl/control/planners/ltl/LTLPlanner.h)

/*********************************************************************
* Software License Agreement (BSD License)
*
*  Copyright (c) 2012, Rice University
*  All rights reserved.
*
*  Redistribution and use in source and binary forms, with or without
*  modification, are permitted provided that the following conditions
*  are met:
*
*   * Redistributions of source code must retain the above copyright
*     notice, this list of conditions and the following disclaimer.
*   * Redistributions in binary form must reproduce the above
*     copyright notice, this list of conditions and the following
*     disclaimer in the documentation and/or other materials provided
*     with the distribution.
*   * Neither the name of the Rice University nor the names of its
*     contributors may be used to endorse or promote products derived
*     from this software without specific prior written permission.
*
*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
*  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
*  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
*  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
*  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
*  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
*  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
*  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
*  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
*  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
*  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
*  POSSIBILITY OF SUCH DAMAGE.
*********************************************************************/

/* Author: Matt Maly */

#ifndef OMPL_CONTROL_PLANNERS_LTL_LTLPLANNER_
#define OMPL_CONTROL_PLANNERS_LTL_LTLPLANNER_

#include "ompl/control/planners/PlannerIncludes.h"
#include "ompl/control/planners/ltl/ProductGraph.h"
#include "ompl/control/planners/ltl/LTLSpaceInformation.h"
#include "ompl/datastructures/PDF.h"
#include <unordered_map>
#include <map>
#include <vector>

namespace ompl
{
    namespace control
    {
        class LTLPlanner : public base::Planner
        {
        public:
            LTLPlanner(const LTLSpaceInformationPtr &si, ProductGraphPtr a, double exploreTime = 0.5);

            ~LTLPlanner() override;


            void setup() override;

            void clear() override;

            base::PlannerStatus solve(const base::PlannerTerminationCondition &ptc) override;

            void getTree(std::vector<base::State *> &tree) const;

            std::vector<ProductGraph::State *> getHighLevelPath(const std::vector<base::State *> &path,
                                                                ProductGraph::State *start = nullptr) const;

        protected:
            struct Motion
            {
            public:
                Motion() = default;

                Motion(const SpaceInformation *si);

                virtual ~Motion();

                base::State *state{nullptr};

                Control *control{nullptr};

                Motion *parent{nullptr};

                unsigned int steps{0};

                ProductGraph::State *abstractState{nullptr};
            };

            struct ProductGraphStateInfo
            {
                ProductGraphStateInfo() = default;

                void addMotion(Motion *m);

                double weight{0.};
                PDF<Motion *> motions;
                std::unordered_map<Motion *, PDF<Motion *>::Element *> motionElems;
                double volume{0.};
                double autWeight{0.};
                unsigned int numSel{0};
                PDF<ProductGraph::State *>::Element *pdfElem{nullptr};
            };

            virtual double updateWeight(ProductGraph::State *as);

            virtual void initAbstractInfo(ProductGraph::State *as);

            virtual void buildAvail(const std::vector<ProductGraph::State *> &lead);

            virtual bool explore(const std::vector<ProductGraph::State *> &lead, Motion *&soln, double duration);

            virtual double abstractEdgeWeight(ProductGraph::State *a, ProductGraph::State *b) const;

            base::StateSamplerPtr sampler_;

            ControlSamplerPtr controlSampler_;

            const LTLSpaceInformation *ltlsi_;

            ProductGraphPtr abstraction_;

            PDF<ProductGraph::State *> availDist_;

            RNG rng_;

            std::vector<Motion *> motions_;

            ProductGraph::State *prodStart_{nullptr};

            double exploreTime_;

            std::unordered_map<ProductGraph::State *, ProductGraphStateInfo> abstractInfo_;

        private:
            void clearMotions();
        };
    }
}

#endif