[3044] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[5445] | 3 | * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[3044] | 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;
|
---|
[4068] | 25 | using HeuristicLab.Analysis;
|
---|
[3376] | 26 | using HeuristicLab.Common;
|
---|
[3044] | 27 | using HeuristicLab.Core;
|
---|
| 28 | using HeuristicLab.Data;
|
---|
[5356] | 29 | using HeuristicLab.Operators;
|
---|
[3044] | 30 | using HeuristicLab.Optimization;
|
---|
| 31 | using HeuristicLab.Optimization.Operators;
|
---|
| 32 | using HeuristicLab.Parameters;
|
---|
| 33 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
[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]
|
---|
[5809] | 40 | public sealed class TabuSearch : HeuristicOptimizationEngineAlgorithm, IStorableContent {
|
---|
[4437] | 41 | public string Filename { get; set; }
|
---|
| 42 |
|
---|
[3074] | 43 | #region Problem Properties
|
---|
| 44 | public override Type ProblemType {
|
---|
[5809] | 45 | get { return typeof(ISingleObjectiveHeuristicOptimizationProblem); }
|
---|
[3074] | 46 | }
|
---|
[5809] | 47 | public new ISingleObjectiveHeuristicOptimizationProblem Problem {
|
---|
| 48 | get { return (ISingleObjectiveHeuristicOptimizationProblem)base.Problem; }
|
---|
[3074] | 49 | set { base.Problem = value; }
|
---|
| 50 | }
|
---|
| 51 | #endregion
|
---|
| 52 |
|
---|
| 53 | #region Parameter Properties
|
---|
[3048] | 54 | private ValueParameter<IntValue> SeedParameter {
|
---|
| 55 | get { return (ValueParameter<IntValue>)Parameters["Seed"]; }
|
---|
[3044] | 56 | }
|
---|
[3048] | 57 | private ValueParameter<BoolValue> SetSeedRandomlyParameter {
|
---|
| 58 | get { return (ValueParameter<BoolValue>)Parameters["SetSeedRandomly"]; }
|
---|
[3044] | 59 | }
|
---|
[6618] | 60 | public ConstrainedValueParameter<IMoveGenerator> MoveGeneratorParameter {
|
---|
[3044] | 61 | get { return (ConstrainedValueParameter<IMoveGenerator>)Parameters["MoveGenerator"]; }
|
---|
| 62 | }
|
---|
[6618] | 63 | public ConstrainedValueParameter<IMoveMaker> MoveMakerParameter {
|
---|
[3074] | 64 | get { return (ConstrainedValueParameter<IMoveMaker>)Parameters["MoveMaker"]; }
|
---|
| 65 | }
|
---|
[6618] | 66 | public ConstrainedValueParameter<ISingleObjectiveMoveEvaluator> MoveEvaluatorParameter {
|
---|
[3074] | 67 | get { return (ConstrainedValueParameter<ISingleObjectiveMoveEvaluator>)Parameters["MoveEvaluator"]; }
|
---|
| 68 | }
|
---|
[6618] | 69 | public ConstrainedValueParameter<ITabuChecker> TabuCheckerParameter {
|
---|
[3340] | 70 | get { return (ConstrainedValueParameter<ITabuChecker>)Parameters["TabuChecker"]; }
|
---|
[3074] | 71 | }
|
---|
[6618] | 72 | public ConstrainedValueParameter<ITabuMaker> TabuMakerParameter {
|
---|
[3340] | 73 | get { return (ConstrainedValueParameter<ITabuMaker>)Parameters["TabuMaker"]; }
|
---|
[3074] | 74 | }
|
---|
| 75 | private ValueParameter<IntValue> TabuTenureParameter {
|
---|
| 76 | get { return (ValueParameter<IntValue>)Parameters["TabuTenure"]; }
|
---|
| 77 | }
|
---|
[3048] | 78 | private ValueParameter<IntValue> MaximumIterationsParameter {
|
---|
| 79 | get { return (ValueParameter<IntValue>)Parameters["MaximumIterations"]; }
|
---|
[3044] | 80 | }
|
---|
[3141] | 81 | private ValueParameter<IntValue> SampleSizeParameter {
|
---|
| 82 | get { return (ValueParameter<IntValue>)Parameters["SampleSize"]; }
|
---|
| 83 | }
|
---|
[3658] | 84 | private ValueParameter<MultiAnalyzer> AnalyzerParameter {
|
---|
| 85 | get { return (ValueParameter<MultiAnalyzer>)Parameters["Analyzer"]; }
|
---|
[3636] | 86 | }
|
---|
[3044] | 87 | #endregion
|
---|
| 88 |
|
---|
| 89 | #region Properties
|
---|
[3048] | 90 | public IntValue Seed {
|
---|
[3044] | 91 | get { return SeedParameter.Value; }
|
---|
| 92 | set { SeedParameter.Value = value; }
|
---|
| 93 | }
|
---|
[3048] | 94 | public BoolValue SetSeedRandomly {
|
---|
[3044] | 95 | get { return SetSeedRandomlyParameter.Value; }
|
---|
| 96 | set { SetSeedRandomlyParameter.Value = value; }
|
---|
| 97 | }
|
---|
| 98 | public IMoveGenerator MoveGenerator {
|
---|
| 99 | get { return MoveGeneratorParameter.Value; }
|
---|
| 100 | set { MoveGeneratorParameter.Value = value; }
|
---|
| 101 | }
|
---|
[3074] | 102 | public IMoveMaker MoveMaker {
|
---|
| 103 | get { return MoveMakerParameter.Value; }
|
---|
| 104 | set { MoveMakerParameter.Value = value; }
|
---|
| 105 | }
|
---|
| 106 | public ISingleObjectiveMoveEvaluator MoveEvaluator {
|
---|
| 107 | get { return MoveEvaluatorParameter.Value; }
|
---|
| 108 | set { MoveEvaluatorParameter.Value = value; }
|
---|
| 109 | }
|
---|
[3340] | 110 | public ITabuChecker TabuChecker {
|
---|
| 111 | get { return TabuCheckerParameter.Value; }
|
---|
| 112 | set { TabuCheckerParameter.Value = value; }
|
---|
[3074] | 113 | }
|
---|
[3340] | 114 | public ITabuMaker TabuMaker {
|
---|
| 115 | get { return TabuMakerParameter.Value; }
|
---|
| 116 | set { TabuMakerParameter.Value = value; }
|
---|
[3074] | 117 | }
|
---|
| 118 | public IntValue TabuTenure {
|
---|
| 119 | get { return TabuTenureParameter.Value; }
|
---|
| 120 | set { TabuTenureParameter.Value = value; }
|
---|
| 121 | }
|
---|
[3048] | 122 | public IntValue MaximumIterations {
|
---|
[3044] | 123 | get { return MaximumIterationsParameter.Value; }
|
---|
| 124 | set { MaximumIterationsParameter.Value = value; }
|
---|
| 125 | }
|
---|
[6618] | 126 | public IntValue SampleSize {
|
---|
| 127 | get { return SampleSizeParameter.Value; }
|
---|
| 128 | set { SampleSizeParameter.Value = value; }
|
---|
| 129 | }
|
---|
[3658] | 130 | public MultiAnalyzer Analyzer {
|
---|
[3636] | 131 | get { return AnalyzerParameter.Value; }
|
---|
| 132 | set { AnalyzerParameter.Value = value; }
|
---|
| 133 | }
|
---|
[3044] | 134 | private RandomCreator RandomCreator {
|
---|
| 135 | get { return (RandomCreator)OperatorGraph.InitialOperator; }
|
---|
| 136 | }
|
---|
| 137 | private SolutionsCreator SolutionsCreator {
|
---|
| 138 | get { return (SolutionsCreator)RandomCreator.Successor; }
|
---|
| 139 | }
|
---|
[3100] | 140 | private TabuSearchMainLoop MainLoop {
|
---|
[5366] | 141 | get { return FindMainLoop(SolutionsCreator.Successor); }
|
---|
[3044] | 142 | }
|
---|
[3689] | 143 | [Storable]
|
---|
[3662] | 144 | private BestAverageWorstQualityAnalyzer moveQualityAnalyzer;
|
---|
[3689] | 145 | [Storable]
|
---|
[3636] | 146 | private TabuNeighborhoodAnalyzer tabuNeighborhoodAnalyzer;
|
---|
[3044] | 147 | #endregion
|
---|
| 148 |
|
---|
[3100] | 149 | public TabuSearch()
|
---|
[3044] | 150 | : base() {
|
---|
[3048] | 151 | Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
|
---|
| 152 | Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
|
---|
[3044] | 153 | Parameters.Add(new ConstrainedValueParameter<IMoveGenerator>("MoveGenerator", "The operator used to generate moves to the neighborhood of the current solution."));
|
---|
[3074] | 154 | Parameters.Add(new ConstrainedValueParameter<IMoveMaker>("MoveMaker", "The operator used to perform a move."));
|
---|
| 155 | Parameters.Add(new ConstrainedValueParameter<ISingleObjectiveMoveEvaluator>("MoveEvaluator", "The operator used to evaluate a move."));
|
---|
[3340] | 156 | Parameters.Add(new ConstrainedValueParameter<ITabuChecker>("TabuChecker", "The operator to check whether a move is tabu or not."));
|
---|
| 157 | Parameters.Add(new ConstrainedValueParameter<ITabuMaker>("TabuMaker", "The operator used to insert attributes of a move into the tabu list."));
|
---|
[3074] | 158 | Parameters.Add(new ValueParameter<IntValue>("TabuTenure", "The length of the tabu list.", new IntValue(10)));
|
---|
[3048] | 159 | Parameters.Add(new ValueParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed.", new IntValue(1000)));
|
---|
[3340] | 160 | Parameters.Add(new ValueParameter<IntValue>("SampleSize", "The neighborhood size for stochastic sampling move generators", new IntValue(100)));
|
---|
[3658] | 161 | Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze the solution.", new MultiAnalyzer()));
|
---|
[4068] | 162 |
|
---|
[3044] | 163 | RandomCreator randomCreator = new RandomCreator();
|
---|
| 164 | SolutionsCreator solutionsCreator = new SolutionsCreator();
|
---|
[5356] | 165 | VariableCreator variableCreator = new VariableCreator();
|
---|
| 166 | ResultsCollector resultsCollector = new ResultsCollector();
|
---|
| 167 | TabuSearchMainLoop mainLoop = new TabuSearchMainLoop();
|
---|
[3044] | 168 | OperatorGraph.InitialOperator = randomCreator;
|
---|
| 169 |
|
---|
| 170 | randomCreator.RandomParameter.ActualName = "Random";
|
---|
| 171 | randomCreator.SeedParameter.ActualName = SeedParameter.Name;
|
---|
| 172 | randomCreator.SeedParameter.Value = null;
|
---|
| 173 | randomCreator.SetSeedRandomlyParameter.ActualName = SetSeedRandomlyParameter.Name;
|
---|
| 174 | randomCreator.SetSeedRandomlyParameter.Value = null;
|
---|
| 175 | randomCreator.Successor = solutionsCreator;
|
---|
| 176 |
|
---|
[3048] | 177 | solutionsCreator.NumberOfSolutions = new IntValue(1);
|
---|
[5356] | 178 | solutionsCreator.Successor = variableCreator;
|
---|
[3044] | 179 |
|
---|
[5356] | 180 | variableCreator.Name = "Initialize EvaluatedMoves";
|
---|
| 181 | variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("EvaluatedMoves", new IntValue()));
|
---|
| 182 | variableCreator.Successor = resultsCollector;
|
---|
[3044] | 183 |
|
---|
[5356] | 184 | resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Evaluated Moves", null, "EvaluatedMoves"));
|
---|
| 185 | resultsCollector.ResultsParameter.ActualName = "Results";
|
---|
| 186 | resultsCollector.Successor = mainLoop;
|
---|
| 187 |
|
---|
| 188 | mainLoop.MoveGeneratorParameter.ActualName = MoveGeneratorParameter.Name;
|
---|
| 189 | mainLoop.MoveMakerParameter.ActualName = MoveMakerParameter.Name;
|
---|
| 190 | mainLoop.MoveEvaluatorParameter.ActualName = MoveEvaluatorParameter.Name;
|
---|
| 191 | mainLoop.TabuCheckerParameter.ActualName = TabuCheckerParameter.Name;
|
---|
| 192 | mainLoop.TabuMakerParameter.ActualName = TabuMakerParameter.Name;
|
---|
| 193 | mainLoop.MaximumIterationsParameter.ActualName = MaximumIterationsParameter.Name;
|
---|
| 194 | mainLoop.RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
|
---|
| 195 | mainLoop.ResultsParameter.ActualName = "Results";
|
---|
| 196 | mainLoop.AnalyzerParameter.ActualName = AnalyzerParameter.Name;
|
---|
| 197 | mainLoop.EvaluatedMovesParameter.ActualName = "EvaluatedMoves";
|
---|
| 198 |
|
---|
[3689] | 199 | moveQualityAnalyzer = new BestAverageWorstQualityAnalyzer();
|
---|
| 200 | tabuNeighborhoodAnalyzer = new TabuNeighborhoodAnalyzer();
|
---|
| 201 | ParameterizeAnalyzers();
|
---|
| 202 | UpdateAnalyzers();
|
---|
| 203 |
|
---|
[3074] | 204 | Initialize();
|
---|
[3044] | 205 | }
|
---|
[3280] | 206 | [StorableConstructor]
|
---|
| 207 | private TabuSearch(bool deserializing) : base(deserializing) { }
|
---|
[4722] | 208 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 209 | private void AfterDeserialization() {
|
---|
| 210 | Initialize();
|
---|
| 211 | }
|
---|
| 212 | private TabuSearch(TabuSearch original, Cloner cloner)
|
---|
| 213 | : base(original, cloner) {
|
---|
| 214 | moveQualityAnalyzer = cloner.Clone(original.moveQualityAnalyzer);
|
---|
| 215 | tabuNeighborhoodAnalyzer = cloner.Clone(original.tabuNeighborhoodAnalyzer);
|
---|
| 216 | Initialize();
|
---|
| 217 | }
|
---|
[3044] | 218 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
[4722] | 219 | return new TabuSearch(this, cloner);
|
---|
[3044] | 220 | }
|
---|
| 221 |
|
---|
[3275] | 222 | public override void Prepare() {
|
---|
[3265] | 223 | if (Problem != null && MoveGenerator != null && MoveMaker != null && MoveEvaluator != null &&
|
---|
[3340] | 224 | TabuChecker != null && TabuMaker != null)
|
---|
[3275] | 225 | base.Prepare();
|
---|
[3189] | 226 | }
|
---|
| 227 |
|
---|
[3044] | 228 | #region Events
|
---|
| 229 | protected override void OnProblemChanged() {
|
---|
| 230 | ParameterizeStochasticOperator(Problem.SolutionCreator);
|
---|
| 231 | ParameterizeStochasticOperator(Problem.Evaluator);
|
---|
| 232 | foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
|
---|
[3074] | 233 | foreach (ISingleObjectiveMoveEvaluator op in Problem.Operators.OfType<ISingleObjectiveMoveEvaluator>()) {
|
---|
| 234 | op.MoveQualityParameter.ActualNameChanged += new EventHandler(MoveEvaluator_MoveQualityParameter_ActualNameChanged);
|
---|
| 235 | }
|
---|
[3232] | 236 | foreach (ITabuChecker op in Problem.Operators.OfType<ITabuChecker>()) {
|
---|
[3340] | 237 | op.MoveTabuParameter.ActualNameChanged += new EventHandler(TabuChecker_MoveTabuParameter_ActualNameChanged);
|
---|
[3104] | 238 | }
|
---|
[3044] | 239 | ParameterizeSolutionsCreator();
|
---|
[3104] | 240 | ParameterizeMainLoop();
|
---|
[3187] | 241 | UpdateMoveGenerator();
|
---|
| 242 | UpdateMoveParameters();
|
---|
[3636] | 243 | UpdateAnalyzers();
|
---|
[3141] | 244 | ParameterizeMoveGenerators();
|
---|
[3074] | 245 | ParameterizeMoveEvaluator();
|
---|
| 246 | ParameterizeMoveMaker();
|
---|
[3340] | 247 | ParameterizeTabuMaker();
|
---|
| 248 | ParameterizeTabuChecker();
|
---|
[3636] | 249 | ParameterizeAnalyzers();
|
---|
[3750] | 250 | ParameterizeIterationBasedOperators();
|
---|
[3044] | 251 | Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
|
---|
| 252 | base.OnProblemChanged();
|
---|
| 253 | }
|
---|
| 254 | protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) {
|
---|
| 255 | ParameterizeStochasticOperator(Problem.SolutionCreator);
|
---|
| 256 | ParameterizeSolutionsCreator();
|
---|
| 257 | base.Problem_SolutionCreatorChanged(sender, e);
|
---|
| 258 | }
|
---|
| 259 | protected override void Problem_EvaluatorChanged(object sender, EventArgs e) {
|
---|
| 260 | ParameterizeStochasticOperator(Problem.Evaluator);
|
---|
| 261 | ParameterizeSolutionsCreator();
|
---|
[3104] | 262 | ParameterizeMainLoop();
|
---|
[3074] | 263 | ParameterizeMoveEvaluator();
|
---|
| 264 | ParameterizeMoveMaker();
|
---|
[3340] | 265 | ParameterizeTabuMaker();
|
---|
| 266 | ParameterizeTabuChecker();
|
---|
[3636] | 267 | ParameterizeAnalyzers();
|
---|
[3044] | 268 | Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
|
---|
| 269 | base.Problem_EvaluatorChanged(sender, e);
|
---|
| 270 | }
|
---|
| 271 | protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
|
---|
| 272 | foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
|
---|
[3074] | 273 | // This may seem pointless, but some operators already have the eventhandler registered, others don't
|
---|
| 274 | // FIXME: Is there another way to solve this problem?
|
---|
| 275 | foreach (ISingleObjectiveMoveEvaluator op in Problem.Operators.OfType<ISingleObjectiveMoveEvaluator>()) {
|
---|
| 276 | op.MoveQualityParameter.ActualNameChanged -= new EventHandler(MoveEvaluator_MoveQualityParameter_ActualNameChanged);
|
---|
| 277 | op.MoveQualityParameter.ActualNameChanged += new EventHandler(MoveEvaluator_MoveQualityParameter_ActualNameChanged);
|
---|
| 278 | }
|
---|
[3232] | 279 | foreach (ITabuChecker op in Problem.Operators.OfType<ITabuChecker>()) {
|
---|
[3340] | 280 | op.MoveTabuParameter.ActualNameChanged -= new EventHandler(TabuChecker_MoveTabuParameter_ActualNameChanged);
|
---|
| 281 | op.MoveTabuParameter.ActualNameChanged += new EventHandler(TabuChecker_MoveTabuParameter_ActualNameChanged);
|
---|
[3104] | 282 | }
|
---|
[3074] | 283 | UpdateMoveGenerator();
|
---|
[3187] | 284 | UpdateMoveParameters();
|
---|
[3636] | 285 | UpdateAnalyzers();
|
---|
[3104] | 286 | ParameterizeMainLoop();
|
---|
[3141] | 287 | ParameterizeMoveGenerators();
|
---|
[3074] | 288 | ParameterizeMoveEvaluator();
|
---|
| 289 | ParameterizeMoveMaker();
|
---|
[3340] | 290 | ParameterizeTabuMaker();
|
---|
| 291 | ParameterizeTabuChecker();
|
---|
[3636] | 292 | ParameterizeAnalyzers();
|
---|
[3750] | 293 | ParameterizeIterationBasedOperators();
|
---|
[3044] | 294 | base.Problem_OperatorsChanged(sender, e);
|
---|
| 295 | }
|
---|
[3074] | 296 | private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
|
---|
[3104] | 297 | ParameterizeMainLoop();
|
---|
[3074] | 298 | ParameterizeMoveEvaluator();
|
---|
| 299 | ParameterizeMoveMaker();
|
---|
[3340] | 300 | ParameterizeTabuMaker();
|
---|
| 301 | ParameterizeTabuChecker();
|
---|
[3044] | 302 | }
|
---|
[3074] | 303 | private void MoveGeneratorParameter_ValueChanged(object sender, EventArgs e) {
|
---|
| 304 | UpdateMoveParameters();
|
---|
[3044] | 305 | }
|
---|
[3074] | 306 | private void MoveEvaluatorParameter_ValueChanged(object sender, EventArgs e) {
|
---|
[3104] | 307 | ParameterizeMainLoop();
|
---|
[3074] | 308 | ParameterizeMoveEvaluator();
|
---|
| 309 | ParameterizeMoveMaker();
|
---|
[3340] | 310 | ParameterizeTabuMaker();
|
---|
| 311 | ParameterizeTabuChecker();
|
---|
[3636] | 312 | ParameterizeAnalyzers();
|
---|
[3044] | 313 | }
|
---|
[3074] | 314 | private void MoveEvaluator_MoveQualityParameter_ActualNameChanged(object sender, EventArgs e) {
|
---|
[3104] | 315 | ParameterizeMainLoop();
|
---|
[3074] | 316 | ParameterizeMoveEvaluator();
|
---|
| 317 | ParameterizeMoveMaker();
|
---|
[3340] | 318 | ParameterizeTabuMaker();
|
---|
| 319 | ParameterizeTabuChecker();
|
---|
[3636] | 320 | ParameterizeAnalyzers();
|
---|
[3044] | 321 | }
|
---|
[3340] | 322 | private void TabuCheckerParameter_ValueChanged(object sender, EventArgs e) {
|
---|
[3104] | 323 | ParameterizeMainLoop();
|
---|
[3636] | 324 | ParameterizeAnalyzers();
|
---|
[3104] | 325 | }
|
---|
[3340] | 326 | private void TabuChecker_MoveTabuParameter_ActualNameChanged(object sender, EventArgs e) {
|
---|
[3104] | 327 | ParameterizeMainLoop();
|
---|
[3636] | 328 | ParameterizeAnalyzers();
|
---|
[3104] | 329 | }
|
---|
[3141] | 330 | private void SampleSizeParameter_NameChanged(object sender, EventArgs e) {
|
---|
| 331 | ParameterizeMoveGenerators();
|
---|
| 332 | }
|
---|
[3044] | 333 | #endregion
|
---|
| 334 |
|
---|
| 335 | #region Helpers
|
---|
[3074] | 336 | private void Initialize() {
|
---|
| 337 | if (Problem != null) {
|
---|
[3044] | 338 | Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
|
---|
[3074] | 339 | foreach (ISingleObjectiveMoveEvaluator op in Problem.Operators.OfType<ISingleObjectiveMoveEvaluator>()) {
|
---|
| 340 | op.MoveQualityParameter.ActualNameChanged += new EventHandler(MoveEvaluator_MoveQualityParameter_ActualNameChanged);
|
---|
| 341 | }
|
---|
| 342 | }
|
---|
| 343 | MoveGeneratorParameter.ValueChanged += new EventHandler(MoveGeneratorParameter_ValueChanged);
|
---|
| 344 | MoveEvaluatorParameter.ValueChanged += new EventHandler(MoveEvaluatorParameter_ValueChanged);
|
---|
[3340] | 345 | TabuCheckerParameter.ValueChanged += new EventHandler(TabuCheckerParameter_ValueChanged);
|
---|
[3141] | 346 | SampleSizeParameter.NameChanged += new EventHandler(SampleSizeParameter_NameChanged);
|
---|
[3044] | 347 | }
|
---|
[3074] | 348 | private void UpdateMoveGenerator() {
|
---|
| 349 | IMoveGenerator oldMoveGenerator = MoveGenerator;
|
---|
| 350 | MoveGeneratorParameter.ValidValues.Clear();
|
---|
| 351 | if (Problem != null) {
|
---|
[3141] | 352 | foreach (IMoveGenerator generator in Problem.Operators.OfType<IMoveGenerator>().OrderBy(x => x.Name)) {
|
---|
[3074] | 353 | MoveGeneratorParameter.ValidValues.Add(generator);
|
---|
[3141] | 354 | }
|
---|
[3074] | 355 | }
|
---|
| 356 | if (oldMoveGenerator != null && MoveGeneratorParameter.ValidValues.Any(x => x.GetType() == oldMoveGenerator.GetType()))
|
---|
| 357 | MoveGenerator = MoveGeneratorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveGenerator.GetType());
|
---|
| 358 | if (MoveGenerator == null) {
|
---|
| 359 | ClearMoveParameters();
|
---|
| 360 | }
|
---|
| 361 | }
|
---|
| 362 | private void UpdateMoveParameters() {
|
---|
| 363 | IMoveMaker oldMoveMaker = MoveMaker;
|
---|
| 364 | ISingleObjectiveMoveEvaluator oldMoveEvaluator = MoveEvaluator;
|
---|
[3340] | 365 | ITabuChecker oldTabuMoveEvaluator = TabuChecker;
|
---|
| 366 | ITabuMaker oldTabuMoveMaker = TabuMaker;
|
---|
[3074] | 367 | ClearMoveParameters();
|
---|
[3131] | 368 | if (MoveGenerator != null) {
|
---|
| 369 | List<Type> moveTypes = MoveGenerator.GetType().GetInterfaces().Where(x => typeof(IMoveOperator).IsAssignableFrom(x)).ToList();
|
---|
| 370 | foreach (Type type in moveTypes.ToList()) {
|
---|
| 371 | if (moveTypes.Any(t => t != type && type.IsAssignableFrom(t)))
|
---|
| 372 | moveTypes.Remove(type);
|
---|
| 373 | }
|
---|
| 374 | foreach (Type type in moveTypes) {
|
---|
| 375 | var operators = Problem.Operators.Where(x => type.IsAssignableFrom(x.GetType())).OrderBy(x => x.Name);
|
---|
| 376 | foreach (IMoveMaker moveMaker in operators.OfType<IMoveMaker>())
|
---|
| 377 | MoveMakerParameter.ValidValues.Add(moveMaker);
|
---|
| 378 | foreach (ISingleObjectiveMoveEvaluator moveEvaluator in operators.OfType<ISingleObjectiveMoveEvaluator>())
|
---|
| 379 | MoveEvaluatorParameter.ValidValues.Add(moveEvaluator);
|
---|
[3232] | 380 | foreach (ITabuChecker tabuMoveEvaluator in operators.OfType<ITabuChecker>())
|
---|
[3340] | 381 | TabuCheckerParameter.ValidValues.Add(tabuMoveEvaluator);
|
---|
[3232] | 382 | foreach (ITabuMaker tabuMoveMaker in operators.OfType<ITabuMaker>())
|
---|
[3340] | 383 | TabuMakerParameter.ValidValues.Add(tabuMoveMaker);
|
---|
[3131] | 384 | }
|
---|
| 385 | if (oldMoveMaker != null) {
|
---|
| 386 | IMoveMaker mm = MoveMakerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveMaker.GetType());
|
---|
| 387 | if (mm != null) MoveMaker = mm;
|
---|
| 388 | }
|
---|
| 389 | if (oldMoveEvaluator != null) {
|
---|
| 390 | ISingleObjectiveMoveEvaluator me = MoveEvaluatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveEvaluator.GetType());
|
---|
| 391 | if (me != null) MoveEvaluator = me;
|
---|
| 392 | }
|
---|
| 393 | if (oldTabuMoveMaker != null) {
|
---|
[3340] | 394 | ITabuMaker tmm = TabuMakerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldTabuMoveMaker.GetType());
|
---|
| 395 | if (tmm != null) TabuMaker = tmm;
|
---|
[3131] | 396 | }
|
---|
| 397 | if (oldTabuMoveEvaluator != null) {
|
---|
[3340] | 398 | ITabuChecker tme = TabuCheckerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldTabuMoveEvaluator.GetType());
|
---|
| 399 | if (tme != null) TabuChecker = tme;
|
---|
[3131] | 400 | }
|
---|
[3074] | 401 | }
|
---|
| 402 | }
|
---|
[3636] | 403 | private void UpdateAnalyzers() {
|
---|
| 404 | Analyzer.Operators.Clear();
|
---|
| 405 | if (Problem != null) {
|
---|
[3816] | 406 | foreach (IAnalyzer analyzer in Problem.Operators.OfType<IAnalyzer>()) {
|
---|
[3671] | 407 | foreach (IScopeTreeLookupParameter param in analyzer.Parameters.OfType<IScopeTreeLookupParameter>())
|
---|
| 408 | param.Depth = 0;
|
---|
[3636] | 409 | Analyzer.Operators.Add(analyzer);
|
---|
[3671] | 410 | }
|
---|
[3636] | 411 | }
|
---|
[3809] | 412 | Analyzer.Operators.Add(moveQualityAnalyzer);
|
---|
| 413 | Analyzer.Operators.Add(tabuNeighborhoodAnalyzer);
|
---|
[3636] | 414 | }
|
---|
[3074] | 415 | private void ClearMoveParameters() {
|
---|
| 416 | MoveMakerParameter.ValidValues.Clear();
|
---|
| 417 | MoveEvaluatorParameter.ValidValues.Clear();
|
---|
[3340] | 418 | TabuCheckerParameter.ValidValues.Clear();
|
---|
| 419 | TabuMakerParameter.ValidValues.Clear();
|
---|
[3074] | 420 | }
|
---|
[3044] | 421 | private void ParameterizeSolutionsCreator() {
|
---|
| 422 | SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
|
---|
| 423 | SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
|
---|
| 424 | }
|
---|
[3104] | 425 | private void ParameterizeMainLoop() {
|
---|
[3141] | 426 | MainLoop.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
|
---|
[3100] | 427 | MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
|
---|
| 428 | MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
[3074] | 429 | if (MoveEvaluator != null)
|
---|
[3100] | 430 | MainLoop.MoveQualityParameter.ActualName = MoveEvaluator.MoveQualityParameter.ActualName;
|
---|
[3340] | 431 | if (TabuChecker != null)
|
---|
| 432 | MainLoop.MoveTabuParameter.ActualName = TabuChecker.MoveTabuParameter.ActualName;
|
---|
[3044] | 433 | }
|
---|
| 434 | private void ParameterizeStochasticOperator(IOperator op) {
|
---|
[6053] | 435 | if (op is IStochasticOperator) {
|
---|
| 436 | IStochasticOperator stOp = (IStochasticOperator)op;
|
---|
| 437 | stOp.RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
|
---|
| 438 | stOp.RandomParameter.Hidden = true;
|
---|
| 439 | }
|
---|
[3044] | 440 | }
|
---|
[3141] | 441 | private void ParameterizeMoveGenerators() {
|
---|
| 442 | if (Problem != null) {
|
---|
[6053] | 443 | foreach (IMultiMoveGenerator generator in Problem.Operators.OfType<IMultiMoveGenerator>()) {
|
---|
[3141] | 444 | generator.SampleSizeParameter.ActualName = SampleSizeParameter.Name;
|
---|
[6053] | 445 | generator.SampleSizeParameter.Hidden = true;
|
---|
| 446 | }
|
---|
[3141] | 447 | }
|
---|
| 448 | }
|
---|
[3074] | 449 | private void ParameterizeMoveEvaluator() {
|
---|
| 450 | foreach (ISingleObjectiveMoveEvaluator op in Problem.Operators.OfType<ISingleObjectiveMoveEvaluator>()) {
|
---|
| 451 | op.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
[6053] | 452 | op.QualityParameter.Hidden = true;
|
---|
[3044] | 453 | }
|
---|
| 454 | }
|
---|
[3074] | 455 | private void ParameterizeMoveMaker() {
|
---|
| 456 | foreach (IMoveMaker op in Problem.Operators.OfType<IMoveMaker>()) {
|
---|
| 457 | op.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
[6053] | 458 | op.QualityParameter.Hidden = true;
|
---|
| 459 | if (MoveEvaluator != null) {
|
---|
[3074] | 460 | op.MoveQualityParameter.ActualName = MoveEvaluator.MoveQualityParameter.ActualName;
|
---|
[6053] | 461 | op.MoveQualityParameter.Hidden = true;
|
---|
| 462 | } else {
|
---|
| 463 | op.MoveQualityParameter.Hidden = false;
|
---|
| 464 | }
|
---|
[3044] | 465 | }
|
---|
| 466 | }
|
---|
[3340] | 467 | private void ParameterizeTabuMaker() {
|
---|
| 468 | foreach (ITabuMaker op in Problem.Operators.OfType<ITabuMaker>()) {
|
---|
| 469 | op.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
[6053] | 470 | op.QualityParameter.Hidden = true;
|
---|
| 471 | if (MoveEvaluator != null) {
|
---|
[3340] | 472 | op.MoveQualityParameter.ActualName = MoveEvaluator.MoveQualityParameter.ActualName;
|
---|
[6053] | 473 | op.MoveQualityParameter.Hidden = true;
|
---|
| 474 | } else {
|
---|
| 475 | op.MoveQualityParameter.Hidden = false;
|
---|
| 476 | }
|
---|
[3340] | 477 | }
|
---|
| 478 | }
|
---|
| 479 | private void ParameterizeTabuChecker() {
|
---|
| 480 | foreach (ITabuChecker op in Problem.Operators.OfType<ITabuChecker>()) {
|
---|
[6053] | 481 | if (MoveEvaluator != null) {
|
---|
[3340] | 482 | op.MoveQualityParameter.ActualName = MoveEvaluator.MoveQualityParameter.ActualName;
|
---|
[6053] | 483 | op.MoveQualityParameter.Hidden = true;
|
---|
| 484 | } else {
|
---|
| 485 | op.MoveQualityParameter.Hidden = false;
|
---|
| 486 | }
|
---|
| 487 | if (TabuChecker != null) {
|
---|
[3340] | 488 | op.MoveTabuParameter.ActualName = TabuChecker.MoveTabuParameter.ActualName;
|
---|
[6053] | 489 | op.MoveTabuParameter.Hidden = true;
|
---|
| 490 | } else {
|
---|
| 491 | op.MoveTabuParameter.Hidden = false;
|
---|
| 492 | }
|
---|
[3340] | 493 | }
|
---|
| 494 | }
|
---|
[3636] | 495 | private void ParameterizeAnalyzers() {
|
---|
| 496 | moveQualityAnalyzer.ResultsParameter.ActualName = "Results";
|
---|
[6053] | 497 | moveQualityAnalyzer.ResultsParameter.Hidden = true;
|
---|
[3636] | 498 | tabuNeighborhoodAnalyzer.ResultsParameter.ActualName = "Results";
|
---|
[6053] | 499 | tabuNeighborhoodAnalyzer.ResultsParameter.Hidden = true;
|
---|
[3636] | 500 | tabuNeighborhoodAnalyzer.PercentTabuParameter.ActualName = "PercentTabu";
|
---|
[6053] | 501 | tabuNeighborhoodAnalyzer.PercentTabuParameter.Hidden = true;
|
---|
[3636] | 502 | if (Problem != null) {
|
---|
| 503 | moveQualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
|
---|
[6053] | 504 | moveQualityAnalyzer.MaximizationParameter.Hidden = true;
|
---|
| 505 | if (MoveEvaluator != null) {
|
---|
[3636] | 506 | moveQualityAnalyzer.QualityParameter.ActualName = MoveEvaluator.MoveQualityParameter.ActualName;
|
---|
[6053] | 507 | moveQualityAnalyzer.QualityParameter.Hidden = true;
|
---|
| 508 | } else {
|
---|
| 509 | moveQualityAnalyzer.QualityParameter.Hidden = false;
|
---|
| 510 | }
|
---|
[3636] | 511 | moveQualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
|
---|
[6053] | 512 | moveQualityAnalyzer.BestKnownQualityParameter.Hidden = true;
|
---|
| 513 | if (TabuChecker != null) {
|
---|
[3636] | 514 | tabuNeighborhoodAnalyzer.IsTabuParameter.ActualName = TabuChecker.MoveTabuParameter.ActualName;
|
---|
[6053] | 515 | tabuNeighborhoodAnalyzer.IsTabuParameter.Hidden = true;
|
---|
| 516 | } else {
|
---|
| 517 | tabuNeighborhoodAnalyzer.IsTabuParameter.Hidden = false;
|
---|
| 518 | }
|
---|
| 519 | } else {
|
---|
| 520 | moveQualityAnalyzer.MaximizationParameter.Hidden = false;
|
---|
| 521 | moveQualityAnalyzer.QualityParameter.Hidden = false;
|
---|
| 522 | moveQualityAnalyzer.BestKnownQualityParameter.Hidden = false;
|
---|
| 523 | tabuNeighborhoodAnalyzer.IsTabuParameter.Hidden = false;
|
---|
[3636] | 524 | }
|
---|
| 525 | }
|
---|
[3750] | 526 | private void ParameterizeIterationBasedOperators() {
|
---|
| 527 | if (Problem != null) {
|
---|
| 528 | foreach (IIterationBasedOperator op in Problem.Operators.OfType<IIterationBasedOperator>()) {
|
---|
| 529 | op.IterationsParameter.ActualName = "Iterations";
|
---|
[6053] | 530 | op.IterationsParameter.Hidden = true;
|
---|
[3750] | 531 | op.MaximumIterationsParameter.ActualName = MaximumIterationsParameter.Name;
|
---|
[6053] | 532 | op.MaximumIterationsParameter.Hidden = true;
|
---|
[3750] | 533 | }
|
---|
| 534 | }
|
---|
| 535 | }
|
---|
[5366] | 536 | private TabuSearchMainLoop FindMainLoop(IOperator start) {
|
---|
| 537 | IOperator mainLoop = start;
|
---|
| 538 | while (mainLoop != null && !(mainLoop is TabuSearchMainLoop))
|
---|
| 539 | mainLoop = ((SingleSuccessorOperator)mainLoop).Successor;
|
---|
| 540 | if (mainLoop == null) return null;
|
---|
| 541 | else return (TabuSearchMainLoop)mainLoop;
|
---|
| 542 | }
|
---|
[3044] | 543 | #endregion
|
---|
| 544 | }
|
---|
| 545 | }
|
---|