Free cookie consent management tool by TermsFeed Policy Generator

source: branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Alba/Moves/ThreeOpt/AlbaTranslocationMoveGenerator.cs @ 5201

Last change on this file since 5201 was 4752, checked in by svonolfe, 14 years ago

Merged relevant changes from the trunk into the branch (cloning,...) (#1177)

File size: 4.5 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 System.Collections.Generic;
23using HeuristicLab.Core;
24using HeuristicLab.Data;
25using HeuristicLab.Encodings.PermutationEncoding;
26using HeuristicLab.Optimization;
27using HeuristicLab.Parameters;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29using HeuristicLab.Problems.VehicleRouting.Interfaces;
30using HeuristicLab.Common;
31
32namespace 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}
Note: See TracBrowser for help on using the repository browser.