Originally posted by: NaomiLearnCplex
Hello there,
Below is the coding for a binary integer minimization problem. My cost function cij is the sum of decision variables xij from i to i+9. The last 9 rows exceed the range of i. I want to express the row index as a function of i. The row index is represented as 1 plus the remainder of i divided by the number of rows (ns), where i iterates from i to i+9. (Detailed formuation is shown in below picture) By doing this, I can form a closed row sum loop by connecting the last row to the first row. However, I don't know how to write my cost function using CPLEX.

What I did is to write
dexpr int c[i in shift, j in comb ] = x [ i] [ j ] +x [ i+1] [ j ] +x [ i+2] [ j ] +x [ i+3] [ j ] +x [ i+4] [ j ] +x [ i+5] [ j ] +x [ i+6] [ j ] +x [ i+7] [ j ] +x [ i+8] [ j ] +x [ i+9] [ j]
;
But definitely, this expression has a range problem.
Anyone could help? Many thanks in advance!
int nc=...;
int ns=...;
range comb=1..nc;
range shift=1..ns;
//define decision variables
dvar boolean x[shift][comb];
//define parameters
int CombSF[comb]=...;
dexpr int c[i in shift, j in comb]= x[i][j]+x[i+1][j]+x[i+2][j]+x[i+3][j]+x[i+4][j]+x[i+5][j]+x[i+6][j]+x[i+7][j]+x[i+8][j]+x[i+9][j];
int dl[shift]=...;
int du[shift]=...;
//define objective function
minimize sum(i in shift, j in comb)c[i][j]*x[i][j];
//define constraints
subject to
{
Con01:
forall(i in shift)
dl[i]<=sum(j in comb)x[i][j]<=du[i];
Con02:
forall(j in comb)
sum(i in shift)x[i][j]==CombSF[j];
}
#DecisionOptimization#OPLusingCPLEXOptimizer