易腐产品衰减函数的分段线性正割近似 - CPLEX

问题描述 投票:0回答:1

衰减函数定义如下。

decay function

这里非线性约束转换为分段线性函数

piecewise linear function

L_p是线性段的集合

g_lp = 1 如果使用线性段 s 来近似衰减函数

TV_b, TV_e 作为开始和结束的运输时间值 分别是线性段 s

的终点

SL_pl, In_pl 分别作为用于近似衰减函数的线性段 s 的斜率和截距

我很难选择这个函数合适的参数斜率和截距。是否有任何提示或公式来计算此函数的斜率和截距?或者在 Cplex 中应用此约束时,我必须通过反复试验来选择。

product cplex piecewise
1个回答
0
投票

你可以插入你的函数。见https://github.com/AlexFleischerParis/opltipsandtricks/blob/master/interpolatewithpiecewiselinear.mod

// 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]));
© www.soinside.com 2019 - 2024. All rights reserved.