[7407] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[16728] | 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;
|
---|
[16728] | 30 | using HEAL.Attic;
|
---|
[7407] | 31 |
|
---|
| 32 | namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment {
|
---|
[7505] | 33 | [Item("N-Move Maker", "Performs an N-Move.")]
|
---|
[16728] | 34 | [StorableType("9DAB4C4D-533A-4990-B591-A4C877F0CCE9")]
|
---|
[15504] | 35 | public class NMoveMaker : SingleSuccessorOperator, IQualityAwareGQAPOperator, IMoveQualityAwareGQAPOperator, IGQAPNMoveOperator, IMoveMaker {
|
---|
[7407] | 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 | }
|
---|
[15504] | 46 | public ILookupParameter<Evaluation> EvaluationParameter {
|
---|
| 47 | get { return (ILookupParameter<Evaluation>)Parameters["Evaluation"]; }
|
---|
[7407] | 48 | }
|
---|
| 49 | public ILookupParameter<DoubleValue> MoveQualityParameter {
|
---|
| 50 | get { return (ILookupParameter<DoubleValue>)Parameters["MoveQuality"]; }
|
---|
| 51 | }
|
---|
[15504] | 52 | public ILookupParameter<Evaluation> MoveEvaluationParameter {
|
---|
| 53 | get { return (ILookupParameter<Evaluation>)Parameters["MoveEvaluation"]; }
|
---|
[7407] | 54 | }
|
---|
| 55 |
|
---|
| 56 | [StorableConstructor]
|
---|
[16728] | 57 | protected NMoveMaker(StorableConstructorFlag _) : base(_) { }
|
---|
[7407] | 58 | protected NMoveMaker(NMoveMaker original, Cloner cloner) : base(original, cloner) { }
|
---|
| 59 | public NMoveMaker()
|
---|
| 60 | : base() {
|
---|
[7419] | 61 | Parameters.Add(new LookupParameter<IntegerVector>("Assignment", GQAPSolutionCreator.AssignmentDescription));
|
---|
| 62 | Parameters.Add(new LookupParameter<NMove>("Move", GQAPNMoveGenerator.MoveDescription));
|
---|
[15504] | 63 | Parameters.Add(new LookupParameter<DoubleValue>("Quality", ""));
|
---|
| 64 | Parameters.Add(new LookupParameter<Evaluation>("Evaluation", GQAP.EvaluationDescription));
|
---|
[7419] | 65 | Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", GQAPNMoveEvaluator.MoveQualityDescription));
|
---|
[15504] | 66 | Parameters.Add(new LookupParameter<Evaluation>("MoveEvaluation", GQAPNMoveEvaluator.MoveEvaluationDescription));
|
---|
[7407] | 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) {
|
---|
[15511] | 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 | }
|
---|
[7407] | 78 | }
|
---|
| 79 |
|
---|
| 80 | public override IOperation Apply() {
|
---|
| 81 | Apply(AssignmentParameter.ActualValue, MoveParameter.ActualValue);
|
---|
| 82 | QualityParameter.ActualValue.Value = MoveQualityParameter.ActualValue.Value;
|
---|
[15504] | 83 | EvaluationParameter.ActualValue = MoveEvaluationParameter.ActualValue;
|
---|
[7407] | 84 | return base.Apply();
|
---|
| 85 | }
|
---|
| 86 | }
|
---|
| 87 | }
|
---|