#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 System.Linq;
using HeuristicLab.Common;
using HeuristicLab.Core;
using HeuristicLab.Data;
using HeuristicLab.Operators;
using HeuristicLab.Parameters;
using HEAL.Attic;
namespace HeuristicLab.Problems.VehicleRouting {
[Item("BestVRPToursMemorizer", "An operator that updates the best VRP tour found so far in the scope three.")]
[StorableType("3E5AF7DC-B85A-453B-8502-DC4FF45EE637")]
public class BestVRPToursMemorizer : SingleSuccessorOperator {
public ScopeTreeLookupParameter DistanceParameter {
get { return (ScopeTreeLookupParameter)Parameters["Distance"]; }
}
public ScopeTreeLookupParameter VehiclesUtilizedParameter {
get { return (ScopeTreeLookupParameter)Parameters["VehiclesUtilized"]; }
}
public ValueLookupParameter BestDistanceParameter {
get { return (ValueLookupParameter)Parameters["BestDistance"]; }
}
public ValueLookupParameter BestVehiclesUtilizedParameter {
get { return (ValueLookupParameter)Parameters["BestVehiclesUtilized"]; }
}
public BestVRPToursMemorizer()
: base() {
Parameters.Add(new ScopeTreeLookupParameter("Distance", "The distances 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("BestVehiclesUtilized", "The best vehicles utilized found so far."));
}
[StorableConstructor]
protected BestVRPToursMemorizer(StorableConstructorFlag _) : base(_) { }
public override IDeepCloneable Clone(Cloner cloner) {
return new BestVRPToursMemorizer(this, cloner);
}
protected BestVRPToursMemorizer(BestVRPToursMemorizer original, Cloner cloner)
: base(original, cloner) {
}
public override IOperation Apply() {
int 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 = 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();
}
}
}