Free cookie consent management tool by TermsFeed Policy Generator

source: branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/ExtendedPotvin/Manipulators/ExtendedPotvinManipulator.cs @ 6851

Last change on this file since 6851 was 6851, checked in by svonolfe, 13 years ago

Added support for multi depot CVRP instances (#1177)

File size: 4.5 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.Problems.VehicleRouting.Encodings.General;
29using HeuristicLab.Problems.VehicleRouting.Interfaces;
30using HeuristicLab.Common;
31using HeuristicLab.Problems.VehicleRouting.Encodings.Potvin;
32
33namespace HeuristicLab.Problems.VehicleRouting.Encodings.ExtendedPotvin {
34  [Item("ExtendedPotvinManipulator", "A VRP manipulation operation.")]
35  [StorableClass]
36  public class ExtendedPotvinManipulator : VRPManipulator, IStochasticOperator, IExtendedPotvinOperator {
37    public ILookupParameter<IRandom> RandomParameter {
38      get { return (LookupParameter<IRandom>)Parameters["Random"]; }
39    }
40
41    public IValueParameter<PotvinManipulator> ToursManipuator {
42      get { return (IValueParameter<PotvinManipulator>)Parameters["ToursManipuator"]; }
43    }
44
45    public IValueParameter<IPermutationManipulator> VehicleAssignmentManipuator {
46      get { return (IValueParameter<IPermutationManipulator>)Parameters["VehicleAssignmentManipuator"]; }
47    }
48
49    public IValueParameter<PercentValue> VehicleAssignmentMutationRate {
50      get { return (IValueParameter<PercentValue>)Parameters["VehicleAssignmentMutationRate"];}
51    }
52
53    public ILookupParameter<Permutation> VehicleAssignmentParameter {
54      get { return (ILookupParameter<Permutation>)Parameters["VehicleAssignment"]; }
55    }
56
57    [StorableConstructor]
58    protected ExtendedPotvinManipulator(bool deserializing) : base(deserializing) { }
59
60    public ExtendedPotvinManipulator() {
61      Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic manipulation operators."));
62      Parameters.Add(new ValueParameter<PotvinManipulator>("ToursManipuator",
63         "The operator used to menipulate the tours.", new PotvinCustomerRelocationMainpulator()));
64      Parameters.Add(new ValueParameter<IPermutationManipulator>("VehicleAssignmentManipuator",
65        "The operator used to menipulate the vehicle assignments.", new Swap2Manipulator()));
66      Parameters.Add(new LookupParameter<Permutation>("VehicleAssignment"));
67      Parameters.Add(new ValueParameter<PercentValue>("VehicleAssignmentMutationRate", "The mutation rate of the vehicle assignments", new PercentValue(0.1)));
68    }
69
70    protected ExtendedPotvinManipulator(ExtendedPotvinManipulator original, Cloner cloner)
71      : base(original, cloner) {
72    }
73
74    public override IDeepCloneable Clone(Cloner cloner) {
75      return new ExtendedPotvinManipulator(this, cloner);
76    }
77
78    public override IOperation Apply()
79    {
80      IVRPEncoding solution = VRPToursParameter.ActualValue;
81      if (!(solution is ExtendedPotvinEncoding)) {
82        VRPToursParameter.ActualValue = ExtendedPotvinEncoding.ConvertFrom(solution, ProblemInstance);
83      }
84
85      OperationCollection next = new OperationCollection(base.Apply());
86
87      ToursManipuator.Value.VRPToursParameter.ActualName = VRPToursParameter.ActualName;
88      next.Insert(0, ExecutionContext.CreateOperation(ToursManipuator.Value));
89
90      if (RandomParameter.ActualValue.NextDouble() < VehicleAssignmentMutationRate.Value.Value) {
91        VehicleAssignmentParameter.ActualValue = (VRPToursParameter.ActualValue as ExtendedPotvinEncoding).VehicleAssignment;
92        VehicleAssignmentManipuator.Value.PermutationParameter.ActualName = VehicleAssignmentParameter.ActualName;
93        next.Insert(1, ExecutionContext.CreateOperation(VehicleAssignmentManipuator.Value));
94      }
95
96      return next;
97    }
98  }
99}
Note: See TracBrowser for help on using the repository browser.