#region License Information
/* HeuristicLab
* Copyright (C) 2002-2013 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.Linq;
using HeuristicLab.Common;
using HeuristicLab.Core;
using HeuristicLab.Data;
using HeuristicLab.Operators;
using HeuristicLab.Parameters;
using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
namespace HeuristicLab.Problems.VehicleRouting {
[Item("BestVRPToursMemorizer", "An operator that updates the best VRP tour found so far in the scope three.")]
[StorableClass]
public class BestVRPToursMemorizer : SingleSuccessorOperator {
public ScopeTreeLookupParameter OverloadParameter {
get { return (ScopeTreeLookupParameter)Parameters["Overload"]; }
}
public ScopeTreeLookupParameter TardinessParameter {
get { return (ScopeTreeLookupParameter)Parameters["Tardiness"]; }
}
public ScopeTreeLookupParameter DistanceParameter {
get { return (ScopeTreeLookupParameter)Parameters["Distance"]; }
}
public ScopeTreeLookupParameter TravelTimeParameter {
get { return (ScopeTreeLookupParameter)Parameters["TravelTime"]; }
}
public ScopeTreeLookupParameter VehiclesUtilizedParameter {
get { return (ScopeTreeLookupParameter)Parameters["VehiclesUtilized"]; }
}
public ValueLookupParameter BestOverloadParameter {
get { return (ValueLookupParameter)Parameters["BestOverload"]; }
}
public ValueLookupParameter BestTardinessParameter {
get { return (ValueLookupParameter)Parameters["BestTardiness"]; }
}
public ValueLookupParameter BestDistanceParameter {
get { return (ValueLookupParameter)Parameters["BestDistance"]; }
}
public ValueLookupParameter BestTravelTimeParameter {
get { return (ValueLookupParameter)Parameters["BestTravelTime"]; }
}
public ValueLookupParameter BestVehiclesUtilizedParameter {
get { return (ValueLookupParameter)Parameters["BestVehiclesUtilized"]; }
}
[StorableConstructor]
protected BestVRPToursMemorizer(bool deserializing) : base(deserializing) { }
protected BestVRPToursMemorizer(BestVRPToursMemorizer original, Cloner cloner)
: base(original, cloner) {
}
public BestVRPToursMemorizer()
: base() {
Parameters.Add(new ScopeTreeLookupParameter("Distance", "The distances of the VRP solutions which should be analyzed."));
Parameters.Add(new ScopeTreeLookupParameter("Overload", "The overloads of the VRP solutions which should be analyzed."));
Parameters.Add(new ScopeTreeLookupParameter("Tardiness", "The tardiness of the VRP solutions which should be analyzed."));
Parameters.Add(new ScopeTreeLookupParameter("TravelTime", "The travel times of the VRP solutions which should be analyzed."));
Parameters.Add(new ScopeTreeLookupParameter("VehiclesUtilized", "The utilized vehicles of the VRP solutions which should be analyzed."));
Parameters.Add(new ValueLookupParameter("BestDistance", "The best distance found so far."));
Parameters.Add(new ValueLookupParameter("BestOverload", "The best overload found so far."));
Parameters.Add(new ValueLookupParameter("BestTardiness", "The best tardiness found so far."));
Parameters.Add(new ValueLookupParameter("BestTravelTime", "The best travel time found so far."));
Parameters.Add(new ValueLookupParameter("BestVehiclesUtilized", "The best vehicles utilized found so far."));
}
public override IDeepCloneable Clone(Cloner cloner) {
return new BestVRPToursMemorizer(this, cloner);
}
public override IOperation Apply() {
int i = OverloadParameter.ActualValue.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
if (BestOverloadParameter.ActualValue == null)
BestOverloadParameter.ActualValue = new DoubleValue(OverloadParameter.ActualValue[i].Value);
else if(OverloadParameter.ActualValue[i].Value <= BestOverloadParameter.ActualValue.Value)
BestOverloadParameter.ActualValue.Value = OverloadParameter.ActualValue[i].Value;
i = TardinessParameter.ActualValue.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
if (BestTardinessParameter.ActualValue == null)
BestTardinessParameter.ActualValue = new DoubleValue(TardinessParameter.ActualValue[i].Value);
else if (TardinessParameter.ActualValue[i].Value <= BestTardinessParameter.ActualValue.Value)
BestTardinessParameter.ActualValue.Value = TardinessParameter.ActualValue[i].Value;
i = DistanceParameter.ActualValue.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
if (BestDistanceParameter.ActualValue == null)
BestDistanceParameter.ActualValue = new DoubleValue(DistanceParameter.ActualValue[i].Value);
else if (DistanceParameter.ActualValue[i].Value <= BestDistanceParameter.ActualValue.Value)
BestDistanceParameter.ActualValue.Value = DistanceParameter.ActualValue[i].Value;
i = TravelTimeParameter.ActualValue.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
if (BestTravelTimeParameter.ActualValue == null)
BestTravelTimeParameter.ActualValue = new DoubleValue(TravelTimeParameter.ActualValue[i].Value);
else if (TravelTimeParameter.ActualValue[i].Value <= BestTravelTimeParameter.ActualValue.Value)
BestTravelTimeParameter.ActualValue.Value = TravelTimeParameter.ActualValue[i].Value;
i = VehiclesUtilizedParameter.ActualValue.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
if (BestVehiclesUtilizedParameter.ActualValue == null)
BestVehiclesUtilizedParameter.ActualValue = new DoubleValue(VehiclesUtilizedParameter.ActualValue[i].Value);
else if (VehiclesUtilizedParameter.ActualValue[i].Value <= BestVehiclesUtilizedParameter.ActualValue.Value)
BestVehiclesUtilizedParameter.ActualValue.Value = VehiclesUtilizedParameter.ActualValue[i].Value;
return base.Apply();
}
}
}