#region License Information /* HeuristicLab * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace HeuristicLab.Problems.BinPacking3D.ExtremePointPruning { internal class ExtremePointPruning : IExtremePointPruning { public void PruneExtremePoints(PackingShape bin, Dictionary>> positions) { PruneExtremePointsBehind(bin, positions); } public void PruneExtremePoints(IList binPackings) { if (binPackings.Count <= 0) { return; } var fixedPositions = new Dictionary>>(); foreach (BinPacking3D bp in binPackings) { var list = new List>(); fixedPositions.Add(bp, list); foreach (var p in bp.Positions) { list.Add(p); } } PruneExtremePointsBehind(binPackings[0].BinShape, fixedPositions); } public void PruneExtremePoints(BinPacking3D binPacking, int sequenceNumber) { var pruningPositions = new List>(); var pruning = new Dictionary>>(); pruning.Add(binPacking, pruningPositions); foreach (var item in binPacking.Items.Where(x => x.Value.SequenceGroup <= sequenceNumber)) { pruningPositions.Add(new KeyValuePair(item.Key, binPacking.Positions[item.Key])); } PruneExtremePointsBehind(binPacking.BinShape, pruning); } /// /// Prunes all extreme point behind the given positions. /// /// /// private static void PruneExtremePointsBehind(PackingShape bin, Dictionary>> positions) { int binHeight = bin.Height; foreach (var kvp in positions) { var bp = kvp.Key; foreach (var item in kvp.Value.OrderByDescending(x => x.Value.Z).ThenByDescending(x => x.Value.X)) { // everything behind the item var limit = new { X = item.Value.X + bp.Items[item.Key].Width, Y = item.Value.Y + binHeight, Z = item.Value.Z }; var eps = bp.ExtremePoints.Where(x => x.Key.X < limit.X && x.Key.Y < limit.Y && x.Key.Z < limit.Z).ToList(); foreach (var ep in eps) { bp.ExtremePoints.Remove(ep); } } } } } }