Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  PieceWise Function with two parameter variables

    Posted 12/01/15 06:12 AM

    Originally posted by: StefanWeiser


    Hey,

    I have a model that includes a price px that depends on a chosen amount x [Periods][Year] which is my decision variable.

    I succesfully implemented the piecewise function for x[Period] and only one year. 

    dexpr float CostPerPeriode [t in Periods] = 
    piecewise ( i in 1..N){
         s[i] -> p[i];
         s[N+1] 
     } (0, 0) x[t];

    My goal is to extend the model to several years, all with the same periods/month. The model should remain the same and the price px should also just depend on the amount choosen per periode. 

    With my extended model a error message says that  the piecewise function is not an array type and does not work with two parameter variables. 

    Do you have an other idea how to solve my problem? 

    regards

     

     

     

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: PieceWise Function with two parameter variables

    Posted 12/03/15 11:26 AM

    Hi,

    let me give you a small example:

    range Periods=1..12;
    int N=5;

    dvar int x[1..4][Periods] in -100..100;

    int s[y in 1..4][i in 1..N]=-i;
    int p[i in 1..N]=i;

    dexpr float CostPerPeriode [y in 1..4][t in Periods] =
    piecewise ( i in 1..N-1){
         s[y][i] -> p[i];
         s[y][N]
     } (0, 0) x[y][t];
     
     subject to
     {
     CostPerPeriode[1][2]<=10;
     }

    regards

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: PieceWise Function with two parameter variables

    Posted 01/07/16 09:59 PM

    Originally posted by: bp325


    Agreed with Alex on the solution, but I created a very similar problem (in which the piecewise curve shapes vary for each time period) and get a strange result that I can't explain...

    I have:

     

    dexpr float ElecCost[p in Period]
      Eprice[p]*(piecewise(l in Line){
       M[p][l] -> X[p][l]; 0
       }(0,0)Gen[p]);
     
     dexpr float TotCost = sum(p in Period) ElecCost[p];
    

    which is fine, except that the values of ElecCost are different before being used in the summation and within the summation. The sum of the latter is ~80% greater than that of the former when they should be exactly the same!

    Any thoughts on why this might be?

    Also, sorry for hijacking the post, but the subject fits (this weirdness isn't happening with other single variable piecewise curves), so thought it would be good to have everything in one place.

     

    Before sum During sum
    1057.239 1955.039
    1040.217 1935.368
    1004.65 1880.262
    1010.951 1887.64
    1014.145 1891.369
    1116.377 2084.49
    1144.415 2102.873
    1218.703 2194.187
    3674.012 6527.651
    0 0
    0 0
    0 0
    0 0
    0 0
    0 0
    3995.685 6860.66
    3442.392 5981.486
    3373.986 5910.807
    1441.588 2533.579
    1276.087 2270.668
    1236.949 2220.636
    1221.636 2196.315
    0 0
    0 0

     

    Best,

    Bryn


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: PieceWise Function with two parameter variables

    Posted 01/08/16 03:13 AM

    Hi,

    can you attach a .mod so that other users can try ?

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: PieceWise Function with two parameter variables

    Posted 01/08/16 07:55 AM

    Originally posted by: bp325


    OK, I've spent time slimming it down to a simple MOD file that shows the problem, see attached. You'll notice that TotCost1 is not the sum of ElecCost1, even though it is set to be!

    Best,

    Bryn

     

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: PieceWise Function with two parameter variables

    Posted 01/09/16 11:13 AM

    Hi,

    indeed this looks strange.

    Can you try with dvar instead of dexpr ?

    dvar float ElecCost_1b[p in Period];
     dvar float TotCost1b;

    and then

    minimize TotCost1b + TotCost2 + EnPurchased;
     
     //Constraints
     subject to {
     
     forall( p in Period) ElecCost_1b[p] ==
      E_price[p]*(piecewise(l in Line){
       M_e1[p][l] -> X_e1[p][l]; 0
       }(0,0)Gen[p][1]);
     
     
     TotCost1b ==  sum(p in Period) E_price[p]*(piecewise(l in Line){
       M_e1[p][l] -> X_e1[p][l]; 0
       }(0,0)Gen[p][1]);

    regards

     

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 7.  Re: PieceWise Function with two parameter variables

    Posted 01/10/16 10:22 AM

    Originally posted by: bp325


    Thank you Alex, that seems to work. So, if creating a piecewise function with two parameters, it is best to have the function as a decision variable rather than decision expression. Would be good to work out why, but for now I'm happy that a solution is possible :)

    Bryn


    #DecisionOptimization
    #OPLusingCPLEXOptimizer