Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/ExtremePointPruning/ExtremePointPruning.cs @ 16147

Last change on this file since 16147 was 15822, checked in by rhanghof, 7 years ago

#2817:

  • Added the property SequenceGroup to the PackingItem
  • Fixed a bug related to the sequence group
File size: 3.4 KB
RevLine 
[15618]1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using System.Text;
26using System.Threading.Tasks;
27
28namespace HeuristicLab.Problems.BinPacking3D.ExtremePointPruning {
29  internal class ExtremePointPruning : IExtremePointPruning {
[15820]30    public void PruneExtremePoints(PackingShape bin, Dictionary<BinPacking3D, List<KeyValuePair<int, PackingPosition>>> positions) {
31      PruneExtremePointsBehind(bin, positions);
[15618]32    }
33
[15820]34    public void PruneExtremePoints(IList<BinPacking3D> binPackings) {
[15618]35      if (binPackings.Count <= 0) {
36        return;
37      }
38      var fixedPositions = new Dictionary<BinPacking3D, List<KeyValuePair<int, PackingPosition>>>();
39      foreach (BinPacking3D bp in binPackings) {
40        var list = new List<KeyValuePair<int, PackingPosition>>();
41        fixedPositions.Add(bp, list);
42        foreach (var p in bp.Positions) {
43          list.Add(p);
44        }
45      }
46      PruneExtremePointsBehind(binPackings[0].BinShape, fixedPositions);
47    }
48
[15822]49    public void PruneExtremePoints(BinPacking3D binPacking, int sequenceNumber) {
[15820]50      var pruningPositions = new List<KeyValuePair<int, PackingPosition>>();
51      var pruning = new Dictionary<BinPacking3D, List<KeyValuePair<int, PackingPosition>>>();
52      pruning.Add(binPacking, pruningPositions);
[15822]53      foreach (var item in binPacking.Items.Where(x => x.Value.SequenceGroup <= sequenceNumber)) {
[15820]54        pruningPositions.Add(new KeyValuePair<int, PackingPosition>(item.Key, binPacking.Positions[item.Key]));
55      }
[15618]56
[15820]57      PruneExtremePointsBehind(binPacking.BinShape, pruning);
58    }
59
60
[15618]61    /// <summary>
62    /// Prunes all extreme point behind the given positions.
63    /// </summary>
64    /// <param name="bin"></param>
65    /// <param name="positions"></param>
66    private static void PruneExtremePointsBehind(PackingShape bin, Dictionary<BinPacking3D, List<KeyValuePair<int, PackingPosition>>> positions) {
67      int binHeight = bin.Height;
68      foreach (var kvp in positions) {
69        var bp = kvp.Key;
70        foreach (var item in kvp.Value.OrderByDescending(x => x.Value.Z).ThenByDescending(x => x.Value.X)) {
71          // everything behind the item
72          var limit = new {
73            X = item.Value.X + bp.Items[item.Key].Width,
74            Y = item.Value.Y + binHeight,
75            Z = item.Value.Z
76          };
77          var eps = bp.ExtremePoints.Where(x => x.Key.X < limit.X && x.Key.Y < limit.Y && x.Key.Z < limit.Z).ToList();
78          foreach (var ep in eps) {
79            bp.ExtremePoints.Remove(ep);
80          }
81        }
82      }
83    }
84  }
85}
Note: See TracBrowser for help on using the repository browser.