简体   繁体   中英

cplex - minimization and sum of matrix values and indexes

I'm using a Cplex Java API for the first time.

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}} .

I want to calculate two sums, first, the sum of all elements e = 1 and second, indexes where elements are equal to 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} .

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).

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[][] .

In your problem description, there is nothing to optimize. All elements in your matrix M are constant. So the two sums you described can be computed directly without involving a tool like CPLEX.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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