Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.

 View Only
Expand all | Collapse all

Piecewise linear function- Basics

  • 1.  Piecewise linear function- Basics

    Posted Fri May 17, 2019 09:49 AM

    Originally posted by: snpny


    Hello, I have trouble to define a really basic piecewise linear function to be used in my objective function of MILP formulation. 

    Here is my objective (where di= distance (km), is a predefined parameter, pv= fuel consumption (lt/km), is the decision variable which depends on the vehicle speed,v):

    ∑v∑i di*pv 

    pv= -24*v+160      for 1<=v<=3

          -40*v +210      for 3<=v<=5

          ...

           3*v-87            for 38<=v<=40.

    I have 6 breakpoints and 7 slopes, so I tried to code piecewise function like the following but I don't know how and I coundt add the constant value for each function (like 160, 210, .., -87), so I failed. I will be so glad if someone can help me!

    int n=6;
    float breakpoints [1..n]=[3,5,15,23,30,38];
    float slope [1..n+1]=[-24, -40,-1, 2, 2, -1, 3];
    dvar int x;
    maximize piecewise (i in 1..n) {slope[i]->breakpoints[i]; slope [n+1]} x;
     

     

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Piecewise linear function- Basics

    Posted Fri May 17, 2019 02:36 PM

    You did not specify what exactly the problem is, so I am guessing.

    One issue probably is that your piecewise linear function has jumps. For example for v==3 the value can be either 24*v+160=232 or -40*v+210=90. In order to model steps you have to duplicate breakpoints. You can find the details for this here. Read through this document carefully. In particular, make sure you understand which function value CPLEX will pick for v==3 and that this is what you want. In particular because your variable x is integer.


    #CPLEXOptimizers
    #DecisionOptimization