Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Prins/Crossovers/PrinsCrossover.cs @ 5658

Last change on this file since 5658 was 5445, checked in by swagner, 14 years ago

Updated year of copyrights (#1406)

File size: 4.6 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 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 HeuristicLab.Common;
23using HeuristicLab.Core;
24using HeuristicLab.Data;
25using HeuristicLab.Optimization;
26using HeuristicLab.Parameters;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28
29namespace HeuristicLab.Problems.VehicleRouting.Encodings.Prins {
30  [Item("PrinsCrossover", "An operator which crosses two VRP representations.")]
31  [StorableClass]
32  public abstract class PrinsCrossover : VRPCrossover, IStochasticOperator {
33    public ILookupParameter<DoubleValue> FleetUsageFactor {
34      get { return (ILookupParameter<DoubleValue>)Parameters["EvalFleetUsageFactor"]; }
35    }
36    public ILookupParameter<DoubleValue> TimeFactor {
37      get { return (ILookupParameter<DoubleValue>)Parameters["EvalTimeFactor"]; }
38    }
39    public ILookupParameter<DoubleValue> DistanceFactor {
40      get { return (ILookupParameter<DoubleValue>)Parameters["EvalDistanceFactor"]; }
41    }
42    public ILookupParameter<DoubleValue> OverloadPenalty {
43      get { return (ILookupParameter<DoubleValue>)Parameters["EvalOverloadPenalty"]; }
44    }
45    public ILookupParameter<DoubleValue> TardinessPenalty {
46      get { return (ILookupParameter<DoubleValue>)Parameters["EvalTardinessPenalty"]; }
47    }
48   
49    public ILookupParameter<IRandom> RandomParameter {
50      get { return (LookupParameter<IRandom>)Parameters["Random"]; }
51    }
52   
53    [StorableConstructor]
54    protected PrinsCrossover(bool deserializing) : base(deserializing) { }
55    protected PrinsCrossover(PrinsCrossover original, Cloner cloner) : base(original, cloner) { }
56    public PrinsCrossover()
57      : base() {
58      Parameters.Add(new LookupParameter<DoubleValue>("EvalFleetUsageFactor", "The fleet usage factor considered in the evaluation."));
59      Parameters.Add(new LookupParameter<DoubleValue>("EvalTimeFactor", "The time factor considered in the evaluation."));
60      Parameters.Add(new LookupParameter<DoubleValue>("EvalDistanceFactor", "The distance factor considered in the evaluation."));
61      Parameters.Add(new LookupParameter<DoubleValue>("EvalOverloadPenalty", "The overload penalty considered in the evaluation."));
62      Parameters.Add(new LookupParameter<DoubleValue>("EvalTardinessPenalty", "The tardiness penalty considered in the evaluation."));
63
64      Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic manipulation operators."));
65    }
66
67    protected abstract PrinsEncoding Crossover(IRandom random, PrinsEncoding parent1, PrinsEncoding parent2);
68
69    public override IOperation Apply() {
70      ItemArray<IVRPEncoding> parents = new ItemArray<IVRPEncoding>(ParentsParameter.ActualValue.Length);
71      for (int i = 0; i < ParentsParameter.ActualValue.Length; i++) {
72        IVRPEncoding solution = ParentsParameter.ActualValue[i];
73
74        if (!(solution is PrinsEncoding)) {
75          parents[i] = PrinsEncoding.ConvertFrom(solution,
76            Cities,
77            DueTimeParameter.ActualValue,
78            ServiceTimeParameter.ActualValue,
79            ReadyTimeParameter.ActualValue,
80            DemandParameter.ActualValue,
81            CapacityParameter.ActualValue,
82            FleetUsageFactor.ActualValue,
83            TimeFactor.ActualValue,
84            DistanceFactor.ActualValue,
85            OverloadPenalty.ActualValue,
86            TardinessPenalty.ActualValue,
87            CoordinatesParameter.ActualValue,
88            DistanceMatrixParameter,
89            UseDistanceMatrixParameter.ActualValue);
90        } else {
91          parents[i] = solution;
92        }
93      }
94      ParentsParameter.ActualValue = parents;
95
96      ChildParameter.ActualValue =
97        Crossover(RandomParameter.ActualValue, parents[0] as PrinsEncoding, parents[1] as PrinsEncoding);
98
99      return base.Apply();
100    }
101  }
102}
Note: See TracBrowser for help on using the repository browser.