@@ -163,10 +163,19 @@ class ResponseWrapper {
163
163
164
164
double UserTime () const { return response_.user_time (); }
165
165
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
+
166
174
int64_t Value (std::shared_ptr<LinearExpr> expr) const {
167
- IntExprVisitor visitor;
168
175
int64_t value;
169
- if (!visitor.Evaluate (expr, response_, &value)) {
176
+ IntExprVisitor visitor;
177
+ visitor.AddToProcess (expr, 1 );
178
+ if (!visitor.Evaluate (response_, &value)) {
170
179
ThrowError (PyExc_ValueError,
171
180
absl::StrCat (" Failed to evaluate linear expression: " ,
172
181
expr->DebugString ()));
@@ -453,9 +462,10 @@ PYBIND11_MODULE(cp_model_helper, m) {
453
462
" Value" ,
454
463
[](const SolutionCallback& callback,
455
464
std::shared_ptr<LinearExpr> expr) {
456
- IntExprVisitor visitor;
457
465
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)) {
459
469
ThrowError (PyExc_ValueError,
460
470
absl::StrCat (" Failed to evaluate linear expression: " ,
461
471
expr->DebugString ()));
@@ -466,6 +476,21 @@ PYBIND11_MODULE(cp_model_helper, m) {
466
476
.def (
467
477
" Value" , [](const SolutionCallback&, int64_t value) { return value; },
468
478
" 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." )
469
494
.def (
470
495
" BooleanValue" ,
471
496
[](const SolutionCallback& callback, std::shared_ptr<Literal> lit) {
@@ -495,6 +520,8 @@ PYBIND11_MODULE(cp_model_helper, m) {
495
520
.def (" sufficient_assumptions_for_infeasibility" ,
496
521
&ResponseWrapper::SufficientAssumptionsForInfeasibility)
497
522
.def (" user_time" , &ResponseWrapper::UserTime)
523
+ .def (" float_value" , &ResponseWrapper::FloatValue, py::arg (" expr" ))
524
+ .def (" float_value" , &ResponseWrapper::FixedFloatValue, py::arg (" value" ))
498
525
.def (" value" , &ResponseWrapper::Value, py::arg (" expr" ))
499
526
.def (" value" , &ResponseWrapper::FixedValue, py::arg (" value" ))
500
527
.def (" wall_time" , &ResponseWrapper::WallTime);
0 commit comments