Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/13/18 16:45:01 (7 years ago)
Author:
rhanghof
Message:

#2817:

  • Added a graph to the BinPacking3D for calculating the weight distribution.
  • Added some materials.
Location:
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/BinPacking3D.cs

    r15731 r15770  
    3838    [Storable]
    3939    public IDictionary<PackingPosition, IEnumerable<ResidualSpace>> ExtremePoints { get; protected set; }
    40 
     40   
    4141    [Storable]
    4242    public IDirectedGraph WeightDistirbution { get; protected set; }
     
    6464      }
    6565
    66       // todo clone WeightDistirbution graph
     66      WeightDistirbution = original.WeightDistirbution.Clone() as IDirectedGraph;
    6767    }
    6868
     
    8888
    8989
    90     #region Graph for the calculating the weight distirbution       
     90    #region Graph for the calculating the weight distirbution     
     91    /// <summary>
     92    /// The given item is added to the graph as the source vertex.
     93    /// Its items below are the target vertices.
     94    /// </summary>
     95    /// <param name="itemId"></param>
     96    /// <param name="item"></param>
     97    /// <param name="position"></param>
    9198    private void AddToGraph(int itemId, PackingItem item, PackingPosition position) {
    9299      var sourceVertex = new VertexWithItemId(itemId);
     
    356363
    357364    #region Weight supported
     365
    358366    //old implementation
    359367    /// <summary>
     
    367375        return true;
    368376      }
    369       IEnumerable<Tuple<PackingPosition, PackingItem>> itemsP1;
    370       IEnumerable<Tuple<PackingPosition, PackingItem>> itemsP2;
    371       IEnumerable<Tuple<PackingPosition, PackingItem>> itemsP3;
    372       IEnumerable<Tuple<PackingPosition, PackingItem>> itemsP4;
    373 
    374       GetItemsUnderItemWithContact(item, position, out itemsP1, out itemsP2, out itemsP3, out itemsP4);
    375 
    376       return itemsP1.Where(x => x.Item2.SupportsStacking(item)).Any() &&
    377         itemsP2.Where(x => x.Item2.SupportsStacking(item)).Any() &&
    378         itemsP3.Where(x => x.Item2.SupportsStacking(item)).Any() &&
    379         itemsP4.Where(x => x.Item2.SupportsStacking(item)).Any();
    380     }
     377
     378      var itemsBelow = Items.Where(x => Positions[x.Key].Y + x.Value.Height == position.Y)
     379                            .Select(x => new {
     380                              ItemId = x.Key,
     381                              Item = Tuple.Create<PackingPosition, PackingItem>(Positions[x.Key], x.Value),                           
     382                              Overlay = CalculateOverlay(Tuple.Create<PackingPosition, PackingItem>(Positions[x.Key], x.Value),
     383                                                         Tuple.Create<PackingPosition, PackingItem>(position, item))
     384                            })
     385                            .Where(x=> x.Overlay > 0);
     386
     387      var area = item.Width * item.Depth;
     388      foreach (var itemBelow in itemsBelow) {
     389        var factor = itemBelow.Overlay / area;
     390        if (itemBelow.Item.Item2.SupportedWeightPerSquareMeter < item.Weight / area) {
     391          return false;
     392        }
     393
     394        if (!IsWeightSupportedRec(itemBelow.Item.Item2, itemBelow.ItemId, item.Weight, factor)) {
     395          return false;
     396        }
     397      }
     398      return true;
     399    }
     400
     401    private bool IsWeightSupportedRec(PackingItem item, int itemId, double weigth, double factor) {
     402      var stackedWeight = GetStackedWeightForItemId(itemId);
     403      if (!item.SupportWeight(weigth * factor + stackedWeight)) {
     404        return false;
     405      }
     406
     407      var arcs = WeightDistirbution.Arcs.Where(x => ((VertexWithItemId)x.Source).ItemId == itemId);
     408      foreach (var arc in arcs) {
     409        var targetItemId = ((VertexWithItemId)arc.Target).ItemId;
     410        var targetItem = Items[targetItemId];
     411        if (!IsWeightSupportedRec(targetItem, targetItemId, weigth, factor * arc.Weight)) {
     412          return false;
     413        }
     414      }
     415
     416      return true;
     417    }
     418   
     419
    381420
    382421    private double CalculateOverlay(Tuple<PackingPosition, PackingItem> item1, Tuple<PackingPosition, PackingItem> item2) {
     
    452491    }
    453492
     493    public IEnumerable<PackingItem> GetItemsBelow(int itemId) {
     494      var item = Items[itemId];
     495      var position = Positions[itemId];
     496
     497      var itemsBelow = Items.Where(x => Positions[x.Key].Y + x.Value.Height == position.Y &&
     498                                        CalculateOverlay(Tuple.Create<PackingPosition, PackingItem>(Positions[x.Key], x.Value),
     499                                                         Tuple.Create<PackingPosition, PackingItem>(position, item)) > 0)
     500                            .Select(x => x.Value);
     501      return itemsBelow;
     502    }
     503
    454504    #endregion
    455505  }
  • branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/PackingItem.cs

    r15731 r15770  
    6060    }
    6161
    62     #region Material
    63     public IFixedValueParameter<EnumValue<MaterialType>> MaterialBottomParameter {
    64       get { return (IFixedValueParameter<EnumValue<MaterialType>>)Parameters["MaterialBottom"]; }
    65     }
    66     public MaterialType MaterialBottom {
    67       get { return MaterialBottomParameter.Value.Value; }
    68       set { MaterialBottomParameter.Value.Value = value; }
    69     }
     62    #region Material   
    7063
    7164    public IFixedValueParameter<EnumValue<MaterialType>> MaterialTopParameter {
     
    8477      get { return SupportedWeightParameter.Value.Value; }
    8578      set { SupportedWeightParameter.Value.Value = value; }
     79    }
     80
     81    public double SupportedWeightPerSquareMeter {
     82      get {
     83        return SupportedWeight / (Width * Depth);
     84      }
    8685    }
    8786
     
    297296      return other.Layer <= this.Layer && SupportedWeight > 0;
    298297    }
     298       
     299    public bool SupportWeight(double weigth) {
     300      return SupportedWeight >= weigth;
     301    }
    299302    #endregion
    300303
     
    314317
    315318      Parameters.Add(new FixedValueParameter<EnumValue<MaterialType>>("MaterialTop"));
    316       Parameters.Add(new FixedValueParameter<EnumValue<MaterialType>>("MaterialBottom"));
    317319
    318320      Parameters.Add(new FixedValueParameter<DoubleValue>("SupportedWeight"));
  • branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/PackingShape.cs

    r15617 r15770  
    2727using HeuristicLab.Parameters;
    2828using HeuristicLab.Problems.BinPacking;
     29using HeuristicLab.Problems.BinPacking3D.Material;
    2930
    3031namespace HeuristicLab.Problems.BinPacking3D {
     
    5758    }
    5859
     60    public IFixedValueParameter<EnumValue<MaterialType>> MaterialBottomParameter {
     61      get { return (IFixedValueParameter<EnumValue<MaterialType>>)Parameters["MaterialBottom"]; }
     62    }
     63    public MaterialType MaterialBottom {
     64      get { return MaterialBottomParameter.Value.Value; }
     65      set { MaterialBottomParameter.Value.Value = value; }
     66    }
     67
    5968    [StorableConstructor]
    6069    protected PackingShape(bool deserializing) : base(deserializing) { }
     
    6877      Parameters.Add(new FixedValueParameter<IntValue>("Height"));
    6978      Parameters.Add(new FixedValueParameter<IntValue>("Depth"));
     79      Parameters.Add(new FixedValueParameter<EnumValue<MaterialType>>("MaterialBottom"));
     80
     81      MaterialBottom = MaterialType.ScreenPrintingPlate;
    7082
    7183      RegisterEvents();
  • branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/ResidualSpaceCalculation/ResidualSpaceCalculator.cs

    r15617 r15770  
    2020#endregion
    2121
     22using HeuristicLab.Core;
    2223using HeuristicLab.Problems.BinPacking3D.Geometry;
    2324using System;
     
    2627using System.Text;
    2728using System.Threading.Tasks;
     29using HeuristicLab.Common;
     30using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2831
    2932namespace HeuristicLab.Problems.BinPacking3D.ResidualSpaceCalculation {
    30   internal class ResidualSpaceCalculator : IResidualSpaceCalculator {
     33  internal class ResidualSpaceCalculator : Item, IResidualSpaceCalculator {
    3134
    3235    internal ResidualSpaceCalculator() {}
    33    
     36
     37    [StorableConstructor]
     38    protected ResidualSpaceCalculator(bool deserializing) : base(deserializing) { }
     39
     40    protected ResidualSpaceCalculator(ResidualSpaceCalculator original, Cloner cloner)
     41      : base(original, cloner) {
     42    }
     43
     44    public override IDeepCloneable Clone(Cloner cloner) {
     45      return new ResidualSpaceCalculator(this, cloner);
     46    }
     47
    3448    public IEnumerable<ResidualSpace> CalculateResidualSpaces(BinPacking3D binPacking, Vector3D point) {
    3549      IList<ResidualSpace> residualSpaces = new List<ResidualSpace>();
Note: See TracChangeset for help on using the changeset viewer.