Program Listing for File Automaton.h

Return to documentation for file (src/ompl/control/planners/ltl/Automaton.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, Keliang He */

#ifndef OMPL_CONTROL_PLANNERS_LTL_AUTOMATON_
#define OMPL_CONTROL_PLANNERS_LTL_AUTOMATON_

#include "ompl/control/planners/ltl/World.h"
#include "ompl/util/ClassForward.h"
#include "ompl/config.h"
#include <unordered_map>
#include <limits>
#include <ostream>
#include <vector>

namespace ompl
{
    namespace control
    {

        OMPL_CLASS_FORWARD(Automaton);

        class Automaton
        {
        public:
            struct TransitionMap
            {
                int eval(const World &w) const;

                mutable std::unordered_map<World, unsigned int> entries;
            };

            Automaton(unsigned int numProps, unsigned int numStates = 0);

#if OMPL_HAVE_SPOT
            Automaton(unsigned numProps, std::string formula, bool isCosafe = true);
#endif

            unsigned int addState(bool accepting = false);

            void setAccepting(unsigned int s, bool a);

            bool isAccepting(unsigned int s) const;

            void setStartState(unsigned int s);

            int getStartState() const;

            void addTransition(unsigned int src, const World &w, unsigned int dest);

            bool run(const std::vector<World> &trace) const;

            int step(int state, const World &w) const;

            TransitionMap &getTransitions(unsigned int src);

            unsigned int numStates() const;

            unsigned int numTransitions() const;

            unsigned int numProps() const;

            void print(std::ostream &out) const;

            unsigned int distFromAccepting(unsigned int s) const;

            static AutomatonPtr AcceptingAutomaton(unsigned int numProps);

            static AutomatonPtr CoverageAutomaton(unsigned int numProps, const std::vector<unsigned int> &covProps);

            static AutomatonPtr SequenceAutomaton(unsigned int numProps, const std::vector<unsigned int> &seqProps);

            static AutomatonPtr DisjunctionAutomaton(unsigned int numProps, const std::vector<unsigned int> &disjProps);

            static AutomatonPtr AvoidanceAutomaton(unsigned int numProps, const std::vector<unsigned int> &avoidProps);

            static AutomatonPtr CoverageAutomaton(unsigned int numProps);

            static AutomatonPtr SequenceAutomaton(unsigned int numProps);

            static AutomatonPtr DisjunctionAutomaton(unsigned int numProps);

        protected:
            unsigned int numProps_;
            unsigned int numStates_;
            int startState_{-1};
            std::vector<bool> accepting_;
            std::vector<TransitionMap> transitions_;
            mutable std::vector<unsigned int> distances_;
        };
    }
}
#endif