[7407] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[16077] | 3 | * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[7407] | 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 |
|
---|
| 22 | using HeuristicLab.Common;
|
---|
| 23 | using HeuristicLab.Core;
|
---|
| 24 | using HeuristicLab.Data;
|
---|
| 25 | using HeuristicLab.Encodings.IntegerVectorEncoding;
|
---|
| 26 | using HeuristicLab.Operators;
|
---|
[7413] | 27 | using HeuristicLab.Optimization;
|
---|
[7407] | 28 | using HeuristicLab.Parameters;
|
---|
| 29 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 30 |
|
---|
| 31 | namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment {
|
---|
[7505] | 32 | [Item("N-Move Maker", "Performs an N-Move.")]
|
---|
[7407] | 33 | [StorableClass]
|
---|
[15504] | 34 | public class NMoveMaker : SingleSuccessorOperator, IQualityAwareGQAPOperator, IMoveQualityAwareGQAPOperator, IGQAPNMoveOperator, IMoveMaker {
|
---|
[7407] | 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 | }
|
---|
[15504] | 45 | public ILookupParameter<Evaluation> EvaluationParameter {
|
---|
| 46 | get { return (ILookupParameter<Evaluation>)Parameters["Evaluation"]; }
|
---|
[7407] | 47 | }
|
---|
| 48 | public ILookupParameter<DoubleValue> MoveQualityParameter {
|
---|
| 49 | get { return (ILookupParameter<DoubleValue>)Parameters["MoveQuality"]; }
|
---|
| 50 | }
|
---|
[15504] | 51 | public ILookupParameter<Evaluation> MoveEvaluationParameter {
|
---|
| 52 | get { return (ILookupParameter<Evaluation>)Parameters["MoveEvaluation"]; }
|
---|
[7407] | 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() {
|
---|
[7419] | 60 | Parameters.Add(new LookupParameter<IntegerVector>("Assignment", GQAPSolutionCreator.AssignmentDescription));
|
---|
| 61 | Parameters.Add(new LookupParameter<NMove>("Move", GQAPNMoveGenerator.MoveDescription));
|
---|
[15504] | 62 | Parameters.Add(new LookupParameter<DoubleValue>("Quality", ""));
|
---|
| 63 | Parameters.Add(new LookupParameter<Evaluation>("Evaluation", GQAP.EvaluationDescription));
|
---|
[7419] | 64 | Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", GQAPNMoveEvaluator.MoveQualityDescription));
|
---|
[15504] | 65 | Parameters.Add(new LookupParameter<Evaluation>("MoveEvaluation", GQAPNMoveEvaluator.MoveEvaluationDescription));
|
---|
[7407] | 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) {
|
---|
[15511] | 73 | for (var i = 0; i < move.N; i++) {
|
---|
| 74 | var equip = move.Indices[i];
|
---|
| 75 | vector[equip] = move.Reassignments[equip] - 1; // location is given 1-based in reassignments
|
---|
| 76 | }
|
---|
[7407] | 77 | }
|
---|
| 78 |
|
---|
| 79 | public override IOperation Apply() {
|
---|
| 80 | Apply(AssignmentParameter.ActualValue, MoveParameter.ActualValue);
|
---|
| 81 | QualityParameter.ActualValue.Value = MoveQualityParameter.ActualValue.Value;
|
---|
[15504] | 82 | EvaluationParameter.ActualValue = MoveEvaluationParameter.ActualValue;
|
---|
[7407] | 83 | return base.Apply();
|
---|
| 84 | }
|
---|
| 85 | }
|
---|
| 86 | }
|
---|