Free cookie consent management tool by TermsFeed Policy Generator

source: branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Moves/NMoveMaker.cs @ 15504

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

#1614: refactored code

  • change problem to derive from basic problem
  • using a combined instance class instead of individual parameters
File size: 3.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2017 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;
30
31namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment {
32  [Item("N-Move Maker", "Performs an N-Move.")]
33  [StorableClass]
34  public class NMoveMaker : SingleSuccessorOperator, IQualityAwareGQAPOperator, IMoveQualityAwareGQAPOperator, IGQAPNMoveOperator, IMoveMaker {
35
36    public ILookupParameter<IntegerVector> AssignmentParameter {
37      get { return (ILookupParameter<IntegerVector>)Parameters["Assignment"]; }
38    }
39    public ILookupParameter<NMove> MoveParameter {
40      get { return (ILookupParameter<NMove>)Parameters["Move"]; }
41    }
42    public ILookupParameter<DoubleValue> QualityParameter {
43      get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; }
44    }
45    public ILookupParameter<Evaluation> EvaluationParameter {
46      get { return (ILookupParameter<Evaluation>)Parameters["Evaluation"]; }
47    }
48    public ILookupParameter<DoubleValue> MoveQualityParameter {
49      get { return (ILookupParameter<DoubleValue>)Parameters["MoveQuality"]; }
50    }
51    public ILookupParameter<Evaluation> MoveEvaluationParameter {
52      get { return (ILookupParameter<Evaluation>)Parameters["MoveEvaluation"]; }
53    }
54
55    [StorableConstructor]
56    protected NMoveMaker(bool deserializing) : base(deserializing) { }
57    protected NMoveMaker(NMoveMaker original, Cloner cloner) : base(original, cloner) { }
58    public NMoveMaker()
59      : base() {
60      Parameters.Add(new LookupParameter<IntegerVector>("Assignment", GQAPSolutionCreator.AssignmentDescription));
61      Parameters.Add(new LookupParameter<NMove>("Move", GQAPNMoveGenerator.MoveDescription));
62      Parameters.Add(new LookupParameter<DoubleValue>("Quality", ""));
63      Parameters.Add(new LookupParameter<Evaluation>("Evaluation", GQAP.EvaluationDescription));
64      Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", GQAPNMoveEvaluator.MoveQualityDescription));
65      Parameters.Add(new LookupParameter<Evaluation>("MoveEvaluation", GQAPNMoveEvaluator.MoveEvaluationDescription));
66    }
67
68    public override IDeepCloneable Clone(Cloner cloner) {
69      return new NMoveMaker(this, cloner);
70    }
71
72    public static void Apply(IntegerVector vector, NMove move) {
73      foreach (var kvp in move.NewAssignments)
74        vector[kvp.Key] = kvp.Value;
75    }
76
77    public override IOperation Apply() {
78      Apply(AssignmentParameter.ActualValue, MoveParameter.ActualValue);
79      QualityParameter.ActualValue.Value = MoveQualityParameter.ActualValue.Value;
80      EvaluationParameter.ActualValue = MoveEvaluationParameter.ActualValue;
81      return base.Apply();
82    }
83  }
84}
Note: See TracBrowser for help on using the repository browser.