private List <BoxCaseSolution> GenerateSolutions() { List <BoxCaseSolution> solutions = new List <BoxCaseSolution>(); int[] patternColumnCount = new int[6]; // loop throw all patterns foreach (LayerPattern pattern in _patterns) { // loop through all vertical axes for (int i = 0; i < 6; ++i) { HalfAxis.HAxis axisOrtho = (HalfAxis.HAxis)i; if (!_constraintSet.AllowOrthoAxis(axisOrtho)) { continue; } try { // build layer Layer layer = new Layer(_bProperties, _caseProperties, axisOrtho); double actualLength = 0.0, actualWidth = 0.0; pattern.GetLayerDimensionsChecked(layer, out actualLength, out actualWidth); pattern.GenerateLayer(layer, actualLength, actualWidth); string title = string.Empty; BoxCaseSolution sol = new BoxCaseSolution(null, axisOrtho, pattern.Name); double offsetX = 0.5 * (_caseProperties.Length - _caseProperties.InsideLength); double offsetY = 0.5 * (_caseProperties.Width - _caseProperties.InsideWidth); double zLayer = 0.5 * (_caseProperties.Height - _caseProperties.InsideHeight); bool maxWeightReached = _constraintSet.UseMaximumCaseWeight && (_caseProperties.Weight + _bProperties.Weight > _constraintSet.MaximumCaseWeight); bool maxHeightReached = _bProperties.Dimension(axisOrtho) > _caseProperties.InsideHeight; bool maxNumberReached = false; int boxCount = 0; while (!maxWeightReached && !maxHeightReached && !maxNumberReached) { BoxLayer bLayer = sol.CreateNewLayer(zLayer, string.Empty); foreach (LayerPosition layerPos in layer) { // increment ++boxCount; if (maxNumberReached = _constraintSet.UseMaximumNumberOfBoxes && (boxCount > _constraintSet.MaximumNumberOfBoxes)) { break; } double weight = _caseProperties.Weight + boxCount * _bProperties.Weight; maxWeightReached = _constraintSet.UseMaximumCaseWeight && weight > _constraintSet.MaximumCaseWeight; if (maxWeightReached) { break; } // insert new box in current layer LayerPosition layerPosTemp = AdjustLayerPosition(layerPos); BoxPosition boxPos = new BoxPosition( layerPosTemp.Position + offsetX * Vector3D.XAxis + offsetY * Vector3D.YAxis + zLayer * Vector3D.ZAxis , layerPosTemp.LengthAxis , layerPosTemp.WidthAxis ); bLayer.Add(boxPos); } zLayer += layer.BoxHeight; if (!maxWeightReached && !maxNumberReached) { maxHeightReached = zLayer + layer.BoxHeight > 0.5 * (_caseProperties.Height + _caseProperties.InsideHeight); } } // set maximum criterion if (maxNumberReached) { sol.LimitReached = BoxCaseSolution.Limit.LIMIT_MAXNUMBERREACHED; } else if (maxWeightReached) { sol.LimitReached = BoxCaseSolution.Limit.LIMIT_MAXWEIGHTREACHED; } else if (maxHeightReached) { sol.LimitReached = BoxCaseSolution.Limit.LIMIT_MAXHEIGHTREACHED; } if (string.Equals(pattern.Name, "Column", StringComparison.CurrentCultureIgnoreCase)) { patternColumnCount[i] = Math.Max(patternColumnCount[i], sol.BoxPerCaseCount); } // insert solution if (sol.BoxPerCaseCount >= patternColumnCount[i]) { solutions.Add(sol); } } catch (NotImplementedException) { _log.Info(string.Format("Pattern {0} is not implemented", pattern.Name)); } catch (Exception ex) { _log.Error(string.Format("Exception caught: {0}", ex.Message)); } } // loop through all vertical axes } // loop through all patterns // sort solutions solutions.Sort(); /* * // removes solutions that do not equal the best number * if (solutions.Count > 0) * { * int indexFrom = 0, maxCount = solutions[0].BoxPerCaseCount; * while (indexFrom < solutions.Count && solutions[indexFrom].BoxPerCaseCount == maxCount) ++indexFrom; * solutions.RemoveRange(indexFrom, solutions.Count - indexFrom); * } */ return(solutions); }