Free cookie consent management tool by TermsFeed Policy Generator

source: branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/General/ShakingOperators/VehicleRoutingShakingOperator.cs @ 7855

Last change on this file since 7855 was 7855, checked in by svonolfe, 12 years ago

Deactivated LS manipulators by default (#1177)

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