14#ifndef ORTOOLS_UTIL_VECTOR_OR_FUNCTION_H_
15#define ORTOOLS_UTIL_VECTOR_OR_FUNCTION_H_
26template <
typename ScalarType,
typename Evaluator>
30 : evaluator_(
std::move(evaluator)) {}
31 void Reset(Evaluator evaluator) { evaluator_ = std::move(evaluator); }
32 ScalarType
operator()(
int i)
const {
return evaluator_(i); }
39template <
typename ScalarType>
43 : values_(
std::move(values)) {}
44 void Reset(std::vector<ScalarType> values) { values_ = std::move(values); }
45 ScalarType
operator()(
int i)
const {
return values_[i]; }
48 std::vector<ScalarType> values_;
53template <
typename ScalarType,
typename Evaluator,
bool square = false>
57 : evaluator_(
std::move(evaluator)) {}
58 void Reset(Evaluator evaluator) { evaluator_ = std::move(evaluator); }
59 ScalarType
operator()(
int i,
int j)
const {
return evaluator_(i, j); }
60 bool Check()
const {
return true; }
67template <
typename ScalarType,
bool square>
72 : matrix_(
std::move(matrix)) {}
73 void Reset(std::vector<std::vector<ScalarType>> matrix) {
74 matrix_ = std::move(matrix);
76 ScalarType
operator()(
int i,
int j)
const {
return matrix_[i][j]; }
80 if (matrix_.empty())
return true;
81 const int size = square ? matrix_.size() : matrix_[0].size();
83 square ?
"Matrix must be square." :
"Matrix must be rectangular.";
84 for (
const std::vector<ScalarType>& row : matrix_) {
85 CHECK_EQ(size, row.size()) << msg;
91 std::vector<std::vector<ScalarType>> matrix_;
95template <
typename ScalarType,
bool square>
99 : matrix_(
std::move(matrix)) {}
101 ScalarType
operator()(
int i,
int j)
const {
return matrix_[i][j]; }
ScalarType operator()(int i, int j) const
MatrixOrFunction(FlatMatrix< ScalarType > matrix)
void Reset(FlatMatrix< 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)
ScalarType operator()(int i) const
VectorOrFunction(Evaluator evaluator)
void Reset(Evaluator evaluator)