Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/24/18 13:17:00 (6 years ago)
Author:
rhanghof
Message:

#2817:

  • Dealing with stackable items
  • Enhanced the Evaluator
  • Added parameters some paramters to the packing items
File:
1 edited

Legend:

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

    r15617 r15646  
    202202    /// <param name="token"></param>
    203203    /// <returns></returns>
    204     private Tuple<Solution, double, SortingMethod?, FittingMethod?, ExtremePointCreationMethod?> 
    205           GetBest(PackingShape bin, 
    206                   IList<PackingItem> items, 
    207                   SortingMethod[] sortings, 
     204    private Tuple<Solution, double, SortingMethod?, FittingMethod?, ExtremePointCreationMethod?>
     205          GetBest(PackingShape bin,
     206                  IList<PackingItem> items,
     207                  SortingMethod[] sortings,
    208208                  FittingMethod[] fittings,
    209209                  ExtremePointCreationMethod[] epCreationMethods,
     
    222222            };
    223223            Permutation sortedItems;
    224                    
     224
    225225            if (SortByMaterialParameter.Value.Value) {
    226226              sortedItems = SortItemsByMaterialAndSortingMethod(bin, items, sort, DeltaParameter.Value.Value);
     
    229229            }
    230230
    231             var result = Optimize(new OptimaizationParamters() {
     231            var solution = Optimize(new OptimaizationParamters() {
    232232              SortedItems = sortedItems,
    233233              Bin = bin,
     
    238238              ExtremePointGeneration = epCreation
    239239            });
    240          
     240
     241            if (solution.IsBetterThan(bestSolution, Problem.SolutionEvaluator, Problem.Maximization)) {
     242              bestSolution = solution;
     243              best = Problem.SolutionEvaluator.Evaluate(solution);
     244              bestSorting = sort;
     245              bestFitting = fit;
     246              bestEPCreation = epCreation;
     247            }
     248
     249
     250            var x = Problem.SolutionEvaluator.Evaluate1(solution);
     251
     252            /*
    241253            if (double.IsNaN(result.Item2) || double.IsInfinity(result.Item2)) {
    242254              continue;
     
    250262              bestEPCreation = epCreation;
    251263            }
     264            return true;*/
     265
    252266            if (token.IsCancellationRequested) {
    253267              return Tuple.Create(bestSolution, best, bestSorting, bestFitting, bestEPCreation);
     
    267281    /// <param name="parameters"></param>
    268282    /// <returns></returns>
    269     private static Tuple<Solution, double> Optimize(OptimaizationParamters parameters) {
    270      
     283    private static Solution Optimize(OptimaizationParamters parameters) {
     284
    271285      var sol = parameters.Decoder.Decode(parameters.SortedItems, parameters.Bin, parameters.Items, parameters.StackingConstraints);
    272       var fit = parameters.Evaluator.Evaluate(sol);
    273 
    274       return Tuple.Create(sol, fit);
     286      //var fit = parameters.Evaluator.Evaluate(sol);
     287
     288      return sol; //Tuple.Create(sol, fit);
    275289    }
    276290
     
    284298      public ExtremePointCreationMethod ExtremePointGeneration { get; set; }
    285299    }
    286    
     300
    287301
    288302    /// <summary>
    289303    /// Returns a new permutation of the given items depending on the sorting method
     304    /// </summary>
     305    /// <param name="bin"></param>
     306    /// <param name="items"></param>
     307    /// <param name="sortingMethod"></param>
     308    /// <param name="delta"></param>
     309    /// <returns></returns>
     310    private Permutation SortItemsByMaterialAndSortingMethod(PackingShape bin, IList<PackingItem> items, SortingMethod sortingMethod, double delta) {
     311      Permutation sorted = null;
     312
     313      switch (sortingMethod) {
     314        case SortingMethod.Given:
     315          sorted = new Permutation(PermutationTypes.Absolute, Enumerable.Range(0, items.Count).ToArray());
     316          break;
     317        case SortingMethod.VolumeHeight:
     318          sorted = items.SortByVolumeHeight();
     319          break;
     320        case SortingMethod.HeightVolume:
     321          sorted = items.SortByMaterialHeightVolume();
     322          break;
     323        case SortingMethod.AreaHeight:
     324          sorted = items.SortByMaterialAreaHeight();
     325          break;
     326        case SortingMethod.HeightArea:
     327          sorted = items.SortByMaterialHeightArea();
     328          break;
     329        case SortingMethod.ClusteredAreaHeight:
     330          sorted = items.SortByMaterialClusteredAreaHeight(bin, delta);
     331          break;
     332        case SortingMethod.ClusteredHeightArea:
     333          sorted = items.SortByMaterialClusteredHeightArea(bin, delta);
     334          break;
     335        default:
     336          throw new ArgumentException("Unknown sorting method: " + sortingMethod);
     337      }
     338      return sorted;
     339    }
     340
     341    /// <summary>
     342    /// Returns a new permutation of the given items depending on the material and sorting method
    290343    /// </summary>
    291344    /// <param name="bin"></param>
     
    296349    private Permutation SortItemsBySortingMethod(PackingShape bin, IList<PackingItem> items, SortingMethod sortingMethod, double delta) {
    297350      Permutation sorted = null;
    298      
     351
    299352      switch (sortingMethod) {
    300353        case SortingMethod.Given:
     
    305358          break;
    306359        case SortingMethod.HeightVolume:
    307           sorted = items.SortByMaterialHeightVolume();
     360          sorted = items.SortByHeightVolume();
    308361          break;
    309362        case SortingMethod.AreaHeight:
    310           sorted = items.SortByMaterialAreaHeight();
     363          sorted = items.SortByAreaHeight();
    311364          break;
    312365        case SortingMethod.HeightArea:
    313           sorted = items.SortByMaterialHeightArea();
     366          sorted = items.SortByHeightArea();
    314367          break;
    315368        case SortingMethod.ClusteredAreaHeight:
    316           sorted = items.SortByMaterialClusteredAreaHeight(bin, delta);
     369          sorted = items.SortByClusteredAreaHeight(bin, delta);
    317370          break;
    318371        case SortingMethod.ClusteredHeightArea:
    319           sorted = items.SortByMaterialClusteredHeightArea(bin, delta);
     372          sorted = items.SortByClusteredHeightArea(bin, delta);
    320373          break;
    321374        default:
     
    324377      return sorted;
    325378    }
    326 
    327     /// <summary>
    328     /// Returns a new permutation of the given items depending on the material and sorting method
    329     /// </summary>
    330     /// <param name="bin"></param>
    331     /// <param name="items"></param>
    332     /// <param name="sortingMethod"></param>
    333     /// <param name="delta"></param>
    334     /// <returns></returns>
    335     private Permutation SortItemsByMaterialAndSortingMethod(PackingShape bin, IList<PackingItem> items, SortingMethod sortingMethod, double delta) {
    336       Permutation sorted = null;
    337 
    338       switch (sortingMethod) {
    339         case SortingMethod.Given:
    340           sorted = new Permutation(PermutationTypes.Absolute, Enumerable.Range(0, items.Count).ToArray());
    341           break;
    342         case SortingMethod.VolumeHeight:
    343           sorted = items.SortByVolumeHeight();
    344           break;
    345         case SortingMethod.HeightVolume:
    346           sorted = items.SortByHeightVolume();
    347           break;
    348         case SortingMethod.AreaHeight:
    349           sorted = items.SortByAreaHeight();
    350           break;
    351         case SortingMethod.HeightArea:
    352           sorted = items.SortByHeightArea();
    353           break;
    354         case SortingMethod.ClusteredAreaHeight:
    355           sorted = items.SortByClusteredAreaHeight(bin, delta);
    356           break;
    357         case SortingMethod.ClusteredHeightArea:
    358           sorted = items.SortByClusteredHeightArea(bin, delta);
    359           break;
    360         default:
    361           throw new ArgumentException("Unknown sorting method: " + sortingMethod);
    362       }
    363       return sorted;
    364     }
    365379  }
    366380}
Note: See TracChangeset for help on using the changeset viewer.