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 |
|
---|
22 | using System.Collections.Generic;
|
---|
23 | using HeuristicLab.Core;
|
---|
24 | using HeuristicLab.Data;
|
---|
25 | using HeuristicLab.Encodings.PermutationEncoding;
|
---|
26 | using HeuristicLab.Optimization;
|
---|
27 | using HeuristicLab.Parameters;
|
---|
28 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
29 | using HeuristicLab.Problems.VehicleRouting.Interfaces;
|
---|
30 | using HeuristicLab.Common;
|
---|
31 |
|
---|
32 | namespace HeuristicLab.Problems.VehicleRouting.Encodings.Alba {
|
---|
33 | [Item("AlbaTranslocationMoveGenerator", "An operator which generates translocation moves 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.")]
|
---|
34 | [StorableClass]
|
---|
35 | public sealed class AlbaTranslocationMoveGenerator : AlbaMoveGenerator, IAlbaTranslocationMoveOperator, IMultiMoveGenerator {
|
---|
36 | public IValueLookupParameter<TranslocationMoveGenerator> TranslocationMoveGeneratorParameter {
|
---|
37 | get { return (IValueLookupParameter<TranslocationMoveGenerator>)Parameters["TranslocationMoveGenerator"]; }
|
---|
38 | }
|
---|
39 |
|
---|
40 | private IPermutationMoveOperator PermutationMoveOperatorParameter {
|
---|
41 | get { return TranslocationMoveGeneratorParameter.Value; }
|
---|
42 | set {
|
---|
43 | TranslocationMoveGeneratorParameter.Value = value as TranslocationMoveGenerator;
|
---|
44 | if (TranslocationMoveGeneratorParameter.Value is IMultiMoveGenerator) {
|
---|
45 | ((IMultiMoveGenerator)TranslocationMoveGeneratorParameter.Value).SampleSizeParameter.ActualName = SampleSizeParameter.Name;
|
---|
46 | }
|
---|
47 | }
|
---|
48 | }
|
---|
49 |
|
---|
50 | public ILookupParameter<TranslocationMove> TranslocationMoveParameter {
|
---|
51 | get {
|
---|
52 | if (TranslocationMoveGeneratorParameter.Value != null)
|
---|
53 | return TranslocationMoveGeneratorParameter.Value.TranslocationMoveParameter;
|
---|
54 | else
|
---|
55 | return null;
|
---|
56 | }
|
---|
57 | }
|
---|
58 |
|
---|
59 | public override ILookupParameter VRPMoveParameter {
|
---|
60 | get { return TranslocationMoveParameter; }
|
---|
61 | }
|
---|
62 |
|
---|
63 | public ILookupParameter<Permutation> PermutationParameter {
|
---|
64 | get {
|
---|
65 | if (TranslocationMoveGeneratorParameter.Value != null)
|
---|
66 | return TranslocationMoveGeneratorParameter.Value.PermutationParameter;
|
---|
67 | else
|
---|
68 | return null;
|
---|
69 | }
|
---|
70 | }
|
---|
71 |
|
---|
72 | public IValueLookupParameter<IntValue> SampleSizeParameter {
|
---|
73 | get { return (IValueLookupParameter<IntValue>)Parameters["SampleSize"]; }
|
---|
74 | }
|
---|
75 |
|
---|
76 | [StorableConstructor]
|
---|
77 | private AlbaTranslocationMoveGenerator(bool deserializing) : base(deserializing) { }
|
---|
78 |
|
---|
79 | public AlbaTranslocationMoveGenerator()
|
---|
80 | : base() {
|
---|
81 | Parameters.Add(new ValueLookupParameter<TranslocationMoveGenerator>("TranslocationMoveGenerator", "The move generator.",
|
---|
82 | new StochasticTranslocationMultiMoveGenerator()));
|
---|
83 | Parameters.Add(new ValueLookupParameter<IntValue>("SampleSize", "The number of moves to generate."));
|
---|
84 |
|
---|
85 | ((IMultiMoveGenerator)TranslocationMoveGeneratorParameter.Value).SampleSizeParameter.ActualName = SampleSizeParameter.Name;
|
---|
86 | }
|
---|
87 |
|
---|
88 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
89 | return new AlbaTranslocationMoveGenerator(this, cloner);
|
---|
90 | }
|
---|
91 |
|
---|
92 | private AlbaTranslocationMoveGenerator(AlbaTranslocationMoveGenerator original, Cloner cloner)
|
---|
93 | : base(original, cloner) {
|
---|
94 | }
|
---|
95 |
|
---|
96 | public override IOperation Apply() {
|
---|
97 | IOperation next = base.Apply();
|
---|
98 |
|
---|
99 | IVRPEncoding solution = VRPToursParameter.ActualValue;
|
---|
100 |
|
---|
101 | PermutationMoveOperatorParameter.PermutationParameter.ActualName = VRPToursParameter.ActualName;
|
---|
102 | IAtomicOperation op = this.ExecutionContext.CreateChildOperation(PermutationMoveOperatorParameter);
|
---|
103 | op.Operator.Execute((IExecutionContext)op);
|
---|
104 |
|
---|
105 | return next;
|
---|
106 | }
|
---|
107 | }
|
---|
108 | }
|
---|