Free cookie consent management tool by TermsFeed Policy Generator

Changeset 14154


Ignore:
Timestamp:
07/21/16 15:08:21 (8 years ago)
Author:
gkronber
Message:

#1966: refactoring

Location:
branches/HeuristicLab.BinPacking
Files:
2 added
22 edited

Legend:

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

    r14151 r14154  
    3232  public class BinPacking2D : BinPacking.BinPacking<PackingPosition, PackingShape, PackingItem> {
    3333
    34     public BinPacking2D(PackingShape binMeasures)
    35       : base(binMeasures) {
     34    public BinPacking2D(PackingShape binShape)
     35      : base(binShape) {
    3636      ExtremePoints = new SortedSet<PackingPosition>(new EPComparer2D());
    37       ExtremePoints.Add(binMeasures.Origin);
    38     }
     37      ExtremePoints.Add(binShape.Origin);
     38      InitializeOccupationLayers();
     39    }
     40
    3941    [StorableConstructor]
    4042    protected BinPacking2D(bool deserializing) : base(deserializing) { }
    4143    protected BinPacking2D(BinPacking2D original, Cloner cloner)
    4244      : base(original, cloner) {
    43       this.ExtremePoints = new SortedSet<PackingPosition>(original.ExtremePoints, new EPComparer2D());
     45      this.ExtremePoints = new SortedSet<PackingPosition>(original.ExtremePoints.Select(p => cloner.Clone(p)), new EPComparer2D());
    4446    }
    4547    public override IDeepCloneable Clone(Cloner cloner) {
     
    5456      //Find ExtremePoints beginning from sourcepointX
    5557      var sourcePointX = new PackingPosition(0, position.X + newWidth, position.Y);
    56       if (sourcePointX.X < BinMeasures.Width && sourcePointX.Y < BinMeasures.Height) {
     58      if (sourcePointX.X < BinShape.Width && sourcePointX.Y < BinShape.Height) {
    5759        //Traversing down the y-axis       
    5860        var newPoint = new PackingPosition(0, sourcePointX.X, sourcePointX.Y - 1);
     
    6668      //Find ExtremePoints beginning from sourcepointY
    6769      var sourcePointY = new PackingPosition(0, position.X, position.Y + newHeight);
    68       if (sourcePointY.X < BinMeasures.Width && sourcePointY.Y < BinMeasures.Height) {
     70      if (sourcePointY.X < BinShape.Width && sourcePointY.Y < BinShape.Height) {
    6971        //Traversing down the x-axis 
    7072        var newPoint = new PackingPosition(0, sourcePointY.X - 1, sourcePointY.Y);
     
    9698    public override PackingPosition FindPositionBySliding(PackingItem item, bool rotated) {
    9799      PackingPosition currentPosition = new PackingPosition(0,
    98         BinMeasures.Width - (rotated ? item.Height : item.Width),
    99         BinMeasures.Height - (rotated ? item.Width : item.Height), rotated);
     100        BinShape.Width - (rotated ? item.Height : item.Width),
     101        BinShape.Height - (rotated ? item.Width : item.Height), rotated);
    100102      //Slide the item as far as possible to the left
    101103      while (IsPositionFeasible(item, PackingPosition.MoveLeft(currentPosition))
     
    159161    public override int ShortestPossibleSideFromPoint(PackingPosition position) {
    160162      int shortestSide = int.MaxValue;
    161       int width = BinMeasures.Width;
    162       int height = BinMeasures.Height;
     163      int width = BinShape.Width;
     164      int height = BinShape.Height;
    163165
    164166      if (position.X >= width || position.Y >= height)
     
    182184    }
    183185
    184 
    185186    protected override void InitializeOccupationLayers() {
    186       for (int i = 0; i * 10 <= BinMeasures.Width; i += 1) {
     187      for (int i = 0; i * 10 <= BinShape.Width; i += 1) {
    187188        OccupationLayers[i] = new List<int>();
    188189      }
    189190    }
    190     protected override void AddNewItemToOccupationLayers(int itemID, PackingItem measures, PackingPosition position) {
     191
     192    protected override void AddNewItemToOccupationLayers(int itemID, PackingItem item, PackingPosition position) {
    191193      int x1 = position.X / 10;
    192       int x2 = (position.X + (position.Rotated ? measures.Height : measures.Width)) / 10;
     194      int x2 = (position.X + (position.Rotated ? item.Height : item.Width)) / 10;
    193195
    194196      for (int i = x1; i <= x2; i++)
     
    198200      return OccupationLayers[position.X / 10];
    199201    }
    200     protected override List<int> GetLayerItemIDs(PackingItem measures, PackingPosition position) {
     202    protected override List<int> GetLayerItemIDs(PackingItem item, PackingPosition position) {
    201203      List<int> result = new List<int>();
    202204      int x1 = position.X / 10;
    203       int x2 = (position.X + (position.Rotated ? measures.Height : measures.Width)) / 10;
     205      int x2 = (position.X + (position.Rotated ? item.Height : item.Width)) / 10;
    204206
    205207      for (int i = x1; i <= x2; i++)
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.2D/3.3/Evaluators/BinUtilizationEvaluator.cs

    r14148 r14154  
    5353
    5454      for (int i = 0; i < nrOfBins; i++) {
    55         totalUsableSpace += solution.BinPackings[i].BinMeasures.Volume;
    56         totalUsedSpace += solution.BinPackings[i].ItemMeasures.Sum(kvp => kvp.Value.Volume);
     55        totalUsableSpace += solution.BinPackings[i].BinShape.Volume;
     56        totalUsedSpace += solution.BinPackings[i].Items.Sum(kvp => kvp.Value.Volume);
    5757      }
    5858
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.2D/3.3/Evaluators/PackingRatioEvaluator.cs

    r14151 r14154  
    6060      const double k = 2;
    6161      for (int i = 0; i < nrOfBins; i++) {
    62         double f = solution.BinPackings[i].ItemMeasures.Sum(kvp => kvp.Value.Volume);
    63         double c = solution.BinPackings[i].BinMeasures.Volume;
     62        double f = solution.BinPackings[i].Items.Sum(kvp => kvp.Value.Volume);
     63        double c = solution.BinPackings[i].BinShape.Volume;
    6464        result += Math.Pow(f / c, k);
    6565      }
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.2D/3.3/HeuristicLab.Problems.BinPacking2D-3.3.csproj

    r14151 r14154  
    172172    <Compile Include="IntegerVectorEncoding\ExtremePointIntegerVectorDecoder.cs" />
    173173    <Compile Include="IntegerVectorEncoding\IntegerVectorProblem.cs" />
     174    <Compile Include="Interfaces\IOperator.cs" />
    174175    <Compile Include="Interfaces\IDecoder.cs" />
    175176    <Compile Include="Interfaces\IEvaluator.cs" />
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.2D/3.3/MoveEvaluatorBase.cs

    r14153 r14154  
    3131  [StorableClass]
    3232  public abstract class MoveEvaluatorBase<TSol, TMove> : SingleSuccessorOperator,
    33     ISingleObjectiveMoveEvaluator, ISingleObjectiveMoveOperator
     33    ISingleObjectiveMoveEvaluator, ISingleObjectiveMoveOperator, IOperator<TSol>
    3434    where TSol : class, IItem
    3535    where TMove : class, IItem {
     
    4343      get { return (ILookupParameter<DoubleValue>)Parameters["MoveQuality"]; }
    4444    }
    45     public ILookupParameter<ReadOnlyItemList<PackingItem>> PackingItemMeasuresParameter {
     45    public ILookupParameter<ReadOnlyItemList<PackingItem>> ItemsParameter {
    4646      get { return (LookupParameter<ReadOnlyItemList<PackingItem>>)Parameters["Items"]; }
    4747    }
    48     public ILookupParameter<PackingShape> PackingBinMeasuresParameter {
     48    public ILookupParameter<PackingShape> BinShapeParameter {
    4949      get { return (LookupParameter<PackingShape>)Parameters["BinShape"]; }
    5050    }
    51     public ILookupParameter<IDecoder<TSol>> PackingSolutionDecoderParameter {
     51    public ILookupParameter<IDecoder<TSol>> DecoderParameter {
    5252      get { return (ILookupParameter<IDecoder<TSol>>)Parameters["Decoder"]; }
    5353    }
    54     public ILookupParameter<IEvaluator> PackingPlanEvaluatorParameter {
     54    public ILookupParameter<IEvaluator> SolutionEvaluatorParameter {
    5555      get { return (ILookupParameter<IEvaluator>)Parameters["SolutionEvaluator"]; }
    5656    }
     
    7878      var move = MoveParameter.ActualValue;
    7979      var encSolCandidate = EncodedSolutionParameter.ActualValue;
    80       var binShape = PackingBinMeasuresParameter.ActualValue;
    81       var items = PackingItemMeasuresParameter.ActualValue;
     80      var binShape = BinShapeParameter.ActualValue;
     81      var items = ItemsParameter.ActualValue;
    8282
    8383
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.2D/3.3/PermutationEncoding/PermutationProblem.cs

    r14153 r14154  
    2323
    2424using System.Linq;
     25using System.Windows.Forms;
    2526using HeuristicLab.Common;
    2627using HeuristicLab.Core;
     
    7273      Encoding.ConfigureOperators(Operators.OfType<IOperator>());
    7374
    74       // TODO: configure the move evaluators (add interface for my move evaluators)
     75      foreach (var op in Operators.OfType<IOperator<Permutation>>()) {
     76        op.BinShapeParameter.ActualName = BinShapeParameter.Name;
     77        op.ItemsParameter.ActualName = ItemsParameter.Name;
     78        op.SolutionEvaluatorParameter.ActualName = SolutionEvaluatorParameter.Name;
     79        op.DecoderParameter.ActualName = DecoderParameter.Name;
     80      }
    7581    }
    7682
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.2D/3.3/PermutationEncoding/Swap2MoveEvaluator.cs

    r14149 r14154  
    5050      // uses full evaluation
    5151      Swap2Manipulator.Apply(permutation, move.Index1, move.Index2);
    52       var solution = PackingSolutionDecoderParameter.ActualValue.Decode(permutation, binShape, items);
     52      var solution = DecoderParameter.ActualValue.Decode(permutation, binShape, items);
    5353
    54       return PackingPlanEvaluatorParameter.ActualValue.Evaluate(solution);
     54      return SolutionEvaluatorParameter.ActualValue.Evaluate(solution);
    5555    }
    5656  }
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.2D/3.3/PermutationEncoding/TranslocationMoveEvaluator.cs

    r14149 r14154  
    5151      // uses full evaluation
    5252      TranslocationManipulator.Apply(permutation, move.Index1, move.Index2, move.Index3);
    53       var solution = PackingSolutionDecoderParameter.ActualValue.Decode(permutation, binShape, items);
     53      var solution = DecoderParameter.ActualValue.Decode(permutation, binShape, items);
    5454
    55       return PackingPlanEvaluatorParameter.ActualValue.Evaluate(solution);
     55      return SolutionEvaluatorParameter.ActualValue.Evaluate(solution);
    5656    }
    5757  }
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.3D/3.3/BinPacking3D.cs

    r14153 r14154  
    3232  public class BinPacking3D : BinPacking<PackingPosition, PackingShape, PackingItem> {
    3333
    34     public BinPacking3D(PackingShape binMeasures)
    35       : base(binMeasures) {
     34    public BinPacking3D(PackingShape binShape)
     35      : base(binShape) {
    3636      ExtremePoints = new SortedSet<PackingPosition>(new EPComparer3D());
    37       ExtremePoints.Add(binMeasures.Origin);
     37      ExtremePoints.Add(binShape.Origin);
     38      InitializeOccupationLayers();
    3839    }
    3940    [StorableConstructor]
     
    4142    protected BinPacking3D(BinPacking3D original, Cloner cloner)
    4243      : base(original, cloner) {
    43       this.ExtremePoints = new SortedSet<PackingPosition>(original.ExtremePoints, new EPComparer3D());
     44      this.ExtremePoints = new SortedSet<PackingPosition>(original.ExtremePoints.Select(p => cloner.Clone(p)), new EPComparer3D());
    4445    }
    4546    public override IDeepCloneable Clone(Cloner cloner) {
     
    5354      //Find ExtremePoints beginning from sourcepointX
    5455      var sourcePointX = new PackingPosition(0, position.X + newWidth, position.Y, position.Z);
    55       if (sourcePointX.X < BinMeasures.Width && sourcePointX.Y < BinMeasures.Height && sourcePointX.Z < BinMeasures.Depth) {
     56      if (sourcePointX.X < BinShape.Width && sourcePointX.Y < BinShape.Height && sourcePointX.Z < BinShape.Depth) {
    5657        //Traversing down the y-axis 
    5758        PackingPosition current = new PackingPosition(0, sourcePointX.X, sourcePointX.Y, sourcePointX.Z);
     
    7980      //Find ExtremePoints beginning from sourcepointY
    8081      var sourcePointY = new PackingPosition(0, position.X, position.Y + newItem.Height, position.Z);
    81       if (sourcePointY.X < BinMeasures.Width && sourcePointY.Y < BinMeasures.Height && sourcePointY.Z < BinMeasures.Depth) {
     82      if (sourcePointY.X < BinShape.Width && sourcePointY.Y < BinShape.Height && sourcePointY.Z < BinShape.Depth) {
    8283        //Traversing down the x-axis         
    8384        PackingPosition current = new PackingPosition(0, sourcePointY.X, sourcePointY.Y, sourcePointY.Z);
     
    105106      //Find ExtremePoints beginning from sourcepointZ
    106107      var sourcePointZ = new PackingPosition(0, position.X, position.Y, position.Z + newDepth);
    107       if (sourcePointZ.X < BinMeasures.Width && sourcePointZ.Y < BinMeasures.Height && sourcePointZ.Z < BinMeasures.Depth) {
     108      if (sourcePointZ.X < BinShape.Width && sourcePointZ.Y < BinShape.Height && sourcePointZ.Z < BinShape.Depth) {
    108109        //Traversing down the x-axis
    109110        PackingPosition current = new PackingPosition(0, sourcePointZ.X, sourcePointZ.Y, sourcePointZ.Z);
     
    130131    }
    131132
    132     public override PackingPosition FindExtremePointForItem(PackingItem measures, bool rotated, bool stackingConstraints) {
    133 
    134       PackingItem item = new PackingItem(
    135         rotated ? measures.Depth : measures.Width,
    136         measures.Height,
    137         rotated ? measures.Width : measures.Depth,
    138         measures.TargetBin);
     133    public override PackingPosition FindExtremePointForItem(PackingItem item, bool rotated, bool stackingConstraints) {
     134
     135      PackingItem newItem = new PackingItem(
     136        rotated ? item.Depth : item.Width,
     137        item.Height,
     138        rotated ? item.Width : item.Depth,
     139        item.TargetBin);
    139140
    140141      int epIndex = 0;
    141142      while (epIndex < ExtremePoints.Count && (
    142         !IsPositionFeasible(item, ExtremePoints.ElementAt(epIndex))
    143         || !IsSupportedByAtLeastOnePoint(item, ExtremePoints.ElementAt(epIndex))
    144         || (stackingConstraints && !IsStaticStable(item, ExtremePoints.ElementAt(epIndex)))
    145         || (stackingConstraints && !IsWeightSupported(item, ExtremePoints.ElementAt(epIndex)))
     143        !IsPositionFeasible(newItem, ExtremePoints.ElementAt(epIndex))
     144        || !IsSupportedByAtLeastOnePoint(newItem, ExtremePoints.ElementAt(epIndex))
     145        || (stackingConstraints && !IsStaticStable(newItem, ExtremePoints.ElementAt(epIndex)))
     146        || (stackingConstraints && !IsWeightSupported(newItem, ExtremePoints.ElementAt(epIndex)))
    146147      )) { epIndex++; }
    147148
     
    154155    }
    155156
    156     public override PackingPosition FindPositionBySliding(PackingItem measures, bool rotated) {
     157    public override PackingPosition FindPositionBySliding(PackingItem item, bool rotated) {
    157158      //TODO: does not support stacking constraints yet
    158159      //Starting-position at upper right corner (=left bottom point of item-rectangle is at position item.width,item.height)
    159160      PackingPosition currentPosition = new PackingPosition(0,
    160         BinMeasures.Width - (rotated ? measures.Depth : measures.Width),
    161         BinMeasures.Height - measures.Height,
    162         BinMeasures.Depth - (rotated ? measures.Width : measures.Depth), rotated);
     161        BinShape.Width - (rotated ? item.Depth : item.Width),
     162        BinShape.Height - item.Height,
     163        BinShape.Depth - (rotated ? item.Width : item.Depth), rotated);
    163164      //Slide the item as far as possible to the bottom
    164       while (IsPositionFeasible(measures, PackingPosition.MoveDown(currentPosition))
    165         || IsPositionFeasible(measures, PackingPosition.MoveLeft(currentPosition))
    166         || IsPositionFeasible(measures, PackingPosition.MoveBack(currentPosition))) {
     165      while (IsPositionFeasible(item, PackingPosition.MoveDown(currentPosition))
     166        || IsPositionFeasible(item, PackingPosition.MoveLeft(currentPosition))
     167        || IsPositionFeasible(item, PackingPosition.MoveBack(currentPosition))) {
    167168        //Slide the item as far as possible to the left
    168         while (IsPositionFeasible(measures, PackingPosition.MoveLeft(currentPosition))
    169       || IsPositionFeasible(measures, PackingPosition.MoveBack(currentPosition))) {
     169        while (IsPositionFeasible(item, PackingPosition.MoveLeft(currentPosition))
     170      || IsPositionFeasible(item, PackingPosition.MoveBack(currentPosition))) {
    170171          //Slide the item as far as possible to the back
    171           while (IsPositionFeasible(measures, PackingPosition.MoveBack(currentPosition))) {
     172          while (IsPositionFeasible(item, PackingPosition.MoveBack(currentPosition))) {
    172173            currentPosition = PackingPosition.MoveBack(currentPosition);
    173174          }
    174           if (IsPositionFeasible(measures, PackingPosition.MoveLeft(currentPosition)))
     175          if (IsPositionFeasible(item, PackingPosition.MoveLeft(currentPosition)))
    175176            currentPosition = PackingPosition.MoveLeft(currentPosition);
    176177        }
    177         if (IsPositionFeasible(measures, PackingPosition.MoveDown(currentPosition)))
     178        if (IsPositionFeasible(item, PackingPosition.MoveDown(currentPosition)))
    178179          currentPosition = PackingPosition.MoveDown(currentPosition);
    179180      }
    180181
    181       return IsPositionFeasible(measures, currentPosition) ? currentPosition : null;
    182     }
    183 
    184     public override void SlidingBasedPacking(ref IList<int> sequence, IList<PackingItem> itemMeasures) {
     182      return IsPositionFeasible(item, currentPosition) ? currentPosition : null;
     183    }
     184
     185    public override void SlidingBasedPacking(ref IList<int> sequence, IList<PackingItem> items) {
    185186      var temp = new List<int>(sequence);
    186187      for (int i = 0; i < temp.Count; i++) {
    187         var item = itemMeasures[temp[i]];
     188        var item = items[temp[i]];
    188189        var position = FindPositionBySliding(item, false);
    189190        if (position != null) {
     
    193194      }
    194195    }
    195     public override void SlidingBasedPacking(ref IList<int> sequence, IList<PackingItem> itemMeasures, Dictionary<int, bool> rotationArray) {
     196    public override void SlidingBasedPacking(ref IList<int> sequence, IList<PackingItem> items, Dictionary<int, bool> rotationArray) {
    196197      var temp = new List<int>(sequence);
    197198      for (int i = 0; i < temp.Count; i++) {
    198         var item = itemMeasures[temp[i]];
     199        var item = items[temp[i]];
    199200        var position = FindPositionBySliding(item, rotationArray[i]);
    200201        if (position != null) {
     
    204205      }
    205206    }
    206     public override void ExtremePointBasedPacking(ref IList<int> sequence, IList<PackingItem> itemMeasures, bool stackingConstraints) {
     207    public override void ExtremePointBasedPacking(ref IList<int> sequence, IList<PackingItem> items, bool stackingConstraints) {
    207208      var temp = new List<int>(sequence);
    208209      foreach (int itemID in temp) {
    209         var item = itemMeasures[itemID];
     210        var item = items[itemID];
    210211        var positionFound = FindExtremePointForItem(item, false, stackingConstraints);
    211212        if (positionFound != null) {
     
    215216      }
    216217    }
    217     public override void ExtremePointBasedPacking(ref IList<int> sequence, IList<PackingItem> itemMeasures, bool stackingConstraints, Dictionary<int, bool> rotationArray) {
     218    public override void ExtremePointBasedPacking(ref IList<int> sequence, IList<PackingItem> items, bool stackingConstraints, Dictionary<int, bool> rotationArray) {
    218219      var temp = new List<int>(sequence);
    219220      foreach (int itemID in temp) {
    220         var item = itemMeasures[itemID];
     221        var item = items[itemID];
    221222        var positionFound = FindExtremePointForItem(item, rotationArray[itemID], stackingConstraints);
    222223        if (positionFound != null) {
     
    230231
    231232      int shortestSide = int.MaxValue;
    232       int width = BinMeasures.Width;
    233       int height = BinMeasures.Height;
    234       int depth = BinMeasures.Depth;
     233      int width = BinShape.Width;
     234      int height = BinShape.Height;
     235      int depth = BinShape.Depth;
    235236
    236237      if (position.X >= width || position.Y >= height || position.Z >= depth)
     
    287288        return true;
    288289
    289       if (ItemMeasures[PointOccupation(new PackingPosition(0, ep.X, ep.Y - 1, ep.Z))].SupportsStacking(item)
    290         && ItemMeasures[PointOccupation(new PackingPosition(0, ep.X + item.Width - 1, ep.Y - 1, ep.Z))].SupportsStacking(item)
    291         && ItemMeasures[PointOccupation(new PackingPosition(0, ep.X, ep.Y - 1, ep.Z + item.Depth - 1))].SupportsStacking(item)
    292         && ItemMeasures[PointOccupation(new PackingPosition(0, ep.X + item.Width - 1, ep.Y - 1, ep.Z + item.Depth - 1))].SupportsStacking(item))
     290      if (Items[PointOccupation(new PackingPosition(0, ep.X, ep.Y - 1, ep.Z))].SupportsStacking(item)
     291        && Items[PointOccupation(new PackingPosition(0, ep.X + item.Width - 1, ep.Y - 1, ep.Z))].SupportsStacking(item)
     292        && Items[PointOccupation(new PackingPosition(0, ep.X, ep.Y - 1, ep.Z + item.Depth - 1))].SupportsStacking(item)
     293        && Items[PointOccupation(new PackingPosition(0, ep.X + item.Width - 1, ep.Y - 1, ep.Z + item.Depth - 1))].SupportsStacking(item))
    293294        return true;
    294295
     
    298299
    299300    protected override void InitializeOccupationLayers() {
    300       for (int i = 0; i * 10 <= BinMeasures.Depth; i += 1) {
     301      for (int i = 0; i * 10 <= BinShape.Depth; i += 1) {
    301302        OccupationLayers[i] = new List<int>();
    302303      }
    303304    }
    304     protected override void AddNewItemToOccupationLayers(int itemID, PackingItem measures, PackingPosition position) {
     305    protected override void AddNewItemToOccupationLayers(int itemID, PackingItem item, PackingPosition position) {
    305306      int z1 = position.Z / 10;
    306       int z2 = (position.Z + (position.Rotated ? measures.Width : measures.Depth)) / 10;
     307      int z2 = (position.Z + (position.Rotated ? item.Width : item.Depth)) / 10;
    307308
    308309      for (int i = z1; i <= z2; i++)
     
    312313      return OccupationLayers[position.Z / 10];
    313314    }
    314     protected override List<int> GetLayerItemIDs(PackingItem measures, PackingPosition position) {
     315    protected override List<int> GetLayerItemIDs(PackingItem item, PackingPosition position) {
    315316      List<int> result = new List<int>();
    316317      int z1 = position.Z / 10;
    317       int z2 = (position.Z + (position.Rotated ? measures.Width : measures.Depth)) / 10;
     318      int z2 = (position.Z + (position.Rotated ? item.Width : item.Depth)) / 10;
    318319
    319320      for (int i = z1; i <= z2; i++)
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.3D/3.3/Evaluators/BinUtilizationEvaluator.cs

    r14153 r14154  
    5454
    5555      for (int i = 0; i < nrOfBins; i++) {
    56         totalUsableSpace += solution.BinPackings[i].BinMeasures.Volume;
    57         totalUsedSpace += solution.BinPackings[i].ItemMeasures.Sum(kvp => kvp.Value.Volume);
     56        totalUsableSpace += solution.BinPackings[i].BinShape.Volume;
     57        totalUsedSpace += solution.BinPackings[i].Items.Sum(kvp => kvp.Value.Volume);
    5858      }
    5959
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.3D/3.3/Evaluators/PackingRatioEvaluator.cs

    r14153 r14154  
    6161      const double k = 2;
    6262      for (int i = 0; i < nrOfBins; i++) {
    63         double f = solution.BinPackings[i].ItemMeasures.Sum(kvp => kvp.Value.Volume);
    64         double c = solution.BinPackings[i].BinMeasures.Volume;
     63        double f = solution.BinPackings[i].Items.Sum(kvp => kvp.Value.Volume);
     64        double c = solution.BinPackings[i].BinShape.Volume;
    6565        result += Math.Pow(f / c, k);
    6666      }
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.3D/3.3/HeuristicLab.Problems.BinPacking3D-3.3.csproj

    r14153 r14154  
    174174    <Compile Include="Interfaces\IDecoder.cs" />
    175175    <Compile Include="Interfaces\IEvaluator.cs" />
     176    <Compile Include="Interfaces\IOperator.cs" />
    176177    <Compile Include="MoveEvaluatorBase.cs" />
    177178    <Compile Include="PackingItem.cs" />
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.3D/3.3/MoveEvaluatorBase.cs

    r14153 r14154  
    3131  [StorableClass]
    3232  public abstract class MoveEvaluatorBase<TSol, TMove> : SingleSuccessorOperator,
    33     ISingleObjectiveMoveEvaluator, ISingleObjectiveMoveOperator
     33    ISingleObjectiveMoveEvaluator, ISingleObjectiveMoveOperator, IOperator<TSol>
    3434    where TSol : class, IItem
    3535    where TMove : class, IItem {
     
    4343      get { return (ILookupParameter<DoubleValue>)Parameters["MoveQuality"]; }
    4444    }
    45     public ILookupParameter<ReadOnlyItemList<PackingItem>> PackingItemMeasuresParameter {
     45    public ILookupParameter<ReadOnlyItemList<PackingItem>> ItemsParameter {
    4646      get { return (LookupParameter<ReadOnlyItemList<PackingItem>>)Parameters["Items"]; }
    4747    }
    48     public ILookupParameter<PackingShape> PackingBinMeasuresParameter {
     48    public ILookupParameter<PackingShape> BinShapeParameter {
    4949      get { return (LookupParameter<PackingShape>)Parameters["BinShape"]; }
    5050    }
    51     public ILookupParameter<IDecoder<TSol>> PackingSolutionDecoderParameter {
     51    public ILookupParameter<IDecoder<TSol>> DecoderParameter {
    5252      get { return (ILookupParameter<IDecoder<TSol>>)Parameters["Decoder"]; }
    5353    }
    54     public ILookupParameter<IEvaluator> PackingPlanEvaluatorParameter {
     54    public ILookupParameter<IEvaluator> SolutionEvaluatorParameter {
    5555      get { return (ILookupParameter<IEvaluator>)Parameters["SolutionEvaluator"]; }
    5656    }
     
    8282      var move = MoveParameter.ActualValue;
    8383      var encSolCandidate = EncodedSolutionParameter.ActualValue;
    84       var binShape = PackingBinMeasuresParameter.ActualValue;
    85       var items = PackingItemMeasuresParameter.ActualValue;
     84      var binShape = BinShapeParameter.ActualValue;
     85      var items = ItemsParameter.ActualValue;
    8686
    8787
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.3D/3.3/PermutationEncoding/PermutationProblem.cs

    r14153 r14154  
    7070      Operators.RemoveAll(x => x is SingleObjectiveMoveEvaluator);
    7171
    72       Encoding.ConfigureOperators(Operators.OfType<IOperator>()); 
     72      Encoding.ConfigureOperators(Operators.OfType<IOperator>());
    7373
    74       // TODO: configure my move evaluators (introduce interface)
     74      foreach (var op in Operators.OfType<IOperator<Permutation>>()) {
     75        op.BinShapeParameter.ActualName = BinShapeParameter.Name;
     76        op.ItemsParameter.ActualName = ItemsParameter.Name;
     77        op.SolutionEvaluatorParameter.ActualName = SolutionEvaluatorParameter.Name;
     78        op.DecoderParameter.ActualName = DecoderParameter.Name;
     79        op.UseStackingConstraintsParameter.ActualName = UseStackingConstraintsParameter.Name;
     80      }
    7581    }
    7682
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.3D/3.3/PermutationEncoding/Swap2MoveEvaluator.cs

    r14153 r14154  
    5050      // uses full evaluation
    5151      Swap2Manipulator.Apply(permutation, move.Index1, move.Index2);
    52       var solution = PackingSolutionDecoderParameter.ActualValue.Decode(permutation, binShape, items, useStackingConstraints);
     52      var solution = DecoderParameter.ActualValue.Decode(permutation, binShape, items, useStackingConstraints);
    5353
    54       return PackingPlanEvaluatorParameter.ActualValue.Evaluate(solution);
     54      return SolutionEvaluatorParameter.ActualValue.Evaluate(solution);
    5555    }
    5656  }
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.3D/3.3/PermutationEncoding/TranslocationMoveEvaluator.cs

    r14153 r14154  
    5151      // uses full evaluation
    5252      TranslocationManipulator.Apply(permutation, move.Index1, move.Index2, move.Index3);
    53       var solution = PackingSolutionDecoderParameter.ActualValue.Decode(permutation, binShape, items, useStackingConstraints);
     53      var solution = DecoderParameter.ActualValue.Decode(permutation, binShape, items, useStackingConstraints);
    5454
    55       return PackingPlanEvaluatorParameter.ActualValue.Evaluate(solution);
     55      return SolutionEvaluatorParameter.ActualValue.Evaluate(solution);
    5656    }
    5757  }
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.Views/3.3/Container2DView.xaml.cs

    r14151 r14154  
    7171      if (packing == null) return;
    7272      // the container should fill the whole size
    73       var scalingX = renderSize.Width / Packing.BinMeasures.Width;
    74       var scalingY = renderSize.Height / Packing.BinMeasures.Width;
     73      var scalingX = renderSize.Width / Packing.BinShape.Width;
     74      var scalingY = renderSize.Height / Packing.BinShape.Width;
    7575      // draw container
    7676      drawingContext.DrawRectangle(Brushes.LightGray, new Pen(Brushes.Black, 1), new Rect(new Point(0, 0), renderSize));
     
    7979      var unselectedBrush = selectedItemKey < 0 ? selectedBrush : Brushes.DarkGray;
    8080
    81       foreach (var t in Packing.ItemMeasures) {
     81      foreach (var t in Packing.Items) {
    8282        var key = t.Key;
    8383        var item = t.Value;
    84         var pos = Packing.ItemPositions[key];
     84        var pos = Packing.Positions[key];
    8585
    8686        var scaledPos = new Point(pos.X * scalingX, pos.Y * scalingY);
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.Views/3.3/Container3DView.xaml

    r14153 r14154  
    128128                        </RotateTransform3D>
    129129                        <TranslateTransform3D OffsetX="0.5" OffsetY="0.5" OffsetZ="0.5" />
    130                         <ScaleTransform3D x:Name="scaleZoom" CenterX="0.5" CenterY="0.5" CenterZ="0.5" ScaleX="0.6" ScaleY="0.6" ScaleZ="0.6"/>
     130                        <ScaleTransform3D x:Name="scaleZoom" CenterX="0.5" CenterY="0.5" CenterZ="0.5" ScaleX="1" ScaleY="1" ScaleZ="1"/>
    131131                    </Transform3DGroup>
    132132                </ModelVisual3D.Transform>
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.Views/3.3/Container3DView.xaml.cs

    r14151 r14154  
    4747    public Container3DView() {
    4848      InitializeComponent();
    49       camMain.Position = new Point3D(0.5, 2, 2); // for design time we use a different camera position
     49      camMain.Position = new Point3D(0.5, 3, 3); // for design time we use a different camera position
    5050      Clear();
    5151    }
     
    8080      //  - from rotation and Z-ordering
    8181
    82       foreach (var item in packing.ItemMeasures.OrderBy(i => packing.ItemPositions[i.Key].Z)) {
    83         var position = packing.ItemPositions[item.Key];
     82      foreach (var item in packing.Items.OrderBy(i => packing.Positions[i.Key].Z)) {
     83        var position = packing.Positions[item.Key];
    8484
    8585        var w = position.Rotated ? item.Value.Depth : item.Value.Width;
     
    9898      }
    9999
    100       var container = packing.BinMeasures;
     100      var container = packing.BinShape;
    101101      // draw a transparent container
    102102      AddCube(meshTransparent, container.Origin.X, container.Origin.Y, container.Origin.Z, container.Width, container.Height, container.Depth, addInsideTriangles: true);
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.Views/3.3/PackingPlan3DView.cs

    r14151 r14154  
    6767      int currentBin = (binSelection != null) ? (int)(binSelection.SelectedIndex) : 0;
    6868      var packing = Content.BinPackings[currentBin];
    69       foreach (var item in packing.ItemMeasures) {
     69      foreach (var item in packing.Items) {
    7070        itemSelection.Items.Add(item.Key);
    7171      }
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/PackingPlans/BinPacking.cs

    r14151 r14154  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using System.Linq;
     
    3031  [Item("BinPacking", "Represents a single-bin packing for a bin-packing problem.")]
    3132  [StorableClass]
    32   public abstract class BinPacking<D, B, I> : Item
    33     where D : class, IPackingPosition
    34     where B : PackingShape<D>
    35     where I : PackingShape<D> {
     33  public abstract class BinPacking<TPos, TBin, TItem> : Item
     34    where TPos : class, IPackingPosition
     35    where TBin : PackingShape<TPos>
     36    where TItem : PackingShape<TPos> {
    3637    #region Properties
    3738    [Storable]
    38     public ObservableDictionary<int, D> ItemPositions { get; private set; }
     39    public ObservableDictionary<int, TPos> Positions { get; private set; }
    3940
    4041    [Storable]
    41     public ObservableDictionary<int, I> ItemMeasures { get; private set; } // TODO: rename to items
     42    public ObservableDictionary<int, TItem> Items { get; private set; }
    4243
    4344    [Storable]
    44     public B BinMeasures { get; private set; }
     45    public TBin BinShape { get; private set; }
    4546
    4647    [Storable]
    47     public SortedSet<D> ExtremePoints { get; protected set; }
     48    public SortedSet<TPos> ExtremePoints { get; protected set; }
    4849
    4950    [Storable]
     
    5253    #endregion Properties
    5354
    54     protected BinPacking(B binMeasures)
     55    protected BinPacking(TBin binShape)
    5556      : base() {
    56       ItemPositions = new ObservableDictionary<int, D>();
    57       ItemMeasures = new ObservableDictionary<int, I>();
    58       BinMeasures = (B)binMeasures.Clone();
     57      Positions = new ObservableDictionary<int, TPos>();
     58      Items = new ObservableDictionary<int, TItem>();
     59      BinShape = (TBin)binShape.Clone();
    5960      OccupationLayers = new Dictionary<int, List<int>>();
    60       InitializeOccupationLayers(); // TODO
    6161    }
    6262
     
    6464    [StorableConstructor]
    6565    protected BinPacking(bool deserializing) : base(deserializing) { }
    66     protected BinPacking(BinPacking<D, B, I> original, Cloner cloner)
     66    protected BinPacking(BinPacking<TPos, TBin, TItem> original, Cloner cloner)
    6767      : base(original, cloner) {
    68       this.ItemPositions = new ObservableDictionary<int, D>(original.ItemPositions);
    69       this.ItemMeasures = new ObservableDictionary<int, I>(original.ItemMeasures);
    70       this.BinMeasures = (B)original.BinMeasures.Clone(cloner);
    71       this.OccupationLayers = new Dictionary<int, List<int>>(original.OccupationLayers);
     68      this.Positions = new ObservableDictionary<int, TPos>();
     69      foreach (var kvp in original.Positions) {
     70        Positions.Add(kvp.Key, cloner.Clone(kvp.Value));
     71      }
     72      this.Items = new ObservableDictionary<int, TItem>();
     73      foreach (var kvp in original.Items) {
     74        Items.Add(kvp.Key, cloner.Clone(kvp.Value));
     75      }
     76      this.BinShape = (TBin)original.BinShape.Clone(cloner);
     77      this.OccupationLayers = new Dictionary<int, List<int>>();
     78      foreach (var kvp in original.OccupationLayers) {
     79        OccupationLayers.Add(kvp.Key, new List<int>(kvp.Value));
     80      }
    7281    }
    7382
    74     protected abstract void GenerateNewExtremePointsForNewItem(I measures, D position);
     83    protected abstract void GenerateNewExtremePointsForNewItem(TItem item, TPos position);
    7584
    76     public abstract D FindExtremePointForItem(I measures, bool rotated, bool stackingConstraints);
    77     public abstract D FindPositionBySliding(I measures, bool rotated);
     85    public abstract TPos FindExtremePointForItem(TItem item, bool rotated, bool stackingConstraints);
     86    public abstract TPos FindPositionBySliding(TItem item, bool rotated);
    7887
    79     public abstract void SlidingBasedPacking(ref IList<int> sequence, IList<I> itemMeasures);
    80     public abstract void SlidingBasedPacking(ref IList<int> sequence, IList<I> itemMeasures, Dictionary<int, bool> rotationArray);
    81     public abstract void ExtremePointBasedPacking(ref IList<int> sequence, IList<I> itemMeasures, bool stackingConstraints);
    82     public abstract void ExtremePointBasedPacking(ref IList<int> sequence, IList<I> itemMeasures, bool stackingConstraints, Dictionary<int, bool> rotationArray);
     88    public abstract void SlidingBasedPacking(ref IList<int> sequence, IList<TItem> items);
     89    public abstract void SlidingBasedPacking(ref IList<int> sequence, IList<TItem> items, Dictionary<int, bool> rotationArray);
     90    public abstract void ExtremePointBasedPacking(ref IList<int> sequence, IList<TItem> items, bool stackingConstraints);
     91    public abstract void ExtremePointBasedPacking(ref IList<int> sequence, IList<TItem> items, bool stackingConstraints, Dictionary<int, bool> rotationArray);
    8392
    84     public void PackItem(int itemID, I measures, D position) {
    85       ItemMeasures[itemID] = measures;
    86       ItemPositions[itemID] = position;
     93    public void PackItem(int itemID, TItem item, TPos position) {
     94      Items[itemID] = item;
     95      Positions[itemID] = position;
    8796      ExtremePoints.Remove(position);
    88       foreach (int id in ItemMeasures.Select(x => x.Key))
    89         GenerateNewExtremePointsForNewItem(ItemMeasures[id], ItemPositions[id]);
     97      foreach (int id in Items.Select(x => x.Key))
     98        GenerateNewExtremePointsForNewItem(Items[id], Positions[id]);
    9099
    91       AddNewItemToOccupationLayers(itemID, measures, position);
     100      AddNewItemToOccupationLayers(itemID, item, position);
    92101    }
    93102
     
    95104      get {
    96105        double result = 0;
    97         foreach (var entry in ItemMeasures)
     106        foreach (var entry in Items)
    98107          result += entry.Value.Volume;
    99         result /= BinMeasures.Volume;
     108        result /= BinShape.Volume;
    100109        return result;
    101110      }
     
    103112
    104113
    105     public int PointOccupation(D position) {
     114    public int PointOccupation(TPos position) {
    106115      foreach (var id in GetLayerItemIDs(position)) {
    107         if (ItemMeasures[id].EnclosesPoint(ItemPositions[id], position))
     116        if (Items[id].EnclosesPoint(Positions[id], position))
    108117          return id;
    109118      }
     
    111120    }
    112121
    113     public bool IsPointOccupied(D position) {
     122    public bool IsPointOccupied(TPos position) {
    114123      foreach (var id in GetLayerItemIDs(position)) {
    115         if (ItemMeasures[id].EnclosesPoint(ItemPositions[id], position))
     124        if (Items[id].EnclosesPoint(Positions[id], position))
    116125          return true;
    117126      }
    118127      return false;
    119128    }
    120     public bool IsPositionFeasible(I measures, D position) {
     129    public bool IsPositionFeasible(TItem item, TPos position) {
    121130      //In this case feasability is defined as following: 1. the item fits into the bin-borders; 2. the point is supported by something; 3. the item does not collide with another already packed item
    122       if (!BinMeasures.Encloses(position, measures))
     131      if (!BinShape.Encloses(position, item))
    123132        return false;
    124133
    125       foreach (var id in GetLayerItemIDs(measures, position)) {
    126         if (ItemMeasures[id].Overlaps(ItemPositions[id], position, measures))
     134      foreach (var id in GetLayerItemIDs(item, position)) {
     135        if (Items[id].Overlaps(Positions[id], position, item))
    127136          return false;
    128137      }
     
    130139      return true;
    131140    }
    132     public abstract int ShortestPossibleSideFromPoint(D position);
    133     public abstract bool IsStaticStable(I measures, D position);
     141    public abstract int ShortestPossibleSideFromPoint(TPos position);
     142    public abstract bool IsStaticStable(TItem measures, TPos position);
    134143
    135144
    136145    protected abstract void InitializeOccupationLayers();
    137     protected abstract void AddNewItemToOccupationLayers(int itemID, I measures, D position);
    138     protected abstract List<int> GetLayerItemIDs(D position);
    139     protected abstract List<int> GetLayerItemIDs(I measures, D position);
     146    protected abstract void AddNewItemToOccupationLayers(int itemID, TItem item, TPos position);
     147    protected abstract List<int> GetLayerItemIDs(TPos position);
     148    protected abstract List<int> GetLayerItemIDs(TItem item, TPos position);
    140149  }
    141150}
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/PackingPlans/PackingPlan.cs

    r14153 r14154  
    8686
    8787    public void UpdateBinPackings() {
    88       BinPackings.RemoveAll(x => x.ItemPositions.Count == 0);
     88      BinPackings.RemoveAll(x => x.Positions.Count == 0);
    8989      BinPackings = new ObservableList<BinPacking<D, B, I>>(BinPackings.OrderByDescending(bp => bp.PackingDensity));
    9090    }
Note: See TracChangeset for help on using the changeset viewer.