I'm using MS Solver to try to solve a bin packing problem, but I can't figure out how to use my Decisions in a Boolean expression to create a Term.
Here's an outline of my problem:
I'm trying to fit items into bins, minimizing the number of bins. All the bins are the same size.
Lets say that I have 3 SKUs (types of items). I have a different amount of each SKU to pack and each SKU is a different size:
SKU Size Qty
- 100 94
- 50 50
- 25 27
Bin Size = 4200
Yes, it's a 1 dimensional bin packing problem.
I know that I can fit all the items for the 3 SKUs that I have to pack into 5 bins, and the theoretical minimum is 3 bins. Can I improve this solution and get down to 4 or even 3 bins using MS Solver?
Here's my problem: Using the MS Solver library, I can set up my decisions and constraints, but I can't seem to define the goal of minimizing the number of bins used.
I create a 2D matrix of decisions - the number of rows corresponds to the first guess of 5 bins, and the 3 columns are the quantity of each SKU in the bins.
I want to minimize the number of bins used, but I can't seem to get the syntax right for my goal. Here is the method I am using to try to create the Goal:
model.AddGoal("MinimumBins", GoalKind.Minimize, CalcBinsUsed(decisions, binCountFirstGuess, ctSizes));
...
private Term CalcBinsUsed(List<List<Decision>> decisions, int binCt, int skuCt )
{
Term binsUsed = 0;
for (int bin = 0; bin < binCt; bin++)
{
for (int sku = 0; sku < skuCt; sku++)
{
if (!ReferenceEquals(decisions[bin][sku], 0))
{
binsUsed += 1;
break;
}
}
}
return binsUsed;
}
I get the following warning: 'Object.ReferenceEquals' is always false because it is called with a value type.
And, indeed I get no solution since the term always evaluates to the same value.
How do I create a Term using these Decisions?