Changeset 15838


Ignore:
Timestamp:
03/12/18 14:19:06 (3 years ago)
Author:
rhanghof
Message:

#2817:

  • Fixed a bug at creating the extreme points with the point projection based method.
Location:
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D
Files:
10 edited

Legend:

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

    r15731 r15838  
    247247            }
    248248
    249 
    250             var x = Problem.SolutionEvaluator.Evaluate1(solution);
    251 
    252             /*
    253             if (double.IsNaN(result.Item2) || double.IsInfinity(result.Item2)) {
    254               continue;
    255             }
    256 
    257             if (double.IsNaN(best) || Problem.Maximization && result.Item2 > best || !Problem.Maximization && result.Item2 < best) {
    258               bestSolution = result.Item1;
    259               best = result.Item2;
    260               bestSorting = sort;
    261               bestFitting = fit;
    262               bestEPCreation = epCreation;
    263             }
    264             return true;*/
    265 
    266249            if (token.IsCancellationRequested) {
    267250              return Tuple.Create(bestSolution, best, bestSorting, bestFitting, bestEPCreation);
     
    277260
    278261    /// <summary>
    279     /// Returns a tuple with the solution and the packing ratio depending on the given parameters
     262    /// Returns a solution depending on the given parameters
    280263    /// </summary>
    281264    /// <param name="parameters"></param>
     
    284267
    285268      var sol = parameters.Decoder.Decode(parameters.SortedItems, parameters.Bin, parameters.Items, parameters.StackingConstraints);
    286       //var fit = parameters.Evaluator.Evaluate(sol);
    287 
    288       return sol; //Tuple.Create(sol, fit);
     269
     270      return sol;
    289271    }
    290272
     
    298280      public ExtremePointCreationMethod ExtremePointGeneration { get; set; }
    299281    }
    300 
    301 
     282   
    302283    /// <summary>
    303284    /// Returns a new permutation of the given items depending on the sorting method
  • branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/Encoding/ExtremePointPermutationDecoder.cs

    r15652 r15838  
    6969      : base(original, cloner) {
    7070      fittingMethodParameter = cloner.Clone(original.fittingMethodParameter);
    71       //_binPacker = cloner.Clone(original._binPacker);
    7271    }
    7372    public ExtremePointPermutationDecoder() {
     
    8685      return new ExtremePointPermutationDecoder(this, cloner);
    8786    }
    88 
    89     /*[Storable]
    90     BinPacker _binPacker;
    91     */
     87   
    9288    /// <summary>
    9389    /// Creates a solution for displaying it on the HEAL gui
     
    108104      }
    109105      return solution;
    110     }
    111 
    112     Permutation AddOffset(Permutation p, int offset) {
    113       var s = p.ToArray();
    114       for (int i = 0; i < s.Length; i++) {
    115         s[i] += offset;
    116       }
    117      
    118       return new Permutation(PermutationTypes.Absolute, s);
    119     }
     106    }   
    120107  }
    121108}
  • branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/Evaluators/BinUtilizationEvaluator.cs

    r15731 r15838  
    8181    }
    8282
    83     public Tuple<int, double, int, int> Evaluate1(Solution solution) {
     83    public Tuple<int, double, int, int> EvaluateBinPacking(Solution solution) {
    8484
    8585
  • branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/Evaluators/IEvaluator.cs

    r15731 r15838  
    4141    /// <param name="solution"></param>
    4242    /// <returns></returns>
    43     Tuple<int, double, int, int> Evaluate1(Solution solution);
     43    Tuple<int, double, int, int> EvaluateBinPacking(Solution solution);
    4444  }
    4545}
  • branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/Evaluators/PackingRatioEvaluator.cs

    r15731 r15838  
    9898    }
    9999
    100     public Tuple<int, double, int, int> Evaluate1(Solution solution) {
     100    public Tuple<int, double, int, int> EvaluateBinPacking(Solution solution) {
    101101
    102102
  • branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/ExtremePointCreation/ExtremePointCreator.cs

    r15617 r15838  
    232232    /// <returns></returns>
    233233    protected bool IsWithinResidualSpaceOfAnotherExtremePoint(BinPacking3D binPacking, Vector3D pos, IEnumerable<ResidualSpace> residualSpaces) {
    234       foreach (var residualSpace in residualSpaces) {
    235         if (IsWithinResidualSpaceOfAnotherExtremePoint(binPacking, pos, residualSpace)) {
    236           return true;
    237         }
    238       }
    239       return false;
     234      return residualSpaces.Any(x => IsWithinResidualSpaceOfAnotherExtremePoint(binPacking, pos, x));
    240235    }
    241236
     
    262257    /// <returns></returns>
    263258    protected virtual bool IsWithinResidualSpaceOfAnotherExtremePoint(Vector3D pos, ResidualSpace rsPos, PackingPosition ep, ResidualSpace rsEp) {
    264       /*old implementation
    265       return rsEp.Width >= pos.X - ep.X + rsPos.Width
    266           && rsEp.Height >= pos.Y - ep.Y + rsPos.Height
    267           && rsEp.Depth >= pos.Z - ep.Z + rsPos.Depth;*/
    268 
    269259      var x = pos.X >= ep.X && pos.X + rsPos.Width <= ep.X + rsEp.Width;
    270260      var y = pos.Y >= ep.Y && pos.Y + rsPos.Height <= ep.Y + rsEp.Height;
     
    294284                             .Select(x => x.Intersect(line))
    295285                             .Where(x => x != null && x.Z <= pos.Z);
    296       if (m.Where(x => x != null).Any()) {
    297         return m.MaxItems(x => x.Y).First();
     286      if (m.Any(x => x != null)) {
     287        return m.MaxItems(x => x.Z).FirstOrDefault();
    298288      }
    299289      return null;
     
    307297                  .Select(x => x.Intersect(line))
    308298                  .Where(x => x != null && x.X <= pos.X);
    309       if (m.Where(x => x != null).Any()) {
    310         return m.MaxItems(x => x.Y).First();
     299      if (m.Any(x => x != null)) {
     300        return m.MaxItems(x => x.X).FirstOrDefault();
    311301      }
    312302      return null;
     
    320310                  .Select(x => x.Intersect(line))
    321311                  .Where(x => x != null && x.Y <= pos.Y);
    322       if (m.Where(x => x != null).Any()) {
    323         return m.MaxItems(x => x.Y).First();
     312      if (m.Any(x => x != null)) {
     313        return m.MaxItems(x => x.Y).FirstOrDefault();
    324314      }
    325315      return null;
     
    333323                  .Select(x => x.Intersect(line))
    334324                  .Where(x => x != null && x.Z >= pos.Z);
    335       if (m.Where(x => x != null).Any()) {
    336         return m.MaxItems(x => x.Y).First();
     325      if (m.Any(x => x != null)) {
     326        return m.MinItems(x => x.Z).FirstOrDefault();
    337327      }
    338328      return null;
     
    346336                  .Select(x => x.Intersect(line))
    347337                  .Where(x => x != null && x.X >= pos.X);
    348       if (m.Where(x => x != null).Any()) {
    349         return m.MaxItems(x => x.Y).First();
     338      if (m.Any(x => x != null)) {
     339        return m.MinItems(x => x.X).FirstOrDefault();
    350340      }
    351341      return null;
     
    359349                  .Select(x => x.Intersect(line))
    360350                  .Where(x => x != null && x.Y >= pos.Y);
    361       if (m.Where(x => x != null).Any()) {
    362         return m.MaxItems(x => x.Y).First();
     351      if (m.Any(x => x != null)) {
     352        return m.MinItems(x => x.Y).FirstOrDefault();
    363353      }
    364354      return null;
  • branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/ExtremePointCreation/ExtremePointCreatorFactory.cs

    r15617 r15838  
    2828namespace HeuristicLab.Problems.BinPacking3D.ExtremePointCreation {
    2929  public static class ExtremePointCreatorFactory {
    30     public static IExtremePointCreator CreateExtremePointCreator(ExtremePointCreationMethod epGenerationMethod, bool useStackingConstraints) {
    31       if (epGenerationMethod == ExtremePointCreationMethod.PointProjection) {
     30   
     31    /// <summary>
     32    /// Returns an extreme point creator depending on the given creation method.
     33    /// </summary>
     34    /// <param name="epCreationMethod"></param>
     35    /// <param name="useStackingConstraints"></param>
     36    /// <returns></returns>
     37    public static IExtremePointCreator CreateExtremePointCreator(ExtremePointCreationMethod epCreationMethod, bool useStackingConstraints) {
     38      if (epCreationMethod == ExtremePointCreationMethod.PointProjection) {
    3239        return new PointProjectionBasedEPCreator();
    33       } else if (epGenerationMethod == ExtremePointCreationMethod.LineProjection) {
     40      } else if (epCreationMethod == ExtremePointCreationMethod.LineProjection) {
    3441        return new LineProjectionBasedEPCreator();
    3542      }
  • branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/ExtremePointCreation/PointProjectionBasedEPCreator.cs

    r15822 r15838  
    5656        GenerateNewExtremePointsForItem(binPacking, it, pos);
    5757      });
    58 
     58     
    5959      // remove not needed extreme points.
    6060      foreach (var extremePoint in binPacking.ExtremePoints.ToList()) {
  • branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/Packer/BinPackerMinRSLeft.cs

    r15822 r15838  
    245245      packingItem.Rotated = rsd.Item.Rotated;
    246246      packingItem.Tilted = rsd.Item.Tilted;
     247
    247248      return rsd.Position;
    248249    }
     
    254255          $"Item: ({packingItem.Width} {packingItem.Depth} {packingItem.Height})");
    255256      }
    256 
    257       var rsd = CalculateResidalSpaceDifferences(packingBin, packingItem, useStackingConstraints).Where(x => x != null).FirstOrDefault();
     257           
     258      var rsds = CalculateResidalSpaceDifferences(packingBin, packingItem, useStackingConstraints).Where(x => x != null);
     259      var rsd = rsds.FirstOrDefault();
     260
    258261
    259262      if (rsd == null) {
     
    263266      packingItem.Rotated = rsd.Item.Rotated;
    264267      packingItem.Tilted = rsd.Item.Tilted;
     268     
    265269      return rsd.Position;
    266270    }
  • branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/Solution.cs

    r15731 r15838  
    4242
    4343    public bool IsBetterThan(Solution other, IEvaluator evaluator, bool problemMaximization = true) {
    44       var evaluatedThis = evaluator.Evaluate1(this);
     44      var evaluatedThis = evaluator.EvaluateBinPacking(this);
    4545
    4646      if (double.IsInfinity(evaluatedThis.Item2) || double.IsNaN(evaluatedThis.Item2)) {
     
    5252      }
    5353
    54       var evaluatedOther = evaluator.Evaluate1(other);
     54      var evaluatedOther = evaluator.EvaluateBinPacking(other);
    5555      if (evaluatedThis.Item1 < evaluatedOther.Item1) {
    5656        return true;
Note: See TracChangeset for help on using the changeset viewer.