1 | using HeuristicLab.Common;
|
---|
2 | using HeuristicLab.Core;
|
---|
3 | using HeuristicLab.Data;
|
---|
4 | using HeuristicLab.Encodings.PermutationEncoding;
|
---|
5 | using HeuristicLab.Operators;
|
---|
6 | using HeuristicLab.Optimization;
|
---|
7 | using HeuristicLab.Parameters;
|
---|
8 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
9 |
|
---|
10 | namespace 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 | }
|
---|