Decision Optimization

Decision Optimization

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

 View Only
Expand all | Collapse all

stepwise-functions with decision variables

ALEX FLEISCHER

ALEX FLEISCHERFri August 30, 2013 11:20 AM

Archive User

Archive UserWed September 18, 2013 03:58 AM

Archive User

Archive UserWed August 09, 2017 01:47 AM

ALEX FLEISCHER

ALEX FLEISCHERTue August 29, 2017 12:12 PM

  • 1.  stepwise-functions with decision variables

    Posted Thu August 08, 2013 04:44 AM

    Originally posted by: Martin-B


    Hello,

    I am having troubles using a decision variable as an index for a stepwise function. Taking the short model description below, it works correctly as long as I index the stepwise function with a range index:

     

    range Periods = 0..3;
    dvar int+ cost[Periods];
    stepFunction stepF = stepwise{ 10 -> 2; 20 -> 3; 0 };

    minimize sum(t in Periods) cost[t];

    forall(t in Periods)
         {
              cost[t] == stepF(t);
         }

    The results are cost = [10 10 20 0], which is correct. The indices used are t = 0 1 2 3.

    I am trying to use a decision variable as the index for the stepwise function. While it is syntactically possible to do so, the results are odd. The model is extended by a decision variable, which always takes the value of the range index t. This variable is used to index the stepwise function:

    range Periods = 0..3;
    dvar int+ cost[Periods];
    stepFunction stepF = stepwise{ 10 -> 2; 20 -> 3; 0 };

    minimize sum(t in Periods) cost[t];

    forall(t in Periods)
         {
            period[t] == t;   
          }  

    forall(t in Periods)
         {
              cost[t] == stepF(period[t]);
         }

    If I minimize this model, the results will be cost = [10 10 10 0] and period = [0 1 2 3]. If I maximize the objective function, the results will be cost = [10 10 20 20] and period = [0 1 2 3]. While the decision variable takes the same values as the range index in the model before, the results are very different.

    So my questions are:

    Why is the outcome of a stepwise function different if I index it with an decision variable? Is it based on my formulation, and what can I do to get the desired result (which is an parameter from an array of parameters, chosen based on a value of a decision variable)?

     

    Best regards,

    Martin


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: stepwise-functions with decision variables

    Posted Fri August 30, 2013 11:20 AM

    Hi,

     

    let me remind you what the documentation states about

    Discontinuous piecewise-linear functions

    The CPLEX and the CP Optimizer engines behave differently with respect to what limit they consider as the discontinuity value. CPLEX allows either of these limits.

    So for example

     

    stepFunction stepF = stepwise{ 10 -> 2; 20 };
     dvar int x;
     minimize stepF(x);
     subject to
     {
       x==2;
     } 

     

    gives objective 10 whereas if you turn minimize into maximize you get objective 20.

    This explains why in your example you get this strange behaviour.

    A way not to fix this in your example is to replace

    cost[t] == stepF(period[t]);

    by

    cost[t] == stepF(period[t]+0.01);

     

    regards

     

    Alex

     

     

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: stepwise-functions with decision variables

    Posted Wed September 18, 2013 03:58 AM

    Originally posted by: Martin-B


    Hi Alex,

     

    thank you, your solution solved my problem.

     

    Best regards,

    Martin


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: stepwise-functions with decision variables

    Posted Wed August 09, 2017 01:47 AM

    Originally posted by: ShafiAhad


    Hello Mr. Alex,

     

    I have a quick question for you. I am trying to use piecewise function in one of my optimization problem. Below is my constraint that contains the piecewise function-

     

    forall (t in 1..6)
          forall(e in 1..3)
          cons4:
         sum(s in 1..3)  Ts[s]*assignment[s][t]*N[e][t] + sum(s in 1..3)(piecewise{0->0; 1->0.1; 2->0.2; 3->0.3; 4->0.4; 5->0.5; 0}(0,0)abs(z[e][s][t]))*N[e][t]*T[s]  <= capacity[t];

     

    My question is, if I want to use different breakpoint and slope for every 'e' (for e=1..3), is there any way to do that?? Thanks in advance. 


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: stepwise-functions with decision variables

    Posted Tue August 29, 2017 12:12 PM

    Hi,

    let me share a tiny example:

    int n=2;
    int m=3;

    float objectiveforxequals0[i in 1..m]=300+i;
    float breakpoint[i in 1..m][j in 1..n]=100*j+i;
    float slope[i in 1..m][j in 1..n+1]=i+j;
    dvar int x;

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

    maximize sum(i in 1..m) obj[i](x);
    subject to
    {
     true;  
    }

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer