private void Pack(Solver cp, IntVar[] binvars, int[] weights, IntVar[] loadvars) { IntVar[] b = new IntVar[binvars.Length]; for(long j=0; j<loadvars.Length; j++) { for (int i = 0; i < binvars.Length; i++) { b[i] = cp.MakeIsEqualCstVar(binvars[i], j); } cp.Add(cp.MakeScalProd(b, weights) == loadvars[j]); } cp.Add(cp.MakeSumEquality(loadvars, cp.MakeIntVar(weights.Sum(), weights.Sum(), "Sum"))); }