Search code examples
algorithmmultidimensional-arrayschedulingcplexopl

CPLE How to set a decision variable array dynamically


I want to formulate a flexible job shop scheduling problem with MIP instead of CP.

If there is an array indicating number of operations of each job.

num_op = [3, 2, 5]

And Xijk is the decision variable indicating if the j-th operation of job i is processed on machine k or not.

My question is that I don't know how t initiate the 3-D array with different number of operations of each job.

I wrote this dvar boolean x[i in Jobs][j in][k in Machs];, and I don't know to how to complete it.

Please help me. Thanks!!


Solution

  • If I understand your example correctly then your definition of num_op indicates that you have three different jobs, the first job has 3 operations, the second has 2 and the last job has 5 operations. That would mean that the second dimension of Xijk has to change depending on the first dimension. Such a flexible array size is not possible with CPLEX.

    Here is an alternative:

    • Define M to be the maximum number of operations (5 in your case).
    • Define dvar boolean x[i in Jobs][j in 1..M][k in Machs];
    • Explicitly fix all variables to 0 that correspond to non-existing operations: forall (i in Jobs, j in 1..M, k in Machs) if (j > num_op[i]) X[i][j][k] == 0;

    The last step is even optional: You can define the variables for non-existing operations but just not use them anywhere in your model (this may give a warning for unused variables, though).

    Another option is to create a tuple tuple { int i; int j; int k }, then create a tuple set that contains all the valid combinations of i, j, k and index X by this tuple set.