Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.VehicleRouting/3.4/Analyzer/BestAverageWorstTours/TimeWindowed/BestTimeWindowedVRPToursMemorizer.cs @ 12694

Last change on this file since 12694 was 12694, checked in by abeham, 9 years ago

#2208: merged trunk changes

File size: 4.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System.Linq;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Operators;
27using HeuristicLab.Parameters;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29
30namespace HeuristicLab.Problems.VehicleRouting {
31  [Item("BestTimeWindowedVRPToursMemorizer", "An operator that updates the best VRP tour found so far in the scope three.")]
32  [StorableClass]
33  public class BestTimeWindowedVRPToursMemorizer : SingleSuccessorOperator {
34    public ScopeTreeLookupParameter<DoubleValue> TardinessParameter {
35      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Tardiness"]; }
36    }
37    public ScopeTreeLookupParameter<DoubleValue> TravelTimeParameter {
38      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["TravelTime"]; }
39    }
40
41    public ValueLookupParameter<DoubleValue> BestTardinessParameter {
42      get { return (ValueLookupParameter<DoubleValue>)Parameters["BestTardiness"]; }
43    }
44    public ValueLookupParameter<DoubleValue> BestTravelTimeParameter {
45      get { return (ValueLookupParameter<DoubleValue>)Parameters["BestTravelTime"]; }
46    }
47
48    public BestTimeWindowedVRPToursMemorizer()
49      : base() {
50      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Tardiness", "The tardiness of the VRP solutions which should be analyzed."));
51      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("TravelTime", "The travel times of the VRP solutions which should be analyzed."));
52
53      Parameters.Add(new ValueLookupParameter<DoubleValue>("BestTardiness", "The best tardiness found so far."));
54      Parameters.Add(new ValueLookupParameter<DoubleValue>("BestTravelTime", "The best travel time found so far."));
55    }
56
57    public override IOperation Apply() {
58      int i = TardinessParameter.ActualValue.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
59      if (BestTardinessParameter.ActualValue == null)
60        BestTardinessParameter.ActualValue = new DoubleValue(TardinessParameter.ActualValue[i].Value);
61      else if (TardinessParameter.ActualValue[i].Value <= BestTardinessParameter.ActualValue.Value)
62        BestTardinessParameter.ActualValue.Value = TardinessParameter.ActualValue[i].Value;
63
64      i = TravelTimeParameter.ActualValue.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
65      if (BestTravelTimeParameter.ActualValue == null)
66        BestTravelTimeParameter.ActualValue = new DoubleValue(TravelTimeParameter.ActualValue[i].Value);
67      else if (TravelTimeParameter.ActualValue[i].Value <= BestTravelTimeParameter.ActualValue.Value)
68        BestTravelTimeParameter.ActualValue.Value = TravelTimeParameter.ActualValue[i].Value;
69
70      return base.Apply();
71    }
72
73    [StorableConstructor]
74    protected BestTimeWindowedVRPToursMemorizer(bool deserializing) : base(deserializing) { }
75
76    public override IDeepCloneable Clone(Cloner cloner) {
77      return new BestTimeWindowedVRPToursMemorizer(this, cloner);
78    }
79
80    protected BestTimeWindowedVRPToursMemorizer(BestTimeWindowedVRPToursMemorizer original, Cloner cloner)
81      : base(original, cloner) {
82    }
83  }
84}
Note: See TracBrowser for help on using the repository browser.