#region License Information
/* HeuristicLab
* Copyright (C) 2002-2012 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;
namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment {
[Item("N-Move Maker", "Performs an N-Move.")]
[StorableClass]
public class NMoveMaker : SingleSuccessorOperator, IAssignmentAwareGQAPOperator, IQualityAwareGQAPOperator, IMoveQualityAwareGQAPOperator, IGQAPNMoveOperator, IMoveMaker {
public ILookupParameter AssignmentParameter {
get { return (ILookupParameter)Parameters["Assignment"]; }
}
public ILookupParameter MoveParameter {
get { return (ILookupParameter)Parameters["Move"]; }
}
ILookupParameter IQualityAwareGQAPOperator.MaximizationParameter {
get { return MaximizationParameter; }
}
ILookupParameter IMoveQualityAwareGQAPOperator.MaximizationParameter {
get { return MaximizationParameter; }
}
public ILookupParameter MaximizationParameter {
get { return (ILookupParameter)Parameters["Maximization"]; }
}
public ILookupParameter QualityParameter {
get { return (ILookupParameter)Parameters["Quality"]; }
}
public ILookupParameter FlowDistanceQualityParameter {
get { return (ILookupParameter)Parameters["FlowDistanceQuality"]; }
}
public ILookupParameter InstallationQualityParameter {
get { return (ILookupParameter)Parameters["InstallationQuality"]; }
}
public ILookupParameter OverbookedCapacityParameter {
get { return (ILookupParameter)Parameters["OverbookedCapacity"]; }
}
public ILookupParameter MoveQualityParameter {
get { return (ILookupParameter)Parameters["MoveQuality"]; }
}
public ILookupParameter MoveFlowDistanceQualityParameter {
get { return (ILookupParameter)Parameters["MoveFlowDistanceQuality"]; }
}
public ILookupParameter MoveInstallationQualityParameter {
get { return (ILookupParameter)Parameters["MoveInstallationQuality"]; }
}
public ILookupParameter MoveOverbookedCapacityParameter {
get { return (ILookupParameter)Parameters["MoveOverbookedCapacity"]; }
}
[StorableConstructor]
protected NMoveMaker(bool deserializing) : base(deserializing) { }
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("Maximization", GeneralizedQuadraticAssignmentProblem.MaximizationDescription));
Parameters.Add(new LookupParameter("Quality", GQAPEvaluator.QualityDescription));
Parameters.Add(new LookupParameter("FlowDistanceQuality", GQAPEvaluator.FlowDistanceQualityDescription));
Parameters.Add(new LookupParameter("InstallationQuality", GQAPEvaluator.InstallationQualityDescription));
Parameters.Add(new LookupParameter("OverbookedCapacity", GQAPEvaluator.OverbookedCapacityDescription));
Parameters.Add(new LookupParameter("MoveQuality", GQAPNMoveEvaluator.MoveQualityDescription));
Parameters.Add(new LookupParameter("MoveFlowDistanceQuality", GQAPNMoveEvaluator.MoveFlowDistanceQualityDescription));
Parameters.Add(new LookupParameter("MoveInstallationQuality", GQAPNMoveEvaluator.MoveInstallationQualityDescription));
Parameters.Add(new LookupParameter("MoveOverbookedCapacity", GQAPNMoveEvaluator.MoveOverbookedCapacityDescription));
}
public override IDeepCloneable Clone(Cloner cloner) {
return new NMoveMaker(this, cloner);
}
public static void Apply(IntegerVector vector, NMove move) {
foreach (var kvp in move.NewAssignments)
vector[kvp.Key] = kvp.Value;
}
public override IOperation Apply() {
Apply(AssignmentParameter.ActualValue, MoveParameter.ActualValue);
QualityParameter.ActualValue.Value = MoveQualityParameter.ActualValue.Value;
FlowDistanceQualityParameter.ActualValue.Value = MoveFlowDistanceQualityParameter.ActualValue.Value;
InstallationQualityParameter.ActualValue.Value = MoveInstallationQualityParameter.ActualValue.Value;
OverbookedCapacityParameter.ActualValue.Value = MoveOverbookedCapacityParameter.ActualValue.Value;
return base.Apply();
}
}
}