public SelBoxCaseSolution(Document document, BoxCaseAnalysis analysis, BoxCaseSolution sol) : base(document) { _analysis = analysis; _analysis.AddDependancy(this); _solution = sol; Name = sol.Title; }
public SelBoxCaseSolution(Document document, BoxCaseAnalysis analysis, BoxCaseSolution sol) : base(document) { _analysis = analysis; _analysis.AddDependancy(this); _solution = sol; ID.Name = sol.Title; }
public void Update(ItemBase item) { // update grid FillGrid(); // select first solution if (gridSolutions.RowsCount > 0) { gridSolutions.Selection.SelectRow(1, true); } if (_analysis.Solutions.Count > 0) { _sol = _analysis.Solutions[0]; } // draw graphCtrlSolution.Invalidate(); }
private void onGridSolutionSelectionChanged(object sender, SourceGrid.RangeRegionChangedEventArgs e) { SourceGrid.RangeRegion region = gridSolutions.Selection.GetSelectionRegion(); int[] indexes = region.GetRowsIndex(); // no selection -> exit if (indexes.Length == 0) { return; } // get selected solution _sol = _analysis.Solutions[indexes[0] - 1]; // update select/unselect button text UpdateSelectButtonText(); // redraw graphCtrlSolution.Invalidate(); }
public void Update(ItemBase item) { // update grid FillGrid(); // select first solution if (gridSolutions.RowsCount > 0) gridSolutions.Selection.SelectRow(1, true); if (_analysis.Solutions.Count > 0) _sol = _analysis.Solutions[0]; // draw graphCtrlSolution.Invalidate(); }
private void onGridSolutionSelectionChanged(object sender, SourceGrid.RangeRegionChangedEventArgs e) { SourceGrid.RangeRegion region = gridSolutions.Selection.GetSelectionRegion(); int[] indexes = region.GetRowsIndex(); // no selection -> exit if (indexes.Length == 0) return; // get selected solution _sol = _analysis.Solutions[indexes[0] - 1]; // update select/unselect button text UpdateSelectButtonText(); // redraw graphCtrlSolution.Invalidate(); }
private string BoxCaseSolutionLimitToString(BoxCaseSolution.Limit limit) { switch (limit) { case BoxCaseSolution.Limit.LIMIT_MAXHEIGHTREACHED: return Resources.ID_PALLETMAXHEIGHT; case BoxCaseSolution.Limit.LIMIT_MAXWEIGHTREACHED: return Resources.ID_PALLETMAXWEIGHT; case BoxCaseSolution.Limit.LIMIT_MAXNUMBERREACHED: return Resources.ID_PALLETMAXNUMBER; default: return string.Empty; } }
public BoxCaseSolutionViewer(BoxCaseSolution boxCaseSolution) { _boxCaseSolution = boxCaseSolution; }
private BoxCaseSolution LoadBoxCaseSolution(XmlElement eltSolution) { // pattern string patternName = eltSolution.Attributes["Pattern"].Value; // orientation HalfAxis.HAxis orthoAxis = HalfAxis.Parse(eltSolution.Attributes["OrthoAxis"].Value); // instantiate box case solution BoxCaseSolution sol = new BoxCaseSolution(null, orthoAxis, patternName); // limit reached if (eltSolution.HasAttribute("LimitReached")) { string sLimitReached = eltSolution.Attributes["LimitReached"].Value; sol.LimitReached = (BoxCaseSolution.Limit)(int.Parse(sLimitReached)); } // layers XmlElement eltLayers = eltSolution.ChildNodes[0] as XmlElement; foreach (XmlNode nodeLayer in eltLayers.ChildNodes) { BoxLayer boxLayer = LoadLayer(nodeLayer as XmlElement) as BoxLayer; sol.Add(boxLayer); } return sol; }
public void SaveBoxCaseSolution(BoxCaseAnalysis analysis, BoxCaseSolution sol, SelBoxCaseSolution selSolution, XmlElement solutionsElt, XmlDocument xmlDoc) { // Solution XmlElement solutionElt = xmlDoc.CreateElement("Solution"); solutionsElt.AppendChild(solutionElt); // Pattern name XmlAttribute patternNameAttribute = xmlDoc.CreateAttribute("Pattern"); patternNameAttribute.Value = sol.PatternName; solutionElt.Attributes.Append(patternNameAttribute); // ortho axis XmlAttribute orthoAxisAttribute = xmlDoc.CreateAttribute("OrthoAxis"); orthoAxisAttribute.Value = HalfAxis.ToString(sol.OrthoAxis); solutionElt.Attributes.Append(orthoAxisAttribute); // limit XmlAttribute limitReached = xmlDoc.CreateAttribute("LimitReached"); limitReached.Value = string.Format("{0}", (int)sol.LimitReached); solutionElt.Attributes.Append(limitReached); // layers XmlElement layersElt = xmlDoc.CreateElement("Layers"); solutionElt.AppendChild(layersElt); foreach (BoxLayer boxLayer in sol) Save(boxLayer, layersElt, xmlDoc); // Is selected ? if (null != selSolution) { // selected attribute XmlAttribute selAttribute = xmlDoc.CreateAttribute("Selected"); selAttribute.Value = "true"; solutionElt.Attributes.Append(selAttribute); } }
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; if (!pattern.GetLayerDimensionsChecked(layer, out actualLength, out actualWidth)) { continue; } 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); }
private void AppendBoxCaseSolutionElement(BoxCaseSolution solution, XmlElement elemBoxCaseAnalysis, XmlDocument xmlDoc) { BoxCaseAnalysis analysis = solution.Analysis; string ns = xmlDoc.DocumentElement.NamespaceURI; // solution XmlElement elemSolution = xmlDoc.CreateElement("boxCaseSolution", ns); elemBoxCaseAnalysis.AppendChild(elemSolution); // title XmlElement elemTitle = xmlDoc.CreateElement("title", ns); elemTitle.InnerText = solution.Title; elemSolution.AppendChild(elemTitle); // boxPerLayerCount XmlElement elemBoxPerLayerCount = xmlDoc.CreateElement("boxPerLayerCount", ns); elemBoxPerLayerCount.InnerText = solution.BoxPerLayerCount.ToString(); elemSolution.AppendChild(elemBoxPerLayerCount); // boxPerCaseCount XmlElement elemBoxPerCaseCount = xmlDoc.CreateElement("boxPerCaseCount", ns); elemBoxPerCaseCount.InnerText = solution.BoxPerCaseCount.ToString(); elemSolution.AppendChild(elemBoxPerCaseCount); // BoxLayersCount XmlElement elemBoxLayersCount = xmlDoc.CreateElement("boxLayersCount", ns); elemBoxLayersCount.InnerText = solution.BoxLayersCount.ToString(); elemSolution.AppendChild(elemBoxLayersCount); // criterions // load weight AppendElementValue(xmlDoc, elemSolution, "LoadWeight", UnitsManager.UnitType.UT_MASS, solution.BoxPerCaseCount * analysis.BProperties.Weight); // case weight AppendElementValue(xmlDoc, elemSolution, "CaseWeight", UnitsManager.UnitType.UT_MASS, solution.CaseWeight); // EfficiencyWeight XmlElement elemEfficiencyWeight = xmlDoc.CreateElement("EfficiencyWeight", ns); if (solution.CaseWeight > 0) elemEfficiencyWeight.InnerText = string.Format("{0:F}", solution.EfficiencyWeight); else elemEfficiencyWeight.InnerText = string.Empty; elemSolution.AppendChild(elemEfficiencyWeight); // EfficiencyVolume XmlElement elemEfficiencyVolume = xmlDoc.CreateElement("EfficiencyVolume", ns); elemEfficiencyVolume.InnerText = string.Format("{0:F}", solution.EfficiencyVolume); elemSolution.AppendChild(elemEfficiencyVolume); // LimitReached string limitReached = string.Empty; switch (solution.LimitReached) { case BoxCaseSolution.Limit.LIMIT_MAXHEIGHTREACHED: limitReached="Maximum height"; break; case BoxCaseSolution.Limit.LIMIT_MAXNUMBERREACHED: limitReached="Maximum number"; break; case BoxCaseSolution.Limit.LIMIT_MAXWEIGHTREACHED: limitReached="Maximum weight"; break; default: break; } XmlElement elemLimitReached = xmlDoc.CreateElement("LimitReached", ns); elemLimitReached.InnerText = limitReached; elemSolution.AppendChild(elemLimitReached); // --- case images for (int i = 0; i < 5; ++i) { // initialize drawing values string viewName = string.Empty; Vector3D cameraPos = Vector3D.Zero; int imageWidth = ImageSizeDetail; bool showDimensions = false; switch (i) { case 0: viewName = "view_caseSolution_front"; cameraPos = Graphics3D.Front; imageWidth = ImageSizeDetail; break; case 1: viewName = "view_caseSolution_left"; cameraPos = Graphics3D.Left; imageWidth = ImageSizeDetail; break; case 2: viewName = "view_caseSolution_right"; cameraPos = Graphics3D.Right; imageWidth = ImageSizeDetail; break; case 3: viewName = "view_caseSolution_back"; cameraPos = Graphics3D.Back; imageWidth = ImageSizeDetail; break; case 4: viewName = "view_caseSolution_iso"; cameraPos = Graphics3D.Corner_0; imageWidth = ImageSizeWide; showDimensions = true; break; default: break; } // instantiate graphics Graphics3DImage graphics = new Graphics3DImage(new Size(imageWidth, imageWidth)); // set camera position graphics.CameraPosition = cameraPos; // instantiate solution viewer BoxCaseSolutionViewer sv = new BoxCaseSolutionViewer(solution); sv.ShowDimensions = showDimensions; sv.Draw(graphics); graphics.Flush(); // --- XmlElement elemImage = xmlDoc.CreateElement(viewName, ns); TypeConverter converter = TypeDescriptor.GetConverter(typeof(Bitmap)); elemImage.InnerText = Convert.ToBase64String((byte[])converter.ConvertTo(graphics.Bitmap, typeof(byte[]))); XmlAttribute styleAttribute = xmlDoc.CreateAttribute("style"); styleAttribute.Value = string.Format("width:{0}pt;height:{1}pt", graphics.Bitmap.Width / 3, graphics.Bitmap.Height / 3); elemImage.Attributes.Append(styleAttribute); elemSolution.AppendChild(elemImage); // Save image ? SaveImageAs(graphics.Bitmap, viewName + ".png"); } }
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; if (!pattern.GetLayerDimensionsChecked(layer, out actualLength, out actualWidth)) continue; 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; }