#region License Information
/* HeuristicLab
* Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using HeuristicLab.Common;
using HeuristicLab.Core;
using HeuristicLab.Data;
using HeuristicLab.Encodings.IntegerVectorEncoding;
using HeuristicLab.Operators;
using HeuristicLab.Optimization;
using HeuristicLab.Parameters;
using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
using HEAL.Attic;
namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment {
[Item("N-Move Maker", "Performs an N-Move.")]
[StorableType("9DAB4C4D-533A-4990-B591-A4C877F0CCE9")]
public class NMoveMaker : SingleSuccessorOperator, IQualityAwareGQAPOperator, IMoveQualityAwareGQAPOperator, IGQAPNMoveOperator, IMoveMaker {
public ILookupParameter AssignmentParameter {
get { return (ILookupParameter)Parameters["Assignment"]; }
}
public ILookupParameter MoveParameter {
get { return (ILookupParameter)Parameters["Move"]; }
}
public ILookupParameter QualityParameter {
get { return (ILookupParameter)Parameters["Quality"]; }
}
public ILookupParameter EvaluationParameter {
get { return (ILookupParameter)Parameters["Evaluation"]; }
}
public ILookupParameter MoveQualityParameter {
get { return (ILookupParameter)Parameters["MoveQuality"]; }
}
public ILookupParameter MoveEvaluationParameter {
get { return (ILookupParameter)Parameters["MoveEvaluation"]; }
}
[StorableConstructor]
protected NMoveMaker(StorableConstructorFlag _) : base(_) { }
protected NMoveMaker(NMoveMaker original, Cloner cloner) : base(original, cloner) { }
public NMoveMaker()
: base() {
Parameters.Add(new LookupParameter("Assignment", GQAPSolutionCreator.AssignmentDescription));
Parameters.Add(new LookupParameter("Move", GQAPNMoveGenerator.MoveDescription));
Parameters.Add(new LookupParameter("Quality", ""));
Parameters.Add(new LookupParameter("Evaluation", GQAP.EvaluationDescription));
Parameters.Add(new LookupParameter("MoveQuality", GQAPNMoveEvaluator.MoveQualityDescription));
Parameters.Add(new LookupParameter("MoveEvaluation", GQAPNMoveEvaluator.MoveEvaluationDescription));
}
public override IDeepCloneable Clone(Cloner cloner) {
return new NMoveMaker(this, cloner);
}
public static void Apply(IntegerVector vector, NMove move) {
for (var i = 0; i < move.N; i++) {
var equip = move.Indices[i];
vector[equip] = move.Reassignments[equip] - 1; // location is given 1-based in reassignments
}
}
public override IOperation Apply() {
Apply(AssignmentParameter.ActualValue, MoveParameter.ActualValue);
QualityParameter.ActualValue.Value = MoveQualityParameter.ActualValue.Value;
EvaluationParameter.ActualValue = MoveEvaluationParameter.ActualValue;
return base.Apply();
}
}
}