Free cookie consent management tool by TermsFeed Policy Generator

source: branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Manipulators/PotvinVehicleAssignmentManipulator.cs @ 7865

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

Added vehicle assignment manipulator and move for multi depot instances (#1177)

File size: 3.4 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 System.Collections.Generic;
28using HeuristicLab.Common;
29using HeuristicLab.Problems.VehicleRouting.Interfaces;
30using HeuristicLab.Problems.VehicleRouting.Encodings.General;
31using HeuristicLab.Problems.VehicleRouting.Variants;
32
33namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin {
34  [Item("PotvinVehicleAssignmentMainpulator", "A manipulator that changes the vehicle assignment")]
35  [StorableClass]
36  public sealed class PotvinVehicleAssignmentMainpulator : VRPManipulator, ITimeWindowedOperator,
37    IMultiDepotOperator, IHeterogenousCapacitatedOperator {
38    public IValueParameter<IPermutationManipulator> VehicleAssignmentManipuator {
39      get { return (IValueParameter<IPermutationManipulator>)Parameters["VehicleAssignmentManipuator"]; }
40    }
41
42    public ILookupParameter<Permutation> VehicleAssignmentParameter {
43      get { return (ILookupParameter<Permutation>)Parameters["VehicleAssignment"]; }
44    }
45
46    [StorableConstructor]
47    private PotvinVehicleAssignmentMainpulator(bool deserializing) : base(deserializing) { }
48
49    public PotvinVehicleAssignmentMainpulator()
50      : base() {
51      Parameters.Add(new ValueParameter<IPermutationManipulator>("VehicleAssignmentManipuator",
52      "The operator used to menipulate the vehicle assignments.", new Swap2Manipulator()));
53      Parameters.Add(new LookupParameter<Permutation>("VehicleAssignment"));
54    }
55
56    public override IDeepCloneable Clone(Cloner cloner) {
57      return new PotvinVehicleAssignmentMainpulator(this, cloner);
58    }
59
60    private PotvinVehicleAssignmentMainpulator(PotvinVehicleAssignmentMainpulator original, Cloner cloner)
61      : base(original, cloner) {
62    }
63
64    public override IOperation Apply() {
65      IVRPEncoding solution = VRPToursParameter.ActualValue;
66      if (!(solution is PotvinEncoding)) {
67        VRPToursParameter.ActualValue = PotvinEncoding.ConvertFrom(solution, ProblemInstance);
68      }
69
70      OperationCollection next = new OperationCollection(base.Apply());
71
72      VehicleAssignmentParameter.ActualValue = (VRPToursParameter.ActualValue as PotvinEncoding).VehicleAssignment;
73      VehicleAssignmentManipuator.Value.PermutationParameter.ActualName = VehicleAssignmentParameter.ActualName;
74      next.Insert(0, ExecutionContext.CreateOperation(VehicleAssignmentManipuator.Value));
75
76      return next;
77    }
78  }
79}
Note: See TracBrowser for help on using the repository browser.