Ortools - 将 MPVariable 设置为 MPCons应变绑定
Ortools - Set MPVariable as MPConstrains bound
我想做这样的事情:
namespace opr = operations_research;
double min = 10;
opr::MPVariable* const y1 = solver.MakeBoolVar("y1");
opr::MPConstraint *const c1 = solver.MakeRowConstraint(-min * y1, 10);
但是编译器抱怨因为数据类型不兼容,取消引用指针也不起作用,编译它的唯一方法是使用y1->solution_value()
但我认为这不是正确的解决方案,因为它复制了当前的 y1 值,我希望绑定随 y1 一起变化。 对于上下文,y1
是一个标志变量,用于满足其他变量的特定条件。 我尝试编写的约束类型如下所示:
-M * y_1 <= x <= 10
正如@LaurentPerron评论中提到的,解决方案只是重写约束,使边界是数字而不是 MPVariable。 对于我发布的示例,如下所示:
-M * y_1 <= x <= 10
写成:
x <= 10
x + M * y1 >= 0
相关文章:
- 我想将一个对T类型的非常量左值引用绑定到一个T类型的临时值
- 在基于范围的for循环中使用结构化绑定声明
- 使用 LuaBridge 将 LuaJIT 绑定到C++会导致"PANIC: unprotected error"
- 尝试通过OCI例程从Oracle获取blob数据,但出现错误:ORA-01008:并非所有变量都绑定
- 在使用GPU支持编译Tensorflow时,会遇到CUDA_TOOLKIT_PATH未绑定变量
- 视觉studo 2019中的漫画和静态/动态绑定
- 将自由函数绑定为类成员函数
- 将常量指针引用绑定到非常量指针
- 在派生类中绑定非静态模板化成员函数
- 绑定派生类方法C++从实例范围之外的分隔 std::function 变量调用
- 在 openGL 中多次绑定缓冲区
- 定义有趣的宏和正则表达式在Z3 C++绑定
- 使用结构化绑定'Reflection'
- 为什么 std::绑定错误参数可以成功?
- 如何绑定 C++ gRPC 客户端的网络接口
- 在 openmp 中,omp_get_thread_num是否绑定到物理线程?
- C++绑定(已弃用)
- 运行时错误:引用绑定到类型为"int"的空指针
- 有没有办法将重载的类函数绑定到函数对象?
- Ortools - 将 MPVariable 设置为 MPCons应变绑定