1

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

  1. 100 94
  2. 50 50
  3. 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?

WingNut
  • 59
  • 5
  • switch `!ReferenceEquals(decisions[bin][sku], 0)` to `decisions[bin][sku] != 0` – lokusking Jul 29 '16 at 22:06
  • I get a compile error "Cannot implicitly convert type 'Microsoft.SolverFoundation.Services.Term' to 'bool'" – WingNut Jul 29 '16 at 22:21
  • Try `decisions[bin][sku].ToDouble() != 0d` as stated [here](https://msdn.microsoft.com/en-us/library/microsoft.solverfoundation.services.decision(v=vs.93).aspx) and be sure, the value you are expecting is numeric one – lokusking Jul 29 '16 at 22:26
  • "Invalid cast exception was unhandled: decision_r0c0 does not yet have a value". The goal has to be defined before the context is solved. – WingNut Jul 29 '16 at 23:06

0 Answers0