|
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 |
|
|
Shinya Kitaoka |
120a6e |
namespace tcg {
|
|
Shinya Kitaoka |
120a6e |
namespace sequence_ops {
|
|
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 {
|
|
Shinya Kitaoka |
120a6e |
typedef It iterator_type;
|
|
Shinya Kitaoka |
120a6e |
typedef Pen penalty_type;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
EdgeEvaluator() {}
|
|
Shinya Kitaoka |
120a6e |
virtual ~EdgeEvaluator() {}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
/*!
|
|
Shinya Kitaoka |
120a6e |
\brief Computes the largest allowed position reachable in a single
|
|
Shinya Kitaoka |
120a6e |
step from given position \a a.
|
|
Shinya Kitaoka |
120a6e |
*/
|
|
Shinya Kitaoka |
120a6e |
virtual iterator_type furthestFrom(const iterator_type &a) = 0;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
/*!
|
|
Shinya Kitaoka |
120a6e |
\brief Computes the penalty for the specified input step.
|
|
Shinya Kitaoka |
120a6e |
\remark Supplied input step is ensured to be allowed, as guaranteed
|
|
Shinya Kitaoka |
120a6e |
by function furthestFrom().
|
|
Shinya Kitaoka |
120a6e |
*/
|
|
Shinya Kitaoka |
120a6e |
virtual penalty_type penalty(const iterator_type &a,
|
|
Shinya Kitaoka |
120a6e |
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 |
|
|
Shinya Kitaoka |
120a6e |
\details This function traverses the input sequence (end excluded) searching
|
|
Shinya Kitaoka |
120a6e |
for the
|
|
Shinya Kitaoka |
120a6e |
minimal allowed path with respect to the number of vertices
|
|
Shinya Kitaoka |
120a6e |
(primarily)
|
|
Shinya Kitaoka |
120a6e |
and the penalty associated to each path edge; returns true whether
|
|
Shinya Kitaoka |
120a6e |
such a
|
|
Shinya Kitaoka |
120a6e |
path could be found, false if \b no path from begin to --end could
|
|
Shinya Kitaoka |
120a6e |
be
|
|
Toshihiro Shimizu |
890ddd |
established.
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
The minimal path function applies a simplified Bellman optimality
|
|
Shinya Kitaoka |
120a6e |
algorithm
|
|
Shinya Kitaoka |
120a6e |
on a sequence, where graph edges are specified through an edge
|
|
Shinya Kitaoka |
120a6e |
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 |
|
|
Shinya Kitaoka |
120a6e |
\li The minimal number of edges required to traverse the sequence
|
|
Shinya Kitaoka |
120a6e |
can be
|
|
Shinya Kitaoka |
120a6e |
found by traversing the sequence with the maximum step
|
|
Shinya Kitaoka |
120a6e |
allowed.
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
\li Each node have the minimal number of edges required to reach
|
|
Shinya Kitaoka |
120a6e |
the
|
|
Shinya Kitaoka |
120a6e |
sequence end, the minimal penalty to it, and obviously the
|
|
Shinya Kitaoka |
120a6e |
next node
|
|
Toshihiro Shimizu |
890ddd |
which allow this optimal configuration.
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
\li The optimal "edge number-penalty" value from one point sums
|
|
Shinya Kitaoka |
120a6e |
with the
|
|
Shinya Kitaoka |
120a6e |
one of the next point in the optimal configuration; thus, it
|
|
Shinya Kitaoka |
120a6e |
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
|
|
Shinya Kitaoka |
120a6e |
remaining steps to achieve the optimal number of edges,
|
|
Shinya Kitaoka |
120a6e |
starting from
|
|
Toshihiro Shimizu |
890ddd |
the end.
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
\remark This function is currently working only for random access
|
|
Shinya Kitaoka |
120a6e |
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>
|
|
Shinya Kitaoka |
120a6e |
bool minimalPath(ranit_type begin, ranit_type end, edge_eval &evaluator,
|
|
Shinya Kitaoka |
120a6e |
containers_reader &output);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Shinya Kitaoka |
120a6e |
} // namespace tcg::sequence_ops
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
#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
|