#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.Operators {
[Item("NMoveShakingOperator", "Performs a number of shaking operations that increase in strength.")]
[StorableType("22D9F959-9BAB-497D-B593-FF19BD8CE9AB")]
public class NMoveShakingOperator : SingleSuccessorOperator, IProblemInstanceAwareGQAPOperator,
IAssignmentAwareGQAPOperator, IMultiNeighborhoodShakingOperator, IStochasticOperator {
public ILookupParameter ProblemInstanceParameter {
get { return (ILookupParameter)Parameters["ProblemInstance"]; }
}
public ILookupParameter AssignmentParameter {
get { return (ILookupParameter)Parameters["Assignment"]; }
}
public IValueLookupParameter CurrentNeighborhoodIndexParameter {
get { return (IValueLookupParameter)Parameters["CurrentNeighborhoodIndex"]; }
}
public ILookupParameter NeighborhoodCountParameter {
get { return (ILookupParameter)Parameters["NeighborhoodCount"]; }
}
public ILookupParameter RandomParameter {
get { return (ILookupParameter)Parameters["Random"]; }
}
[StorableConstructor]
protected NMoveShakingOperator(StorableConstructorFlag _) : base(_) { }
protected NMoveShakingOperator(NMoveShakingOperator original, Cloner cloner) : base(original, cloner) { }
public NMoveShakingOperator() {
Parameters.Add(new LookupParameter("ProblemInstance", GQAP.ProblemInstanceDescription));
Parameters.Add(new LookupParameter("Assignment", GQAPSolutionCreator.AssignmentDescription));
Parameters.Add(new ValueLookupParameter("CurrentNeighborhoodIndex", "The index of the operator that should be applied (k)."));
Parameters.Add(new LookupParameter("NeighborhoodCount", "The number of operators that are available."));
Parameters.Add(new LookupParameter("Random", "The random number generator to use."));
}
public override IDeepCloneable Clone(Cloner cloner) {
return new NMoveShakingOperator(this, cloner);
}
public override IOperation Apply() {
var random = RandomParameter.ActualValue;
var assignment = AssignmentParameter.ActualValue;
var capacities = ProblemInstanceParameter.ActualValue.Capacities;
if (NeighborhoodCountParameter.ActualValue == null)
NeighborhoodCountParameter.ActualValue = new IntValue(assignment.Length);
else NeighborhoodCountParameter.ActualValue.Value = assignment.Length;
int index = CurrentNeighborhoodIndexParameter.ActualValue.Value;
var move = StochasticNMoveSingleMoveGenerator.GenerateUpToN(random, assignment, index + 1, capacities);
NMoveMaker.Apply(assignment, move);
return base.Apply();
}
}
}