1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2019 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.Data;
|
---|
25 | using HeuristicLab.Optimization;
|
---|
26 | using HeuristicLab.Parameters;
|
---|
27 | using HEAL.Attic;
|
---|
28 | using HeuristicLab.Problems.VehicleRouting.Interfaces;
|
---|
29 |
|
---|
30 | namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin {
|
---|
31 | [Item("PotvinVehicleAssignmentMoveMaker", "Peforms the vehicle assignment move on a given VRP encoding and updates the quality.")]
|
---|
32 | [StorableType("3D2B1F7F-DCF7-4223-8A91-19A44B6B9EF6")]
|
---|
33 | public class PotvinVehicleAssignmentMoveMaker : PotvinMoveMaker, IPotvinVehicleAssignmentMoveOperator, IMoveMaker {
|
---|
34 | public ILookupParameter<PotvinVehicleAssignmentMove> VehicleAssignmentMoveParameter {
|
---|
35 | get { return (ILookupParameter<PotvinVehicleAssignmentMove>)Parameters["PotvinVehicleAssignmentMove"]; }
|
---|
36 | }
|
---|
37 |
|
---|
38 | public override ILookupParameter VRPMoveParameter {
|
---|
39 | get { return VehicleAssignmentMoveParameter; }
|
---|
40 | }
|
---|
41 |
|
---|
42 | public ILookupParameter<VariableCollection> MemoriesParameter {
|
---|
43 | get { return (ILookupParameter<VariableCollection>)Parameters["Memories"]; }
|
---|
44 | }
|
---|
45 |
|
---|
46 | public IValueParameter<StringValue> AdditionFrequencyMemoryKeyParameter {
|
---|
47 | get { return (IValueParameter<StringValue>)Parameters["AdditionFrequencyMemoryKey"]; }
|
---|
48 | }
|
---|
49 |
|
---|
50 | [StorableConstructor]
|
---|
51 | protected PotvinVehicleAssignmentMoveMaker(StorableConstructorFlag _) : base(_) { }
|
---|
52 |
|
---|
53 | public PotvinVehicleAssignmentMoveMaker()
|
---|
54 | : base() {
|
---|
55 | Parameters.Add(new LookupParameter<PotvinVehicleAssignmentMove>("PotvinVehicleAssignmentMove", "The moves that should be made."));
|
---|
56 |
|
---|
57 | Parameters.Add(new LookupParameter<VariableCollection>("Memories", "The TS memory collection."));
|
---|
58 | Parameters.Add(new ValueParameter<StringValue>("AdditionFrequencyMemoryKey", "The key that is used for the addition frequency in the TS memory.", new StringValue("AdditionFrequency")));
|
---|
59 | }
|
---|
60 |
|
---|
61 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
62 | return new PotvinVehicleAssignmentMoveMaker(this, cloner);
|
---|
63 | }
|
---|
64 |
|
---|
65 | protected PotvinVehicleAssignmentMoveMaker(PotvinVehicleAssignmentMoveMaker original, Cloner cloner)
|
---|
66 | : base(original, cloner) {
|
---|
67 | }
|
---|
68 |
|
---|
69 | public static void Apply(PotvinEncoding solution, PotvinVehicleAssignmentMove move, IVRPProblemInstance problemInstance) {
|
---|
70 | int vehicle1 = solution.VehicleAssignment[move.Tour1];
|
---|
71 | int vehicle2 = solution.VehicleAssignment[move.Tour2];
|
---|
72 |
|
---|
73 | solution.VehicleAssignment[move.Tour1] = vehicle2;
|
---|
74 | solution.VehicleAssignment[move.Tour2] = vehicle1;
|
---|
75 | }
|
---|
76 |
|
---|
77 | protected override void PerformMove() {
|
---|
78 | PotvinVehicleAssignmentMove move = VehicleAssignmentMoveParameter.ActualValue;
|
---|
79 |
|
---|
80 | PotvinEncoding newSolution = move.Individual.Clone() as PotvinEncoding;
|
---|
81 | Apply(newSolution, move, ProblemInstance);
|
---|
82 | newSolution.Repair();
|
---|
83 | VRPToursParameter.ActualValue = newSolution;
|
---|
84 | }
|
---|
85 | }
|
---|
86 | }
|
---|