@@ -163,10 +163,19 @@ class ResponseWrapper {
163163
164164 double UserTime () const { return response_.user_time (); }
165165
166+ double FloatValue (std::shared_ptr<LinearExpr> expr) const {
167+ FloatExprVisitor visitor;
168+ visitor.AddToProcess (expr, 1 );
169+ return visitor.Evaluate (response_);
170+ }
171+
172+ double FixedFloatValue (double value) const { return value; }
173+
166174 int64_t Value (std::shared_ptr<LinearExpr> expr) const {
167- IntExprVisitor visitor;
168175 int64_t value;
169- if (!visitor.Evaluate (expr, response_, &value)) {
176+ IntExprVisitor visitor;
177+ visitor.AddToProcess (expr, 1 );
178+ if (!visitor.Evaluate (response_, &value)) {
170179 ThrowError (PyExc_ValueError,
171180 absl::StrCat (" Failed to evaluate linear expression: " ,
172181 expr->DebugString ()));
@@ -453,9 +462,10 @@ PYBIND11_MODULE(cp_model_helper, m) {
453462 " Value" ,
454463 [](const SolutionCallback& callback,
455464 std::shared_ptr<LinearExpr> expr) {
456- IntExprVisitor visitor;
457465 int64_t value;
458- if (!visitor.Evaluate (expr, callback.Response (), &value)) {
466+ IntExprVisitor visitor;
467+ visitor.AddToProcess (expr, 1 );
468+ if (!visitor.Evaluate (callback.Response (), &value)) {
459469 ThrowError (PyExc_ValueError,
460470 absl::StrCat (" Failed to evaluate linear expression: " ,
461471 expr->DebugString ()));
@@ -466,6 +476,21 @@ PYBIND11_MODULE(cp_model_helper, m) {
466476 .def (
467477 " Value" , [](const SolutionCallback&, int64_t value) { return value; },
468478 " Returns the value of a linear expression after solve." )
479+ .def (
480+ " FloatValue" ,
481+ [](const SolutionCallback& callback,
482+ std::shared_ptr<LinearExpr> expr) {
483+ FloatExprVisitor visitor;
484+ visitor.AddToProcess (expr, 1.0 );
485+ return visitor.Evaluate (callback.Response ());
486+ },
487+ " Returns the value of a floating point linear expression after "
488+ " solve." )
489+ .def (
490+ " FloatValue" ,
491+ [](const SolutionCallback&, double value) { return value; },
492+ " Returns the value of a floating point linear expression after "
493+ " solve." )
469494 .def (
470495 " BooleanValue" ,
471496 [](const SolutionCallback& callback, std::shared_ptr<Literal> lit) {
@@ -495,6 +520,8 @@ PYBIND11_MODULE(cp_model_helper, m) {
495520 .def (" sufficient_assumptions_for_infeasibility" ,
496521 &ResponseWrapper::SufficientAssumptionsForInfeasibility)
497522 .def (" user_time" , &ResponseWrapper::UserTime)
523+ .def (" float_value" , &ResponseWrapper::FloatValue, py::arg (" expr" ))
524+ .def (" float_value" , &ResponseWrapper::FixedFloatValue, py::arg (" value" ))
498525 .def (" value" , &ResponseWrapper::Value, py::arg (" expr" ))
499526 .def (" value" , &ResponseWrapper::FixedValue, py::arg (" value" ))
500527 .def (" wall_time" , &ResponseWrapper::WallTime);
0 commit comments