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);
If MaxValue was 1 then
would be equivalent to
Likewise
means x is either 0,1 or 2
which will the same result as