#region License Information
/* HeuristicLab
* Copyright (C) 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 System;
using HeuristicLab.Common;
using HeuristicLab.Core;
using HeuristicLab.Data;
using HeuristicLab.Operators;
using HeuristicLab.Optimization;
using HeuristicLab.Parameters;
using HEAL.Attic;
namespace HeuristicLab.Encodings.RealVectorEncoding {
[Item("AdditiveMoveTabuChecker", "Prevents falling back into ranges that have been moved over before.")]
[StorableType("CA7D09FF-C936-474C-A0F8-17D9DBF783C2")]
public class AdditiveMoveTabuChecker : SingleSuccessorOperator, IAdditiveRealVectorMoveOperator, ITabuChecker {
public override bool CanChangeName {
get { return false; }
}
public ILookupParameter AdditiveMoveParameter {
get { return (LookupParameter)Parameters["AdditiveMove"]; }
}
public ILookupParameter RealVectorParameter {
get { return (LookupParameter)Parameters["RealVector"]; }
}
public ILookupParameter> TabuListParameter {
get { return (ILookupParameter>)Parameters["TabuList"]; }
}
public ILookupParameter MoveTabuParameter {
get { return (ILookupParameter)Parameters["MoveTabu"]; }
}
public IValueLookupParameter MaximizationParameter {
get { return (IValueLookupParameter)Parameters["Maximization"]; }
}
public ILookupParameter MoveQualityParameter {
get { return (ILookupParameter)Parameters["MoveQuality"]; }
}
public ValueParameter UseAspirationCriterionParameter {
get { return (ValueParameter)Parameters["UseAspirationCriterion"]; }
}
public BoolValue UseAspirationCriterion {
get { return UseAspirationCriterionParameter.Value; }
set { UseAspirationCriterionParameter.Value = value; }
}
[StorableConstructor]
protected AdditiveMoveTabuChecker(StorableConstructorFlag _) : base(_) { }
protected AdditiveMoveTabuChecker(AdditiveMoveTabuChecker original, Cloner cloner) : base(original, cloner) { }
public AdditiveMoveTabuChecker()
: base() {
Parameters.Add(new LookupParameter("AdditiveMove", "The move to evaluate."));
Parameters.Add(new LookupParameter("MoveTabu", "The variable to store if a move was tabu."));
Parameters.Add(new LookupParameter("RealVector", "The solution as real vector."));
Parameters.Add(new LookupParameter>("TabuList", "The tabu list."));
Parameters.Add(new ValueParameter("UseAspirationCriterion", "Whether to use the aspiration criterion or not.", new BoolValue(true)));
Parameters.Add(new ValueLookupParameter("Maximization", "True if the problem is a maximization problem, else if it is a minimization problem."));
Parameters.Add(new LookupParameter("MoveQuality", "The quality of the current move."));
}
public override IDeepCloneable Clone(Cloner cloner) {
return new AdditiveMoveTabuChecker(this, cloner);
}
public override IOperation Apply() {
ItemList tabuList = TabuListParameter.ActualValue;
AdditiveMove move = AdditiveMoveParameter.ActualValue;
RealVector vector = RealVectorParameter.ActualValue;
double moveQuality = MoveQualityParameter.ActualValue.Value;
bool maximization = MaximizationParameter.ActualValue.Value;
bool useAspiration = UseAspirationCriterion.Value;
bool isTabu = false;
foreach (IItem tabuMove in tabuList) {
AdditiveMoveTabuAttribute attribute = (tabuMove as AdditiveMoveTabuAttribute);
if (attribute != null && attribute.Dimension == move.Dimension) {
if (!useAspiration
|| maximization && moveQuality <= attribute.MoveQuality
|| !maximization && moveQuality >= attribute.MoveQuality) {
double newPos = vector[move.Dimension] + move.MoveDistance;
if (Math.Min(attribute.MovedPosition, attribute.OriginalPosition) < newPos
&& newPos < Math.Max(attribute.MovedPosition, attribute.OriginalPosition)) {
isTabu = true;
break;
}
}
}
}
MoveTabuParameter.ActualValue = new BoolValue(isTabu);
return base.Apply();
}
}
}