Paint production

The problem description in this section is taken from Section 7.5 Paint production of the book Applications of optimization with Xpress-MP. As a part of its weekly production a paint company produces five batches of paints, always the same, for some big clients who have a stable demand. Every paint batch is produced in a single production process, all in the same blender that needs to be cleaned between every two batches. The durations of blending paint batches 1 to 5 are respectively 40, 35, 45, 32, and 50 minutes. The cleaning times depend on the colors and the paint types. For example, a long cleaning period is required if an oil-based paint is produced after a water-based paint, or to produce white paint after a dark color. The times are given in minutes in the following table:

CLEAN(i,j)

1

2

3

4

5

1

0

11

7

13

11

2

5

0

13

15

15

3

13

15

0

23

11

4

9

13

5

0

3

5

3

7

7

7

0

Since the company also has other activities, it wishes to deal with this weekly production in the shortest possible time (blending and cleaning). Which is the corresponding order of paint batches? The order will be applied every week, so the cleaning time between the last batch of one week and the first of the following week needs to be counted for the total duration of cleaning.

Formulation of model 1

As for the problem in section 11.3 we are going to present two alternative model formulations. The first one is closer to the Mathematical Programming formulation in Applications of optimization with Xpress-MP, the second uses a two-dimensional element constraint. Let JOBS = \{1, ..., NJ\} be the set of batches to produce, DUR_j the processing time for batch j, and CLEAN_{i,j} the cleaning time between the consecutive batches i and j. We introduce decision variables succ_j taking their values in JOBS, to indicate the successor of every job, and variables clean_j for the duration of the cleaning after every job. The cleaning time after every job is obtained by indexing CLEAN_{i,j} with the value of succ_j. We thus have the following problem formulation:

&\text{minimize } \sum_{j \in JOBS}(DUR_j + clean_j)\\
&\forall j \in JOBS : succ_j \in {JOBS} \backslash \{j\}\\
&\forall j \in JOBS : clean_j = CLEAN_{j,succ_j}\\
&\text{all-different}(\bigcup\limits_{j \in JOBS}^{} succ_j)\\

The objective function sums up the processing and cleaning times of all batches. The last (all-different) constraint guarantees that every batch occurs exactly once in the production sequence.

Unfortunately, this model does not guarantee that the solution forms a single cycle. Solving it indeed results in a total duration of 239 with an invalid solution that contains two sub-cycles 1 \rightarrow 3 \rightarrow 2 \rightarrow 1 and 4 \rightarrow 5 \rightarrow 4. A first possibility is to add a disjunction excluding this solution to our model and re-solve it iteratively until we reach a solution without sub-cycles.

&succ_1 \ne 3 \vee succ_3 \ne 2 \vee succ_2 \ne 1 \vee succ_1 \ne 5 \vee succ_5 \ne 4\\

However, this procedure is likely to become impractical with larger data sets since it may potentially introduce an extremely large number of disjunctions. We therefore choose a different, a-priori formulation of the sub-cycle elimination constraints with a variable y_j per batch and (NJ-1)^2 implication constraints.

&\forall j \in JOBS : rank_j \in \{1, ..., NJ\}\\
&\forall i \in JOBS, \forall j \in \{2, ..., NJ\}, i \ne j : succ_i = j \Rightarrow y_j = y_i + 1\\
&\forall j \in JOBS : rank_j \in \{1, ..., NJ\}\\

The variables y_j correspond to the position of job j in the production cycle. With these constraints, job 1 always takes the first position.

Implementation of model 1

The implementation of the model formulated in the previous section is quite straightforward. The sub-cycle elimination constraints are implemented as logic relations with implies (a stronger formulation of these constraints is obtained by replacing the implications by equivalences, using KEquiv).

// Number of paint batches (=jobs)
int NJ = 5;
// Durations of jobs
int DUR[]  = {40, 35, 45, 32, 50};

// Cleaning times between jobs
int CLEAN[5][5] = {
    {  0, 11,  7, 13, 11 },
    {  5,  0, 13, 15, 15 },
    { 13, 15,  0, 23, 11 },
    {  9, 13,  5,  0,  3 },
    {  3,  7,  7,  7,  0 } };


