[4383] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[17180] | 3 | * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[4383] | 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 |
|
---|
[8053] | 22 | using HeuristicLab.Common;
|
---|
[4383] | 23 | using HeuristicLab.Core;
|
---|
| 24 | using HeuristicLab.Data;
|
---|
| 25 | using HeuristicLab.Encodings.PermutationEncoding;
|
---|
[16565] | 26 | using HEAL.Attic;
|
---|
[4383] | 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.")]
|
---|
[16565] | 31 | [StorableType("AB2D93A5-BECF-4ABE-B704-5DA883426CAF")]
|
---|
[5867] | 32 | public sealed class AlbaStochasticTranslocationSingleMoveGenerator : AlbaMoveGenerator, IAlbaTranslocationMoveOperator {
|
---|
[5130] | 33 | [Storable]
|
---|
[4383] | 34 | private TranslocationMoveGenerator generator = new StochasticTranslocationSingleMoveGenerator();
|
---|
[8053] | 35 |
|
---|
[4383] | 36 | public ILookupParameter<TranslocationMove> TranslocationMoveParameter {
|
---|
| 37 | get {
|
---|
[8053] | 38 | return generator.TranslocationMoveParameter;
|
---|
[4383] | 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]
|
---|
[16565] | 57 | private AlbaStochasticTranslocationSingleMoveGenerator(StorableConstructorFlag _) : base(_) { }
|
---|
[4383] | 58 |
|
---|
| 59 | public AlbaStochasticTranslocationSingleMoveGenerator()
|
---|
| 60 | : base() {
|
---|
| 61 | }
|
---|
| 62 |
|
---|
[4752] | 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 |
|
---|
[10298] | 71 | public override IOperation InstrumentedApply() {
|
---|
| 72 | IOperation next = base.InstrumentedApply();
|
---|
[4383] | 73 |
|
---|
| 74 | IVRPEncoding solution = VRPToursParameter.ActualValue;
|
---|
| 75 |
|
---|
| 76 | generator.PermutationParameter.ActualName = VRPToursParameter.ActualName;
|
---|
| 77 | IAtomicOperation op = this.ExecutionContext.CreateChildOperation(generator);
|
---|
[5867] | 78 | op.Operator.Execute((IExecutionContext)op, CancellationToken);
|
---|
[4383] | 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 | }
|
---|