【问题标题】:Taking integral of a function in CPLEX在 CPLEX 中对函数进行积分
【发布时间】:2021-11-18 17:27:24
【问题描述】:

我尝试在 CPLEX 中为 MIP 模型建模。我有一个包含决策变量的函数,我需要对该函数进行积分来计算其预期值。有没有办法在 CPLEX 中对函数进行积分?谢谢!

【问题讨论】:

    标签: python optimization cplex opl


    【解决方案1】:

    使用分段线性,您可以逼近任何函数并依赖数学规划。

    Interpolate any functionTips and Tricks in OPL

    // linearization of f(x)=1/x through a piecewise linear function
    
    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;
    

    通过 CPLEX 中的约束编程,您可以使用任何函数(甚至不是线性函数)甚至黑盒函数。

    Example of not linear function:

    using CP;
    
    // CPOptimizer allows all kind of non linearities
    
    int nbKids=300;
    float costBus40=500;
    float costBus30=400;
     
    dvar int+ nbBus40;
    dvar int+ nbBus30;
     
    // Non linear objective (exponential) 
    minimize
     costBus40*exp(nbBus40) +exp(nbBus30)*costBus30;
     
    subject to
    {
     40*nbBus40+nbBus30*30>=nbKids;
    } 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-11
      • 1970-01-01
      • 1970-01-01
      • 2013-08-24
      • 1970-01-01
      • 1970-01-01
      • 2016-12-13
      • 2019-03-28
      相关资源
      最近更新 更多