// Cleaning times after a batch
KIntArray CB;
// Successor of a batch
KIntVarArray succ;
// Cleaning time after batches
KIntVarArray clean;
// Variables for excluding subtours
KIntVarArray y;
// Objective variable
KIntVar * cycleTime;

// Creation of the problem in this session
KProblem problem(session,"B-5 Paint production");

// variables creation
char name[80];
int j,i;
for (j=0;j<NJ;j++) {
    sprintf(name,"succ(%i)",j);
    succ += (* new KIntVar( problem,name,0,NJ-1) );
    succ[j].remVal(j);
    sprintf(name,"y(%i)",j);
    y += (* new KIntVar( problem,name,0,NJ-1) );
}

// initialization of CB array
for (j=0;j<NJ;j++) {
    CB += 0;
}
// Cleaning time after every batch
for (j=0;j<NJ;j++) {
    sprintf(name,"clean(%i)",j);
    clean += (* new KIntVar( problem,name,0,1000) );
    for (i=0;i<NJ;i++) {
        CB[i] = CLEAN[j][i];
    }
    KEltTerm kelt(CB,succ[j]);
    problem.post(new KElement(kelt,clean[j],"element"));
}

// objective variable creation
cycleTime = new KIntVar(problem,"cycleTime",0,1000);
// Objective: minimize the duration of a production cycle
KLinTerm cycleTerm;
for (j=0;j<NJ;j++) {
    cycleTerm = cycleTerm + clean[j] + DUR[j];
}
problem.post(cycleTerm == *cycleTime);

// One successor and one predecessor per batch
problem.post(new KAllDifferent("alldiff",succ));

