1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2016 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.Encodings.PermutationEncoding;
|
---|
26 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
27 | using HeuristicLab.Problems.VehicleRouting.Interfaces;
|
---|
28 |
|
---|
29 | namespace HeuristicLab.Problems.VehicleRouting.Encodings.Alba {
|
---|
30 | [Item("AlbaStochasticTranslocationSingleMoveGenerator", "An operator which generates a single translocation move for a VRP representation. It is implemented as described in Alba, E. and Dorronsoro, B. (2004). Solving the Vehicle Routing Problem by Using Cellular Genetic Algorithms.")]
|
---|
31 | [StorableClass]
|
---|
32 | public sealed class AlbaStochasticTranslocationSingleMoveGenerator : AlbaMoveGenerator, IAlbaTranslocationMoveOperator {
|
---|
33 | [Storable]
|
---|
34 | private TranslocationMoveGenerator generator = new StochasticTranslocationSingleMoveGenerator();
|
---|
35 |
|
---|
36 | public ILookupParameter<TranslocationMove> TranslocationMoveParameter {
|
---|
37 | get {
|
---|
38 | return generator.TranslocationMoveParameter;
|
---|
39 | }
|
---|
40 | }
|
---|
41 |
|
---|
42 | public override ILookupParameter VRPMoveParameter {
|
---|
43 | get { return TranslocationMoveParameter; }
|
---|
44 | }
|
---|
45 |
|
---|
46 | public ILookupParameter<Permutation> PermutationParameter {
|
---|
47 | get {
|
---|
48 | return generator.PermutationParameter;
|
---|
49 | }
|
---|
50 | }
|
---|
51 |
|
---|
52 | public IValueLookupParameter<IntValue> SampleSizeParameter {
|
---|
53 | get { return (IValueLookupParameter<IntValue>)Parameters["SampleSize"]; }
|
---|
54 | }
|
---|
55 |
|
---|
56 | [StorableConstructor]
|
---|
57 | private AlbaStochasticTranslocationSingleMoveGenerator(bool deserializing) : base(deserializing) { }
|
---|
58 |
|
---|
59 | public AlbaStochasticTranslocationSingleMoveGenerator()
|
---|
60 | : base() {
|
---|
61 | }
|
---|
62 |
|
---|
63 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
64 | return new AlbaStochasticTranslocationSingleMoveGenerator(this, cloner);
|
---|
65 | }
|
---|
66 |
|
---|
67 | private AlbaStochasticTranslocationSingleMoveGenerator(AlbaStochasticTranslocationSingleMoveGenerator original, Cloner cloner)
|
---|
68 | : base(original, cloner) {
|
---|
69 | }
|
---|
70 |
|
---|
71 | public override IOperation InstrumentedApply() {
|
---|
72 | IOperation next = base.InstrumentedApply();
|
---|
73 |
|
---|
74 | IVRPEncoding solution = VRPToursParameter.ActualValue;
|
---|
75 |
|
---|
76 | generator.PermutationParameter.ActualName = VRPToursParameter.ActualName;
|
---|
77 | IAtomicOperation op = this.ExecutionContext.CreateChildOperation(generator);
|
---|
78 | op.Operator.Execute((IExecutionContext)op, CancellationToken);
|
---|
79 |
|
---|
80 | foreach (IScope scope in this.ExecutionContext.Scope.SubScopes) {
|
---|
81 | IVariable moveVariable = scope.Variables[
|
---|
82 | TranslocationMoveParameter.ActualName];
|
---|
83 |
|
---|
84 | if (moveVariable.Value is TranslocationMove &&
|
---|
85 | !(moveVariable.Value is AlbaTranslocationMove)) {
|
---|
86 | TranslocationMove move = moveVariable.Value as TranslocationMove;
|
---|
87 | moveVariable.Value =
|
---|
88 | new AlbaTranslocationMove(
|
---|
89 | move.Index1, move.Index2, move.Index3, solution as AlbaEncoding);
|
---|
90 | }
|
---|
91 | }
|
---|
92 |
|
---|
93 | return next;
|
---|
94 | }
|
---|
95 | }
|
---|
96 | }
|
---|