Chris_Q
Chris_Q

Reputation: 13

Cplex: minimize the number of times when state change

My problem is very similar to this:

A machine can be equipped with a tool among a set of n possible tools. Each operation o executed on the machine needs a specific tool RequiredTool[o]. The machine can process several operations simultaneously provided these operations are compatible with the tool currently installed on the machine. Changing the tool installed on the machine needs some constant set-up time.

My question is how to define objective function so that it minimizes the number of times to change tools? In other words, is there a way to count the number of times for state change within the stateFunction?

int nbTools = ...;
int nbOps = ...;
int setupTime = ...;
range Tools = 1..nbTools;
range Operations = 1..nbOps;
int Duration [Operations] = ...;
int RequiredTool [Operations] = ...;

dvar interval op[o in Operations] size Duration[o];

tuple triplet { int tl1; int tl2; int value; };
{ triplet } Transition = { <tl1,tl2,setupTIme> } tl1, tl2 in Tools };
stateFunction machineTool with Transition;

constraints {
forall(o in Operations) {
alwaysEqual(machineTool, op[o], RequiredTool[o]);
}
}

Upvotes: 0

Views: 141

Answers (1)

Olivier Lhomme
Olivier Lhomme

Reputation: 136

you can use sequence variables and associate a type for each kind of tools:

using CP;

int nbTools = 4+1; //5 is an additional type for handling the ending operation
int nbOps = 10;
int setupTime = 10;
range Tools = 1..nbTools;
range Operations = 1..nbOps;
int Duration [Operations] =  [1, 1, 1, 1, 1,  1, 1, 1, 1, 1];
int RequiredTool [Operations] = [3, 3, 1, 2, 4, 3, 2, 4, 1, 2];

dvar interval op[o in Operations] size Duration[o];

tuple triplet { int tl1; int tl2; int value; };
{ triplet } Transition = { <tl1,tl2,setupTime> | tl1, tl2 in Tools: tl1!=tl2&&tl1<5&&tl2<5 } 
                         union  { <tl1,tl1,0> | tl1 in Tools} 
                         union  { <5,tl1,0> | tl1 in Tools} 
                         union  { <tl1,5,0> | tl1 in Tools} ;

dvar sequence s1 in all(i in Operations) op[i] types all(i in Operations) RequiredTool[i];

dexpr int numberOfTransitions = sum(i in Operations) (typeOfNext(s1, op[i], RequiredTool[i], RequiredTool[i])!= RequiredTool[i]);

minimize numberOfTransitions;

subject to {
  numberOfTransitions >= 3; // a lower bound
  noOverlap(s1,Transition );
}
  
execute {
    writeln(s1);
};

Upvotes: 1

Related Questions