private void BuildAnalyses(object status) { try { IProgressCallback callback = status as IProgressCallback; callback.SetRange(0, CheckedIndices.Count - 1); callback.Begin(); int expectedCount = uCtrlNumberPerCase.Value.Activated ? uCtrlNumberPerCase.Value.Value : -1; PackableBrick packable = cbBoxes.SelectedType as PackableBrick; // build list of analyses for (int i = 0; i < CheckedIndices.Count; ++i) { try { if (callback.IsAborting) { break; } callback.StepTo(i); callback.SetText(string.Format(Resources.ID_EVALUATINGCASE, i + 1, CheckedIndices.Count)); if ((chklbCases.Items[CheckedIndices[i]] as ItemBaseCB).Item is BoxProperties caseProperties) { // build constraint set ConstraintSetBoxCase constraintSet = new ConstraintSetBoxCase(caseProperties); constraintSet.SetAllowedOrientations(uCtrlCaseOrient.AllowedOrientations); if (uCtrlNumberPerCase.Value.Activated) { constraintSet.SetMaxNumber(uCtrlNumberPerCase.Value.Value); } // build solver + get analyses SolverBoxCase solver = new SolverBoxCase(packable, caseProperties); var listAnalyses = solver.BuildAnalyses(constraintSet, false); foreach (var analysis in listAnalyses) { if ((-1 == expectedCount) || (expectedCount == analysis.Solution.ItemCount)) { Analyses.Add(analysis); } } } } catch (Exception) {} } callback.SetText(Resources.ID_SORTINGSOLUTIONS); // sort analysis Analyses.Sort(new AnalysisComparer()); callback.End(); } catch (Exception) {} }
protected void ComputeSolutions() { // sanity checks if (cbBoxes.Items.Count == 0 || chklbCases.Items.Count == 0) { return; } // clear existing analyses _analyses.Clear(); int expectedCount = uCtrlNumberPerCase.Value.Activated ? uCtrlNumberPerCase.Value.Value : -1; try { PackableBrick packable = cbBoxes.SelectedType as PackableBrick; // build list of analyses for (int i = 0; i < _checkedIndices.Count; ++i) { if ((chklbCases.Items[_checkedIndices[i]] as ItemBaseCB).Item is BoxProperties caseProperties) { // build constraint set ConstraintSetBoxCase constraintSet = new ConstraintSetBoxCase(caseProperties); constraintSet.SetAllowedOrientations(uCtrlCaseOrient.AllowedOrientations); if (uCtrlNumberPerCase.Value.Activated) { constraintSet.SetMaxNumber(uCtrlNumberPerCase.Value.Value); } // build solver + get analyses SolverBoxCase solver = new SolverBoxCase(packable, caseProperties); var listAnalyses = solver.BuildAnalyses(constraintSet, false); foreach (var analysis in listAnalyses) { if ((-1 == expectedCount) || (expectedCount == analysis.Solution.ItemCount)) { _analyses.Add(analysis); } } } } // sort analysis _analyses.Sort(new AnalysisComparer()); // fill grid FillGrid(); } catch (Exception ex) { _log.Error(ex.Message); } }
protected void ComputeSolutions() { // sanity checks if (cbBoxes.Items.Count == 0 || chklbCases.Items.Count == 0) { return; } // clear existing analyses _analyses.Clear(); try { PackableBrick packable = cbBoxes.SelectedType as PackableBrick; // build list of analyses for (int i = 0; i < _checkedIndices.Count; ++i) { BoxProperties caseProperties = (chklbCases.Items[_checkedIndices[i]] as ItemBaseCB).Item as BoxProperties; if (null != caseProperties) { // build constraint set ConstraintSetBoxCase constraintSet = new ConstraintSetBoxCase(caseProperties); constraintSet.SetAllowedOrientations(uCtrlCaseOrient.AllowedOrientations); // build solver + get analyses SolverBoxCase solver = new SolverBoxCase(packable, caseProperties); _analyses.AddRange(solver.BuildAnalyses(constraintSet)); } } // sort analysis _analyses.Sort(new AnalysisComparer()); // fill grid FillGrid(); } catch (Exception ex) { _log.Error(ex.Message); } }
public static bool GetBestSolution(PackableBrick packableProperties, BoxProperties caseProperties, InterlayerProperties interlayer , ConstraintSetBoxCase constraintSet, bool allowMultipleLayerOrientations , Vector3D cameraPosition, bool showCotations, float fontSizeRatio, Size sz , ref int layerCount, ref int caseCount, ref int interlayerCount , ref double weightTotal, ref double weightLoad, ref double?weightNet , ref Vector3D bbLoad, ref Vector3D bbGlob , ref double volumeEfficency, ref double?weightEfficiency , ref byte[] imageBytes , ref string[] errors ) { List <string> lErrors = new List <string>(); if (!packableProperties.FitsIn(caseProperties, constraintSet)) { lErrors.Add($"{packableProperties.Name} does not fit in {caseProperties.Name} with given constraint set!"); return(false); } try { SolverBoxCase solver = new SolverBoxCase(packableProperties, caseProperties); List <Analysis> analyses = solver.BuildAnalyses(constraintSet, allowMultipleLayerOrientations); if (analyses.Count > 0) { Analysis analysis = analyses[0]; layerCount = analysis.Solution.LayerCount; caseCount = analysis.Solution.ItemCount; interlayerCount = analysis.Solution.LayerCount; weightLoad = analysis.Solution.LoadWeight; weightTotal = analysis.Solution.Weight; OptDouble optNetWeight = analysis.Solution.NetWeight; weightNet = optNetWeight.Activated ? optNetWeight.Value : (double?)null; bbGlob = analysis.Solution.BBoxGlobal.DimensionsVec; bbLoad = analysis.Solution.BBoxLoad.DimensionsVec; volumeEfficency = analysis.Solution.VolumeEfficiency; weightEfficiency = null; if (analysis.Solution.WeightEfficiency.Activated) { weightEfficiency = analysis.Solution.WeightEfficiency.Value; } // generate image path Graphics3DImage graphics = new Graphics3DImage(sz) { FontSizeRatio = fontSizeRatio, CameraPosition = cameraPosition, ShowDimensions = showCotations }; ViewerSolution sv = new ViewerSolution(analysis.Solution); sv.Draw(graphics, Transform3D.Identity); graphics.Flush(); Bitmap bmp = graphics.Bitmap; ImageConverter converter = new ImageConverter(); imageBytes = (byte[])converter.ConvertTo(bmp, typeof(byte[])); } else { lErrors.Add("No solution found!"); } } catch (Exception ex) { lErrors.Add(ex.Message); } errors = lErrors.ToArray(); return(0 == lErrors.Count); }
private void GenerateResult( string name , double length, double width, double height , double?weight , ref int stackCount, ref double stackWeight, ref double stackEfficiency , ref string stackImagePath) { stackCount = 0; stackWeight = 0.0; stackImagePath = string.Empty; // generate case BoxProperties bProperties = new BoxProperties(null, length, width, height); if (weight.HasValue) { bProperties.SetWeight(weight.Value); } bProperties.SetColor(Color.Chocolate); bProperties.TapeWidth = new OptDouble(true, Math.Min(50.0, 0.5 * width)); bProperties.TapeColor = Color.Beige; Graphics3DImage graphics = null; if (GenerateImage || GenerateImageInFolder) { // generate image path stackImagePath = Path.Combine(Path.ChangeExtension(Path.GetTempFileName(), "png")); if (GenerateImageInFolder) { stackImagePath = Path.ChangeExtension(Path.Combine(Path.Combine(DirectoryPathImages, name)), "png"); } graphics = new Graphics3DImage(new Size(ImageSize, ImageSize)) { FontSizeRatio = this.FontSizeRatio, CameraPosition = Graphics3D.Corner_0 }; } // compute analysis if (0 == Mode) { ConstraintSetCasePallet constraintSet = new ConstraintSetCasePallet(); constraintSet.SetAllowedOrientations(new bool[] { !AllowOnlyZOrientation, !AllowOnlyZOrientation, true }); constraintSet.SetMaxHeight(new OptDouble(true, PalletMaximumHeight)); SolverCasePallet solver = new SolverCasePallet(bProperties, PalletProperties, constraintSet); List <AnalysisLayered> analyses = solver.BuildAnalyses(false); if (analyses.Count > 0) { AnalysisLayered analysis = analyses[0]; stackCount = analysis.Solution.ItemCount; stackWeight = analysis.Solution.Weight; stackEfficiency = analysis.Solution.VolumeEfficiency; if (stackCount <= StackCountMax) { if (GenerateImage || GenerateImageInFolder) { ViewerSolution sv = new ViewerSolution(analysis.Solution as SolutionLayered); sv.Draw(graphics, Transform3D.Identity); graphics.Flush(); } if (GenerateReport) { ReportDataAnalysis inputData = new ReportDataAnalysis(analysis); string outputFilePath = Path.ChangeExtension(Path.Combine(Path.GetDirectoryName(OutputFilePath), string.Format("Report_{0}_on_{1}", analysis.Content.Name, analysis.Container.Name)), "doc"); ReportNode rnRoot = null; Margins margins = new Margins(); Reporter reporter = new ReporterMSWord(inputData, ref rnRoot, Reporter.TemplatePath, outputFilePath, margins); } } } } else { BoxProperties container = new BoxProperties(null, TruckLength, TruckWidth, TruckHeight, TruckLength, TruckWidth, TruckHeight); Color lblue = Color.LightBlue; container.SetAllColors(new Color[] { lblue, lblue, lblue, lblue, lblue, lblue }); container.SetWeight(0.0); ConstraintSetBoxCase constraintSet = new ConstraintSetBoxCase(container); constraintSet.SetAllowedOrientations(new bool[] { !AllowOnlyZOrientation, !AllowOnlyZOrientation, true }); SolverBoxCase solver = new SolverBoxCase(bProperties, container, constraintSet); List <AnalysisLayered> analyses = solver.BuildAnalyses(false); if (analyses.Count > 0) { AnalysisLayered analysis = analyses[0]; stackCount = analysis.Solution.ItemCount; stackWeight = analysis.Solution.Weight; if ((GenerateImage || GenerateImageInFolder) && stackCount <= StackCountMax) { ViewerSolution sv = new ViewerSolution(analysis.Solution as SolutionLayered); sv.Draw(graphics, Transform3D.Identity); graphics.Flush(); } } } if (GenerateImage) { Bitmap bmp = graphics.Bitmap; bmp.Save(stackImagePath, System.Drawing.Imaging.ImageFormat.Png); } }