#region License Information
/* HeuristicLab
* Copyright (C) 2002-2019 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.Operators;
using HeuristicLab.Optimization;
using HeuristicLab.Parameters;
using HEAL.Attic;
using HeuristicLab.Problems.VehicleRouting.Interfaces;
namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin {
[Item("PotvinVehicleAssignmentMoveTabuMaker", "Declares a given vehicle assignment move as tabu.")]
[StorableType("7E620554-BA0A-49E1-ACD4-4BF4966F6EE5")]
public class PotvinVehicleAssignmentMoveTabuMaker : SingleSuccessorOperator, ITabuMaker, IPotvinVehicleAssignmentMoveOperator, IPotvinOperator, ISingleObjectiveOperator {
public LookupParameter> TabuListParameter {
get { return (LookupParameter>)Parameters["TabuList"]; }
}
public ValueLookupParameter TabuTenureParameter {
get { return (ValueLookupParameter)Parameters["TabuTenure"]; }
}
public ILookupParameter MoveQualityParameter {
get { return (ILookupParameter)Parameters["MoveQuality"]; }
}
public ILookupParameter QualityParameter {
get { return (ILookupParameter)Parameters["Quality"]; }
}
public IValueLookupParameter MaximizationParameter {
get { return (IValueLookupParameter)Parameters["Maximization"]; }
}
public ILookupParameter VehicleAssignmentMoveParameter {
get { return (ILookupParameter)Parameters["PotvinVehicleAssignmentMove"]; }
}
public ILookupParameter VRPMoveParameter {
get { return VehicleAssignmentMoveParameter; }
}
public ILookupParameter VRPToursParameter {
get { return (ILookupParameter)Parameters["VRPTours"]; }
}
public ILookupParameter ProblemInstanceParameter {
get { return (LookupParameter)Parameters["ProblemInstance"]; }
}
public ILookupParameter DistanceParameter {
get { return (ILookupParameter)Parameters["Distance"]; }
}
public ILookupParameter OverloadParameter {
get { return (ILookupParameter)Parameters["Overload"]; }
}
public ILookupParameter TardinessParameter {
get { return (ILookupParameter)Parameters["Tardiness"]; }
}
[StorableConstructor]
protected PotvinVehicleAssignmentMoveTabuMaker(StorableConstructorFlag _) : base(_) { }
protected PotvinVehicleAssignmentMoveTabuMaker(PotvinVehicleAssignmentMoveTabuMaker original, Cloner cloner) : base(original, cloner) { }
public PotvinVehicleAssignmentMoveTabuMaker()
: base() {
Parameters.Add(new LookupParameter>("TabuList", "The tabu list where move attributes are stored."));
Parameters.Add(new ValueLookupParameter("TabuTenure", "The tenure of the tabu list."));
Parameters.Add(new LookupParameter("MoveQuality", "The quality of the move."));
Parameters.Add(new LookupParameter("Quality", "The quality of the solution."));
Parameters.Add(new ValueLookupParameter("Maximization", "True if the problem is a maximization problem, else if it is a minimization problem."));
Parameters.Add(new LookupParameter("PotvinVehicleAssignmentMove", "The moves that should be made."));
Parameters.Add(new LookupParameter("VRPTours", "The VRP tours considered in the move."));
Parameters.Add(new LookupParameter("ProblemInstance", "The VRP problem instance"));
Parameters.Add(new LookupParameter("Distance", "The distance of the individual"));
Parameters.Add(new LookupParameter("Overload", "The overload of the individual"));
Parameters.Add(new LookupParameter("Tardiness", "The tardiness of the individual"));
}
public override IDeepCloneable Clone(Cloner cloner) {
return new PotvinVehicleAssignmentMoveTabuMaker(this, cloner);
}
public override IOperation Apply() {
ItemList tabuList = TabuListParameter.ActualValue;
int tabuTenure = TabuTenureParameter.ActualValue.Value;
int overlength = tabuList.Count - tabuTenure;
if (overlength >= 0) {
for (int i = 0; i < tabuTenure - 1; i++)
tabuList[i] = tabuList[i + overlength + 1];
while (tabuList.Count >= tabuTenure)
tabuList.RemoveAt(tabuList.Count - 1);
}
PotvinVehicleAssignmentMove move = VehicleAssignmentMoveParameter.ActualValue;
double moveQuality = MoveQualityParameter.ActualValue.Value;
double quality = QualityParameter.ActualValue.Value;
double baseQuality = moveQuality;
if (quality < moveQuality) baseQuality = quality; // we make an uphill move, the lower bound is the solution quality
double distance = 0;
if (DistanceParameter.ActualValue != null)
distance = DistanceParameter.ActualValue.Value;
double overload = 0;
if (OverloadParameter.ActualValue != null)
overload = OverloadParameter.ActualValue.Value;
double tardiness = 0;
if (TardinessParameter.ActualValue != null)
tardiness = TardinessParameter.ActualValue.Value;
tabuList.Add(new PotvinVehicleAssignmentMoveAttribute(baseQuality, move.Tour1, move.Individual.GetVehicleAssignment(move.Tour1),
distance, overload, tardiness));
tabuList.Add(new PotvinVehicleAssignmentMoveAttribute(baseQuality, move.Tour2, move.Individual.GetVehicleAssignment(move.Tour2),
distance, overload, tardiness));
return base.Apply();
}
}
}