Changeset 14039


Ignore:
Timestamp:
07/12/16 17:12:15 (14 months ago)
Author:
gkronber
Message:

#1966 restored functionality after splitting into 2d and 3d problems

Location:
branches/HeuristicLab.BinPacking
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.2D/3.3/RectangularIdenticalBinPackingProblem.cs

    r13611 r14039  
    3434using HeuristicLab.Problems.Instances;
    3535using HeuristicLab.Encodings.PackingEncoding.MultiComponentVector;
     36using HeuristicLab.Data;
     37using System;
    3638
    3739namespace HeuristicLab.Problems.BinPacking.Problem {
     
    101103    }
    102104
     105    #region Problem instance handling
     106    public override void Load(BPPData data) {
     107      var realData = data as RealBPPData;
     108      var binData = new RectangularPackingBin(data.BinMeasures[0], data.BinMeasures[1]);
     109
     110      var itemData = new ItemList<RectangularPackingItem>(data.Items);
     111      for (int j = 0; j < data.Items; j++) {
     112        var bin = new RectangularPackingBin(data.BinMeasures[0], data.BinMeasures[1]);
     113        var item = new RectangularPackingItem(data.ItemMeasures[j][0], data.ItemMeasures[j][1], bin);
     114        if (realData != null) {
     115          item.Weight = realData.ItemWeights[j];
     116          item.Material = realData.ItemMaterials[j];
     117        }
     118        itemData.Add(item);
     119      }
     120
     121      BestKnownQuality = data.BestKnownQuality.HasValue ? new DoubleValue(data.BestKnownQuality.Value) : null;
     122
     123      PackingBinMeasures = binData;
     124      PackingItemMeasures = itemData;
     125
     126      ApplyHorizontalOrientation();
     127      SortItems();
     128      PackingItemsParameter.Value.Value = PackingItemMeasures.Count;
     129      LowerBoundParameter.Value.Value = CalculateLowerBound();
     130    }
     131
     132
     133    public override BPPData Export() {
     134      var result = new BPPData {
     135        Name = Name,
     136        Description = Description,
     137        Items = PackingItemsParameter.Value.Value,
     138        BinMeasures = new int[] { PackingBinMeasures.Width, PackingBinMeasures.Height }
     139      };
     140
     141      var itemMeasures = new int[result.Items][];
     142      int i = 0;
     143      foreach (var item in PackingItemMeasures) {
     144        itemMeasures[i] = new int[] { item.Width, item.Height };
     145        i++;
     146      }
     147      result.ItemMeasures = itemMeasures;
     148      return result;
     149    }
     150    #endregion
    103151
    104152    #region Helpers
     
    107155
    108156      PackingSolutionDecoderParameter.ValidValues.Clear();
    109       if (SolutionCreator is PackingSequenceRandomCreator) {       
     157      if (SolutionCreator is PackingSequenceRandomCreator) {
    110158        PackingSolutionDecoderParameter.ValidValues.UnionWith(ApplicationManager.Manager.GetInstances<I2DPSDecoder>());
    111       } else if (SolutionCreator is GroupingVectorRandomCreator) { 
     159      } else if (SolutionCreator is GroupingVectorRandomCreator) {
    112160        PackingSolutionDecoderParameter.ValidValues.UnionWith(ApplicationManager.Manager.GetInstances<I2DGVDecoder>());
    113       } else if (SolutionCreator is MultiComponentVectorRandomCreator) { 
     161      } else if (SolutionCreator is MultiComponentVectorRandomCreator) {
    114162        PackingSolutionDecoderParameter.ValidValues.UnionWith(ApplicationManager.Manager.GetInstances<I2DMCVDecoder>());
    115163      } else {
     
    120168
    121169    protected override IPackingPlanEvaluator CreateDefaultEvaluator() {
    122       return new PackingRatioRectangularIdenticalBinEvaluator ();
     170      return new PackingRatioRectangularIdenticalBinEvaluator();
    123171    }
    124172
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.2D/3.3/RectangularPackingItem.cs

    r13606 r14039  
    6969    public RectangularPackingItem(int width, int height, RectangularPackingBin targetBin)
    7070      : this() {
    71       this.Weight = width;
     71      this.Width = width;
    7272      this.Height = height;
    7373      this.TargetBin = (RectangularPackingBin)targetBin.Clone();
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.3D/3.3/CuboidIdenticalBinPackingProblem.cs

    r13608 r14039  
    3434using HeuristicLab.Encodings.PackingEncoding.MultiComponentVector;
    3535using HeuristicLab.PluginInfrastructure;
     36using System;
     37using HeuristicLab.Data;
    3638
    3739namespace HeuristicLab.Problems.BinPacking.Problem {
     
    4244
    4345    #region Default Instance
    44     private static readonly BPPData DefaultInstance = new BPPData() { 
    45       Name = "3D BPP Default Instance", 
     46    private static readonly BPPData DefaultInstance = new BPPData() {
     47      Name = "3D BPP Default Instance",
    4648      Description = "The default instance for 3D Bin Packing.",
    47       BinMeasures = new int[] {25,25,35},
     49      BinMeasures = new int[] { 25, 25, 35 },
    4850      ItemMeasures = new int[][] {
    4951        new int[] {12,5,10},
     
    9294    };
    9395    #endregion
    94    
     96
    9597    [StorableConstructor]
    9698    protected CuboidIdenticalBinPackingProblem(bool deserializing) : base(deserializing) { }
     
    107109
    108110
     111    public override void Load(BPPData data) {
     112      var realData = data as RealBPPData;
     113      var binData = new CuboidPackingBin(data.BinMeasures[0], data.BinMeasures[1], data.BinMeasures[2]);
     114
     115      var itemData = new ItemList<CuboidPackingItem>(data.Items);
     116      for (int j = 0; j < data.Items; j++) {
     117        var bin = new CuboidPackingBin(data.BinMeasures[0], data.BinMeasures[1], data.BinMeasures[2]);
     118        var item = new CuboidPackingItem(data.ItemMeasures[j][0], data.ItemMeasures[j][1], data.ItemMeasures[j][2], bin);
     119        if (realData != null) {
     120          item.Weight = realData.ItemWeights[j];
     121          item.Material = realData.ItemMaterials[j];
     122        }
     123        itemData.Add(item);
     124      }
     125
     126      BestKnownQuality = data.BestKnownQuality.HasValue ? new DoubleValue(data.BestKnownQuality.Value) : null;
     127
     128      PackingBinMeasures = binData;
     129      PackingItemMeasures = itemData;
     130
     131      ApplyHorizontalOrientation();
     132      SortItems();
     133      PackingItemsParameter.Value.Value = PackingItemMeasures.Count;
     134      LowerBoundParameter.Value.Value = CalculateLowerBound();
     135    }
     136
     137    public override BPPData Export() {
     138      var result = new BPPData {
     139        Name = Name,
     140        Description = Description,
     141        Items = PackingItemsParameter.Value.Value,
     142        BinMeasures = new int[] { PackingBinMeasures.Width, PackingBinMeasures.Height, PackingBinMeasures.Depth }
     143      };
     144
     145      var itemMeasures = new int[result.Items][];
     146      int i = 0;
     147      foreach (var item in PackingItemMeasures) {
     148        itemMeasures[i] = new int[] { item.Width, item.Height, item.Depth };
     149        i++;
     150      }
     151      result.ItemMeasures = itemMeasures;
     152      return result;
     153    }
     154
    109155    #region Helpers
    110156    protected override void InitializeDecoder() {
     
    112158
    113159      PackingSolutionDecoderParameter.ValidValues.Clear();
    114       if (SolutionCreator is PackingSequenceRandomCreator) {   
     160      if (SolutionCreator is PackingSequenceRandomCreator) {
    115161        PackingSolutionDecoderParameter.ValidValues.UnionWith(ApplicationManager.Manager.GetInstances<I3DPSDecoder>());
    116       } else if (SolutionCreator is GroupingVectorRandomCreator) {     
     162      } else if (SolutionCreator is GroupingVectorRandomCreator) {
    117163        PackingSolutionDecoderParameter.ValidValues.UnionWith(ApplicationManager.Manager.GetInstances<I3DGVDecoder>());
    118       } else if (SolutionCreator is MultiComponentVectorRandomCreator) {   
     164      } else if (SolutionCreator is MultiComponentVectorRandomCreator) {
    119165        PackingSolutionDecoderParameter.ValidValues.UnionWith(ApplicationManager.Manager.GetInstances<I3DMCVDecoder>());
    120166      } else {
     
    133179
    134180    protected override void RemoveTooBigItems() {
    135       PackingItemMeasures.RemoveAll(pi => 
    136         !PackingBinMeasures.Encloses (new ThreeDimensionalPacking(0, 0, 0, 0, false), pi) &&
     181      PackingItemMeasures.RemoveAll(pi =>
     182        !PackingBinMeasures.Encloses(new ThreeDimensionalPacking(0, 0, 0, 0, false), pi) &&
    137183        !PackingBinMeasures.Encloses(new ThreeDimensionalPacking(0, 0, 0, 0, true), pi));
    138184    }
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/RegularIdenticalBinPackingProblem.cs

    r13608 r14039  
    4141  [Item("RegularIdenticalBinPackingProblem", "Represents a bin-packing problem-instance using only bins with identical measures and bins/items with regular shapes (e.g. rectangle, cuboid).")]
    4242  [StorableClass]
    43   public abstract class RegularIdenticalBinPackingProblem<D, B, I> : BinPackingProblem<D, B, I>, IProblemInstanceConsumer<BPPData>,  IProblemInstanceExporter<BPPData>
     43  public abstract class RegularIdenticalBinPackingProblem<D, B, I> : BinPackingProblem<D, B, I>, IProblemInstanceConsumer<BPPData>, IProblemInstanceExporter<BPPData>
    4444    where D : class, IPackingDimensions
    4545    where B : PackingShape<D>, IPackingBin, IRegularPackingShape, new()
    46     where I : PackingShape<D>, IPackingItem, IRegularPackingShape, new() {       
     46    where I : PackingShape<D>, IPackingItem, IRegularPackingShape, new() {
    4747
    4848    #region Parameter Properties
     
    5858    public B PackingBinMeasures {
    5959      get { return PackingBinMeasuresParameter.Value; }
    60       set { PackingBinMeasuresParameter.Value = value; } 
    61     }
    62     public PackingSolutionDecoder<D,B,I> PackingSolutionDecoder {
     60      set { PackingBinMeasuresParameter.Value = value; }
     61    }
     62    public PackingSolutionDecoder<D, B, I> PackingSolutionDecoder {
    6363      get { return PackingSolutionDecoderParameter.Value as PackingSolutionDecoder<D, B, I>; }
    6464      set { PackingSolutionDecoderParameter.Value = value; }
     
    6969    [StorableConstructor]
    7070    protected RegularIdenticalBinPackingProblem(bool deserializing) : base(deserializing) { }
    71     protected RegularIdenticalBinPackingProblem(RegularIdenticalBinPackingProblem<D,B,I> original, Cloner cloner)
     71    protected RegularIdenticalBinPackingProblem(RegularIdenticalBinPackingProblem<D, B, I> original, Cloner cloner)
    7272      : base(original, cloner) {
    7373      InitializeEventHandlers();
     
    8686    }
    8787
    88    
     88
    8989
    9090
     
    101101    protected abstract void InitializeProblemData();
    102102    protected abstract IPackingPlanEvaluator CreateDefaultEvaluator();
    103     private void ApplyHorizontalOrientation() {
     103    protected void ApplyHorizontalOrientation() {
    104104      PackingBinMeasures.ApplyHorizontalOrientation();
    105105      foreach (IRegularPackingShape shape in PackingItemMeasures) {
     
    107107      }
    108108    }
    109     private void SortItems() {
     109    protected void SortItems() {
    110110      PackingItemMeasures.Sort((x, y) => y.CompareTo(x));
    111111    }
    112     private int CalculateLowerBound() {
     112    protected int CalculateLowerBound() {
    113113      //This is the obvious continuous lower bound calculation; Martello and Vigo proposed a better way but it has not been implemented yet;
    114114      int items = PackingItemMeasures.Select(x => x.Volume).Sum();
    115115      int bin = PackingBinMeasures.Volume;
    116       return (items + bin - 1)/(bin);
     116      return (items + bin - 1) / (bin);
    117117    }
    118118
    119119    protected override void InitializeOperators() {
    120       Operators.Clear(); 
     120      Operators.Clear();
    121121      Operators.Add(new BestBinPackingSolutionAnalyzer<D, B, I>());
    122122
     
    134134        Operators.AddRange(ApplicationManager.Manager.GetInstances<IMultiComponentVectorOperator>());
    135135        InitializeDecoder();
    136       } 
    137     }
    138     private void ParameterizeOperators() {   
     136      }
     137    }
     138    private void ParameterizeOperators() {
    139139      foreach (var op in Operators.OfType<BestBinPackingSolutionAnalyzer<D, B, I>>()) {
    140140        op.QualityParameter.ActualName = PackingPlanEvaluator.QualityParameter.ActualName;
     
    224224      ParameterizeOperators();
    225225    }
    226     #endregion
    227 
    228 
    229     #region Problem instance handling
    230     public virtual void Load(BPPData data) {
    231       // var realData = data as RealBPPData;
    232       // var binData = new B();
    233       // binData.InitializeFromMeasures (data.BinMeasures);
    234       //
    235       // var itemData = new ItemList<I>(data.Items);
    236       // for (int j = 0; j < data.Items; j++) {
    237       //   var item = new I();
    238       //   item.InitializeFromMeasures(data.ItemMeasures[j]);
    239       //   item.AddTargetBinMeasures(data.BinMeasures);
    240       //   if (realData != null) {
    241       //     item.Weight = realData.ItemWeights[j];
    242       //     item.Material = realData.ItemMaterials[j];
    243       //   }
    244       //   itemData.Add(item);
    245       // }
    246       //
    247       // BestKnownQuality = data.BestKnownQuality.HasValue ? new DoubleValue(data.BestKnownQuality.Value) : null;
    248       //
    249       // PackingBinMeasures = binData;   
    250       // PackingItemMeasures = itemData;
    251       //
    252       // ApplyHorizontalOrientation();
    253       // SortItems();
    254       // PackingItemsParameter.Value.Value = PackingItemMeasures.Count;
    255       // LowerBoundParameter.Value.Value = CalculateLowerBound();
    256 
    257       throw new NotImplementedException();
    258     }
    259 
    260     public BPPData Export() {
    261       // var result = new BPPData{
    262       //   Name = Name,
    263       //   Description = Description,
    264       //   Items = PackingItemsParameter.Value.Value,
    265       //   BinMeasures = PackingBinMeasures.ToArray() // TODO: split functionality of class in 2d and 3d code
    266       // };
    267       //
    268       // var itemMeasures = new int[result.Items][];
    269       // int i = 0;
    270       // foreach (var item in PackingItemMeasures) {
    271       //   itemMeasures[i] = item.ToArray();
    272       //   i++;
    273       // }
    274       // result.ItemMeasures = itemMeasures;
    275       // return result;
    276 
    277       throw new NotImplementedException();
    278     }
    279     #endregion
     226
     227    public abstract void Load(BPPData data);
     228
     229    public abstract BPPData Export();
     230    #endregion
     231
    280232  }
    281233}
Note: See TracChangeset for help on using the changeset viewer.