[3938] | 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;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Linq;
|
---|
| 25 | using System.Text;
|
---|
| 26 | using HeuristicLab.Encodings.PermutationEncoding;
|
---|
| 27 | using HeuristicLab.Optimization;
|
---|
| 28 | using HeuristicLab.Core;
|
---|
| 29 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 30 | using HeuristicLab.Parameters;
|
---|
[3947] | 31 | using HeuristicLab.Data;
|
---|
[3938] | 32 |
|
---|
| 33 | namespace HeuristicLab.Problems.VehicleRouting.Encodings.Alba {
|
---|
| 34 | [Item("AlbaTranslocationMoveGenerator", "An operator which generates translocation moves for the alba representation.")]
|
---|
| 35 | [StorableClass]
|
---|
[3947] | 36 | public sealed class AlbaTranslocationMoveGenerator : AlbaMoveOperator, IPermutationTranslocationMoveOperator, IMultiMoveGenerator {
|
---|
[3938] | 37 | public IValueLookupParameter<TranslocationMoveGenerator> TranslocationMoveGeneratorParameter {
|
---|
| 38 | get { return (IValueLookupParameter<TranslocationMoveGenerator>)Parameters["TranslocationMoveGenerator"]; }
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | protected override IPermutationMoveOperator PermutationMoveOperatorParameter {
|
---|
| 42 | get { return TranslocationMoveGeneratorParameter.Value; }
|
---|
[3947] | 43 | set {
|
---|
| 44 | TranslocationMoveGeneratorParameter.Value = value as TranslocationMoveGenerator;
|
---|
| 45 | if (TranslocationMoveGeneratorParameter.Value is IMultiMoveGenerator) {
|
---|
| 46 | ((IMultiMoveGenerator)TranslocationMoveGeneratorParameter.Value).SampleSizeParameter.ActualName = SampleSizeParameter.Name;
|
---|
| 47 | }
|
---|
| 48 | }
|
---|
[3938] | 49 | }
|
---|
| 50 |
|
---|
| 51 | public ILookupParameter<TranslocationMove> TranslocationMoveParameter {
|
---|
| 52 | get {
|
---|
| 53 | if (TranslocationMoveGeneratorParameter.Value != null)
|
---|
| 54 | return TranslocationMoveGeneratorParameter.Value.TranslocationMoveParameter;
|
---|
| 55 | else
|
---|
| 56 | return null;
|
---|
| 57 | }
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | public ILookupParameter<Permutation> PermutationParameter {
|
---|
| 61 | get {
|
---|
| 62 | if (TranslocationMoveGeneratorParameter.Value != null)
|
---|
| 63 | return TranslocationMoveGeneratorParameter.Value.PermutationParameter;
|
---|
| 64 | else
|
---|
| 65 | return null;
|
---|
| 66 | }
|
---|
| 67 | }
|
---|
| 68 |
|
---|
[3947] | 69 | public IValueLookupParameter<IntValue> SampleSizeParameter {
|
---|
| 70 | get { return (IValueLookupParameter<IntValue>)Parameters["SampleSize"]; }
|
---|
| 71 | }
|
---|
| 72 |
|
---|
[3938] | 73 | public AlbaTranslocationMoveGenerator(): base() {
|
---|
| 74 | Parameters.Add(new ValueLookupParameter<TranslocationMoveGenerator>("TranslocationMoveGenerator", "The move generator.",
|
---|
| 75 | new StochasticTranslocationMultiMoveGenerator()));
|
---|
[3947] | 76 | Parameters.Add(new ValueLookupParameter<IntValue>("SampleSize", "The number of moves to generate."));
|
---|
| 77 |
|
---|
| 78 | ((IMultiMoveGenerator)TranslocationMoveGeneratorParameter.Value).SampleSizeParameter.ActualName = SampleSizeParameter.Name;
|
---|
[3938] | 79 | }
|
---|
| 80 |
|
---|
| 81 | public override IOperation Apply() {
|
---|
| 82 | IOperation successor = base.Apply();
|
---|
| 83 |
|
---|
| 84 | Permutation permutation = VRPSolutionParameter.ActualValue as Permutation;
|
---|
| 85 | string moveName = TranslocationMoveGeneratorParameter.ActualValue.TranslocationMoveParameter.Name;
|
---|
| 86 |
|
---|
| 87 | List<Scope> toBeDeleted = new List<Scope>();
|
---|
| 88 | foreach (Scope scope in this.ExecutionContext.Scope.SubScopes) {
|
---|
| 89 | if (scope.Variables.ContainsKey(moveName)) {
|
---|
| 90 | TranslocationMove move = scope.Variables[moveName].Value as TranslocationMove;
|
---|
| 91 |
|
---|
| 92 | if (move != null) {
|
---|
| 93 | bool criteria1 = true;
|
---|
| 94 | if(move.Index1 - 1 >= 0 &&
|
---|
| 95 | move.Index3 -1 >= 0)
|
---|
| 96 | criteria1 = (permutation[move.Index1] >= 100 &&
|
---|
| 97 | permutation[move.Index1 - 1] >= 100 &&
|
---|
| 98 | permutation[move.Index3 - 1] >= 100);
|
---|
| 99 |
|
---|
| 100 | int index3 = move.Index3 + (move.Index2 - move.Index1) + 1;
|
---|
| 101 | bool criteria2 = true;
|
---|
| 102 | if (move.Index2 + 1 < permutation.Length &&
|
---|
| 103 | index3 < permutation.Length)
|
---|
| 104 | criteria2 = (permutation[move.Index2] >= 100 &&
|
---|
| 105 | permutation[move.Index2 + 1] >= 100 &&
|
---|
| 106 | permutation[index3] >= 100);
|
---|
| 107 |
|
---|
| 108 | if(criteria1 && criteria2)
|
---|
| 109 | toBeDeleted.Add(scope);
|
---|
| 110 | }
|
---|
| 111 | }
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | foreach (Scope scope in toBeDeleted) {
|
---|
| 115 | this.ExecutionContext.Scope.SubScopes.Remove(scope);
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | return successor;
|
---|
| 119 | }
|
---|
| 120 | }
|
---|
| 121 | }
|
---|