Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Algorithms.TabuSearch/3.3/TabuSearch.cs @ 5755

Last change on this file since 5755 was 5445, checked in by swagner, 14 years ago

Updated year of copyrights (#1406)

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