Search code examples
cplexopl

Creating a tuple in post-process execute command of OPL


I have a worker assignment problem where jobs have three components (sub-skills) to identify them:

{job} Jobs = { < c1, c2, c3 > | c1 in Cat1, c2 in Cat2, c3 in Cat3 };

From the pool of workers I now create tuples of possibilities for assigning a worker to a job if they match the criteria:

{possibleTuple} = Possibles = { < n, c1, c2, c3 > | < c1,c2,c3> in Jobs, n in Workers };

A binary array onTeam[Possibles] indicates if worker n is assigned to the team.

My model runs fine and I am getting sensible results. However, I am unable to print these out nicely in the post-processing "execute" command. I would like to output the team of workers for each job with something like:

for (var j in Jobs)
{
   for (var n in Workers)
   {
     if onTeam[<n,c1,c2,c3>] == 1, output n
   }
}

It is this inner logic that I am having difficulty with. I am not able to recreate the tuple in order to index the onTeam set.

Can anybody help, please?

Many thanks, Patrick Healy


Solution

  • let me give you a small example:

    {string} Cat1={"A","B"};
    {string} Cat2={"C","D"};
    {string} Cat3={"E","F"};
    
    tuple job
    {
    string j1;
    string j2;
    string j3;
    }
    
    {job} Jobs = { < c1, c2, c3 > | c1 in Cat1, c2 in Cat2, c3 in Cat3 };
    
    {string} Workers={"Albert","Bob","Charles"};
    
    tuple possibleTuple
    {
    string n;
    
    string j1;
    string j2;
    string j3;
    }
    
    {possibleTuple} Possibles = { < n, c1, c2, c3 > | < c1,c2,c3> in Jobs, n in Workers };
    
    dvar boolean onTeam[Possibles];
    
    subject to
    {
    onTeam[<"Albert","A","C","E">]==1;
    onTeam[<"Bob","A","C","E">]==1;
    onTeam[<"Charles","A","C","F">]==1;
    }
    
    {string} workersPerJob[j in Jobs]=
    {w | w in Workers : onTeam[<w,j.j1,j.j2,j.j3>]==1};
    
    execute
    {
    for(var j in Jobs) if ( workersPerJob[j].size!=0)
    {
    writeln("for job ",j," workers : ", workersPerJob[j]);
    }
    }
    

    which gives

    for job  <"A" "C" "E"> workers :  {"Albert" "Bob"}
    for job  <"A" "C" "F"> workers :  {"Charles"}