Ignore:
Timestamp:
07/20/16 14:02:36 (5 years ago)
Author:
gkronber
Message:

#1966: refactoring of bin packing implementation

File:
1 edited

Legend:

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

    r14064 r14128  
    2323
    2424using System;
     25using System.CodeDom;
    2526using System.Linq;
     27using System.Text;
    2628using HeuristicLab.Common;
    2729using HeuristicLab.Core;
    2830using HeuristicLab.Data;
    29 using HeuristicLab.Encodings.PackingEncoding.PackingSequence;
     31using HeuristicLab.Encodings.PermutationEncoding;
    3032using HeuristicLab.Optimization;
    3133using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     34using HeuristicLab.Problems.BinPacking;
    3235
    33 namespace HeuristicLab.Problems.BinPacking2d {
     36namespace HeuristicLab.Problems.BinPacking {
    3437  [StorableClass]
    35   abstract class PackingSequenceProblem : SingleObjectiveBasicProblem<Encoding> {
     38  public abstract class PackingSequenceProblem<TSolution, TEncoding> : SingleObjectiveBasicProblem<TEncoding>
     39    where TSolution : class, IItem
     40    where TEncoding : class, IEncoding {
    3641
    3742    // persistence
     
    4348
    4449    // cloning
    45     protected PackingSequenceProblem(PackingSequenceProblem original, Cloner cloner)
     50    protected PackingSequenceProblem(PackingSequenceProblem<TSolution, TEncoding> original, Cloner cloner)
    4651      : base(original, cloner) {
    4752    }
     
    5358    }
    5459
    55     public sealed override double Evaluate(Individual individual, IRandom random) {
    56       return Evaluate(individual.PackingSequence(), random);
    57     }
    58     public abstract double Evaluate(PackingSequence sequence, IRandom random);
    59 
    60     public virtual void Analyze(PackingSequence[] trees, double[] qualities, ResultCollection results,
     60    public virtual void Analyze(TSolution[] solutions, double[] qualities, ResultCollection results,
    6161      IRandom random) {
    6262      if (!results.ContainsKey("Best Solution Quality")) {
     
    6464      }
    6565      if (!results.ContainsKey("Best Solution")) {
    66         results.Add(new Result("Best Solution", typeof(PackingSequence)));
     66        results.Add(new Result("Best Solution", typeof(TSolution)));
    6767      }
    6868
     
    7272          IsBetter(bestQuality, ((DoubleValue)results["Best Solution Quality"].Value).Value)) {
    7373        var bestIdx = Array.IndexOf(qualities, bestQuality);
    74         var bestClone = (IItem)trees[bestIdx].Clone();
     74        var bestClone = (IItem)solutions[bestIdx].Clone();
    7575        results["Best Solution"].Value = bestClone;
    7676        results["Best Solution Quality"].Value = new DoubleValue(bestQuality);
    7777      }
    7878    }
    79 
    80     public sealed override void Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random) {
    81       Analyze(individuals.Select(ind => ind.PackingSequence()).ToArray(), qualities, results, random);
    82     }
    8379  }
    8480}
Note: See TracChangeset for help on using the changeset viewer.