Decision Optimization

Decision Optimization

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

 View Only
  • 1.  named constraints

    Posted Mon March 10, 2025 06:57 AM

    Hello, 

    I have a problem in naming the constraints in my .lp file. I got an error saying I should used named constraints. Based on a past discussion on the subject I tried

    constraint con10SH[<j,i> in Sjs][<j,i> in Sjs][p in H];

    subject to
    {
      //single hoist constraint
      forall(ja in Jit,   ia in 1..rs[rJ[ja]]-1,   jb in Jit,   ib in 1..rs[rJ[jb]]-1,   p in H:        ja!=jb )
        {
          con10SH[<ja,ia>,<jb,ib>,p]:  
            t[<jb,ib>]-t[<ja,ia>] >= alphaSH[<rJ[ja],ia>][<rJ[jb],ib>][p]
                                      -(3-z[<jb,ib>][p]-z[<ja,ia>][p]-y[<ja,ia>][<jb,ib>])*M;
        }; 

    };

    where

    {tupAB} Sjs = {<j,i> | j in Jit, i in 1..rs[rJ[j]]-1};

    tuple tupAB 

     int i1;  
     int i2; 
    }

    and the following set increases its sizes by one at every iterations until it reaches its maximum size. 

    {int} Jit = ...; 

    Running this code I have an error saying 

    Invalid initialization expression for element "con10SH"

    What am I doing wrong? 

    Thank you in advance!!

    Sam



    ------------------------------
    Samuele Viaro
    ------------------------------


  • 2.  RE: named constraints

    Posted Tue March 11, 2025 04:33 AM

    Hi

    {int} Jit = asSet(1..10);
    int rs[i in 1..10]=10;
    int rJ[j in 1..10]=10;
    range H=1..2;
    
    
    
    
    tuple tupAB 
    { 
     int i1;  
     int i2; 
    }
    
    {tupAB} Sjs = {<j,i> | j in Jit, i in 1..rs[rJ[j]]-1};
    
    dvar float t[Sjs];
    
    
    constraint con10SH[<j,i> in Sjs][<j,i> in Sjs][p in H];
    
    subject to
    {
      //single hoist constraint
      forall(ja in Jit,   ia in 1..rs[rJ[ja]]-1,   jb in Jit,   ib in 1..rs[rJ[jb]]-1,   p in H:        ja!=jb )
        {
          con10SH[<ja,ia>,<jb,ib>,p]:  
            t[<jb,ib>]-t[<ja,ia>] >= -10;
        }; 
    
    };

    works fine.

    Can you share a full example with an error so that other users could reproduce your error ?

    regards



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