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