Skip to content

Commit

Permalink
internal renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
lperron committed Jan 3, 2025
1 parent d77feb4 commit e01a1fe
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 36 deletions.
22 changes: 11 additions & 11 deletions ortools/sat/python/linear_expr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ LinearExpr* LinearExpr::WeightedSumInt(const std::vector<LinearExpr*>& exprs,
return new IntWeightedSum(exprs, coeffs, 0);
}

LinearExpr* LinearExpr::WeightedSumDouble(const std::vector<LinearExpr*>& exprs,
const std::vector<double>& coeffs) {
LinearExpr* LinearExpr::WeightedSumFloat(const std::vector<LinearExpr*>& exprs,
const std::vector<double>& coeffs) {
if (exprs.empty()) return new FloatConstant(0.0);
if (exprs.size() == 1) {
return new FloatAffine(exprs[0], coeffs[0], 0.0);
Expand Down Expand Up @@ -140,7 +140,7 @@ LinearExpr* LinearExpr::MixedWeightedSumInt(
return new IntWeightedSum(lin_exprs, lin_coeffs, int_cst);
}

LinearExpr* LinearExpr::MixedWeightedSumDouble(
LinearExpr* LinearExpr::MixedWeightedSumFloat(
const std::vector<ExprOrValue>& exprs, const std::vector<double>& coeffs) {
std::vector<LinearExpr*> lin_exprs;
std::vector<double> lin_coeffs;
Expand All @@ -166,7 +166,7 @@ LinearExpr* LinearExpr::TermInt(LinearExpr* expr, int64_t coeff) {
return new IntAffine(expr, coeff, 0);
}

LinearExpr* LinearExpr::TermDouble(LinearExpr* expr, double coeff) {
LinearExpr* LinearExpr::TermFloat(LinearExpr* expr, double coeff) {
return new FloatAffine(expr, coeff, 0.0);
}

Expand All @@ -176,8 +176,8 @@ LinearExpr* LinearExpr::AffineInt(LinearExpr* expr, int64_t coeff,
return new IntAffine(expr, coeff, offset);
}

LinearExpr* LinearExpr::AffineDouble(LinearExpr* expr, double coeff,
double offset) {
LinearExpr* LinearExpr::AffineFloat(LinearExpr* expr, double coeff,
double offset) {
if (coeff == 1.0 && offset == 0.0) return expr;
return new FloatAffine(expr, coeff, offset);
}
Expand All @@ -186,7 +186,7 @@ LinearExpr* LinearExpr::ConstantInt(int64_t value) {
return new IntConstant(value);
}

LinearExpr* LinearExpr::ConstantDouble(double value) {
LinearExpr* LinearExpr::ConstantFloat(double value) {
return new FloatConstant(value);
}

Expand All @@ -199,7 +199,7 @@ LinearExpr* LinearExpr::AddInt(int64_t cst) {
return new IntAffine(this, 1, cst);
}

LinearExpr* LinearExpr::AddDouble(double cst) {
LinearExpr* LinearExpr::AddFloat(double cst) {
if (cst == 0.0) return this;
return new FloatAffine(this, 1.0, cst);
}
Expand All @@ -213,7 +213,7 @@ LinearExpr* LinearExpr::SubInt(int64_t cst) {
return new IntAffine(this, 1, -cst);
}

LinearExpr* LinearExpr::SubDouble(double cst) {
LinearExpr* LinearExpr::SubFloat(double cst) {
if (cst == 0.0) return this;
return new FloatAffine(this, 1.0, -cst);
}
Expand All @@ -222,7 +222,7 @@ LinearExpr* LinearExpr::RSubInt(int64_t cst) {
return new IntAffine(this, -1, cst);
}

LinearExpr* LinearExpr::RSubDouble(double cst) {
LinearExpr* LinearExpr::RSubFloat(double cst) {
return new FloatAffine(this, -1.0, cst);
}

Expand All @@ -232,7 +232,7 @@ LinearExpr* LinearExpr::MulInt(int64_t cst) {
return new IntAffine(this, cst, 0);
}

LinearExpr* LinearExpr::MulDouble(double cst) {
LinearExpr* LinearExpr::MulFloat(double cst) {
if (cst == 0.0) return new IntConstant(0);
if (cst == 1.0) return this;
return new FloatAffine(this, cst, 0.0);
Expand Down
21 changes: 10 additions & 11 deletions ortools/sat/python/linear_expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,30 +65,29 @@ class LinearExpr {
static LinearExpr* MixedSum(const std::vector<ExprOrValue>& exprs);
static LinearExpr* WeightedSumInt(const std::vector<LinearExpr*>& exprs,
const std::vector<int64_t>& coeffs);
static LinearExpr* WeightedSumDouble(const std::vector<LinearExpr*>& exprs,
const std::vector<double>& coeffs);
static LinearExpr* WeightedSumFloat(const std::vector<LinearExpr*>& exprs,
const std::vector<double>& coeffs);
static LinearExpr* MixedWeightedSumInt(const std::vector<ExprOrValue>& exprs,
const std::vector<int64_t>& coeffs);
static LinearExpr* MixedWeightedSumDouble(
static LinearExpr* MixedWeightedSumFloat(
const std::vector<ExprOrValue>& exprs, const std::vector<double>& coeffs);
static LinearExpr* TermInt(LinearExpr* expr, int64_t coeff);
static LinearExpr* TermDouble(LinearExpr* expr, double coeff);
static LinearExpr* TermFloat(LinearExpr* expr, double coeff);
static LinearExpr* AffineInt(LinearExpr* expr, int64_t coeff, int64_t offset);
static LinearExpr* AffineDouble(LinearExpr* expr, double coeff,
double offset);
static LinearExpr* AffineFloat(LinearExpr* expr, double coeff, double offset);
static LinearExpr* ConstantInt(int64_t value);
static LinearExpr* ConstantDouble(double value);
static LinearExpr* ConstantFloat(double value);

LinearExpr* Add(LinearExpr* expr);
LinearExpr* AddInt(int64_t cst);
LinearExpr* AddDouble(double cst);
LinearExpr* AddFloat(double cst);
LinearExpr* Sub(LinearExpr* expr);
LinearExpr* SubInt(int64_t cst);
LinearExpr* SubDouble(double cst);
LinearExpr* SubFloat(double cst);
LinearExpr* RSubInt(int64_t cst);
LinearExpr* RSubDouble(double cst);
LinearExpr* RSubFloat(double cst);
LinearExpr* MulInt(int64_t cst);
LinearExpr* MulDouble(double cst);
LinearExpr* MulFloat(double cst);
LinearExpr* Neg();

BoundedLinearExpression* Eq(LinearExpr* rhs);
Expand Down
28 changes: 14 additions & 14 deletions ortools/sat/python/swig_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ PYBIND11_MODULE(swig_helper, m) {
PyExc_ValueError,
"The number of expressions and coefficients must match.");
}
return LinearExpr::WeightedSumDouble(exprs, coeffs);
return LinearExpr::WeightedSumFloat(exprs, coeffs);
},
py::return_value_policy::automatic, py::keep_alive<0, 1>())
.def_static(
Expand All @@ -425,27 +425,27 @@ PYBIND11_MODULE(swig_helper, m) {
PyExc_ValueError,
"The number of expressions and coefficients must match.");
}
return LinearExpr::MixedWeightedSumDouble(exprs, coeffs);
return LinearExpr::MixedWeightedSumFloat(exprs, coeffs);
},
py::return_value_policy::automatic, py::keep_alive<0, 1>())
// Make sure to keep the order of the overloads: int before float as an
// an integer value will be silently converted to a float.
.def_static("term", &LinearExpr::TermInt, arg("expr").none(false),
arg("coeff"), "Returns expr * coeff.",
py::return_value_policy::automatic, py::keep_alive<0, 1>())
.def_static("term", &LinearExpr::TermDouble, arg("expr").none(false),
.def_static("term", &LinearExpr::TermFloat, arg("expr").none(false),
arg("coeff"), "Returns expr * coeff.",
py::return_value_policy::automatic, py::keep_alive<0, 1>())
.def_static("affine", &LinearExpr::AffineInt, arg("expr").none(false),
arg("coeff"), arg("offset"), "Returns expr * coeff + offset.",
py::return_value_policy::automatic, py::keep_alive<0, 1>())
.def_static("affine", &LinearExpr::AffineDouble, arg("expr").none(false),
.def_static("affine", &LinearExpr::AffineFloat, arg("expr").none(false),
arg("coeff"), arg("offset"), "Returns expr * coeff + offset.",
py::return_value_policy::automatic, py::keep_alive<0, 1>())
.def_static("constant", &LinearExpr::ConstantInt, arg("value"),
"Returns a constant linear expression.",
py::return_value_policy::automatic)
.def_static("constant", &LinearExpr::ConstantDouble, arg("value"),
.def_static("constant", &LinearExpr::ConstantFloat, arg("value"),
"Returns a constant linear expression.",
py::return_value_policy::automatic)
// Pre PEP8 compatibility layer.
Expand Down Expand Up @@ -474,13 +474,13 @@ PYBIND11_MODULE(swig_helper, m) {
PyExc_ValueError,
"The number of expressions and coefficients must match.");
}
return LinearExpr::MixedWeightedSumDouble(exprs, coeffs);
return LinearExpr::MixedWeightedSumFloat(exprs, coeffs);
},
py::return_value_policy::automatic, py::keep_alive<0, 1>())
.def_static("Term", &LinearExpr::TermInt, arg("expr").none(false),
arg("coeff"), "Returns expr * coeff.",
py::return_value_policy::automatic, py::keep_alive<0, 1>())
.def_static("Term", &LinearExpr::TermDouble, arg("expr").none(false),
.def_static("Term", &LinearExpr::TermFloat, arg("expr").none(false),
arg("coeff"), "Returns expr * coeff.",
py::return_value_policy::automatic, py::keep_alive<0, 1>())
// Methods.
Expand All @@ -495,30 +495,30 @@ PYBIND11_MODULE(swig_helper, m) {
py::keep_alive<0, 2>())
.def("__add__", &LinearExpr::AddInt, arg("cst"),
py::return_value_policy::automatic, py::keep_alive<0, 1>())
.def("__add__", &LinearExpr::AddDouble, arg("cst"),
.def("__add__", &LinearExpr::AddFloat, arg("cst"),
py::return_value_policy::automatic, py::keep_alive<0, 1>())
.def("__radd__", &LinearExpr::AddInt, arg("cst"),
py::return_value_policy::automatic, py::keep_alive<0, 1>())
.def("__radd__", &LinearExpr::AddDouble, arg("cst"),
.def("__radd__", &LinearExpr::AddFloat, arg("cst"),
py::return_value_policy::automatic, py::keep_alive<0, 1>())
.def("__sub__", &LinearExpr::Sub, arg("other").none(false),
py::return_value_policy::automatic, py::keep_alive<0, 1>(),
py::keep_alive<0, 2>())
.def("__sub__", &LinearExpr::SubInt, arg("cst"),
py::return_value_policy::automatic, py::keep_alive<0, 1>())
.def("__sub__", &LinearExpr::SubDouble, arg("cst"),
.def("__sub__", &LinearExpr::SubFloat, arg("cst"),
py::return_value_policy::automatic, py::keep_alive<0, 1>())
.def("__rsub__", &LinearExpr::RSubInt, arg("cst"),
py::return_value_policy::automatic, py::keep_alive<0, 1>())
.def("__rsub__", &LinearExpr::RSubDouble, arg("cst"),
.def("__rsub__", &LinearExpr::RSubFloat, arg("cst"),
py::return_value_policy::automatic, py::keep_alive<0, 1>())
.def("__mul__", &LinearExpr::MulInt, arg("cst"),
py::return_value_policy::automatic, py::keep_alive<0, 1>())
.def("__mul__", &LinearExpr::MulDouble, arg("cst"),
.def("__mul__", &LinearExpr::MulFloat, arg("cst"),
py::return_value_policy::automatic, py::keep_alive<0, 1>())
.def("__rmul__", &LinearExpr::MulInt, arg("cst"),
py::return_value_policy::automatic, py::keep_alive<0, 1>())
.def("__rmul__", &LinearExpr::MulDouble, arg("cst"),
.def("__rmul__", &LinearExpr::MulFloat, arg("cst"),
py::return_value_policy::automatic, py::keep_alive<0, 1>())
.def("__neg__", &LinearExpr::Neg, py::return_value_policy::automatic,
py::keep_alive<0, 1>())
Expand Down Expand Up @@ -724,7 +724,7 @@ PYBIND11_MODULE(swig_helper, m) {
This method implements the logical negation of a Boolean variable.
It is only valid if the variable has a Boolean domain (0 or 1).
Note that this method is nilpotent: `x.negated().negated() == x`.
Note that this method is nilpotent: `x.negated().negated() == x`.
)doc")
.def("__invert__", &Literal::negated,
"Returns the negation of the current literal.")
Expand Down

0 comments on commit e01a1fe

Please sign in to comment.