#region License Information
/* HeuristicLab
* Copyright (C) 2002-2015 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("BestTimeWindowedVRPToursMemorizer", "An operator that updates the best VRP tour found so far in the scope three.")]
[StorableClass]
public class BestTimeWindowedVRPToursMemorizer : SingleSuccessorOperator {
public ScopeTreeLookupParameter TardinessParameter {
get { return (ScopeTreeLookupParameter)Parameters["Tardiness"]; }
}
public ScopeTreeLookupParameter TravelTimeParameter {
get { return (ScopeTreeLookupParameter)Parameters["TravelTime"]; }
}
public ValueLookupParameter BestTardinessParameter {
get { return (ValueLookupParameter)Parameters["BestTardiness"]; }
}
public ValueLookupParameter BestTravelTimeParameter {
get { return (ValueLookupParameter)Parameters["BestTravelTime"]; }
}
public BestTimeWindowedVRPToursMemorizer()
: base() {
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 ValueLookupParameter("BestTardiness", "The best tardiness found so far."));
Parameters.Add(new ValueLookupParameter("BestTravelTime", "The best travel time found so far."));
}
public override IOperation Apply() {
int 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 = 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;
return base.Apply();
}
[StorableConstructor]
protected BestTimeWindowedVRPToursMemorizer(bool deserializing) : base(deserializing) { }
public override IDeepCloneable Clone(Cloner cloner) {
return new BestTimeWindowedVRPToursMemorizer(this, cloner);
}
protected BestTimeWindowedVRPToursMemorizer(BestTimeWindowedVRPToursMemorizer original, Cloner cloner)
: base(original, cloner) {
}
}
}