[3044] | 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;
|
---|
[3074] | 24 | using System.Linq;
|
---|
[3376] | 25 | using HeuristicLab.Common;
|
---|
[3044] | 26 | using HeuristicLab.Core;
|
---|
| 27 | using HeuristicLab.Data;
|
---|
| 28 | using HeuristicLab.Optimization;
|
---|
| 29 | using HeuristicLab.Operators;
|
---|
| 30 | using HeuristicLab.Optimization.Operators;
|
---|
| 31 | using HeuristicLab.Parameters;
|
---|
| 32 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 33 | using HeuristicLab.PluginInfrastructure;
|
---|
[3368] | 34 | using HeuristicLab.Random;
|
---|
[3044] | 35 |
|
---|
[3100] | 36 | namespace HeuristicLab.Algorithms.TabuSearch {
|
---|
[3280] | 37 | [Item("Tabu Search", "A tabu search algorithm.")]
|
---|
[3074] | 38 | [Creatable("Algorithms")]
|
---|
[3201] | 39 | [StorableClass]
|
---|
[3100] | 40 | public sealed class TabuSearch : EngineAlgorithm {
|
---|
[3074] | 41 | #region Problem Properties
|
---|
| 42 | public override Type ProblemType {
|
---|
| 43 | get { return typeof(ISingleObjectiveProblem); }
|
---|
| 44 | }
|
---|
| 45 | public new ISingleObjectiveProblem Problem {
|
---|
| 46 | get { return (ISingleObjectiveProblem)base.Problem; }
|
---|
| 47 | set { base.Problem = value; }
|
---|
| 48 | }
|
---|
| 49 | #endregion
|
---|
| 50 |
|
---|
| 51 | #region Parameter Properties
|
---|
[3048] | 52 | private ValueParameter<IntValue> SeedParameter {
|
---|
| 53 | get { return (ValueParameter<IntValue>)Parameters["Seed"]; }
|
---|
[3044] | 54 | }
|
---|
[3048] | 55 | private ValueParameter<BoolValue> SetSeedRandomlyParameter {
|
---|
| 56 | get { return (ValueParameter<BoolValue>)Parameters["SetSeedRandomly"]; }
|
---|
[3044] | 57 | }
|
---|
| 58 | private ConstrainedValueParameter<IMoveGenerator> MoveGeneratorParameter {
|
---|
| 59 | get { return (ConstrainedValueParameter<IMoveGenerator>)Parameters["MoveGenerator"]; }
|
---|
| 60 | }
|
---|
[3074] | 61 | private ConstrainedValueParameter<IMoveMaker> MoveMakerParameter {
|
---|
| 62 | get { return (ConstrainedValueParameter<IMoveMaker>)Parameters["MoveMaker"]; }
|
---|
| 63 | }
|
---|
| 64 | private ConstrainedValueParameter<ISingleObjectiveMoveEvaluator> MoveEvaluatorParameter {
|
---|
| 65 | get { return (ConstrainedValueParameter<ISingleObjectiveMoveEvaluator>)Parameters["MoveEvaluator"]; }
|
---|
| 66 | }
|
---|
[3340] | 67 | private ConstrainedValueParameter<ITabuChecker> TabuCheckerParameter {
|
---|
| 68 | get { return (ConstrainedValueParameter<ITabuChecker>)Parameters["TabuChecker"]; }
|
---|
[3074] | 69 | }
|
---|
[3340] | 70 | private ConstrainedValueParameter<ITabuMaker> TabuMakerParameter {
|
---|
| 71 | get { return (ConstrainedValueParameter<ITabuMaker>)Parameters["TabuMaker"]; }
|
---|
[3074] | 72 | }
|
---|
| 73 | private ValueParameter<IntValue> TabuTenureParameter {
|
---|
| 74 | get { return (ValueParameter<IntValue>)Parameters["TabuTenure"]; }
|
---|
| 75 | }
|
---|
[3048] | 76 | private ValueParameter<IntValue> MaximumIterationsParameter {
|
---|
| 77 | get { return (ValueParameter<IntValue>)Parameters["MaximumIterations"]; }
|
---|
[3044] | 78 | }
|
---|
[3141] | 79 | private ValueParameter<IntValue> SampleSizeParameter {
|
---|
| 80 | get { return (ValueParameter<IntValue>)Parameters["SampleSize"]; }
|
---|
| 81 | }
|
---|
[3044] | 82 | #endregion
|
---|
| 83 |
|
---|
| 84 | #region Properties
|
---|
[3048] | 85 | public IntValue Seed {
|
---|
[3044] | 86 | get { return SeedParameter.Value; }
|
---|
| 87 | set { SeedParameter.Value = value; }
|
---|
| 88 | }
|
---|
[3048] | 89 | public BoolValue SetSeedRandomly {
|
---|
[3044] | 90 | get { return SetSeedRandomlyParameter.Value; }
|
---|
| 91 | set { SetSeedRandomlyParameter.Value = value; }
|
---|
| 92 | }
|
---|
| 93 | public IMoveGenerator MoveGenerator {
|
---|
| 94 | get { return MoveGeneratorParameter.Value; }
|
---|
| 95 | set { MoveGeneratorParameter.Value = value; }
|
---|
| 96 | }
|
---|
[3074] | 97 | public IMoveMaker MoveMaker {
|
---|
| 98 | get { return MoveMakerParameter.Value; }
|
---|
| 99 | set { MoveMakerParameter.Value = value; }
|
---|
| 100 | }
|
---|
| 101 | public ISingleObjectiveMoveEvaluator MoveEvaluator {
|
---|
| 102 | get { return MoveEvaluatorParameter.Value; }
|
---|
| 103 | set { MoveEvaluatorParameter.Value = value; }
|
---|
| 104 | }
|
---|
[3340] | 105 | public ITabuChecker TabuChecker {
|
---|
| 106 | get { return TabuCheckerParameter.Value; }
|
---|
| 107 | set { TabuCheckerParameter.Value = value; }
|
---|
[3074] | 108 | }
|
---|
[3340] | 109 | public ITabuMaker TabuMaker {
|
---|
| 110 | get { return TabuMakerParameter.Value; }
|
---|
| 111 | set { TabuMakerParameter.Value = value; }
|
---|
[3074] | 112 | }
|
---|
| 113 | public IntValue TabuTenure {
|
---|
| 114 | get { return TabuTenureParameter.Value; }
|
---|
| 115 | set { TabuTenureParameter.Value = value; }
|
---|
| 116 | }
|
---|
[3048] | 117 | public IntValue MaximumIterations {
|
---|
[3044] | 118 | get { return MaximumIterationsParameter.Value; }
|
---|
| 119 | set { MaximumIterationsParameter.Value = value; }
|
---|
| 120 | }
|
---|
| 121 | private RandomCreator RandomCreator {
|
---|
| 122 | get { return (RandomCreator)OperatorGraph.InitialOperator; }
|
---|
| 123 | }
|
---|
| 124 | private SolutionsCreator SolutionsCreator {
|
---|
| 125 | get { return (SolutionsCreator)RandomCreator.Successor; }
|
---|
| 126 | }
|
---|
[3100] | 127 | private TabuSearchMainLoop MainLoop {
|
---|
| 128 | get { return (TabuSearchMainLoop)SolutionsCreator.Successor; }
|
---|
[3044] | 129 | }
|
---|
| 130 | #endregion
|
---|
| 131 |
|
---|
[3100] | 132 | public TabuSearch()
|
---|
[3044] | 133 | : base() {
|
---|
[3048] | 134 | Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
|
---|
| 135 | Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
|
---|
[3044] | 136 | Parameters.Add(new ConstrainedValueParameter<IMoveGenerator>("MoveGenerator", "The operator used to generate moves to the neighborhood of the current solution."));
|
---|
[3074] | 137 | Parameters.Add(new ConstrainedValueParameter<IMoveMaker>("MoveMaker", "The operator used to perform a move."));
|
---|
| 138 | Parameters.Add(new ConstrainedValueParameter<ISingleObjectiveMoveEvaluator>("MoveEvaluator", "The operator used to evaluate a move."));
|
---|
[3340] | 139 | Parameters.Add(new ConstrainedValueParameter<ITabuChecker>("TabuChecker", "The operator to check whether a move is tabu or not."));
|
---|
| 140 | Parameters.Add(new ConstrainedValueParameter<ITabuMaker>("TabuMaker", "The operator used to insert attributes of a move into the tabu list."));
|
---|
[3074] | 141 | Parameters.Add(new ValueParameter<IntValue>("TabuTenure", "The length of the tabu list.", new IntValue(10)));
|
---|
[3048] | 142 | Parameters.Add(new ValueParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed.", new IntValue(1000)));
|
---|
[3340] | 143 | Parameters.Add(new ValueParameter<IntValue>("SampleSize", "The neighborhood size for stochastic sampling move generators", new IntValue(100)));
|
---|
[3044] | 144 |
|
---|
| 145 | RandomCreator randomCreator = new RandomCreator();
|
---|
| 146 | SolutionsCreator solutionsCreator = new SolutionsCreator();
|
---|
[3100] | 147 | TabuSearchMainLoop tsMainLoop = new TabuSearchMainLoop();
|
---|
[3044] | 148 | OperatorGraph.InitialOperator = randomCreator;
|
---|
| 149 |
|
---|
| 150 | randomCreator.RandomParameter.ActualName = "Random";
|
---|
| 151 | randomCreator.SeedParameter.ActualName = SeedParameter.Name;
|
---|
| 152 | randomCreator.SeedParameter.Value = null;
|
---|
| 153 | randomCreator.SetSeedRandomlyParameter.ActualName = SetSeedRandomlyParameter.Name;
|
---|
| 154 | randomCreator.SetSeedRandomlyParameter.Value = null;
|
---|
| 155 | randomCreator.Successor = solutionsCreator;
|
---|
| 156 |
|
---|
[3048] | 157 | solutionsCreator.NumberOfSolutions = new IntValue(1);
|
---|
[3044] | 158 | solutionsCreator.Successor = tsMainLoop;
|
---|
| 159 |
|
---|
| 160 | tsMainLoop.MoveGeneratorParameter.ActualName = MoveGeneratorParameter.Name;
|
---|
[3074] | 161 | tsMainLoop.MoveMakerParameter.ActualName = MoveMakerParameter.Name;
|
---|
| 162 | tsMainLoop.MoveEvaluatorParameter.ActualName = MoveEvaluatorParameter.Name;
|
---|
[3340] | 163 | tsMainLoop.TabuCheckerParameter.ActualName = TabuCheckerParameter.Name;
|
---|
| 164 | tsMainLoop.TabuMakerParameter.ActualName = TabuMakerParameter.Name;
|
---|
[3074] | 165 | tsMainLoop.MaximumIterationsParameter.ActualName = MaximumIterationsParameter.Name;
|
---|
[3044] | 166 | tsMainLoop.RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
|
---|
| 167 | tsMainLoop.ResultsParameter.ActualName = "Results";
|
---|
| 168 |
|
---|
[3074] | 169 | Initialize();
|
---|
[3044] | 170 | }
|
---|
[3280] | 171 | [StorableConstructor]
|
---|
| 172 | private TabuSearch(bool deserializing) : base(deserializing) { }
|
---|
[3074] | 173 |
|
---|
[3044] | 174 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
[3100] | 175 | TabuSearch clone = (TabuSearch)base.Clone(cloner);
|
---|
[3074] | 176 | clone.Initialize();
|
---|
[3044] | 177 | return clone;
|
---|
| 178 | }
|
---|
| 179 |
|
---|
[3275] | 180 | public override void Prepare() {
|
---|
[3265] | 181 | if (Problem != null && MoveGenerator != null && MoveMaker != null && MoveEvaluator != null &&
|
---|
[3340] | 182 | TabuChecker != null && TabuMaker != null)
|
---|
[3275] | 183 | base.Prepare();
|
---|
[3189] | 184 | }
|
---|
| 185 |
|
---|
[3044] | 186 | #region Events
|
---|
| 187 | protected override void OnProblemChanged() {
|
---|
| 188 | ParameterizeStochasticOperator(Problem.SolutionCreator);
|
---|
| 189 | ParameterizeStochasticOperator(Problem.Evaluator);
|
---|
| 190 | foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
|
---|
[3074] | 191 | foreach (ISingleObjectiveMoveEvaluator op in Problem.Operators.OfType<ISingleObjectiveMoveEvaluator>()) {
|
---|
| 192 | op.MoveQualityParameter.ActualNameChanged += new EventHandler(MoveEvaluator_MoveQualityParameter_ActualNameChanged);
|
---|
| 193 | }
|
---|
[3232] | 194 | foreach (ITabuChecker op in Problem.Operators.OfType<ITabuChecker>()) {
|
---|
[3340] | 195 | op.MoveTabuParameter.ActualNameChanged += new EventHandler(TabuChecker_MoveTabuParameter_ActualNameChanged);
|
---|
[3104] | 196 | }
|
---|
[3044] | 197 | ParameterizeSolutionsCreator();
|
---|
[3104] | 198 | ParameterizeMainLoop();
|
---|
[3187] | 199 | UpdateMoveGenerator();
|
---|
| 200 | UpdateMoveParameters();
|
---|
[3141] | 201 | ParameterizeMoveGenerators();
|
---|
[3074] | 202 | ParameterizeMoveEvaluator();
|
---|
| 203 | ParameterizeMoveMaker();
|
---|
[3340] | 204 | ParameterizeTabuMaker();
|
---|
| 205 | ParameterizeTabuChecker();
|
---|
[3044] | 206 | Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
|
---|
| 207 | base.OnProblemChanged();
|
---|
| 208 | }
|
---|
| 209 | protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) {
|
---|
| 210 | ParameterizeStochasticOperator(Problem.SolutionCreator);
|
---|
| 211 | ParameterizeSolutionsCreator();
|
---|
| 212 | base.Problem_SolutionCreatorChanged(sender, e);
|
---|
| 213 | }
|
---|
| 214 | protected override void Problem_EvaluatorChanged(object sender, EventArgs e) {
|
---|
| 215 | ParameterizeStochasticOperator(Problem.Evaluator);
|
---|
| 216 | ParameterizeSolutionsCreator();
|
---|
[3104] | 217 | ParameterizeMainLoop();
|
---|
[3074] | 218 | ParameterizeMoveEvaluator();
|
---|
| 219 | ParameterizeMoveMaker();
|
---|
[3340] | 220 | ParameterizeTabuMaker();
|
---|
| 221 | ParameterizeTabuChecker();
|
---|
[3044] | 222 | Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
|
---|
| 223 | base.Problem_EvaluatorChanged(sender, e);
|
---|
| 224 | }
|
---|
[3141] | 225 | protected override void Problem_VisualizerChanged(object sender, EventArgs e) {
|
---|
| 226 | ParameterizeStochasticOperator(Problem.Visualizer);
|
---|
| 227 | ParameterizeMainLoop();
|
---|
| 228 | if (Problem.Visualizer != null) Problem.Visualizer.VisualizationParameter.ActualNameChanged += new EventHandler(Visualizer_VisualizationParameter_ActualNameChanged);
|
---|
| 229 | base.Problem_VisualizerChanged(sender, e);
|
---|
| 230 | }
|
---|
[3044] | 231 | protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
|
---|
| 232 | foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
|
---|
[3074] | 233 | // This may seem pointless, but some operators already have the eventhandler registered, others don't
|
---|
| 234 | // FIXME: Is there another way to solve this problem?
|
---|
| 235 | foreach (ISingleObjectiveMoveEvaluator op in Problem.Operators.OfType<ISingleObjectiveMoveEvaluator>()) {
|
---|
| 236 | op.MoveQualityParameter.ActualNameChanged -= new EventHandler(MoveEvaluator_MoveQualityParameter_ActualNameChanged);
|
---|
| 237 | op.MoveQualityParameter.ActualNameChanged += new EventHandler(MoveEvaluator_MoveQualityParameter_ActualNameChanged);
|
---|
| 238 | }
|
---|
[3232] | 239 | foreach (ITabuChecker op in Problem.Operators.OfType<ITabuChecker>()) {
|
---|
[3340] | 240 | op.MoveTabuParameter.ActualNameChanged -= new EventHandler(TabuChecker_MoveTabuParameter_ActualNameChanged);
|
---|
| 241 | op.MoveTabuParameter.ActualNameChanged += new EventHandler(TabuChecker_MoveTabuParameter_ActualNameChanged);
|
---|
[3104] | 242 | }
|
---|
[3074] | 243 | UpdateMoveGenerator();
|
---|
[3187] | 244 | UpdateMoveParameters();
|
---|
[3104] | 245 | ParameterizeMainLoop();
|
---|
[3141] | 246 | ParameterizeMoveGenerators();
|
---|
[3074] | 247 | ParameterizeMoveEvaluator();
|
---|
| 248 | ParameterizeMoveMaker();
|
---|
[3340] | 249 | ParameterizeTabuMaker();
|
---|
| 250 | ParameterizeTabuChecker();
|
---|
[3044] | 251 | base.Problem_OperatorsChanged(sender, e);
|
---|
| 252 | }
|
---|
[3074] | 253 | private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
|
---|
[3104] | 254 | ParameterizeMainLoop();
|
---|
[3074] | 255 | ParameterizeMoveEvaluator();
|
---|
| 256 | ParameterizeMoveMaker();
|
---|
[3340] | 257 | ParameterizeTabuMaker();
|
---|
| 258 | ParameterizeTabuChecker();
|
---|
[3044] | 259 | }
|
---|
[3074] | 260 | private void MoveGeneratorParameter_ValueChanged(object sender, EventArgs e) {
|
---|
| 261 | UpdateMoveParameters();
|
---|
[3044] | 262 | }
|
---|
[3074] | 263 | private void MoveEvaluatorParameter_ValueChanged(object sender, EventArgs e) {
|
---|
[3104] | 264 | ParameterizeMainLoop();
|
---|
[3074] | 265 | ParameterizeMoveEvaluator();
|
---|
| 266 | ParameterizeMoveMaker();
|
---|
[3340] | 267 | ParameterizeTabuMaker();
|
---|
| 268 | ParameterizeTabuChecker();
|
---|
[3044] | 269 | }
|
---|
[3074] | 270 | private void MoveEvaluator_MoveQualityParameter_ActualNameChanged(object sender, EventArgs e) {
|
---|
[3104] | 271 | ParameterizeMainLoop();
|
---|
[3074] | 272 | ParameterizeMoveEvaluator();
|
---|
| 273 | ParameterizeMoveMaker();
|
---|
[3340] | 274 | ParameterizeTabuMaker();
|
---|
| 275 | ParameterizeTabuChecker();
|
---|
[3044] | 276 | }
|
---|
[3340] | 277 | private void TabuCheckerParameter_ValueChanged(object sender, EventArgs e) {
|
---|
[3104] | 278 | ParameterizeMainLoop();
|
---|
| 279 | }
|
---|
[3340] | 280 | private void TabuChecker_MoveTabuParameter_ActualNameChanged(object sender, EventArgs e) {
|
---|
[3104] | 281 | ParameterizeMainLoop();
|
---|
| 282 | }
|
---|
[3141] | 283 | private void Visualizer_VisualizationParameter_ActualNameChanged(object sender, EventArgs e) {
|
---|
| 284 | ParameterizeMainLoop();
|
---|
| 285 | }
|
---|
| 286 | private void SampleSizeParameter_NameChanged(object sender, EventArgs e) {
|
---|
| 287 | ParameterizeMoveGenerators();
|
---|
| 288 | }
|
---|
[3044] | 289 | #endregion
|
---|
| 290 |
|
---|
| 291 | #region Helpers
|
---|
| 292 | [StorableHook(HookType.AfterDeserialization)]
|
---|
[3074] | 293 | private void Initialize() {
|
---|
| 294 | if (Problem != null) {
|
---|
[3044] | 295 | Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
|
---|
[3074] | 296 | foreach (ISingleObjectiveMoveEvaluator op in Problem.Operators.OfType<ISingleObjectiveMoveEvaluator>()) {
|
---|
| 297 | op.MoveQualityParameter.ActualNameChanged += new EventHandler(MoveEvaluator_MoveQualityParameter_ActualNameChanged);
|
---|
| 298 | }
|
---|
[3141] | 299 | if (Problem.Visualizer != null) Problem.Visualizer.VisualizationParameter.ActualNameChanged += new EventHandler(Visualizer_VisualizationParameter_ActualNameChanged);
|
---|
[3074] | 300 | }
|
---|
| 301 | MoveGeneratorParameter.ValueChanged += new EventHandler(MoveGeneratorParameter_ValueChanged);
|
---|
| 302 | MoveEvaluatorParameter.ValueChanged += new EventHandler(MoveEvaluatorParameter_ValueChanged);
|
---|
[3340] | 303 | TabuCheckerParameter.ValueChanged += new EventHandler(TabuCheckerParameter_ValueChanged);
|
---|
[3141] | 304 | SampleSizeParameter.NameChanged += new EventHandler(SampleSizeParameter_NameChanged);
|
---|
[3044] | 305 | }
|
---|
[3074] | 306 | private void UpdateMoveGenerator() {
|
---|
| 307 | IMoveGenerator oldMoveGenerator = MoveGenerator;
|
---|
| 308 | MoveGeneratorParameter.ValidValues.Clear();
|
---|
| 309 | if (Problem != null) {
|
---|
[3141] | 310 | foreach (IMoveGenerator generator in Problem.Operators.OfType<IMoveGenerator>().OrderBy(x => x.Name)) {
|
---|
[3074] | 311 | MoveGeneratorParameter.ValidValues.Add(generator);
|
---|
[3141] | 312 | }
|
---|
[3074] | 313 | }
|
---|
| 314 | if (oldMoveGenerator != null && MoveGeneratorParameter.ValidValues.Any(x => x.GetType() == oldMoveGenerator.GetType()))
|
---|
| 315 | MoveGenerator = MoveGeneratorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveGenerator.GetType());
|
---|
| 316 | if (MoveGenerator == null) {
|
---|
| 317 | ClearMoveParameters();
|
---|
| 318 | }
|
---|
| 319 | }
|
---|
| 320 | private void UpdateMoveParameters() {
|
---|
| 321 | IMoveMaker oldMoveMaker = MoveMaker;
|
---|
| 322 | ISingleObjectiveMoveEvaluator oldMoveEvaluator = MoveEvaluator;
|
---|
[3340] | 323 | ITabuChecker oldTabuMoveEvaluator = TabuChecker;
|
---|
| 324 | ITabuMaker oldTabuMoveMaker = TabuMaker;
|
---|
[3074] | 325 | ClearMoveParameters();
|
---|
[3131] | 326 | if (MoveGenerator != null) {
|
---|
| 327 | List<Type> moveTypes = MoveGenerator.GetType().GetInterfaces().Where(x => typeof(IMoveOperator).IsAssignableFrom(x)).ToList();
|
---|
| 328 | foreach (Type type in moveTypes.ToList()) {
|
---|
| 329 | if (moveTypes.Any(t => t != type && type.IsAssignableFrom(t)))
|
---|
| 330 | moveTypes.Remove(type);
|
---|
| 331 | }
|
---|
| 332 | foreach (Type type in moveTypes) {
|
---|
| 333 | var operators = Problem.Operators.Where(x => type.IsAssignableFrom(x.GetType())).OrderBy(x => x.Name);
|
---|
| 334 | foreach (IMoveMaker moveMaker in operators.OfType<IMoveMaker>())
|
---|
| 335 | MoveMakerParameter.ValidValues.Add(moveMaker);
|
---|
| 336 | foreach (ISingleObjectiveMoveEvaluator moveEvaluator in operators.OfType<ISingleObjectiveMoveEvaluator>())
|
---|
| 337 | MoveEvaluatorParameter.ValidValues.Add(moveEvaluator);
|
---|
[3232] | 338 | foreach (ITabuChecker tabuMoveEvaluator in operators.OfType<ITabuChecker>())
|
---|
[3340] | 339 | TabuCheckerParameter.ValidValues.Add(tabuMoveEvaluator);
|
---|
[3232] | 340 | foreach (ITabuMaker tabuMoveMaker in operators.OfType<ITabuMaker>())
|
---|
[3340] | 341 | TabuMakerParameter.ValidValues.Add(tabuMoveMaker);
|
---|
[3131] | 342 | }
|
---|
| 343 | if (oldMoveMaker != null) {
|
---|
| 344 | IMoveMaker mm = MoveMakerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveMaker.GetType());
|
---|
| 345 | if (mm != null) MoveMaker = mm;
|
---|
| 346 | }
|
---|
| 347 | if (oldMoveEvaluator != null) {
|
---|
| 348 | ISingleObjectiveMoveEvaluator me = MoveEvaluatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveEvaluator.GetType());
|
---|
| 349 | if (me != null) MoveEvaluator = me;
|
---|
| 350 | }
|
---|
| 351 | if (oldTabuMoveMaker != null) {
|
---|
[3340] | 352 | ITabuMaker tmm = TabuMakerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldTabuMoveMaker.GetType());
|
---|
| 353 | if (tmm != null) TabuMaker = tmm;
|
---|
[3131] | 354 | }
|
---|
| 355 | if (oldTabuMoveEvaluator != null) {
|
---|
[3340] | 356 | ITabuChecker tme = TabuCheckerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldTabuMoveEvaluator.GetType());
|
---|
| 357 | if (tme != null) TabuChecker = tme;
|
---|
[3131] | 358 | }
|
---|
[3074] | 359 | }
|
---|
| 360 | }
|
---|
| 361 | private void ClearMoveParameters() {
|
---|
| 362 | MoveMakerParameter.ValidValues.Clear();
|
---|
| 363 | MoveEvaluatorParameter.ValidValues.Clear();
|
---|
[3340] | 364 | TabuCheckerParameter.ValidValues.Clear();
|
---|
| 365 | TabuMakerParameter.ValidValues.Clear();
|
---|
[3074] | 366 | }
|
---|
[3044] | 367 | private void ParameterizeSolutionsCreator() {
|
---|
| 368 | SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
|
---|
| 369 | SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
|
---|
| 370 | }
|
---|
[3104] | 371 | private void ParameterizeMainLoop() {
|
---|
[3141] | 372 | MainLoop.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
|
---|
[3100] | 373 | MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
|
---|
| 374 | MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
[3074] | 375 | if (MoveEvaluator != null)
|
---|
[3100] | 376 | MainLoop.MoveQualityParameter.ActualName = MoveEvaluator.MoveQualityParameter.ActualName;
|
---|
[3340] | 377 | if (TabuChecker != null)
|
---|
| 378 | MainLoop.MoveTabuParameter.ActualName = TabuChecker.MoveTabuParameter.ActualName;
|
---|
[3141] | 379 | MainLoop.VisualizerParameter.ActualName = Problem.VisualizerParameter.Name;
|
---|
| 380 | if (Problem.Visualizer != null)
|
---|
| 381 | MainLoop.VisualizationParameter.ActualName = Problem.Visualizer.VisualizationParameter.ActualName;
|
---|
[3044] | 382 | }
|
---|
| 383 | private void ParameterizeStochasticOperator(IOperator op) {
|
---|
| 384 | if (op is IStochasticOperator)
|
---|
| 385 | ((IStochasticOperator)op).RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
|
---|
| 386 | }
|
---|
[3141] | 387 | private void ParameterizeMoveGenerators() {
|
---|
| 388 | if (Problem != null) {
|
---|
| 389 | foreach (IMultiMoveGenerator generator in Problem.Operators.OfType<IMultiMoveGenerator>())
|
---|
| 390 | generator.SampleSizeParameter.ActualName = SampleSizeParameter.Name;
|
---|
| 391 | }
|
---|
| 392 | }
|
---|
[3074] | 393 | private void ParameterizeMoveEvaluator() {
|
---|
| 394 | foreach (ISingleObjectiveMoveEvaluator op in Problem.Operators.OfType<ISingleObjectiveMoveEvaluator>()) {
|
---|
| 395 | op.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
[3044] | 396 | }
|
---|
| 397 | }
|
---|
[3074] | 398 | private void ParameterizeMoveMaker() {
|
---|
| 399 | foreach (IMoveMaker op in Problem.Operators.OfType<IMoveMaker>()) {
|
---|
| 400 | op.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
| 401 | if (MoveEvaluator != null)
|
---|
| 402 | op.MoveQualityParameter.ActualName = MoveEvaluator.MoveQualityParameter.ActualName;
|
---|
[3044] | 403 | }
|
---|
| 404 | }
|
---|
[3340] | 405 | private void ParameterizeTabuMaker() {
|
---|
| 406 | foreach (ITabuMaker op in Problem.Operators.OfType<ITabuMaker>()) {
|
---|
| 407 | op.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
| 408 | if (MoveEvaluator != null)
|
---|
| 409 | op.MoveQualityParameter.ActualName = MoveEvaluator.MoveQualityParameter.ActualName;
|
---|
| 410 | }
|
---|
| 411 | }
|
---|
| 412 | private void ParameterizeTabuChecker() {
|
---|
| 413 | foreach (ITabuChecker op in Problem.Operators.OfType<ITabuChecker>()) {
|
---|
| 414 | if (MoveEvaluator != null)
|
---|
| 415 | op.MoveQualityParameter.ActualName = MoveEvaluator.MoveQualityParameter.ActualName;
|
---|
| 416 | if (TabuChecker != null)
|
---|
| 417 | op.MoveTabuParameter.ActualName = TabuChecker.MoveTabuParameter.ActualName;
|
---|
| 418 | }
|
---|
| 419 | }
|
---|
[3044] | 420 | #endregion
|
---|
| 421 | }
|
---|
| 422 | }
|
---|