14#ifndef OR_TOOLS_UTIL_VECTOR_OR_FUNCTION_H_
15#define OR_TOOLS_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_) {
91 std::vector<std::vector<ScalarType>> matrix_;
#define CHECK_EQ(val1, val2)
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
MatrixOrFunction(Evaluator evaluator)
void Reset(Evaluator evaluator)
VectorOrFunction(std::vector< ScalarType > values)
void Reset(std::vector< ScalarType > values)
ScalarType operator()(int i) const
VectorOrFunction(Evaluator evaluator)
void Reset(Evaluator evaluator)
ScalarType operator()(int i) const
The vehicle routing library lets one model and solve generic vehicle routing problems ranging from th...