有没有办法将 3 维数组从 CPLEX 写入 Excel?

Is there a way to write 3 dimensional array from CPLEX to Excel?

我有一个 X[k][i][j] 的结果数组(k 在 Day 范围从 1 到 365,i 在 Task 范围从 1 到 200,j 在 Repetition 范围从 0 到365).

我知道如何将二维数组从 cplex 写入 excel,但是将 3 维数组写入 excel 似乎是个问题。

有没有办法将 3 维数组从 cplex 写入 excel?我尝试使用 this link 中的方法,但它说约束冲突(可能是因为我的 j 范围从 0 到 365?)

有人可以帮帮我吗? 提前致谢!

using CP;
int scale=1000;

int NumbDay =...;
int NumbTask =...;

range Day = 1 .. NumbDay;
range Task = 1 .. NumbTask;

int maxRepetition = NumbDay;
dvar int F [Task] in 1..maxRepetition;
range Repetition = 0 .. maxRepetition;

int h [Day]=...;
int R [Task]=...;
int c [Day]=...;
int E [Task]=...;
int d [Day]=...;
int O [Task]=...;
int P [Task] =...;
float t [Task]=...;

dvar int+ r [Task][Repetition];
dvar int+ e [Task][Repetition];
dvar int+ o [Task][Repetition];
dvar int+ q [Task][Repetition];
dvar int+ n [Task][Repetition];
dvar int+ m [Task][Repetition];
dvar int scalenW[Day] in 0..100;
dexpr float W [k in Day]=scalenW[k]/scale;
dvar boolean X [Day][Task][Repetition];


dexpr float e1 = sum(k in Day)(((sum(k in Day, i in Task, j in Repetition) t [i]*X[k][i][j])/365) - W [k])^2;

dexpr float e2 = sum(i in Task, j in Repetition)(q[i][j]*n[i][j]*m[i][j]);

minimize staticLex(e1, e2);
subject to 
{   constraint_1:
        forall (i in Task){
            F [i] >= P [i] && F[i] <= NumbDay;
    }
    constraint_2:
        forall (k in Day){
            abs(sum(i in Task) (sum(j in Repetition)(t [i]*X [k][i][j]*(j<=F[i]-1))) - W [k])<=1;
    }
    constraint_3:
        forall (i in Task, j in Repetition){
            sum(k in Day) X [k][i][j] == 1 * (j<=F[i]-1);
    }
    constraint_4:
        forall (k in Day, i in Task, j in Repetition){
            X [k][i][j] == 0 || X [k][i][j] == 1;
    }
    constraint_5:
        forall (i in Task, j in Repetition){
          (r[i][j]!=0) => sum(k in Day)(X [k][i][j] * h [k]) <= r [i][j];
    }
    constraint_6:
        forall (i in Task, j in Repetition){
           q [i][j] == r [i][j] - sum(k in Day)( X [k][i][j] * h [k]);
    }
    constraint_7:
        forall (i in Task, j in Repetition){
           r [i][j] <= 10 * NumbDay;
    }
    constraint_8:
        forall (i in Task){
            r [i][0] == R [i];
    }
    constraint_9:
        forall (i in Task, j in 1..NumbDay){
          r [i][j] == (R [i] + sum(k in Day) (X [k][i][j-1] * h [k])) * (j<=F[i]-1);
    }
    constraint_10:
        forall (i in Task, j in Repetition){
           (e[i][j]!=0) => sum(k in Day)(X [k][i][j] * c [k]) <= e [i][j];
    }
    constraint_11:
        forall (i in Task, j in Repetition){
           n [i][j] == e [i][j] - sum(k in Day)( X [k][i][j] * c [k]);
    }
    constraint_12:
        forall (i in Task, j in Repetition){
           e [i][j] <= 10 * NumbDay;
    }
    constraint_13:
        forall (i in Task){
            e [i][0] == E [i];
    }
    constraint_14:
        forall (i in Task, j in 1..NumbDay){
            e [i][j] == (E [i] + sum(k in Day) (X [k][i][j-1] * c [k])) * (j<=F[i]-1);
    }
     constraint_15:
        forall (i in Task, j in Repetition){
           (o[i][j]!=0) => sum(k in Day)(X [k][i][j] * d [k]) <= o [i][j];
    }
   constraint_16:
        forall (i in Task, j in Repetition){
           m [i][j] == o [i][j] - sum(k in Day)( X [k][i][j] * d [k]);
    }
    constraint_17:
        forall (i in Task, j in Repetition){
           o [i][j] <= 10 * NumbDay;
    }
    constraint_18:
        forall (i in Task){
            o [i][0] == O [i];
    }
    constraint_19:
        forall (i in Task, j in 1..NumbDay){
            o [i][j] == (O [i] + sum(k in Day) (X [k][i][j-1] * d [k])) * (j<=F[i]-1);
    }
}

对于 3D,您可以将数组转换为元组集,然后将您的元组集 Sheetwrite

参见 Excel 和 opl https://www.linkedin.com/pulse/excel-rocket-science-optimization-alex-fleischer