Topic
  • 1 reply
  • Latest Post - ‏2013-06-12T11:37:05Z by AlexFleischer
EXRE_Aric_Johnson
EXRE_Aric_Johnson
3 Posts

Pinned topic Piecewise Linear Fxns (all-unit)

‏2013-06-03T17:57:09Z |

So I have an issue in a model that is using PwL fxn to model transportation costs. I have searched the help documents with no avail. Below is the opl code in question...

dexpr float laneCosts[h in dcs][s in dcs]=
    piecewise(<h,s,minlbs,maxlbs,minc,rate> in lanes){
      rate -> maxlbs;
      maxrate //defined elsewhere
      }laneWeight[h][s]; // laneWeight  is a dexpr that corresponds to how much weight is on a lane

This formulation works as far as determining the correct bracket (breakpoints) that each laneWeight[h][s] is in. My issue is that the PwL fxn seems to be defined in a sort of cummulative manner, e.g...

Suppose I have 3 weight breakpoints (b1=100, b2=200, b3=300) and n+1 rates (slopes= 10, 8, 6, 5). Now suppose that a hypothetical laneWeight is 250 lbs. Cplex will then return (100*10) + ((200-100)*8) + ((250-200)*6) = 2100. However, I want it to realize that it is in the third bracket (b2<=250<=b3) and return 250*6= 1500. I guess this would be similar to an analogy of EOQ models w/ discounts: all-unit vs incremental discounts. I want the all-unit discount!

Is this possible in Cplex? I'm using opl in the studio ide, v12.2. I thought that maybe there would be some kind of option in the opl piecewise fxn definition but I have not found it. Else I have to formulate my PwL fxns on my own with binaries, which is possible but messier.

Thanks in advance

 

 

 

  • AlexFleischer
    AlexFleischer
    2068 Posts

    Re: Piecewise Linear Fxns (all-unit)

    ‏2013-06-12T11:37:05Z  

    Hi

     

    why do not you try something like

     

    pwlFunction p=piecewise{10->100;-200 -> 100;
     8->200;-400->200;6->300;-300->300;5};

    execute
    {
     writeln(p(250));
    }

     

    ?

     

    regards