Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PTSP/HeuristicLab.Problems.PTSP/3.3/MoveMakers/TwoPointFiveMoveMaker.cs @ 12272

Last change on this file since 12272 was 12272, checked in by apolidur, 9 years ago

#2221: Adding 2.5-opt-EEs operators to PTSP

File size: 2.7 KB
Line 
1using HeuristicLab.Common;
2using HeuristicLab.Core;
3using HeuristicLab.Data;
4using HeuristicLab.Encodings.PermutationEncoding;
5using HeuristicLab.Operators;
6using HeuristicLab.Optimization;
7using HeuristicLab.Parameters;
8using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
9
10namespace HeuristicLab.Problems.PTSP {
11  [Item("TwoPointFiveMoveMaker", "Peforms an inversion and shift (2.5-opt) on a given permutation and updates the quality.")]
12  [StorableClass]
13  public class TwoPointFiveMoveMaker : SingleSuccessorOperator, I25MoveOperator, IMoveMaker {
14    public override bool CanChangeName {
15      get { return false; }
16    }
17    public ILookupParameter<DoubleValue> QualityParameter {
18      get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; }
19    }
20    public ILookupParameter<DoubleValue> MoveQualityParameter {
21      get { return (ILookupParameter<DoubleValue>)Parameters["MoveQuality"]; }
22    }
23    public ILookupParameter<TwoPointFiveMove> TwoPointFiveMoveParameter {
24      get { return (ILookupParameter<TwoPointFiveMove>)Parameters["TwoPointFiveMove"]; }
25    }
26    public ILookupParameter<Permutation> PermutationParameter {
27      get { return (ILookupParameter<Permutation>)Parameters["Permutation"]; }
28    }
29    [StorableConstructor]
30    protected TwoPointFiveMoveMaker(bool deserializing) : base(deserializing) { }
31    protected TwoPointFiveMoveMaker(TwoPointFiveMoveMaker original, Cloner cloner) : base(original, cloner) { }
32    public TwoPointFiveMoveMaker()
33      : base() {
34      Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of the solution."));
35      Parameters.Add(new LookupParameter<TwoPointFiveMove>("TwoPointFiveMove", "The move to evaluate."));
36      Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The relative quality of the move."));
37      Parameters.Add(new LookupParameter<Permutation>("Permutation", "The solution as permutation."));
38    }
39
40    public override IDeepCloneable Clone(Cloner cloner) {
41      return new TwoPointFiveMoveMaker(this, cloner);
42    }
43
44    public override IOperation Apply() {
45      TwoPointFiveMove move = TwoPointFiveMoveParameter.ActualValue;
46      Permutation permutation = PermutationParameter.ActualValue;
47      DoubleValue moveQuality = MoveQualityParameter.ActualValue;
48      DoubleValue quality = QualityParameter.ActualValue;
49
50      if (move.IsInvert) {
51        InversionManipulator.Apply(permutation, move.Index1, move.Index2);
52      } else {
53        TranslocationManipulator.Apply(permutation, move.Index1, move.Index1, move.Index2);
54      }
55     
56      quality.Value = moveQuality.Value;
57
58      return base.Apply();
59    }
60  }
61}
Note: See TracBrowser for help on using the repository browser.