Decision Optimization

Decision Optimization

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

 View Only
  • 1.  Performance issues modeling per-period consumption with interval variables in OPL

    Posted Tue March 24, 2026 12:08 PM
    Dear all,
     
    Below, I share an excerpt of the OPL code I am using to model the energy consumption cost of equipment u1_wh_1 over a planning horizon of H periods, with the objective of minimizing it. To determine consumption at each period t, I use Load_u1, which includes a base consumption B_u1 plus the additional consumption of U units when the interval variable u1_wh_1 is active.
     
    int H = 96;
    int B_u1[1..H] = ...;
    int U = 10;
     
    float Cost[t in 1..H] =
       (t <= 28) ? 0.06:
       (t <= 72) ? 0.13:
       (t <= 88) ? 0.29:
                   0.14;
     
    dvar interval u1_wh_1 in 25..41 size 8;
     
    dvar int Load_u1[t in 1..H];
     
    dexpr float TC_u1 = sum(t in 1..H)(Cost[t] * Load_u1[t]);
     
    minimize TC_u1;
     
    forall(t in 1..H) Load_u1[t] == B_u1[t] + U * (t >= startOf(u1_wh_1) && t < endOf(u1_wh_1));
     
    The results obtained are consistent with cost minimization; however, as I add more equipment, CP Optimizer quickly struggles to find the optimal solution. It seems that the expression (t >= startOf(u1_wh_1) && t < endOf(u1_wh_1)) is causing the difficulty; however, I have not been able to find a more efficient alternative formulation from the perspective of the CP Optimizer. I would appreciate any guidance on a possible solution.


    ------------------------------
    Francisco Yuraszeck
    Yuraszeck
    ------------------------------


  • 2.  RE: Performance issues modeling per-period consumption with interval variables in OPL

    Posted Wed March 25, 2026 02:37 AM

    Hi,

    can you turn Load_u1 into a cumulFunction and replace " (t >= startOf(u1_wh_1) && t < endOf(u1_wh_1)) " by a pulse ?

    regards



    ------------------------------
    [Alex] [Fleischer]
    [Data and AI Technical Sales]
    [IBM]
    ------------------------------



  • 3.  RE: Performance issues modeling per-period consumption with interval variables in OPL

    Posted Wed March 25, 2026 08:09 AM

    Thanks @ALEX FLEISCHER for your reply. Unfortunately, I don't think I can use pulse-at least not the way I tried. I attempted to definecumulFunction Load_u1[t in 1..H] = B_u1[t] + pulse(u1_wh_1, 50000);, but OPL returned the error: 'Operator not available for int + cumulFunction'. Additionally, I need to access the value of Load_u1 in each period t to calculate the total cost TC_u1. Is there an alternative approach you would suggest?



    ------------------------------
    Francisco Yuraszeck
    Yuraszeck
    ------------------------------



  • 4.  RE: Performance issues modeling per-period consumption with interval variables in OPL

    Posted Thu March 26, 2026 12:56 PM

    Hi,

    how to fix your syntax error ?

    using CP;
    
    int H = 96;
    int B_u1[i in 1..H] = i;
    int U = 10;
     
    float Cost[t in 1..H] =
       (t <= 28) ? 0.06:
       (t <= 72) ? 0.13:
       (t <= 88) ? 0.29:
                   0.14;
     
    dvar interval u1_wh_1 in 25..41 size 8;
     
    cumulFunction Load_u1= pulse(u1_wh_1, 50000)+sum(i in 1..H) pulse(i,i+1,B_u1[i]);
     
    
    subject to
    {
    Load_u1<=10000000;
    }
     

    Using startOf and endOf is not very efficient and I recommend overlapLength

    using CP;
    
    int H = 96;
    int B_u1[i in 1..H] = i;
    int U = 10;
     
    float Cost[t in 1..H] =
       (t <= 28) ? 0.06:
       (t <= 72) ? 0.13:
       (t <= 88) ? 0.29:
                   0.14;
     
    dvar interval u1_wh_1 in 25..41 size 8;
     
    dvar int Load_u1[t in 1..H];
    
     
    dexpr float TC_u1 = sum(t in 1..H)(Cost[t] * Load_u1[t]);
     
    minimize TC_u1;
    subject to
    {
      
     
    forall(t in 1..H) Load_u1[t] == B_u1[t] + U * (overlapLength(u1_wh_1,t,t+1));
    
     
     
    }
     
    
    
    

    works better



    ------------------------------
    [Alex] [Fleischer]
    [Data and AI Technical Sales]
    [IBM]
    ------------------------------



  • 5.  RE: Performance issues modeling per-period consumption with interval variables in OPL

    Posted Thu March 26, 2026 05:34 PM
    Thanks, @ALEX FLEISCHER, for your reply. Using overlapLength as you suggested has been effective; however, it presents similar performance issues to my original approach based on startOf and endOf.
     
    On the other hand, your idea of defining Load_u1 as a cumulFunction is clear to me. However, it does not seem suitable for computing consumption costs over the planning horizon, so I would have to discard it as an alternative. Do you agree?


    ------------------------------
    Francisco Yuraszeck
    Yuraszeck
    ------------------------------



  • 6.  RE: Performance issues modeling per-period consumption with interval variables in OPL

    Posted Fri March 27, 2026 06:18 AM

    Hi,

    I would go on with the overlapLength idea and instead of sum I would use bigger interval than size 1

    regards



    ------------------------------
    [Alex] [Fleischer]
    [Data and AI Technical Sales]
    [IBM]
    ------------------------------