1 | #region License Information |
---|
2 | /* HeuristicLab |
---|
3 | * Copyright (C) 2002-2013 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 HeuristicLab.Common; |
---|
23 | using HeuristicLab.Core; |
---|
24 | using HeuristicLab.Encodings.PermutationEncoding; |
---|
25 | using HeuristicLab.Parameters; |
---|
26 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; |
---|
27 | using HeuristicLab.Problems.VehicleRouting.Encodings.General; |
---|
28 | using HeuristicLab.Problems.VehicleRouting.Interfaces; |
---|
29 | using HeuristicLab.Problems.VehicleRouting.Variants; |
---|
30 | |
---|
31 | namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin { |
---|
32 | [Item("PotvinVehicleAssignmentMainpulator", "A manipulator that changes the vehicle assignment")] |
---|
33 | [StorableClass] |
---|
34 | public sealed class PotvinVehicleAssignmentMainpulator : VRPManipulator, ITimeWindowedOperator, |
---|
35 | IMultiDepotOperator, IHeterogenousCapacitatedOperator { |
---|
36 | public IValueParameter<IPermutationManipulator> VehicleAssignmentManipuator { |
---|
37 | get { return (IValueParameter<IPermutationManipulator>)Parameters["VehicleAssignmentManipuator"]; } |
---|
38 | } |
---|
39 | |
---|
40 | public ILookupParameter<Permutation> VehicleAssignmentParameter { |
---|
41 | get { return (ILookupParameter<Permutation>)Parameters["VehicleAssignment"]; } |
---|
42 | } |
---|
43 | |
---|
44 | [StorableConstructor] |
---|
45 | private PotvinVehicleAssignmentMainpulator(bool deserializing) : base(deserializing) { } |
---|
46 | |
---|
47 | public PotvinVehicleAssignmentMainpulator() |
---|
48 | : base() { |
---|
49 | Parameters.Add(new ValueParameter<IPermutationManipulator>("VehicleAssignmentManipuator", |
---|
50 | "The operator used to menipulate the vehicle assignments.", new Swap2Manipulator())); |
---|
51 | Parameters.Add(new LookupParameter<Permutation>("VehicleAssignment")); |
---|
52 | } |
---|
53 | |
---|
54 | public override IDeepCloneable Clone(Cloner cloner) { |
---|
55 | return new PotvinVehicleAssignmentMainpulator(this, cloner); |
---|
56 | } |
---|
57 | |
---|
58 | private PotvinVehicleAssignmentMainpulator(PotvinVehicleAssignmentMainpulator original, Cloner cloner) |
---|
59 | : base(original, cloner) { |
---|
60 | } |
---|
61 | |
---|
62 | public override IOperation InstrumentedApply() { |
---|
63 | IVRPEncoding solution = VRPToursParameter.ActualValue; |
---|
64 | if (!(solution is PotvinEncoding)) { |
---|
65 | VRPToursParameter.ActualValue = PotvinEncoding.ConvertFrom(solution, ProblemInstance); |
---|
66 | } |
---|
67 | |
---|
68 | OperationCollection next = new OperationCollection(base.InstrumentedApply()); |
---|
69 | |
---|
70 | VehicleAssignmentParameter.ActualValue = (VRPToursParameter.ActualValue as PotvinEncoding).VehicleAssignment; |
---|
71 | VehicleAssignmentManipuator.Value.PermutationParameter.ActualName = VehicleAssignmentParameter.ActualName; |
---|
72 | next.Insert(0, ExecutionContext.CreateOperation(VehicleAssignmentManipuator.Value)); |
---|
73 | |
---|
74 | return next; |
---|
75 | } |
---|
76 | } |
---|
77 | } |
---|