[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;
|
---|
[4068] | 23 | using HeuristicLab.Common;
|
---|
[3938] | 24 | using HeuristicLab.Core;
|
---|
| 25 | using HeuristicLab.Data;
|
---|
[4068] | 26 | using HeuristicLab.Encodings.PermutationEncoding;
|
---|
| 27 | using HeuristicLab.Optimization;
|
---|
[3938] | 28 | using HeuristicLab.Parameters;
|
---|
| 29 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 30 |
|
---|
| 31 | namespace HeuristicLab.Problems.VehicleRouting.Encodings.Alba {
|
---|
[4177] | 32 | [Item("AlbaPermutationCreator", "An operator which creates a new Alba VRP representation.")]
|
---|
[3938] | 33 | [StorableClass]
|
---|
| 34 | public sealed class AlbaPermutationCreator : VRPCreator, IStochasticOperator {
|
---|
| 35 | public IValueLookupParameter<IPermutationCreator> PermutationCreatorParameter {
|
---|
| 36 | get { return (IValueLookupParameter<IPermutationCreator>)Parameters["PermutationCreatorParameter"]; }
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | #region IStochasticOperator Members
|
---|
| 40 | public ILookupParameter<IRandom> RandomParameter {
|
---|
| 41 | get { return (LookupParameter<IRandom>)Parameters["Random"]; }
|
---|
| 42 | }
|
---|
| 43 | #endregion
|
---|
[4068] | 44 |
|
---|
[3938] | 45 | public AlbaPermutationCreator()
|
---|
| 46 | : base() {
|
---|
| 47 | Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator."));
|
---|
| 48 | Parameters.Add(new ValueLookupParameter<IPermutationCreator>("PermutationCreatorParameter", "The permutation creator.", new RandomPermutationCreator()));
|
---|
| 49 |
|
---|
[3991] | 50 | Initialize();
|
---|
[3938] | 51 | ParameterizeSolutionCreator();
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | [StorableConstructor]
|
---|
| 55 | private AlbaPermutationCreator(bool deserializing) : base() { }
|
---|
| 56 |
|
---|
| 57 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 58 | private void Initialize() {
|
---|
| 59 | CitiesParameter.ValueChanged += new EventHandler(CitiesParameter_ValueChanged);
|
---|
[4068] | 60 | if (CitiesParameter.Value != null)
|
---|
| 61 | CitiesParameter.Value.ValueChanged += new EventHandler(CitiesValue_ValueChanged);
|
---|
[3938] | 62 | }
|
---|
| 63 |
|
---|
| 64 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 65 | AlbaPermutationCreator clone = (AlbaPermutationCreator)base.Clone(cloner);
|
---|
| 66 | clone.Initialize();
|
---|
| 67 | return clone;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | void CitiesParameter_ValueChanged(object sender, EventArgs e) {
|
---|
| 71 | CitiesParameter.Value.ValueChanged += new EventHandler(CitiesValue_ValueChanged);
|
---|
| 72 | ParameterizeSolutionCreator();
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | void CitiesValue_ValueChanged(object sender, EventArgs e) {
|
---|
| 76 | ParameterizeSolutionCreator();
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | private void ParameterizeSolutionCreator() {
|
---|
| 80 | PermutationCreatorParameter.Value.PermutationTypeParameter.Value = new PermutationType(PermutationTypes.RelativeUndirected);
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | public override IOperation Apply() {
|
---|
| 84 | PermutationCreatorParameter.Value.LengthParameter.Value = new IntValue(CitiesParameter.Value.Value + VehiclesParameter.ActualValue.Value - 1);
|
---|
| 85 |
|
---|
| 86 | IPermutationCreator creator = PermutationCreatorParameter.ActualValue;
|
---|
| 87 | IAtomicOperation op = this.ExecutionContext.CreateOperation(creator);
|
---|
| 88 | op.Operator.Execute((IExecutionContext)op);
|
---|
| 89 |
|
---|
| 90 | Permutation permutation = ExecutionContext.Scope.Variables["Permutation"].Value as Permutation;
|
---|
| 91 | ExecutionContext.Scope.Variables.Remove("Permutation");
|
---|
| 92 |
|
---|
| 93 | VRPSolutionParameter.ActualValue = new AlbaEncoding(permutation, CitiesParameter.ActualValue.Value);
|
---|
| 94 |
|
---|
| 95 | return base.Apply();
|
---|
| 96 | }
|
---|
| 97 | }
|
---|
| 98 | }
|
---|