Free cookie consent management tool by TermsFeed Policy Generator

source: branches/GP-MoveOperators/HeuristicLab.Algorithms.SimulatedAnnealing/3.3/SimulatedAnnealing.cs @ 7968

Last change on this file since 7968 was 7517, checked in by mkommend, 13 years ago

#1691: Updated SimulatedAnnealing to use default operators.

File size: 23.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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.PluginInfrastructure;
35using HeuristicLab.Random;
36
37namespace HeuristicLab.Algorithms.SimulatedAnnealing {
38  [Item("Simulated Annealing", "A simulated annealing algorithm.")]
39  [Creatable("Algorithms")]
40  [StorableClass]
41  public sealed class SimulatedAnnealing : HeuristicOptimizationEngineAlgorithm, IStorableContent {
42    public string Filename { get; set; }
43
44    #region Problem Properties
45    public override Type ProblemType {
46      get { return typeof(ISingleObjectiveHeuristicOptimizationProblem); }
47    }
48    public new ISingleObjectiveHeuristicOptimizationProblem Problem {
49      get { return (ISingleObjectiveHeuristicOptimizationProblem)base.Problem; }
50      set { base.Problem = value; }
51    }
52    #endregion
53
54    #region Parameter Properties
55    private ValueParameter<IntValue> SeedParameter {
56      get { return (ValueParameter<IntValue>)Parameters["Seed"]; }
57    }
58    private ValueParameter<BoolValue> SetSeedRandomlyParameter {
59      get { return (ValueParameter<BoolValue>)Parameters["SetSeedRandomly"]; }
60    }
61    public ConstrainedValueParameter<IMultiMoveGenerator> MoveGeneratorParameter {
62      get { return (ConstrainedValueParameter<IMultiMoveGenerator>)Parameters["MoveGenerator"]; }
63    }
64    public ConstrainedValueParameter<IMoveMaker> MoveMakerParameter {
65      get { return (ConstrainedValueParameter<IMoveMaker>)Parameters["MoveMaker"]; }
66    }
67    public ConstrainedValueParameter<ISingleObjectiveMoveEvaluator> MoveEvaluatorParameter {
68      get { return (ConstrainedValueParameter<ISingleObjectiveMoveEvaluator>)Parameters["MoveEvaluator"]; }
69    }
70    public ConstrainedValueParameter<IDiscreteDoubleValueModifier> AnnealingOperatorParameter {
71      get { return (ConstrainedValueParameter<IDiscreteDoubleValueModifier>)Parameters["AnnealingOperator"]; }
72    }
73    private ValueParameter<IntValue> MaximumIterationsParameter {
74      get { return (ValueParameter<IntValue>)Parameters["MaximumIterations"]; }
75    }
76    private ValueParameter<IntValue> InnerIterationsParameter {
77      get { return (ValueParameter<IntValue>)Parameters["InnerIterations"]; }
78    }
79    private ValueParameter<DoubleValue> StartTemperatureParameter {
80      get { return (ValueParameter<DoubleValue>)Parameters["StartTemperature"]; }
81    }
82    private ValueParameter<DoubleValue> EndTemperatureParameter {
83      get { return (ValueParameter<DoubleValue>)Parameters["EndTemperature"]; }
84    }
85    private ValueParameter<MultiAnalyzer> AnalyzerParameter {
86      get { return (ValueParameter<MultiAnalyzer>)Parameters["Analyzer"]; }
87    }
88    #endregion
89
90    #region Properties
91    public IntValue Seed {
92      get { return SeedParameter.Value; }
93      set { SeedParameter.Value = value; }
94    }
95    public BoolValue SetSeedRandomly {
96      get { return SetSeedRandomlyParameter.Value; }
97      set { SetSeedRandomlyParameter.Value = value; }
98    }
99    public IMultiMoveGenerator MoveGenerator {
100      get { return MoveGeneratorParameter.Value; }
101      set { MoveGeneratorParameter.Value = value; }
102    }
103    public IMoveMaker MoveMaker {
104      get { return MoveMakerParameter.Value; }
105      set { MoveMakerParameter.Value = value; }
106    }
107    public ISingleObjectiveMoveEvaluator MoveEvaluator {
108      get { return MoveEvaluatorParameter.Value; }
109      set { MoveEvaluatorParameter.Value = value; }
110    }
111    public IDiscreteDoubleValueModifier AnnealingOperator {
112      get { return AnnealingOperatorParameter.Value; }
113      set { AnnealingOperatorParameter.Value = value; }
114    }
115    public IntValue MaximumIterations {
116      get { return MaximumIterationsParameter.Value; }
117      set { MaximumIterationsParameter.Value = value; }
118    }
119    public IntValue InnerIterations {
120      get { return InnerIterationsParameter.Value; }
121      set { InnerIterationsParameter.Value = value; }
122    }
123    public DoubleValue StartTemperature {
124      get { return StartTemperatureParameter.Value; }
125      set { StartTemperatureParameter.Value = value; }
126    }
127    public DoubleValue EndTemperature {
128      get { return EndTemperatureParameter.Value; }
129      set { EndTemperatureParameter.Value = value; }
130    }
131    public MultiAnalyzer Analyzer {
132      get { return AnalyzerParameter.Value; }
133      set { AnalyzerParameter.Value = value; }
134    }
135    private RandomCreator RandomCreator {
136      get { return (RandomCreator)OperatorGraph.InitialOperator; }
137    }
138    private SolutionsCreator SolutionsCreator {
139      get { return (SolutionsCreator)RandomCreator.Successor; }
140    }
141    private SimulatedAnnealingMainLoop MainLoop {
142      get { return FindMainLoop(SolutionsCreator.Successor); }
143    }
144    [Storable]
145    private QualityAnalyzer qualityAnalyzer;
146    #endregion
147
148    [StorableConstructor]
149    private SimulatedAnnealing(bool deserializing) : base(deserializing) { }
150    [StorableHook(HookType.AfterDeserialization)]
151    private void AfterDeserialization() {
152      Initialize();
153    }
154    private SimulatedAnnealing(SimulatedAnnealing original, Cloner cloner)
155      : base(original, cloner) {
156      qualityAnalyzer = cloner.Clone(original.qualityAnalyzer);
157      Initialize();
158    }
159    public override IDeepCloneable Clone(Cloner cloner) {
160      return new SimulatedAnnealing(this, cloner);
161    }
162    public SimulatedAnnealing()
163      : base() {
164      Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
165      Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
166      Parameters.Add(new ConstrainedValueParameter<IMultiMoveGenerator>("MoveGenerator", "The operator used to generate moves to the neighborhood of the current solution."));
167      Parameters.Add(new ConstrainedValueParameter<ISingleObjectiveMoveEvaluator>("MoveEvaluator", "The operator used to evaluate a move."));
168      Parameters.Add(new ConstrainedValueParameter<IMoveMaker>("MoveMaker", "The operator used to perform a move."));
169      Parameters.Add(new ConstrainedValueParameter<IDiscreteDoubleValueModifier>("AnnealingOperator", "The operator used to modify the temperature."));
170      Parameters.Add(new ValueParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed.", new IntValue(100)));
171      Parameters.Add(new ValueParameter<IntValue>("InnerIterations", "The amount of inner iterations (number of moves before temperature is adjusted again).", new IntValue(10)));
172      Parameters.Add(new ValueParameter<DoubleValue>("StartTemperature", "The initial temperature.", new DoubleValue(100)));
173      Parameters.Add(new ValueParameter<DoubleValue>("EndTemperature", "The final temperature which should be reached when iterations reaches maximum iterations.", new DoubleValue(1e-6)));
174      Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze each generation.", new MultiAnalyzer()));
175
176      RandomCreator randomCreator = new RandomCreator();
177      SolutionsCreator solutionsCreator = new SolutionsCreator();
178      VariableCreator variableCreator = new VariableCreator();
179      ResultsCollector resultsCollector = new ResultsCollector();
180      SimulatedAnnealingMainLoop mainLoop = new SimulatedAnnealingMainLoop();
181      OperatorGraph.InitialOperator = randomCreator;
182
183      randomCreator.RandomParameter.ActualName = "Random";
184      randomCreator.SeedParameter.ActualName = SeedParameter.Name;
185      randomCreator.SeedParameter.Value = null;
186      randomCreator.SetSeedRandomlyParameter.ActualName = SetSeedRandomlyParameter.Name;
187      randomCreator.SetSeedRandomlyParameter.Value = null;
188      randomCreator.Successor = solutionsCreator;
189
190      solutionsCreator.NumberOfSolutions = new IntValue(1);
191      solutionsCreator.Successor = variableCreator;
192
193      variableCreator.Name = "Initialize EvaluatedMoves";
194      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("EvaluatedMoves", new IntValue()));
195      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Iterations", new IntValue(0)));
196      variableCreator.Successor = resultsCollector;
197
198      resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Evaluated Moves", null, "EvaluatedMoves"));
199      resultsCollector.ResultsParameter.ActualName = "Results";
200      resultsCollector.Successor = mainLoop;
201
202      mainLoop.MoveGeneratorParameter.ActualName = MoveGeneratorParameter.Name;
203      mainLoop.MoveEvaluatorParameter.ActualName = MoveEvaluatorParameter.Name;
204      mainLoop.MoveMakerParameter.ActualName = MoveMakerParameter.Name;
205      mainLoop.AnnealingOperatorParameter.ActualName = AnnealingOperatorParameter.Name;
206      mainLoop.MaximumIterationsParameter.ActualName = MaximumIterationsParameter.Name;
207      mainLoop.StartTemperatureParameter.ActualName = StartTemperatureParameter.Name;
208      mainLoop.EndTemperatureParameter.ActualName = EndTemperatureParameter.Name;
209      mainLoop.RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
210      mainLoop.ResultsParameter.ActualName = "Results";
211      mainLoop.AnalyzerParameter.ActualName = AnalyzerParameter.Name;
212      mainLoop.EvaluatedMovesParameter.ActualName = "EvaluatedMoves";
213      mainLoop.IterationsParameter.ActualName = "Iterations";
214
215      foreach (IDiscreteDoubleValueModifier op in ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>().OrderBy(x => x.Name))
216        AnnealingOperatorParameter.ValidValues.Add(op);
217      ParameterizeAnnealingOperators();
218
219      qualityAnalyzer = new QualityAnalyzer();
220      ParameterizeAnalyzers();
221      UpdateAnalyzers();
222
223      Initialize();
224    }
225
226    public override void Prepare() {
227      if (Problem != null && MoveGenerator != null && MoveMaker != null && MoveEvaluator != null)
228        base.Prepare();
229    }
230
231    #region Events
232    protected override void OnProblemChanged() {
233      ParameterizeStochasticOperator(Problem.SolutionCreator);
234      ParameterizeStochasticOperator(Problem.Evaluator);
235      foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
236      foreach (ISingleObjectiveMoveEvaluator op in Problem.Operators.OfType<ISingleObjectiveMoveEvaluator>()) {
237        op.MoveQualityParameter.ActualNameChanged += new EventHandler(MoveEvaluator_MoveQualityParameter_ActualNameChanged);
238      }
239      ParameterizeSolutionsCreator();
240      ParameterizeMainLoop();
241      UpdateMoveGenerator();
242      UpdateMoveParameters();
243      UpdateAnalyzers();
244      ParameterizeMoveEvaluators();
245      ParameterizeMoveMakers();
246      ParameterizeMoveGenerators();
247      ParameterizeAnalyzers();
248      ParameterizeIterationBasedOperators();
249      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
250      base.OnProblemChanged();
251    }
252    protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) {
253      ParameterizeStochasticOperator(Problem.SolutionCreator);
254      ParameterizeSolutionsCreator();
255      base.Problem_SolutionCreatorChanged(sender, e);
256    }
257    protected override void Problem_EvaluatorChanged(object sender, EventArgs e) {
258      ParameterizeStochasticOperator(Problem.Evaluator);
259      ParameterizeSolutionsCreator();
260      ParameterizeMainLoop();
261      ParameterizeMoveEvaluators();
262      ParameterizeMoveMakers();
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      UpdateMoveGenerator();
276      UpdateMoveParameters();
277      UpdateAnalyzers();
278      ParameterizeMainLoop();
279      ParameterizeMoveEvaluators();
280      ParameterizeMoveMakers();
281      ParameterizeMoveGenerators();
282      ParameterizeIterationBasedOperators();
283      base.Problem_OperatorsChanged(sender, e);
284    }
285    private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
286      ParameterizeMainLoop();
287      ParameterizeMoveEvaluators();
288      ParameterizeMoveMakers();
289      ParameterizeAnalyzers();
290    }
291    private void MoveGeneratorParameter_ValueChanged(object sender, EventArgs e) {
292      UpdateMoveParameters();
293    }
294    private void MoveEvaluatorParameter_ValueChanged(object sender, EventArgs e) {
295      ParameterizeMainLoop();
296      ParameterizeMoveEvaluators();
297      ParameterizeMoveMakers();
298    }
299    private void MoveEvaluator_MoveQualityParameter_ActualNameChanged(object sender, EventArgs e) {
300      ParameterizeMainLoop();
301      ParameterizeMoveEvaluators();
302      ParameterizeMoveMakers();
303    }
304    #endregion
305
306    #region Helpers
307    private void Initialize() {
308      if (Problem != null) {
309        Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
310        foreach (ISingleObjectiveMoveEvaluator op in Problem.Operators.OfType<ISingleObjectiveMoveEvaluator>()) {
311          op.MoveQualityParameter.ActualNameChanged += new EventHandler(MoveEvaluator_MoveQualityParameter_ActualNameChanged);
312        }
313      }
314      MoveGeneratorParameter.ValueChanged += new EventHandler(MoveGeneratorParameter_ValueChanged);
315      MoveEvaluatorParameter.ValueChanged += new EventHandler(MoveEvaluatorParameter_ValueChanged);
316    }
317    private void UpdateMoveGenerator() {
318      IMultiMoveGenerator oldMoveGenerator = MoveGenerator;
319      IMultiMoveGenerator defaultMoveGenerator = Problem.Operators.OfType<IMultiMoveGenerator>().FirstOrDefault();
320      MoveGeneratorParameter.ValidValues.Clear();
321      if (Problem != null) {
322        foreach (IMultiMoveGenerator generator in Problem.Operators.OfType<IMultiMoveGenerator>().OrderBy(x => x.Name))
323          MoveGeneratorParameter.ValidValues.Add(generator);
324      }
325      if (oldMoveGenerator != null) {
326        IMultiMoveGenerator newMoveGenerator = MoveGeneratorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveGenerator.GetType());
327        if (newMoveGenerator != null) MoveGenerator = newMoveGenerator;
328        else oldMoveGenerator = null;
329      }
330      if (oldMoveGenerator == null && defaultMoveGenerator != null)
331        MoveGenerator = defaultMoveGenerator;
332      if (MoveGenerator == null) {
333        ClearMoveParameters();
334      }
335    }
336    private void ParameterizeAnalyzers() {
337      qualityAnalyzer.ResultsParameter.ActualName = "Results";
338      if (Problem != null) {
339        qualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
340        qualityAnalyzer.MaximizationParameter.Hidden = true;
341        qualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
342        qualityAnalyzer.QualityParameter.Depth = 0;
343        qualityAnalyzer.QualityParameter.Hidden = true;
344        qualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
345        qualityAnalyzer.BestKnownQualityParameter.Hidden = true;
346      } else {
347        qualityAnalyzer.MaximizationParameter.Hidden = false;
348        qualityAnalyzer.QualityParameter.Hidden = false;
349        qualityAnalyzer.BestKnownQualityParameter.Hidden = false;
350      }
351    }
352    private void UpdateMoveParameters() {
353      IMoveMaker oldMoveMaker = MoveMaker;
354      ISingleObjectiveMoveEvaluator oldMoveEvaluator = MoveEvaluator;
355      ClearMoveParameters();
356
357      if (MoveGenerator != null) {
358        List<Type> moveTypes = MoveGenerator.GetType().GetInterfaces().Where(x => typeof(IMoveOperator).IsAssignableFrom(x)).ToList();
359        foreach (Type type in moveTypes.ToList()) {
360          if (moveTypes.Any(t => t != type && type.IsAssignableFrom(t)))
361            moveTypes.Remove(type);
362        }
363        var operators = Problem.Operators.Where(op => moveTypes.Any(m => m.IsInstanceOfType(op))).ToList();
364        IMoveMaker defaultMoveMaker = operators.OfType<IMoveMaker>().FirstOrDefault();
365        ISingleObjectiveMoveEvaluator defaultMoveEvaluator = operators.OfType<ISingleObjectiveMoveEvaluator>().FirstOrDefault();
366
367        foreach (IMoveMaker moveMaker in operators.OfType<IMoveMaker>().OrderBy(op => op.Name))
368          MoveMakerParameter.ValidValues.Add(moveMaker);
369        foreach (ISingleObjectiveMoveEvaluator moveEvaluator in operators.OfType<ISingleObjectiveMoveEvaluator>().OrderBy(op => op.Name))
370          MoveEvaluatorParameter.ValidValues.Add(moveEvaluator);
371
372        if (oldMoveMaker != null) {
373          IMoveMaker mm = MoveMakerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveMaker.GetType());
374          if (mm != null) MoveMaker = mm;
375          else oldMoveMaker = null;
376        }
377        if (oldMoveMaker == null && defaultMoveMaker != null)
378          MoveMaker = defaultMoveMaker;
379
380        if (oldMoveEvaluator != null) {
381          ISingleObjectiveMoveEvaluator me = MoveEvaluatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveEvaluator.GetType());
382          if (me != null) MoveEvaluator = me;
383          else oldMoveEvaluator = null;
384        }
385        if (oldMoveEvaluator == null & defaultMoveEvaluator != null)
386          MoveEvaluator = defaultMoveEvaluator;
387      }
388    }
389    private void ClearMoveParameters() {
390      MoveMakerParameter.ValidValues.Clear();
391      MoveEvaluatorParameter.ValidValues.Clear();
392    }
393    private void ParameterizeSolutionsCreator() {
394      SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
395      SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
396    }
397    private void ParameterizeMainLoop() {
398      if (Problem != null) {
399        MainLoop.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
400        MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
401        MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
402      }
403      if (MoveEvaluator != null)
404        MainLoop.MoveQualityParameter.ActualName = MoveEvaluator.MoveQualityParameter.ActualName;
405    }
406    private void ParameterizeStochasticOperator(IOperator op) {
407      if (op is IStochasticOperator) {
408        IStochasticOperator stOp = (IStochasticOperator)op;
409        stOp.RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
410        stOp.RandomParameter.Hidden = true;
411      }
412    }
413    private void ParameterizeMoveEvaluators() {
414      foreach (ISingleObjectiveMoveEvaluator op in Problem.Operators.OfType<ISingleObjectiveMoveEvaluator>()) {
415        op.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
416        op.QualityParameter.Hidden = true;
417      }
418    }
419    private void ParameterizeMoveMakers() {
420      foreach (IMoveMaker op in Problem.Operators.OfType<IMoveMaker>()) {
421        op.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
422        op.QualityParameter.Hidden = true;
423        if (MoveEvaluator != null) {
424          op.MoveQualityParameter.ActualName = MoveEvaluator.MoveQualityParameter.ActualName;
425          op.MoveQualityParameter.Hidden = true;
426        } else {
427          op.MoveQualityParameter.Hidden = false;
428        }
429      }
430    }
431    private void ParameterizeAnnealingOperators() {
432      foreach (IDiscreteDoubleValueModifier op in AnnealingOperatorParameter.ValidValues) {
433        op.IndexParameter.ActualName = "Iterations";
434        op.IndexParameter.Hidden = true;
435        op.StartIndexParameter.Value = new IntValue(0);
436        op.EndIndexParameter.ActualName = MaximumIterationsParameter.Name;
437        op.ValueParameter.ActualName = "Temperature";
438        op.ValueParameter.Hidden = true;
439        op.StartValueParameter.ActualName = StartTemperatureParameter.Name;
440        op.StartValueParameter.Hidden = true;
441        op.EndValueParameter.ActualName = EndTemperatureParameter.Name;
442        op.EndValueParameter.Hidden = true;
443        ParameterizeStochasticOperator(op);
444      }
445    }
446    private void ParameterizeMoveGenerators() {
447      foreach (IMultiMoveGenerator op in Problem.Operators.OfType<IMultiMoveGenerator>()) {
448        op.SampleSizeParameter.ActualName = InnerIterationsParameter.Name;
449        op.SampleSizeParameter.Hidden = true;
450      }
451    }
452    private void ParameterizeIterationBasedOperators() {
453      if (Problem != null) {
454        foreach (IIterationBasedOperator op in Problem.Operators.OfType<IIterationBasedOperator>()) {
455          op.IterationsParameter.ActualName = "Iterations";
456          op.IterationsParameter.Hidden = true;
457          op.MaximumIterationsParameter.ActualName = MaximumIterationsParameter.Name;
458          op.MaximumIterationsParameter.Hidden = true;
459        }
460      }
461    }
462    private void UpdateAnalyzers() {
463      Analyzer.Operators.Clear();
464      if (Problem != null) {
465        foreach (IAnalyzer analyzer in Problem.Operators.OfType<IAnalyzer>()) {
466          foreach (IScopeTreeLookupParameter param in analyzer.Parameters.OfType<IScopeTreeLookupParameter>())
467            param.Depth = 0;
468          Analyzer.Operators.Add(analyzer, analyzer.EnabledByDefault);
469        }
470      }
471      Analyzer.Operators.Add(qualityAnalyzer, qualityAnalyzer.EnabledByDefault);
472    }
473    private SimulatedAnnealingMainLoop FindMainLoop(IOperator start) {
474      IOperator mainLoop = start;
475      while (mainLoop != null && !(mainLoop is SimulatedAnnealingMainLoop))
476        mainLoop = ((SingleSuccessorOperator)mainLoop).Successor;
477      if (mainLoop == null) return null;
478      else return (SimulatedAnnealingMainLoop)mainLoop;
479    }
480    #endregion
481  }
482}
Note: See TracBrowser for help on using the repository browser.