Issue in understanding Multiple Knapsack Problem IBM CPLEX

139 Views Asked by At

I found this example in the IBM CPLEX Studio in OPL Examples. However, I am not able to understand these two lines in the program. Is it a special way to use int decision variables instead of boolean?

int MaxValue = max(r in Resources) Capacity[r];
dvar int Take[Items] in 0..MaxValue;

Why do we find the maximum value of the resource capacity? Can someone please explain the logic behind it. I am new to Linear programming but curious about this. I believed that I should use a boolean variable in such situations. Thanks in advance.

int NbItems = ...;
    int NbResources = ...;
    range Items = 1..NbItems;
    range Resources = 1..NbResources;
    int Capacity[Resources] = ...;
    int Value[Items] = ...;
    int Use[Resources][Items] = ...;
    int MaxValue = max(r in Resources) Capacity[r];
    
    
    dvar int Take[Items] in 0..MaxValue;
    
    maximize
      sum(i in Items) Value[i] * Take[i];
      
    subject to {
      forall( r in Resources )
        ct:
          sum( i in Items ) 
            Use[r][i] * Take[i] <= Capacity[r];
    }
    
    
    tuple TakeSolutionT{ 
        int Items; 
        int value; 
    };
    {TakeSolutionT} TakeSolution = {<i0,Take[i0]> | i0 in Items};
    execute{ 
        writeln(TakeSolution);
1

There are 1 best solutions below

1
On

If MaxValue was 1 then

dvar int Take[Items] in 0..MaxValue;

would be equivalent to

dvar boolean Take[Items];

Likewise

dvar int x in 0..2;

means x is either 0,1 or 2

which will the same result as

dvar int x;

subject to
{
  0<=x<=2;
}