简体   繁体   English

Cplex Java多维决策变量,最小化

[英]Cplex java multidimensional decision variable, minimization

I'm using Cplex in Java and want to minimize the sum of the products of elements from two matrices (products of elements with the same index). 我在Java中使用Cplex,并希望最小化来自两个矩阵的元素乘积之和(具有相同索引的元素的乘积)。

x[n][n] contains decisionvariables [0, 1] x [n] [n]包含决策变量[0,1]

cost[n][n] contains the cost for the way from i to j cost [n] [n]包含从i到j的成本

I want to minimize the sum of costs x[i][j] * j[i][j] for all i..n; 我想最小化所有i..n的成本总和x [i] [j] * j [i] [j]; j..n. j..n。

I created the variables like this: 我创建了这样的变量:

[...]
static double   lb = 0.0;
static double   ub = 1.0;
static double   cost[][] = new double[n][n];

IloNumVar[][] x = new IloNumVar[n][n];
        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                x[i][j] = cplex.numVar(lb, ub);
                }
        }

My Problem is that I don't know how to create the minimize part. 我的问题是我不知道如何创建最小化部分。

I found something that seems to be very similar to my problem ( Cplex c++ multidimensional decision variable ) but as I am not familiar to c++, I don't get any solution out of it. 我发现了一些看起来与我的问题非常相似的东西( Cplex c ++多维决策变量 ),但是由于我对c ++不熟悉,所以我没有得到任何解决方案。

This should do it: 应该这样做:

IloLinearNumExpr obj = cplex.linearNumExpr();

for (int i = 0; i < n; i++) {
  for (int j = 0; j < n; j++) {
    obj.addTerm(cost[i][j], x[i][j]);
  }
}

cplex.addMinimize(obj); cplex.addMinimize(OBJ);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM