Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/21/16 12:06:43 (6 years ago)
Author:
gkronber
Message:

#1966: refactoring 2d problem

File:
1 edited

Legend:

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

    r14148 r14149  
    2222using HeuristicLab.Common;
    2323using HeuristicLab.Core;
    24 using HeuristicLab.Data;
    2524using HeuristicLab.Encodings.PermutationEncoding;
    26 using HeuristicLab.Operators;
    27 using HeuristicLab.Optimization;
    28 using HeuristicLab.Parameters;
    2925using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3026
     
    3228  [Item("TranslocationMoveEvaluator", "Move evaluator for insertion or translocation moves.")]
    3329  [StorableClass]
    34   public sealed class TranslocationMoveEvaluator : SingleSuccessorOperator,
    35     ISingleObjectiveMoveEvaluator, ISingleObjectiveMoveOperator, IPermutationTranslocationMoveOperator {
    36     public override bool CanChangeName {
    37       get { return false; }
     30  public sealed class TranslocationMoveEvaluator : MoveEvaluatorBase<Permutation, TranslocationMove>, IPermutationTranslocationMoveOperator {
     31    public ILookupParameter<TranslocationMove> TranslocationMoveParameter {
     32      get { return MoveParameter; }
    3833    }
    3934    public ILookupParameter<Permutation> PermutationParameter {
    40       get { return (ILookupParameter<Permutation>)Parameters["PackingSequence"]; }
     35      get { return EncodedSolutionParameter; }
    4136    }
    42     public ILookupParameter<DoubleValue> QualityParameter {
    43       get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; }
    44     }
    45     public ILookupParameter<DoubleValue> MoveQualityParameter {
    46       get { return (ILookupParameter<DoubleValue>)Parameters["MoveQuality"]; }
    47     }
    48     public ILookupParameter<ReadOnlyItemList<PackingItem>> PackingItemMeasuresParameter {
    49       get { return (LookupParameter<ReadOnlyItemList<PackingItem>>)Parameters["Items"]; }
    50     }
    51     public ILookupParameter<PackingShape> PackingBinMeasuresParameter {
    52       get { return (LookupParameter<PackingShape>)Parameters["BinShape"]; }
    53     }
    54     public ILookupParameter<IPermutationDecoder> PackingSolutionDecoderParameter {
    55       get { return (ILookupParameter<IPermutationDecoder>)Parameters["Decoder"]; }
    56     }
    57     public ILookupParameter<IEvaluator> PackingPlanEvaluatorParameter {
    58       get { return (ILookupParameter<IEvaluator>)Parameters["SolutionEvaluator"]; }
    59     }
    60 
    61     public ILookupParameter<TranslocationMove> TranslocationMoveParameter {
    62       get { return (ILookupParameter<TranslocationMove>)Parameters["TranslocationMove"]; }
    63     }
    64 
    6537    [StorableConstructor]
    6638    private TranslocationMoveEvaluator(bool deserializing) : base(deserializing) { }
     
    6840    public TranslocationMoveEvaluator()
    6941      : base() {
    70       Parameters.Add(new LookupParameter<Permutation>("PackingSequence", "The encoded solution candidate to evaluate"));
    71       Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of a packing solution."));
    72       Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The evaluated quality of a move on a packing solution."));
    73       Parameters.Add(new LookupParameter<ReadOnlyItemList<PackingItem>>("Items", "Packing-item data taken from the bin-packing problem-instance."));
    74       Parameters.Add(new LookupParameter<PackingShape>("BinShape", "Packing-bin data taken from the bin-packing problem-instance."));
    75       Parameters.Add(new LookupParameter<IPermutationDecoder>("Decoder", "The decoding operator that is used to calculate a packing plan from the used representation."));
    76       Parameters.Add(new LookupParameter<IEvaluator>("SolutionEvaluator", "The actual packing plan evaluation operator."));
    77       Parameters.Add(new LookupParameter<TranslocationMove>("TranslocationMove", "The move to evaluate."));
    7842    }
    7943
     
    8246    }
    8347
    84 
    85     public override IOperation Apply() {
    86       var move = TranslocationMoveParameter.ActualValue;
    87       var permutation = PermutationParameter.ActualValue;
    88       var binShape = PackingBinMeasuresParameter.ActualValue;
    89       var items = PackingItemMeasuresParameter.ActualValue;
     48    public override double EvaluateMove(Permutation permutation, TranslocationMove move, PackingShape binShape,
     49      ReadOnlyItemList<PackingItem> items) {
    9050
    9151      // uses full evaluation
    92 
    9352      TranslocationManipulator.Apply(permutation, move.Index1, move.Index2, move.Index3);
    9453      var solution = PackingSolutionDecoderParameter.ActualValue.Decode(permutation, binShape, items);
    9554
    96       var quality = PackingPlanEvaluatorParameter.ActualValue.Evaluate(solution);
    97 
    98       double moveQuality = quality;
    99 
    100       if (MoveQualityParameter.ActualValue == null)
    101         MoveQualityParameter.ActualValue = new DoubleValue(moveQuality);
    102       else
    103         MoveQualityParameter.ActualValue.Value = moveQuality;
    104       return base.Apply();
     55      return PackingPlanEvaluatorParameter.ActualValue.Evaluate(solution);
    10556    }
    10657  }
Note: See TracChangeset for help on using the changeset viewer.