How to define a tuple for reading 4 dimensional parameter in cplex .mod file and .dat file?

52 Views Asked by At

How can I read data 4D from Excel file for MILP model in Cplex?

I want to know how to define this parameter and apply in constraint enter image description here

enter image description here

1

There are 1 best solutions below

1
Alex Fleischer On

You can do that with a tuple set.

.mod

range A=1..2;
range B=1..3;
range C=1..4;
range D=1..2;


tuple someTuple{
    key int a;
    key int b;
    key int c;
    key int d;
    int value;
    };
    

{someTuple} someSet = ...;

int v[a in A][b in B][c in C][d in D]=item(someSet,<a,b,c,d>).value;

dvar int X[A][B][C][D];

subject to
{
    forall(a in A,b in B,c in C,d in D) X[a][b][c][d]==v[a][b][c][d];
}


assert forall(a in A,b in B,c in C,d in D) X[a][b][c][d]==a*b*c*d;

.dat

SheetConnection sheet("write4Darray.xlsx");

someSet from SheetRead(sheet,"A1:E48"); 

enter image description here