Free cookie consent management tool by TermsFeed Policy Generator

source: branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Moves/VehicleAssignment/PotvinVehicleAssignmentMoveMaker.cs @ 12440

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

Merged changes from trunk into branch (#1177)

File size: 3.9 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.Data;
24using HeuristicLab.Operators;
25using HeuristicLab.Optimization;
26using HeuristicLab.Parameters;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28using HeuristicLab.Common;
29using HeuristicLab.Problems.VehicleRouting.ProblemInstances;
30using HeuristicLab.Problems.VehicleRouting.Interfaces;
31using HeuristicLab.Problems.VehicleRouting.Variants;
32
33namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin {
34  [Item("PotvinVehicleAssignmentMoveMaker", "Peforms the vehicle assignment move on a given VRP encoding and updates the quality.")]
35  [StorableClass]
36  public class PotvinVehicleAssignmentMoveMaker : PotvinMoveMaker, IPotvinVehicleAssignmentMoveOperator, IMoveMaker {
37    public ILookupParameter<PotvinVehicleAssignmentMove> VehicleAssignmentMoveParameter {
38      get { return (ILookupParameter<PotvinVehicleAssignmentMove>)Parameters["PotvinVehicleAssignmentMove"]; }
39    }
40
41    public override ILookupParameter VRPMoveParameter {
42         get { return VehicleAssignmentMoveParameter; }
43    }
44
45    public ILookupParameter<VariableCollection> MemoriesParameter {
46      get { return (ILookupParameter<VariableCollection>)Parameters["Memories"]; }
47    }
48
49    public IValueParameter<StringValue> AdditionFrequencyMemoryKeyParameter {
50      get { return (IValueParameter<StringValue>)Parameters["AdditionFrequencyMemoryKey"]; }
51    }
52
53    [StorableConstructor]
54    protected PotvinVehicleAssignmentMoveMaker(bool deserializing) : base(deserializing) { }
55
56    public PotvinVehicleAssignmentMoveMaker()
57      : base() {
58      Parameters.Add(new LookupParameter<PotvinVehicleAssignmentMove>("PotvinVehicleAssignmentMove", "The moves that should be made."));
59
60      Parameters.Add(new LookupParameter<VariableCollection>("Memories", "The TS memory collection."));
61      Parameters.Add(new ValueParameter<StringValue>("AdditionFrequencyMemoryKey", "The key that is used for the addition frequency in the TS memory.", new StringValue("AdditionFrequency")));
62    }
63
64    public override IDeepCloneable Clone(Cloner cloner) {
65      return new PotvinVehicleAssignmentMoveMaker(this, cloner);
66    }
67
68    protected PotvinVehicleAssignmentMoveMaker(PotvinVehicleAssignmentMoveMaker original, Cloner cloner)
69      : base(original, cloner) {
70    }
71
72    public static void Apply(PotvinEncoding solution, PotvinVehicleAssignmentMove move, IVRPProblemInstance problemInstance) {
73      int vehicle1 = solution.VehicleAssignment[move.Tour1];
74      int vehicle2 = solution.VehicleAssignment[move.Tour2];
75
76      solution.VehicleAssignment[move.Tour1] = vehicle2;
77      solution.VehicleAssignment[move.Tour2] = vehicle1;
78    }
79
80    protected override void PerformMove() {
81      PotvinVehicleAssignmentMove move = VehicleAssignmentMoveParameter.ActualValue;
82
83      PotvinEncoding newSolution = move.Individual.Clone() as PotvinEncoding;
84      Apply(newSolution, move, ProblemInstance);
85      newSolution.Repair();
86      VRPToursParameter.ActualValue = newSolution;
87    }
88  }
89}
Note: See TracBrowser for help on using the repository browser.