Originally posted by: AndyHam
Hi IBM,
I am new to CP with just 6 months' experience. I simply tried to execute the example called "Batch scheduling" to understand the stateFunction, but I got a following error:
Exception in presolve: Transition matrix for state function does not satisfy the triangle inequality (path 1->0->2)..
I did not change any single character, but the error occurs.
Can you please tell me why I am having this error and how to fix it?
ps - I just copy & paste the codes in below.
Thanks,
Andy
/***********************************************************
* CP Optimizer Training - Batch Scheduling SOLUTION 4 Data *
************************************************************/
numberProducts = 5;
preparationTime = 30;
steps = [
{<1, 30, 1>, <2, 30, 2>, <3, 30, 3>}, // <stepNumber, duration, temperatureCode>
{<1, 45, 2>, <2, 45, 3>, <3, 45, 4>, <4, 45, 1>},
{<1, 30, 1>, <2, 30, 4>, <3, 30, 3>},
{<1, 45, 4>, <2, 45, 1>, <3, 45, 2>},
{<1, 30, 4>, <2, 30, 3>, <3, 30, 2>}
];
orders = [12, 16, 14, 18, 13];
numberOvens = 3;
ovenCapacity = [4, 4, 4];
transitionTimes = { // <code1, code2, transitionTime>
<1, 1, 0>, <1, 2, 5>, <1, 3, 10>, <1, 4, 15>,
<2, 1, 5>, <2, 2, 0>, <2, 3, 5>, <2, 4, 10>,
<3, 1, 10>, <3, 2, 5>, <3, 3, 0>, <3, 4, 5>,
<4, 1, 15>, <4, 2, 10>, <4, 3, 5>, <4, 4, 0>
};
/******************************************************
* CP Optimizer Traning - Batch Scheduling SOLUTION 4 *
* *
******************************************************/
using CP;
/*******
* Data *
********/
int numberProducts = ...;
int preparationTime = ...;
range products = 1..numberProducts;
tuple productStepT {
key int stepNumber;
int duration;
int temperatureCode;
};
{productStepT} steps[products] = ...;
int orders[p in products] = ...;
tuple taskT {
key int productId;
key int stepNumber;
key int orderId;
int duration;
int temperatureCode;
};
{taskT} allTasks = {<p, s.stepNumber, o,
s.duration, s.temperatureCode>
| p in products, s in steps[p], o in 1..orders[p]};
int numberOvens = ...;
range ovens = 1..numberOvens;
int ovenCapacity[ovens] = ...;
tuple transitionTimeT {
key int code1;
key int code2;
int transitionTime;
};
{transitionTimeT} transitionTimes = ...;
int maxTime = sum(t in allTasks)(t.duration + preparationTime);
dvar interval tasks[t in allTasks] in preparationTime..maxTime size t.duration;
dvar interval taskOvenAlts[t in allTasks][o in ovens] optional;
cumulFunction ovenUsage[o in ovens] = sum(t in allTasks) pulse(taskOvenAlts[t][o], 1);
stateFunction ovenTemperature[o in ovens] with transitionTimes;
minimize max(t in allTasks) endOf(tasks[t]);
/**************
* Constraints *
***************/
constraints {
// 30 minutes preparation is required between steps for each product order
forall(t1,t2 in allTasks : t1.productId == t2.productId &&
t1.stepNumber + 1 == t2.stepNumber &&
t1.orderId == t2.orderId) {
endBeforeStart(tasks[t1], tasks[t2], preparationTime);
}
// for each oven, ovenUsage cannot exceed oven capacity
forall(o in ovens)
ovenUsage[o] <= ovenCapacity[o];
// each task can be executed on at most one oven
forall(t in allTasks)
alternative(tasks[t], all (o in ovens) taskOvenAlts[t][o]);
// the temperatureCode on an oven should correspond to the temperature of the task scheduled on the oven at any point in time
forall(t in allTasks, o in ovens)
alwaysEqual(ovenTemperature[o], taskOvenAlts[t][o], t.temperatureCode);
}
int usedCapacity = sum(t in allTasks) t.duration;
int availPower = sum(f in ovens) ovenCapacity[f];
execute {
writeln("Shortest possible makespan = " + (preparationTime + usedCapacity / availPower));
}
#CPOptimizer#DecisionOptimization