Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/12/16 10:42:58 (9 years ago)
Author:
gkronber
Message:

#1966: fixed various problems: bugs in cloning, bugs in persistence, method names, various minor improvements of source code for readability.

Location:
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/PackingBin/RectangularPackingBin.cs

    r13461 r13497  
    3232
    3333    public RectangularPackingBin(int width, int height) : base(width, height) { }
    34     public RectangularPackingBin()
    35       : base() {
    36 
    37     }
     34    public RectangularPackingBin() : base() { }
    3835
    3936    [StorableConstructor]
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/PackingItem/CuboidPackingItem.cs

    r13461 r13497  
    2929
    3030namespace HeuristicLab.Problems.BinPacking.PackingItem {
    31   [Item ("CuboidPackingItem", "Represents a cuboidic packing-item for bin-packing problems.")]
     31  [Item("CuboidPackingItem", "Represents a cuboidic packing-item for bin-packing problems.")]
    3232  [StorableClass]
    3333  public class CuboidPackingItem : CuboidPackingShape, IPackingItem {
     34    [Storable]
     35    public CuboidPackingBin TargetBin { get; set; }
    3436
    35     public CuboidPackingBin TargetBin { get; set; }
     37    [Storable]
    3638    public double Weight { get; set; }
     39
     40    [Storable]
    3741    public int Material { get; set; }
     42
    3843    public bool SupportsStacking(IPackingItem other) {
    3944      return ((other.Material < this.Material) || (other.Material.Equals(this.Material) && other.Weight <= this.Weight));
     
    4449    protected CuboidPackingItem(CuboidPackingItem original, Cloner cloner)
    4550      : base(original, cloner) {
    46         this.Weight = original.Weight;
    47         this.Material = original.Material;
     51      this.Weight = original.Weight;
     52      this.Material = original.Material;
     53      this.TargetBin = cloner.Clone(TargetBin);
    4854    }
    4955    public override IDeepCloneable Clone(Cloner cloner) {
    5056      return new CuboidPackingItem(this, cloner);
    5157    }
    52     public CuboidPackingItem() : base() {
     58    public CuboidPackingItem()
     59      : base() {
    5360    }
    5461
    55     public CuboidPackingItem(int width, int height, int depth, CuboidPackingBin targetBin, double weight, int material) : this(width, height, depth, targetBin) { this.Weight = weight; this.Material = material; }
    56     public CuboidPackingItem(int width, int height, int depth, CuboidPackingBin targetBin) : base(width, height, depth) { this.TargetBin = new CuboidPackingBin(targetBin.Width, targetBin.Height, targetBin.Depth); }
     62    public CuboidPackingItem(int width, int height, int depth, CuboidPackingBin targetBin, double weight, int material)
     63      : this(width, height, depth, targetBin) {
     64      this.Weight = weight;
     65      this.Material = material;
     66    }
     67
     68    public CuboidPackingItem(int width, int height, int depth, CuboidPackingBin targetBin)
     69      : base(width, height, depth) {
     70      this.TargetBin = (CuboidPackingBin)targetBin.Clone();
     71    }
    5772
    5873    public void AddTargetBinMeasures(int[] targetBinMeasures) {
     
    6176
    6277    public override string ToString() {
    63       return String.Format("CuboidPackingItem ({0}, {1}, {2}; w={3}, m={4})", this.Width, this.Height, this.Depth, this.Weight,this.Material);
     78      return String.Format("CuboidPackingItem ({0}, {1}, {2}; w={3}, m={4})", this.Width, this.Height, this.Depth, this.Weight, this.Material);
    6479    }
    6580  }
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/PackingItem/RectangularPackingItem.cs

    r13461 r13497  
    3333  public class RectangularPackingItem : RectangularPackingShape, IPackingItem {
    3434
     35    [Storable]
    3536    public RectangularPackingBin TargetBin { get; set; }
     37
     38    [Storable]
    3639    public double Weight { get; set; }
     40
     41    [Storable]
    3742    public int Material { get; set; }
     43
    3844    public bool SupportsStacking(IPackingItem other) {
    3945      return ((other.Material < this.Material) || (other.Material.Equals(this.Material) && other.Weight <= this.Weight));
     
    4652      this.Weight = original.Weight;
    4753      this.Material = original.Material;
     54      this.TargetBin = cloner.Clone(TargetBin);
    4855    }
    4956    public override IDeepCloneable Clone(Cloner cloner) {
     
    5461    }
    5562
    56     public RectangularPackingItem(int width, int height, RectangularPackingBin targetBin) : base(width, height) { this.TargetBin = new RectangularPackingBin(targetBin.Width, targetBin.Height); }
     63    public RectangularPackingItem(int width, int height, RectangularPackingBin targetBin)
     64      : base(width, height) {
     65      this.TargetBin = (RectangularPackingBin)targetBin.Clone();
     66    }
    5767
    5868    public void AddTargetBinMeasures(int[] targetBinMeasures) {
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Shapes/CuboidPackingShape.cs

    r13461 r13497  
    2121
    2222using System;
     23using System.Diagnostics;
    2324using HeuristicLab.Problems.BinPacking.Interfaces;
    2425using HeuristicLab.Core;
     
    148149
    149150    public int CompareTo(object obj) {
    150       if (obj.GetType() == this.GetType())
    151         return this.CompareTo((CuboidPackingShape)obj);
    152       else return 0;
     151      var other = (CuboidPackingShape)obj;
     152      if (other != null) return CompareTo(other);
     153      else throw new ArgumentException(string.Format("Cannot compare with object {0}", obj), "obj");
    153154    }
    154155
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Shapes/PackingShape.cs

    r13461 r13497  
    3030  [Item("PackingShape", "Represents an abstract shape to describe the measures and the positioning of objects related to bin-packing problems.")]
    3131  [StorableClass]
    32   public abstract class PackingShape<D> : Item, IPackingShape
    33     where D : class, IPackingDimensions {
     32  public abstract class PackingShape<T> : Item, IPackingShape
     33    where T : class, IPackingDimensions {
    3434    public static Type PositionType {
    35       get { return typeof(D); }
     35      get { return typeof(T); }
    3636    }
    3737
    38     public abstract bool EnclosesPoint(D myPosition, D checkedPoint);
    39     public abstract bool Encloses(D checkedPosition, PackingShape<D> checkedShape);
    40     public abstract bool Overlaps(D myPosition, D checkedPosition, PackingShape<D> checkedShape);
     38    public abstract bool EnclosesPoint(T myPosition, T checkedPoint);
     39    public abstract bool Encloses(T checkedPosition, PackingShape<T> checkedShape);
     40    public abstract bool Overlaps(T myPosition, T checkedPosition, PackingShape<T> checkedShape);
    4141    public abstract void InitializeFromMeasures(int[] measures);
    4242    public abstract int[] ToArray();
    4343    public abstract int MultipliedMeasures { get; }
    44     public abstract D Origin { get; }
     44    public abstract T Origin { get; }
    4545
    4646    protected PackingShape(int[] measures) {
     
    5353    [StorableConstructor]
    5454    protected PackingShape(bool deserializing) : base(deserializing) { }
    55     protected PackingShape(PackingShape<D> original, Cloner cloner)
     55    protected PackingShape(PackingShape<T> original, Cloner cloner)
    5656      : base(original, cloner) {
    5757    }
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Shapes/RectangularPackingShape.cs

    r13032 r13497  
    3333  public abstract class RectangularPackingShape : PackingShape<TwoDimensionalPacking>, IRegularPackingShape, IComparable<RectangularPackingShape> {
    3434    #region Properties
    35     /// <summary>
    36     /// Describes the size on the Y-axis
    37     /// </summary>
    3835    [Storable]
    3936    public int Height { get; set; }
    40     /// <summary>
    41     /// Describes the size on the X-axis
    42     /// </summary> 
     37
    4338    [Storable]
    4439    public int Width { get; set; }
     
    6055    private bool Encloses(TwoDimensionalPacking checkedPosition, RectangularPackingShape checkedShape) {
    6156      return Encloses(new RectangleDiagonal(this), new RectangleDiagonal(checkedPosition, checkedShape));
    62     }       
     57    }
    6358    private bool Encloses(RectangleDiagonal r1, RectangleDiagonal r2) {
    64       return  ( r1.x1 <= r2.x1 &&
     59      return (r1.x1 <= r2.x1 &&
    6560                r1.x2 >= r2.x2 &&
    6661                r1.y1 <= r2.y1 &&
     
    7166      return Overlaps(myPosition, checkedPosition, (RectangularPackingShape)checkedShape);
    7267    }
    73     private bool Overlaps(TwoDimensionalPacking myPosition, TwoDimensionalPacking checkedPosition, RectangularPackingShape checkedShape) {   
    74       return Overlaps(new RectangleDiagonal (myPosition, this),new RectangleDiagonal (checkedPosition, checkedShape));
     68    private bool Overlaps(TwoDimensionalPacking myPosition, TwoDimensionalPacking checkedPosition, RectangularPackingShape checkedShape) {
     69      return Overlaps(new RectangleDiagonal(myPosition, this), new RectangleDiagonal(checkedPosition, checkedShape));
    7570    }
    7671    private bool Overlaps(RectangleDiagonal r1, RectangleDiagonal r2) {
     
    9085    #endregion
    9186
    92     public RectangularPackingShape(int width, int height) : base () {
     87    protected RectangularPackingShape() : base() { }
     88    protected RectangularPackingShape(int width, int height)
     89      : base() {
    9390      this.Height = height;
    9491      this.Width = width;
     
    10198      this.Height = measures[1];
    10299    }
    103     public override int[] ToArray() {
    104       return new int[] { Width, Height };
    105     }
     100
    106101
    107102    [StorableConstructor]
     
    112107      this.Height = original.Height;
    113108    }
    114     public RectangularPackingShape() : base() {}
    115109
    116110    public override string ToString() {
     
    124118      if (result == 0) {
    125119        result = this.Width.CompareTo(other.Width);
    126         if (result == 0) 
     120        if (result == 0)
    127121          result = this.Height.CompareTo(other.Height);
    128122      }
     
    131125
    132126    public int CompareTo(object obj) {
    133       if (obj.GetType().Equals(this.GetType()))
    134         return this.CompareTo((RectangularPackingShape)obj);
    135       else return 0;
     127      var other = obj as RectangularPackingShape;
     128      if (other != null) return CompareTo(other);
     129      else throw new ArgumentException(string.Format("Cannot compare to object {0}", obj), "obj");
    136130    }
    137131
    138132    #endregion
     133
     134    public override int[] ToArray() {
     135      return new int[] { Width, Height };
     136    }
    139137
    140138    private struct RectangleDiagonal {
Note: See TracChangeset for help on using the changeset viewer.