Decision Optimization

 View Only
Expand all | Collapse all

Array range for integer programming

  • 1.  Array range for integer programming

    Posted Sun March 12, 2017 09:05 PM

    Originally posted by: UYPJ_Ha-eun_Park


    Hello, I'm a beginner of CPLEX and need your help.

    I wanna solve a simple integer programming problem for scheduling and my whole code is below.

    The errors are generated in ct2 and ct3 and I think yellow blocked code is wrong.

    My question is, how can I make array ranges for "forall" and "sum" function?

     

    Really hope I can get some answer at this forum.

    ---- 
    int NbGroup = ...;
    int NbAutoclave = ...;
    int NbTimeslot = ...;
    range Group = 1..NbGroup;
    range Autoclave = 1..NbAutoclave;
    range Timeslot = 1..NbTimeslot;
    int MonthlyProduct[Group] = ...;
    int CycleTime[Group] = ...;
    int CureTime[Group] = ...;

     

    dvar int Assign[Group][Autoclave][Timeslot] in 0..1;

    minimize
      sum( g in Group, a in Autoclave, t in Timeslot ) t * Assign[g][a][t];
      
    subject to {
      forall (g in Group)
        ct1:
          sum( a in Autoclave, t in Timeslot ) 
            Assign[g][a][t] == MonthlyProduct[g]; 
      
      forall (g in Group)
        forall (t in 1..(NbTimeslot-CycleTime[g]+1))     
          ct2:
            sum( a in Autoclave, cy in 1..CycleTime[g] )
                 Assign[g][a][t+cy-1] <= 1;                  
             
      forall( a in Autoclave, t in Timeslot )
        ct3:
            sum( g in Group, cu in 1..CureTime[g])
               Assign[g][a][t-cu+1] <= 1; 
                      
    }

    tuple SolutionT{ 
        int a;
        int b;
        int c;
        int d; 
    };
    {SolutionT} Solution = {<a0,b0,c0,Assign[a0][b0][c0]> | a0 in Group, b0 in Autoclave, c0 in Timeslot};
    execute{ 
        writeln(Solution);
    }
     


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Array range for integer programming

    Posted Mon March 13, 2017 03:03 AM

    Hi,

    in documentation IDE and OPL > Optimization Programming Language (OPL) > Language Reference Manual > OPL, the modeling language > Constraints > Constraint labels

    you should read

    Labels and a variable size indexer

    Constraint labels with a variable size indexer are not allowed. For example, this model generates an error message.

    
    
    tuple RangeTuple
     {
         int i;
         int j;
         string k;
     };
     {RangeTuple} RT = {<1, 2, "bla">};
     
     minimize 1;
     
     subject to
     {
         forall(<p1, p2, p3> in RT)
             forall(i in p1..p2)
         range
    Label:
         1 == 1;
    }
    

    Write the following code instead.

    
    
    
    tuple RangeTuple
    {
        int i;
        int j;
        string k;
    };
    {RangeTuple} RT = {<1, 2, "bla">};
    
    {int} s={1,2};
    
    
    constraint range
    Label[RT][s];
    
    minimize 1;
    
    subject to
    {
        forall(<p1, p2, p3> in RT)
            forall(i in p1..p2)
        range
    Label[<p1, p2, p3>,i]:
         1 == 1;
    }
    

    Note the difference in rangeLabel.

    regards

     


    #CPLEXOptimizers
    #DecisionOptimization