java - 使用具有可变大小的 cplex 在 java 中定义二元决策变量
问题描述
我正在尝试在 java cplex 中定义一个 3D 二进制决策变量,假设 x[i][j][k] 其中 k 的大小是可变的并且取决于 f[i] 的值。我在这样的约束中使用它:forall i forall j Sum{k} x[i][j][k] = 1。
如何定义这个变量?
谢谢您的帮助。
解决方案
This is unrelated to CPLEX. You just have to define the 3rd dimension of the array depending on f[i]
like so (...
has to be filled with your correct dimensions):
IloIntVar[][][] x = new IloIntVar[...][][];
for (int i = 0; i < ...; ++i) {
x[i] = new IloIntVar[...][];
for (int j = 0; j < ...; ++j) {
x[i][j] = new IloIntVar[f[i]];
for (int k = 0; k < f[i]; ++k) {
x[i][j][k] = cplex.boolVar();
}
}
}
推荐阅读
- javascript - 当属性没有值时,dom解析器抛出错误
- ios - 如何使用 Xamarin 在 iOS 上设置 Material Components 标签栏的宽度
- sql-server-data-tools - 需要帮助使用代码将数据库引用添加到数据库项目
- ruby-on-rails - Ruby On Rails Searchkick gem 错误:“NGram Tokenizer 中的 max_gram 和 min_gram 之间的差异必须小于或等于:[1]
- python - 在 python 中修改模块的最佳方法是什么?
- arrays - 找到一对互质数
- angular - Angular 5->8 升级后,材质对话框显示在 DOM 中,但不呈现在屏幕上
- amazon-web-services - NestJS:图像上传和服务 API
- python - Django-rest ,返回自定义的 Json
- spring - 忽略 URL 路径变量值中的“/”