Il est une forme d'un problème d'emballage bin 2D. La première dimension est une limite de la capacité par bac (= de contrainte dure), la seconde dimension est de minimiser le poids de le plus lourd bin (= de contrainte souple).
Avec Drools Planner, je « d commencer par the cloud balance example et mettent en place comme ceci:
rule "maxCapacity"
when
// When there is a bin ...
$bin : Bin($binCapacity : binCapacity)
// ... where the total of the item capacity is bigger than the bin capacity ...
$itemCapacityTotal : Number(intValue > $binCapacity) from accumulate(
ItemAssignment(
bin == $bin,
$itemCapacity : itemCapacity),
sum($itemCapacity)
)
then
// ... then lower the hard score with the insufficient capacity
insertLogical(new IntConstraintOccurrence("maxCapacity",
ConstraintType.NEGATIVE_HARD,
$itemCapacityTotal.intValue() - $binCapacity,
$bin));
end
rule "calculateWeight"
when
$bin : Bin()
$itemWeightTotal : Number() from accumulate(
ItemAssignment(
bin == $bin,
$itemWeight : itemWeight),
sum($itemWeight)
)
then
insertLogical(new BinToWeight($bin, $itemWeightTotal);
end
rule "minimizeWeight"
when
BinToWeight($bin : bin, $itemWeightTotal : itemWeightTotal)
not BinToWeight (itemWeightTotal > $itemWeightTotal, bin != $bin)
then
insertLogical(new IntConstraintOccurrence("minimizeWeight",
ConstraintType.NEGATIVE_SOFT,
$itemWeightTotal,
$bin));
end
Merci Geoffrey, mais je ne sais pas comment implémenter ceci :( – user593062