简体   繁体   English

cplex - 矩阵值和索引的最小化和总和

[英]cplex - minimization and sum of matrix values and indexes

I'm using a Cplex Java API for the first time.我第一次使用 Cplex Java API。

I want to minimize the sum of values in matrix on some indexes, which is given by condition.我想最小化某些索引上矩阵中的值的总和,这是由条件给出的。

For example, if I have the matrix M = {{ 0, 1, 2, 1},{ 1, 2, 1, 0},{ 0, 1, 1, 0},{ 1, 1, 1, 2}} .例如,如果我有矩阵M = {{ 0, 1, 2, 1},{ 1, 2, 1, 0},{ 0, 1, 1, 0},{ 1, 1, 1, 2}}

I want to calculate two sums, first, the sum of all elements e = 1 and second, indexes where elements are equal to 1 .我想计算两个总和,首先,所有元素的总和e = 1和第二,元素等于1的索引。

So, indexes where element is equal 1 are {{0,1} {1,0} {1,2} {2,1} {2,2} {3,0} {3,1} {3,2} .因此,元素等于1的索引是{{0,1} {1,0} {1,2} {2,1} {2,2} {3,0} {3,1} {3,2} .

Result for first case is 9 (1+1+1+1+1+1+1+1+1)` and for second case is 24 (0+1+1+0+1+2+2+1+2+2+3+0+3+1+3+2).第一种情况的结果是 9 (1+1+1+1+1+1+1+1+1)`,第二种情况的结果是 24 (0+1+1+0+1+2+2+1+2 +2+3+0+3+1+3+2)。

I'm not sure how to use IloNumVar[] and create an expression using IloLinearNumExpr which is used in sum and minimize a function, while matrix M is type int[][] .我不确定如何使用IloNumVar[]并使用IloLinearNumExpr创建一个表达式,该表达式用于总和并最小化 function,而矩阵Mint[][]类型。

In your problem description, there is nothing to optimize.在您的问题描述中,没有什么可以优化的。 All elements in your matrix M are constant.矩阵M中的所有元素都是常数。 So the two sums you described can be computed directly without involving a tool like CPLEX.因此,您描述的两个总和可以直接计算,而无需使用 CPLEX 之类的工具。

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

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