Decision Optimization

Decision Optimization

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

 View Only
Expand all | Collapse all

piecewise-linear functions in OPL.

  • 1.  piecewise-linear functions in OPL.

    Posted Mon December 23, 2019 04:29 PM

    Originally posted by: 88Simon88


    Hello everyone, 

     

    I want to write an opl code to do the piecewise-linear function but the origin of the function is not zero. I appreciate you if could help me in this regard.

     

    Best regards.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: piecewise-linear functions in OPL.

    Posted Tue December 24, 2019 01:20 AM

    Hi,

    the example in the OPL documentation answers this:

     

    int n=2;
    float objectiveforxequals0=300;
    float breakpoint[1..n]=[100,200];
    float slope[1..n+1]=[1,2,-3];
    dvar int x;
    
    maximize piecewise(i in 1..n) 
    {slope[i] -> breakpoint[i]; slope[n+1]}(0,objectiveforxequals0) x; 
    
    subject to
    {
     true;  
    

    }

     

    but let me try to make this even clearer

     

    int n=2;
    float objectiveforxequals0=300;
    float breakpoint[1..n]=[100,200];
    float slope[1..n+1]=[1,2,-3];


    pwlFunction f= piecewise(i in 1..n)
    {slope[i] -> breakpoint[i]; slope[n+1]}(0,objectiveforxequals0) ;

    float v=f(0);

    execute
    {
      writeln(v);
    }

     

     

    gives

     

    300

     

    regards

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: piecewise-linear functions in OPL.

    Posted Fri January 10, 2020 11:58 AM

    Originally posted by: 88Simon88


    Thank you very much Alex. You are always helpful.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer