如何用复杂的代码写出从供应商到制造商的成本函数的运费范围集合?



如何用复杂的代码写出从供应商到制造商的成本函数的运费范围集合?

单位数运费率
22-62美元/单元63-134美元/台10.8135-312美元/件313-654 $/单位655-1249美元/单位5.91250-1964 $/单位1965-2500 $ 5533

我不知道怎么写这段代码

您应该使用分段线性函数,所有Cplex api都可以使用

在opl中,例如

https://github.com/AlexFleischerParis/zooopl/blob/master/zoopiecewise.mod

int nbKids=300;
float costBus40=500;
float costBus30=400;
// If we take more than 4 buses for a given size, 20% cheaper for additional buses

dvar int+ nbBus40;
dvar int+ nbBus30;
pwlFunction pricePerQuantity=piecewise{1->4;0.8};
assert forall(k in 1..4 ) pricePerQuantity(k)==k;
assert forall(k in 5..10) as:abs(pricePerQuantity(k)-4-(k-4)*0.8)<=0.00001;

minimize
costBus40*pricePerQuantity(nbBus40)  +pricePerQuantity(nbBus30)*costBus30;

subject to
{
40*nbBus40+nbBus30*30>=nbKids;
}

最新更新