1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2014 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 |
|
---|
22 | using System.Linq;
|
---|
23 | using HeuristicLab.Common;
|
---|
24 | using HeuristicLab.Core;
|
---|
25 | using HeuristicLab.Data;
|
---|
26 | using HeuristicLab.Operators;
|
---|
27 | using HeuristicLab.Parameters;
|
---|
28 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
29 |
|
---|
30 | namespace 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 | }
|
---|