衰减函数定义如下。
这里非线性约束转换为分段线性函数
L_p是线性段的集合
g_lp = 1 如果使用线性段 s 来近似衰减函数
TV_b, TV_e 作为开始和结束的运输时间值 分别是线性段 s
的终点SL_pl, In_pl 分别作为用于近似衰减函数的线性段 s 的斜率和截距
我很难选择这个函数合适的参数斜率和截距。是否有任何提示或公式来计算此函数的斜率和截距?或者在 Cplex 中应用此约束时,我必须通过反复试验来选择。
// linearization of f(x)=1/x through a piecewise linear function
// relying on https://github.com/AlexFleischerParis/howtowithopl/blob/master/pwlwithbreakpoints.mod
// our world is not 100% linear so sometimes it's helpful to turn any non linear function
// into a piecewise linear approximation
int sampleSize=10000;
float s=1;
float e=10;
float x[i in 0..sampleSize]=s+(e-s)*i/sampleSize;
int nbSegments=5;
float x2[i in 0..nbSegments]=(s)+(e-s)*i/nbSegments;
float y2[i in 0..nbSegments]=1/x2[i]; // y=f(x)
float firstSlope=0;
float lastSlope=0;
tuple breakpoint // y=f(x)
{
key float x;
float y;
}
sorted { breakpoint } breakpoints={<x2[i],y2[i]> | i in 0..nbSegments};
float slopesBeforeBreakpoint[b in breakpoints]=
(b.x==first(breakpoints).x)
?firstSlope
:(b.y-prev(breakpoints,b).y)/(b.x-prev(breakpoints,b).x);
pwlFunction f=piecewise(b in breakpoints)
{ slopesBeforeBreakpoint[b]->b.x; lastSlope } (first(breakpoints).x, first(breakpoints).y);
assert forall(b in breakpoints) abs(f(b.x)-b.y)<=0.001;
float maxError=max (i in 0..sampleSize) abs(1/x[i]-f(x[i]));
float averageError=1/(sampleSize+1)*sum (i in 0..sampleSize) abs(1/x[i]-f(x[i]));