Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 5405 was 5366, checked in by abeham, 14 years ago

#1344

  • Fixed discovery of the main loop operator in the MainLoop property
File size: 23.8 KB
RevLine 
[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
22using System;
23using System.Collections.Generic;
[3074]24using System.Linq;
[4068]25using HeuristicLab.Analysis;
[3376]26using HeuristicLab.Common;
[3044]27using HeuristicLab.Core;
28using HeuristicLab.Data;
[5356]29using HeuristicLab.Operators;
[3044]30using HeuristicLab.Optimization;
31using HeuristicLab.Optimization.Operators;
32using HeuristicLab.Parameters;
33using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
[3368]34using HeuristicLab.Random;
[3044]35
[3100]36namespace HeuristicLab.Algorithms.TabuSearch {
[3280]37  [Item("Tabu Search", "A tabu search algorithm.")]
[3074]38  [Creatable("Algorithms")]
[3201]39  [StorableClass]
[4437]40  public sealed class TabuSearch : EngineAlgorithm, IStorableContent {
41    public string Filename { get; set; }
42
[3074]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
[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    }
60    private ConstrainedValueParameter<IMoveGenerator> MoveGeneratorParameter {
61      get { return (ConstrainedValueParameter<IMoveGenerator>)Parameters["MoveGenerator"]; }
62    }
[3074]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    }
[3340]69    private ConstrainedValueParameter<ITabuChecker> TabuCheckerParameter {
70      get { return (ConstrainedValueParameter<ITabuChecker>)Parameters["TabuChecker"]; }
[3074]71    }
[3340]72    private ConstrainedValueParameter<ITabuMaker> TabuMakerParameter {
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    }
[3658]126    public MultiAnalyzer Analyzer {
[3636]127      get { return AnalyzerParameter.Value; }
128      set { AnalyzerParameter.Value = value; }
129    }
[3044]130    private RandomCreator RandomCreator {
131      get { return (RandomCreator)OperatorGraph.InitialOperator; }
132    }
133    private SolutionsCreator SolutionsCreator {
134      get { return (SolutionsCreator)RandomCreator.Successor; }
135    }
[3100]136    private TabuSearchMainLoop MainLoop {
[5366]137      get { return FindMainLoop(SolutionsCreator.Successor); }
[3044]138    }
[3689]139    [Storable]
[3662]140    private BestAverageWorstQualityAnalyzer moveQualityAnalyzer;
[3689]141    [Storable]
[3636]142    private TabuNeighborhoodAnalyzer tabuNeighborhoodAnalyzer;
[3044]143    #endregion
144
[3100]145    public TabuSearch()
[3044]146      : base() {
[3048]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)));
[3044]149      Parameters.Add(new ConstrainedValueParameter<IMoveGenerator>("MoveGenerator", "The operator used to generate moves to the neighborhood of the current solution."));
[3074]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."));
[3340]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."));
[3074]154      Parameters.Add(new ValueParameter<IntValue>("TabuTenure", "The length of the tabu list.", new IntValue(10)));
[3048]155      Parameters.Add(new ValueParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed.", new IntValue(1000)));
[3340]156      Parameters.Add(new ValueParameter<IntValue>("SampleSize", "The neighborhood size for stochastic sampling move generators", new IntValue(100)));
[3658]157      Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze the solution.", new MultiAnalyzer()));
[4068]158
[3044]159      RandomCreator randomCreator = new RandomCreator();
160      SolutionsCreator solutionsCreator = new SolutionsCreator();
[5356]161      VariableCreator variableCreator = new VariableCreator();
162      ResultsCollector resultsCollector = new ResultsCollector();
163      TabuSearchMainLoop mainLoop = new TabuSearchMainLoop();
[3044]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
[3048]173      solutionsCreator.NumberOfSolutions = new IntValue(1);
[5356]174      solutionsCreator.Successor = variableCreator;
[3044]175
[5356]176      variableCreator.Name = "Initialize EvaluatedMoves";
177      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("EvaluatedMoves", new IntValue()));
178      variableCreator.Successor = resultsCollector;
[3044]179
[5356]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
[3689]195      moveQualityAnalyzer = new BestAverageWorstQualityAnalyzer();
196      tabuNeighborhoodAnalyzer = new TabuNeighborhoodAnalyzer();
197      ParameterizeAnalyzers();
198      UpdateAnalyzers();
199
[3074]200      Initialize();
[3044]201    }
[3280]202    [StorableConstructor]
203    private TabuSearch(bool deserializing) : base(deserializing) { }
[4722]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    }
[3044]214    public override IDeepCloneable Clone(Cloner cloner) {
[4722]215      return new TabuSearch(this, cloner);
[3044]216    }
217
[3275]218    public override void Prepare() {
[3265]219      if (Problem != null && MoveGenerator != null && MoveMaker != null && MoveEvaluator != null &&
[3340]220          TabuChecker != null && TabuMaker != null)
[3275]221        base.Prepare();
[3189]222    }
223
[3044]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);
[3074]229      foreach (ISingleObjectiveMoveEvaluator op in Problem.Operators.OfType<ISingleObjectiveMoveEvaluator>()) {
230        op.MoveQualityParameter.ActualNameChanged += new EventHandler(MoveEvaluator_MoveQualityParameter_ActualNameChanged);
231      }
[3232]232      foreach (ITabuChecker op in Problem.Operators.OfType<ITabuChecker>()) {
[3340]233        op.MoveTabuParameter.ActualNameChanged += new EventHandler(TabuChecker_MoveTabuParameter_ActualNameChanged);
[3104]234      }
[3044]235      ParameterizeSolutionsCreator();
[3104]236      ParameterizeMainLoop();
[3187]237      UpdateMoveGenerator();
238      UpdateMoveParameters();
[3636]239      UpdateAnalyzers();
[3141]240      ParameterizeMoveGenerators();
[3074]241      ParameterizeMoveEvaluator();
242      ParameterizeMoveMaker();
[3340]243      ParameterizeTabuMaker();
244      ParameterizeTabuChecker();
[3636]245      ParameterizeAnalyzers();
[3750]246      ParameterizeIterationBasedOperators();
[3044]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();
[3104]258      ParameterizeMainLoop();
[3074]259      ParameterizeMoveEvaluator();
260      ParameterizeMoveMaker();
[3340]261      ParameterizeTabuMaker();
262      ParameterizeTabuChecker();
[3636]263      ParameterizeAnalyzers();
[3044]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);
[3074]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      }
[3232]275      foreach (ITabuChecker op in Problem.Operators.OfType<ITabuChecker>()) {
[3340]276        op.MoveTabuParameter.ActualNameChanged -= new EventHandler(TabuChecker_MoveTabuParameter_ActualNameChanged);
277        op.MoveTabuParameter.ActualNameChanged += new EventHandler(TabuChecker_MoveTabuParameter_ActualNameChanged);
[3104]278      }
[3074]279      UpdateMoveGenerator();
[3187]280      UpdateMoveParameters();
[3636]281      UpdateAnalyzers();
[3104]282      ParameterizeMainLoop();
[3141]283      ParameterizeMoveGenerators();
[3074]284      ParameterizeMoveEvaluator();
285      ParameterizeMoveMaker();
[3340]286      ParameterizeTabuMaker();
287      ParameterizeTabuChecker();
[3636]288      ParameterizeAnalyzers();
[3750]289      ParameterizeIterationBasedOperators();
[3044]290      base.Problem_OperatorsChanged(sender, e);
291    }
[3074]292    private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
[3104]293      ParameterizeMainLoop();
[3074]294      ParameterizeMoveEvaluator();
295      ParameterizeMoveMaker();
[3340]296      ParameterizeTabuMaker();
297      ParameterizeTabuChecker();
[3044]298    }
[3074]299    private void MoveGeneratorParameter_ValueChanged(object sender, EventArgs e) {
300      UpdateMoveParameters();
[3044]301    }
[3074]302    private void MoveEvaluatorParameter_ValueChanged(object sender, EventArgs e) {
[3104]303      ParameterizeMainLoop();
[3074]304      ParameterizeMoveEvaluator();
305      ParameterizeMoveMaker();
[3340]306      ParameterizeTabuMaker();
307      ParameterizeTabuChecker();
[3636]308      ParameterizeAnalyzers();
[3044]309    }
[3074]310    private void MoveEvaluator_MoveQualityParameter_ActualNameChanged(object sender, EventArgs e) {
[3104]311      ParameterizeMainLoop();
[3074]312      ParameterizeMoveEvaluator();
313      ParameterizeMoveMaker();
[3340]314      ParameterizeTabuMaker();
315      ParameterizeTabuChecker();
[3636]316      ParameterizeAnalyzers();
[3044]317    }
[3340]318    private void TabuCheckerParameter_ValueChanged(object sender, EventArgs e) {
[3104]319      ParameterizeMainLoop();
[3636]320      ParameterizeAnalyzers();
[3104]321    }
[3340]322    private void TabuChecker_MoveTabuParameter_ActualNameChanged(object sender, EventArgs e) {
[3104]323      ParameterizeMainLoop();
[3636]324      ParameterizeAnalyzers();
[3104]325    }
[3141]326    private void SampleSizeParameter_NameChanged(object sender, EventArgs e) {
327      ParameterizeMoveGenerators();
328    }
[3044]329    #endregion
330
331    #region Helpers
[3074]332    private void Initialize() {
333      if (Problem != null) {
[3044]334        Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
[3074]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);
[3340]341      TabuCheckerParameter.ValueChanged += new EventHandler(TabuCheckerParameter_ValueChanged);
[3141]342      SampleSizeParameter.NameChanged += new EventHandler(SampleSizeParameter_NameChanged);
[3044]343    }
[3074]344    private void UpdateMoveGenerator() {
345      IMoveGenerator oldMoveGenerator = MoveGenerator;
346      MoveGeneratorParameter.ValidValues.Clear();
347      if (Problem != null) {
[3141]348        foreach (IMoveGenerator generator in Problem.Operators.OfType<IMoveGenerator>().OrderBy(x => x.Name)) {
[3074]349          MoveGeneratorParameter.ValidValues.Add(generator);
[3141]350        }
[3074]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;
[3340]361      ITabuChecker oldTabuMoveEvaluator = TabuChecker;
362      ITabuMaker oldTabuMoveMaker = TabuMaker;
[3074]363      ClearMoveParameters();
[3131]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);
[3232]376          foreach (ITabuChecker tabuMoveEvaluator in operators.OfType<ITabuChecker>())
[3340]377            TabuCheckerParameter.ValidValues.Add(tabuMoveEvaluator);
[3232]378          foreach (ITabuMaker tabuMoveMaker in operators.OfType<ITabuMaker>())
[3340]379            TabuMakerParameter.ValidValues.Add(tabuMoveMaker);
[3131]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) {
[3340]390          ITabuMaker tmm = TabuMakerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldTabuMoveMaker.GetType());
391          if (tmm != null) TabuMaker = tmm;
[3131]392        }
393        if (oldTabuMoveEvaluator != null) {
[3340]394          ITabuChecker tme = TabuCheckerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldTabuMoveEvaluator.GetType());
395          if (tme != null) TabuChecker = tme;
[3131]396        }
[3074]397      }
398    }
[3636]399    private void UpdateAnalyzers() {
400      Analyzer.Operators.Clear();
401      if (Problem != null) {
[3816]402        foreach (IAnalyzer analyzer in Problem.Operators.OfType<IAnalyzer>()) {
[3671]403          foreach (IScopeTreeLookupParameter param in analyzer.Parameters.OfType<IScopeTreeLookupParameter>())
404            param.Depth = 0;
[3636]405          Analyzer.Operators.Add(analyzer);
[3671]406        }
[3636]407      }
[3809]408      Analyzer.Operators.Add(moveQualityAnalyzer);
409      Analyzer.Operators.Add(tabuNeighborhoodAnalyzer);
[3636]410    }
[3074]411    private void ClearMoveParameters() {
412      MoveMakerParameter.ValidValues.Clear();
413      MoveEvaluatorParameter.ValidValues.Clear();
[3340]414      TabuCheckerParameter.ValidValues.Clear();
415      TabuMakerParameter.ValidValues.Clear();
[3074]416    }
[3044]417    private void ParameterizeSolutionsCreator() {
418      SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
419      SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
420    }
[3104]421    private void ParameterizeMainLoop() {
[3141]422      MainLoop.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
[3100]423      MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
424      MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
[3074]425      if (MoveEvaluator != null)
[3100]426        MainLoop.MoveQualityParameter.ActualName = MoveEvaluator.MoveQualityParameter.ActualName;
[3340]427      if (TabuChecker != null)
428        MainLoop.MoveTabuParameter.ActualName = TabuChecker.MoveTabuParameter.ActualName;
[3044]429    }
430    private void ParameterizeStochasticOperator(IOperator op) {
431      if (op is IStochasticOperator)
432        ((IStochasticOperator)op).RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
433    }
[3141]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    }
[3074]440    private void ParameterizeMoveEvaluator() {
441      foreach (ISingleObjectiveMoveEvaluator op in Problem.Operators.OfType<ISingleObjectiveMoveEvaluator>()) {
442        op.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
[3044]443      }
444    }
[3074]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;
[3044]450      }
451    }
[3340]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    }
[3636]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    }
[3750]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    }
[5366]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    }
[3044]495    #endregion
496  }
497}
Note: See TracBrowser for help on using the repository browser.