usama
usama

Reputation: 15

is there any way to iterate in 2-D array in CPLEX

I want to model these Constraints in figure in CPLEX OPL, but CPLEX does not give opportunity to iterate in the multidimensional arrays. Cst and Tst are binary matrices, and the idea is to only sum for non zero elements. How can I do this please.

Upvotes: 0

Views: 449

Answers (1)

Alex Fleischer
Alex Fleischer

Reputation: 10037

What I answered in community.ibm.com

range S=1..3;
range T=1..3;

int Cst[S][T] = [[0, 0 ,1],
         [1 ,0, 1],
         [0 ,1 ,0]];
         
dvar boolean x[S][T];

dvar int su; // sum all x such as Cst is 1

maximize su;
subject to
{
  su==sum(s in S,t in T:Cst[s][t]==1) x[s][t];
} 

works fine and gives su=4

Upvotes: 1

Related Questions