Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef TCG_SEQUENCE_OPS_H
Toshihiro Shimizu 890ddd
#define TCG_SEQUENCE_OPS_H
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*!
Toshihiro Shimizu 890ddd
  \file     sequence_ops.h
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
  \brief    This file contains algorithms returning sub-sequences of
Toshihiro Shimizu 890ddd
            some input iterator range.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
namespace tcg
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
namespace sequence_ops
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//**************************************************************************************
Toshihiro Shimizu 890ddd
//    Sequence Operations
Toshihiro Shimizu 890ddd
//**************************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*!
Toshihiro Shimizu 890ddd
  \brief    Base interface for an evaluator object supported by function
Toshihiro Shimizu 890ddd
            \p tcg::minimalPath().
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
template <typename it,="" pen="" typename=""></typename>
Toshihiro Shimizu 890ddd
struct EdgeEvaluator {
Toshihiro Shimizu 890ddd
	typedef It iterator_type;
Toshihiro Shimizu 890ddd
	typedef Pen penalty_type;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	EdgeEvaluator() {}
Toshihiro Shimizu 890ddd
	virtual ~EdgeEvaluator() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*!
Toshihiro Shimizu 890ddd
    \brief    Computes the largest allowed position reachable in a single
Toshihiro Shimizu 890ddd
              step from given position \a a.
Toshihiro Shimizu 890ddd
  */
Toshihiro Shimizu 890ddd
	virtual iterator_type furthestFrom(const iterator_type &a) = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*!
Toshihiro Shimizu 890ddd
    \brief    Computes the penalty for the specified input step.
Toshihiro Shimizu 890ddd
    \remark   Supplied input step is ensured to be allowed, as guaranteed
Toshihiro Shimizu 890ddd
              by function furthestFrom().
Toshihiro Shimizu 890ddd
  */
Toshihiro Shimizu 890ddd
	virtual penalty_type penalty(const iterator_type &a, const iterator_type &b) = 0;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*!
Toshihiro Shimizu 890ddd
  \brief    Builds the sequence's minimal subpath from the specified evaluator.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
  \details  This function traverses the input sequence (end excluded) searching for the
Toshihiro Shimizu 890ddd
            minimal allowed path with respect to the number of vertices (primarily)
Toshihiro Shimizu 890ddd
            and the penalty associated to each path edge; returns true whether such a
Toshihiro Shimizu 890ddd
            path could be found, false if \b no path from begin to --end could be
Toshihiro Shimizu 890ddd
            established.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
            The minimal path function applies a simplified Bellman optimality algorithm
Toshihiro Shimizu 890ddd
            on a sequence, where graph edges are specified through an edge evaluator
Toshihiro Shimizu 890ddd
            functor, rather than being built in a graph class.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
            It works this way:
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
              \li The minimal number of edges required to traverse the sequence can be
Toshihiro Shimizu 890ddd
                  found by traversing the sequence with the maximum step allowed.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
              \li Each node have the minimal number of edges required to reach the
Toshihiro Shimizu 890ddd
                  sequence end, the minimal penalty to it, and obviously the next node
Toshihiro Shimizu 890ddd
                  which allow this optimal configuration.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
              \li The optimal "edge number-penalty" value from one point sums with the
Toshihiro Shimizu 890ddd
                  one of the next point in the optimal configuration; thus, it can be
Toshihiro Shimizu 890ddd
                  found retroactively starting from the end.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
              \li The path retrieved with the maximum step allowed defines the
Toshihiro Shimizu 890ddd
                  remaining steps to achieve the optimal number of edges, starting from
Toshihiro Shimizu 890ddd
                  the end.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
  \remark     This function is currently working only for random access iterators.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
  \sa         The EdgeEvaluator class for the supported evaluator interface.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <typename containers_reader="" edge_eval,="" ranit_type,="" typename=""></typename>
Toshihiro Shimizu 890ddd
bool minimalPath(ranit_type begin, ranit_type end, edge_eval &evaluator, containers_reader &output);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
} //namespace tcg::sequence_ops
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif //TCG_SEQUENCE_OPS_H
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef INCLUDE_HPP
Toshihiro Shimizu 890ddd
#include "hpp/sequence_ops.hpp"
Toshihiro Shimizu 890ddd
#endif