[6093] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[17226] | 3 | * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[6093] | 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 System.Linq;
|
---|
[17717] | 24 | using HEAL.Attic;
|
---|
[6093] | 25 | using HeuristicLab.Collections;
|
---|
| 26 | using HeuristicLab.Common;
|
---|
| 27 | using HeuristicLab.Core;
|
---|
| 28 | using HeuristicLab.Optimization;
|
---|
| 29 | using HeuristicLab.Optimization.Operators;
|
---|
| 30 | using HeuristicLab.Parameters;
|
---|
| 31 | using HeuristicLab.PluginInfrastructure;
|
---|
| 32 | using HeuristicLab.Problems.VehicleRouting.Encodings.General;
|
---|
| 33 | using HeuristicLab.Problems.VehicleRouting.Interfaces;
|
---|
| 34 |
|
---|
| 35 | namespace HeuristicLab.Problems.VehicleRouting {
|
---|
| 36 | [Item("VRPShakingOperator", "A shaking operator for VNS that applies available mutation operators.")]
|
---|
[16723] | 37 | [StorableType("1D7EAC11-693C-4CE0-A4BB-A2C67F364A95")]
|
---|
[6093] | 38 | public class VehicleRoutingShakingOperator : ShakingOperator<IVRPManipulator>, IVRPMultiNeighborhoodShakingOperator, IGeneralVRPOperator, IStochasticOperator {
|
---|
| 39 | #region Parameters
|
---|
[17698] | 40 | public ILookupParameter<IVRPEncodedSolution> VRPToursParameter {
|
---|
| 41 | get { return (ILookupParameter<IVRPEncodedSolution>)Parameters["VRPTours"]; }
|
---|
[6093] | 42 | }
|
---|
| 43 |
|
---|
| 44 | public ILookupParameter<IRandom> RandomParameter {
|
---|
| 45 | get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | public ILookupParameter<IVRPProblemInstance> ProblemInstanceParameter {
|
---|
| 49 | get { return (LookupParameter<IVRPProblemInstance>)Parameters["ProblemInstance"]; }
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | public IVRPProblemInstance ProblemInstance {
|
---|
| 53 | get { return ProblemInstanceParameter.ActualValue; }
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | #endregion
|
---|
| 57 |
|
---|
| 58 | [StorableConstructor]
|
---|
[16723] | 59 | protected VehicleRoutingShakingOperator(StorableConstructorFlag _) : base(_) { }
|
---|
[6093] | 60 | protected VehicleRoutingShakingOperator(VehicleRoutingShakingOperator original, Cloner cloner) : base(original, cloner) { }
|
---|
| 61 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 62 | return new VehicleRoutingShakingOperator(this, cloner);
|
---|
| 63 | }
|
---|
| 64 | public VehicleRoutingShakingOperator()
|
---|
| 65 | : base() {
|
---|
[17698] | 66 | Parameters.Add(new LookupParameter<IVRPEncodedSolution>("VRPTours", "The vrp tour encoding to shake."));
|
---|
[6093] | 67 | Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator that will be used for stochastic shaking operators."));
|
---|
| 68 | Parameters.Add(new LookupParameter<IVRPProblemInstance>("ProblemInstance", "The VRP problem instance"));
|
---|
| 69 |
|
---|
| 70 | foreach (IVRPManipulator shaker in ApplicationManager.Manager.GetInstances<IVRPManipulator>().OrderBy(x => x.Name))
|
---|
[7855] | 71 | if (!(shaker is MultiVRPSolutionManipulator)) Operators.Add(shaker, !(shaker is IVRPLocalSearchManipulator));
|
---|
[6093] | 72 | }
|
---|
| 73 |
|
---|
| 74 | #region Wiring of some parameters
|
---|
| 75 | protected override void Operators_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<IVRPManipulator>> e) {
|
---|
| 76 | base.Operators_ItemsAdded(sender, e);
|
---|
| 77 | ParameterizeOperators(e.Items);
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | protected override void Operators_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<IVRPManipulator>> e) {
|
---|
| 81 | base.Operators_ItemsReplaced(sender, e);
|
---|
| 82 | ParameterizeOperators(e.Items);
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | private void ParameterizeOperators(IEnumerable<IndexedItem<IVRPManipulator>> items) {
|
---|
| 86 | if (items.Any()) {
|
---|
| 87 | foreach (IStochasticOperator op in items.Select(x => x.Value).OfType<IStochasticOperator>())
|
---|
| 88 | op.RandomParameter.ActualName = RandomParameter.Name;
|
---|
| 89 | foreach (IVRPManipulator op in items.Select(x => x.Value).OfType<IVRPManipulator>()) {
|
---|
| 90 | op.VRPToursParameter.ActualName = VRPToursParameter.Name;
|
---|
| 91 | if (op.ProblemInstanceParameter != null) op.ProblemInstanceParameter.ActualName = ProblemInstanceParameter.Name;
|
---|
| 92 | }
|
---|
| 93 | }
|
---|
| 94 | }
|
---|
| 95 | #endregion
|
---|
| 96 | }
|
---|
| 97 | }
|
---|