22#include "absl/status/status.h"
23#include "absl/status/statusor.h"
24#include "absl/strings/escaping.h"
25#include "absl/strings/str_cat.h"
26#include "absl/strings/str_join.h"
35absl::Status ValidateRelation(
Relation relation) {
40 return absl::OkStatus();
43 <<
"Invalid Relation: " <<
static_cast<int>(relation);
60 ostr <<
"__invalid_Relation_" <<
static_cast<int>(relation) <<
"__";
65 auto term_format = [](std::string* out,
66 const std::pair<double, VariableIndex>& term) {
70 ostr <<
"terms: {" << absl::StrJoin(constraint.
terms,
", ", term_format)
71 <<
"} relation: " << constraint.
relation
73 << absl::CEscape(constraint.
name) <<
"\"";
78 if (!constraint.
name.empty()) {
81 if (constraint.
terms.empty()) {
82 return absl::InvalidArgumentError(
"constraint must have at least one term");
87 <<
"variable ids should be in [0," << variables_.
end_index()
88 <<
") but found: " <<
var;
90 if (!std::isfinite(
coef)) {
92 <<
"All coefficients in constraints must be finite and not NaN "
98 if (std::isnan(constraint.
rhs)) {
99 return absl::InvalidArgumentError(
"rhs of constraint was NaN");
101 ConstraintIndex result = constraints_.end_index();
102 constraints_.push_back(std::move(constraint));
107 if (variable_names_.contains(
name)) {
109 <<
"duplicate variable name: " <<
name;
119 ostr <<
"SUBJECT TO" << std::endl;
122 if (!constraint.name.empty()) {
123 ostr << constraint.name <<
": ";
126 for (
const auto [
coef,
var] : constraint.terms) {
142 ostr <<
" " << constraint.relation <<
" "
145 ostr <<
"END" << std::endl;
#define RETURN_IF_ERROR(expr)
void push_back(const value_type &val)
IntType end_index() const
const std::string name
A name for logging purposes.
StatusBuilder InvalidArgumentErrorBuilder()