Free cookie consent management tool by TermsFeed Policy Generator

source: branches/CloningRefactoring/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Prins/Crossovers/PrinsCrossover.cs @ 4691

Last change on this file since 4691 was 4686, checked in by abeham, 14 years ago

#922

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