Free cookie consent management tool by TermsFeed Policy Generator

source: branches/1614_GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Moves/NMoveMaker.cs @ 17328

Last change on this file since 17328 was 16728, checked in by abeham, 6 years ago

#1614: updated to new persistence and .NET 4.6.1

File size: 3.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using HeuristicLab.Common;
23using HeuristicLab.Core;
24using HeuristicLab.Data;
25using HeuristicLab.Encodings.IntegerVectorEncoding;
26using HeuristicLab.Operators;
27using HeuristicLab.Optimization;
28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30using HEAL.Attic;
31
32namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment {
33  [Item("N-Move Maker", "Performs an N-Move.")]
34  [StorableType("9DAB4C4D-533A-4990-B591-A4C877F0CCE9")]
35  public class NMoveMaker : SingleSuccessorOperator, IQualityAwareGQAPOperator, IMoveQualityAwareGQAPOperator, IGQAPNMoveOperator, IMoveMaker {
36
37    public ILookupParameter<IntegerVector> AssignmentParameter {
38      get { return (ILookupParameter<IntegerVector>)Parameters["Assignment"]; }
39    }
40    public ILookupParameter<NMove> MoveParameter {
41      get { return (ILookupParameter<NMove>)Parameters["Move"]; }
42    }
43    public ILookupParameter<DoubleValue> QualityParameter {
44      get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; }
45    }
46    public ILookupParameter<Evaluation> EvaluationParameter {
47      get { return (ILookupParameter<Evaluation>)Parameters["Evaluation"]; }
48    }
49    public ILookupParameter<DoubleValue> MoveQualityParameter {
50      get { return (ILookupParameter<DoubleValue>)Parameters["MoveQuality"]; }
51    }
52    public ILookupParameter<Evaluation> MoveEvaluationParameter {
53      get { return (ILookupParameter<Evaluation>)Parameters["MoveEvaluation"]; }
54    }
55
56    [StorableConstructor]
57    protected NMoveMaker(StorableConstructorFlag _) : base(_) { }
58    protected NMoveMaker(NMoveMaker original, Cloner cloner) : base(original, cloner) { }
59    public NMoveMaker()
60      : base() {
61      Parameters.Add(new LookupParameter<IntegerVector>("Assignment", GQAPSolutionCreator.AssignmentDescription));
62      Parameters.Add(new LookupParameter<NMove>("Move", GQAPNMoveGenerator.MoveDescription));
63      Parameters.Add(new LookupParameter<DoubleValue>("Quality", ""));
64      Parameters.Add(new LookupParameter<Evaluation>("Evaluation", GQAP.EvaluationDescription));
65      Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", GQAPNMoveEvaluator.MoveQualityDescription));
66      Parameters.Add(new LookupParameter<Evaluation>("MoveEvaluation", GQAPNMoveEvaluator.MoveEvaluationDescription));
67    }
68
69    public override IDeepCloneable Clone(Cloner cloner) {
70      return new NMoveMaker(this, cloner);
71    }
72
73    public static void Apply(IntegerVector vector, NMove move) {
74      for (var i = 0; i < move.N; i++) {
75        var equip = move.Indices[i];
76        vector[equip] = move.Reassignments[equip] - 1; // location is given 1-based in reassignments
77      }
78    }
79
80    public override IOperation Apply() {
81      Apply(AssignmentParameter.ActualValue, MoveParameter.ActualValue);
82      QualityParameter.ActualValue.Value = MoveQualityParameter.ActualValue.Value;
83      EvaluationParameter.ActualValue = MoveEvaluationParameter.ActualValue;
84      return base.Apply();
85    }
86  }
87}
Note: See TracBrowser for help on using the repository browser.