14#ifndef OR_TOOLS_UTIL_VECTOR_OR_FUNCTION_H_
15#define OR_TOOLS_UTIL_VECTOR_OR_FUNCTION_H_
25template <
typename ScalarType,
typename Evaluator>
29 : evaluator_(
std::move(evaluator)) {}
30 void Reset(Evaluator evaluator) { evaluator_ = std::move(evaluator); }
31 ScalarType
operator()(
int i)
const {
return evaluator_(i); }
38template <
typename ScalarType>
42 : values_(
std::move(values)) {}
43 void Reset(std::vector<ScalarType> values) { values_ = std::move(values); }
44 ScalarType
operator()(
int i)
const {
return values_[i]; }
47 std::vector<ScalarType> values_;
52template <
typename ScalarType,
typename Evaluator,
bool square = false>
56 : evaluator_(
std::move(evaluator)) {}
57 void Reset(Evaluator evaluator) { evaluator_ = std::move(evaluator); }
58 ScalarType
operator()(
int i,
int j)
const {
return evaluator_(i, j); }
59 bool Check()
const {
return true; }
66template <
typename ScalarType,
bool square>
71 : matrix_(
std::move(matrix)) {}
72 void Reset(std::vector<std::vector<ScalarType>> matrix) {
73 matrix_ = std::move(matrix);
75 ScalarType
operator()(
int i,
int j)
const {
return matrix_[i][j]; }
79 if (matrix_.empty())
return true;
80 const int size = square ? matrix_.size() : matrix_[0].size();
82 square ?
"Matrix must be square." :
"Matrix must be rectangular.";
83 for (
const std::vector<ScalarType>&
row : matrix_) {
84 CHECK_EQ(
size,
row.size()) << msg;
90 std::vector<std::vector<ScalarType>> matrix_;
ScalarType operator()(int i, int j) const
void Reset(std::vector< std::vector< ScalarType > > matrix)
MatrixOrFunction(std::vector< std::vector< ScalarType > > matrix)
ScalarType operator()(int i, int j) const
void Reset(Evaluator evaluator)
MatrixOrFunction(Evaluator evaluator)
VectorOrFunction(std::vector< ScalarType > values)
ScalarType operator()(int i) const
void Reset(std::vector< ScalarType > values)
Template to abstract the access to STL functions or vector values.
ScalarType operator()(int i) const
VectorOrFunction(Evaluator evaluator)
void Reset(Evaluator evaluator)
In SWIG mode, we don't want anything besides these top-level includes.