// Exclude subtours
for (i=0;i<NJ;i++) {
    for (j=1;j<NJ;j++) {
        if (i!=j) {
            problem.post(new KGuard( succ[i] == j , y[j] == y[i] + 1  );                }
    }
}
// propagating problem
if (problem.propagate()) {
    printf("Problem is infeasible\n");
    exit(1);
}

// Solve the problem
// creation of the solver
KSolver solver(problem);

// setting objective and sense of optimization
problem.setSense(KProblem::Minimize);
problem.setObjective(*cycleTime);

int result = solver.optimize();
// solution printing
KSolution * sol = &problem.getSolution();
// print solution resume
sol->printResume();


// Solution printing
printf("Minimum cycle time: %i\n", sol->getValue(*cycleTime));
printf("Sequence of batches:\nBatch Duration Cleaning\n");
int first=0;
do {
    printf("%i\t%i\t%i\n", first, DUR[first],sol->getValue(clean[first]));
    first = sol->getValue(succ[first]);
} while (first!=0);

Formulation of model 2

We may choose to implement the paint production problem using rank variables similarly to the sequencing model in section 11.3. As before, let JOBS = \{1, ..., NJ\} be the set of batches to produce, DUR_j the processing time for batch j, and CLEAN_{i,j} the cleaning time between the consecutive batches i and j. We introduce decision variables rank_k taking their values in JOBS, for the number of the job in position k. Variables clean_k with k \in JOBS now denote the duration of the k^{\text{th}} cleaning time. This duration is obtained by indexing CLEAN_{i,j} with the values of two consecutive rank_k variables. We thus have the following problem formulation.

&\text{minimize } \sum_{j \in JOBS}DUR_j + \sum_{k \in JOBS}clean_k\\
&\forall k \in JOBS : rank_k \in {JOBS} \backslash \{k\}\\
&\forall k \in \{1, ..., NJ-1\} : clean_k = CLEAN_{rank_k,rank_{k+1}}\\
& clean_{NJ} = CLEAN_{rank_{NJ},rank_{1}}\\
&\text{all-different}(\bigcup\limits_{k \in JOBS}^{} rank_k)\\

As in model 1, the objective function sums up the processing and cleaning times of all batches. Although not strictly necessary from the mathematical point of view, we use different sum indices for durations and cleaning times to show the difference between summing over jobs or job positions. We now have an all-different constraint over the rank variables to guarantee that every batch occurs exactly once in the production sequence.

Implementation of model 2

The implementation of the second model uses the 2-dimensional version of the KElement constraint in Artelys Kalis.

// Number of paint batches (=jobs)
int NJ = 5;
// Durations of jobs
int DUR[]  = {40, 35, 45 ,32 ,50};

// Cleaning times between jobs
KIntMatrix CLEAN(5,5,0,"CLEAN");

CLEAN[0][0] = 0;CLEAN[1][0] = 11;CLEAN[2][0] = 7;CLEAN[3][0] = 13;CLEAN[4][0] = 11;
CLEAN[0][1] = 5;CLEAN[1][1] = 0;CLEAN[2][1] = 13;CLEAN[3][1] = 15;CLEAN[4][1] = 15;
CLEAN[0][2] = 13;CLEAN[1][2] = 15;CLEAN[2][2] = 0;CLEAN[3][2] = 23;CLEAN[4][2] = 11;
CLEAN[0][3] = 9;CLEAN[1][3] = 13;CLEAN[2][3] = 5;CLEAN[3][3] = 0;CLEAN[4][3] = 3;
CLEAN[0][4] = 3;CLEAN[1][4] = 7;CLEAN[2][4] = 7;CLEAN[3][4] = 7;CLEAN[4][4] = 0;

// Successor of a batch
KIntVarArray rank;
// Cleaning time after batches
KIntVarArray clean;
// Objective variable
KIntVar * cycleTime;

// Creation of the problem in this session
KProblem problem(session,"B-5 Paint production");

// variables creation
char name[80];
int k,j,i;
for (j=0;j<NJ;j++) {
    sprintf(name,"rank(%i)",j);
    rank += (* new KIntVar( problem,name,0,NJ-1) );
    sprintf(name,"clean(%i)",j);
    clean += (* new KIntVar( problem,name,0,1000) );
}

// Cleaning time after every batch
for (k=0;k<NJ;k++) {
    if (k < NJ-1) {
        KEltTerm2D kelt(CLEAN,rank[k],rank[k+1]);
        problem.post(new KElement2D(kelt,clean[k],"element"));
    } else {
        KEltTerm2D kelt(CLEAN,rank[k],rank[0]);
        problem.post(new KElement2D(kelt,clean[k],"element"));
    }
}

// objective variable creation
cycleTime = new KIntVar(problem,"cycleTime",0,1000);

// Objective: minimize the duration of a production cycle
KLinTerm cycleTerm;
for (j=0;j<NJ;j++) {
    cycleTerm = cycleTerm + DUR[j];
}
KLinTerm cleanTerm;
for (k=0;k<NJ;k++) {
    cleanTerm = cleanTerm + clean[k];
}
problem.post(cycleTerm + cleanTerm == *cycleTime);

// One position for every job
problem.post(new KAllDifferent("alldiff",rank));

// propagating problem
if (problem.propagate()) {
    printf("Problem is infeasible\n");
    exit(1);
}

// Solve the problem
// creation of the solver
KSolver solver(problem);

// setting objective and sense of optimization
problem.setSense(KProblem::Minimize);
problem.setObjective(*cycleTime);

int result = solver.optimize();
// solution printing
KSolution * sol = &problem.getSolution();
// print solution resume
sol->printResume();

// Solution printing
printf("Minimum cycle time: %i\n", sol->getValue(*cycleTime));
printf("Sequence of batches:\nBatch Duration Cleaning\n");
for (k=0;k<NJ;k++) {
    printf("%i\t%i\t%i\n", sol->getValue(rank[k]), DUR[sol->getValue(rank[k])], sol->getValue(clean[k]));
}

Results

The minimum cycle time for this problem is 243 minutes which is achieved with the following sequence of batches: 1 \rightarrow 2 \rightarrow 5 \rightarrow 3 \rightarrow 4 \rightarrow 1. This time includes 202 minutes of (incompressible) processing time and 41 minutes of cleaning.