Free cookie consent management tool by TermsFeed Policy Generator

source: branches/SimulatedAnnealing/HeuristicLab.Algorithms.SimulatedAnnealing/3.4/SimulatedAnnealing.cs @ 15866

Last change on this file since 15866 was 9086, checked in by abeham, 12 years ago

#1836: Changed reheating strategy

File size: 27.2 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.Linq;
24using HeuristicLab.Analysis;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Data;
28using HeuristicLab.Operators;
29using HeuristicLab.Optimization;
30using HeuristicLab.Optimization.Operators;
31using HeuristicLab.Parameters;
32using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
33using HeuristicLab.PluginInfrastructure;
34using HeuristicLab.Random;
35
36namespace HeuristicLab.Algorithms.SimulatedAnnealing {
37  [Item("Simulated Annealing", "An advanced simulated annealing algorithm.")]
38  [Creatable("Algorithms")]
39  [StorableClass]
40  public sealed class SimulatedAnnealing : HeuristicOptimizationEngineAlgorithm, IStorableContent {
41    #region Strings
42    private const string SeedName = "Seed";
43    private const string SetSeedRandomlyName = "SetSeedRandomly";
44    private const string MoveGeneratorName = "MoveGenerator";
45    private const string MoveEvaluatorName = "MoveEvaluator";
46    private const string MoveMakerName = "MoveMaker";
47    private const string AnnealingOperatorName = "AnnealingOperator";
48    private const string HeatingOperatorName = "HeatingOperator";
49    private const string MaximumIterationsName = "MaximumIterations";
50    private const string UpperTemperatureName = "UpperTemperature";
51    private const string LowerTemperatureName = "LowerTemperature";
52    private const string AnalyzerName = "Analyzer";
53    private const string RandomName = "Random";
54    private const string EvaluatedMovesName = "EvaluatedMoves";
55    private const string IterationsName = "Iterations";
56    private const string TemperatureStartIndexName = "TemperatureStartIndex";
57    private const string CoolingName = "Cooling";
58    private const string StartTemperatureName = "StartTemperature";
59    private const string EndTemperatureName = "EndTemperature";
60    private const string TemperatureName = "Temperature";
61    private const string ResultsName = "Results";
62    private const string TemperatureChartName = "Temperature Chart";
63    private const string TemperatureAnalyzerName = "Temperature Analyzer";
64    private const string ThresholdName = "Threshold";
65    private const string MemorySizeName = "MemorySize";
66    #endregion
67
68    public string Filename { get; set; }
69
70    #region Problem Properties
71    public override Type ProblemType {
72      get { return typeof(ISingleObjectiveHeuristicOptimizationProblem); }
73    }
74    public new ISingleObjectiveHeuristicOptimizationProblem Problem {
75      get { return (ISingleObjectiveHeuristicOptimizationProblem)base.Problem; }
76      set { base.Problem = value; }
77    }
78    #endregion
79
80    #region Parameter Properties
81    private ValueParameter<IntValue> SeedParameter {
82      get { return (ValueParameter<IntValue>)Parameters[SeedName]; }
83    }
84    private ValueParameter<BoolValue> SetSeedRandomlyParameter {
85      get { return (ValueParameter<BoolValue>)Parameters[SetSeedRandomlyName]; }
86    }
87    public IConstrainedValueParameter<IMultiMoveGenerator> MoveGeneratorParameter {
88      get { return (IConstrainedValueParameter<IMultiMoveGenerator>)Parameters[MoveGeneratorName]; }
89    }
90    public IConstrainedValueParameter<IMoveMaker> MoveMakerParameter {
91      get { return (IConstrainedValueParameter<IMoveMaker>)Parameters[MoveMakerName]; }
92    }
93    public IConstrainedValueParameter<ISingleObjectiveMoveEvaluator> MoveEvaluatorParameter {
94      get { return (IConstrainedValueParameter<ISingleObjectiveMoveEvaluator>)Parameters[MoveEvaluatorName]; }
95    }
96    public IConstrainedValueParameter<IDiscreteDoubleValueModifier> AnnealingOperatorParameter {
97      get { return (IConstrainedValueParameter<IDiscreteDoubleValueModifier>)Parameters[AnnealingOperatorName]; }
98    }
99    public OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier> HeatingOperatorParameter {
100      get { return (OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier>)Parameters[HeatingOperatorName]; }
101    }
102    private ValueParameter<DoubleRange> ThresholdParameter {
103      get { return (ValueParameter<DoubleRange>) Parameters[ThresholdName]; }
104    }
105    private ValueParameter<IntValue> MemorySizeParameter {
106      get { return (ValueParameter<IntValue>) Parameters[MemorySizeName]; }
107    }
108    private ValueParameter<IntValue> MaximumIterationsParameter {
109      get { return (ValueParameter<IntValue>)Parameters[MaximumIterationsName]; }
110    }
111    private ValueParameter<DoubleValue> UpperTemperatureParameter {
112      get { return (ValueParameter<DoubleValue>)Parameters[UpperTemperatureName]; }
113    }
114    private ValueParameter<DoubleValue> LowerTemperatureParameter {
115      get { return (ValueParameter<DoubleValue>)Parameters[LowerTemperatureName]; }
116    }
117    private ValueParameter<MultiAnalyzer> AnalyzerParameter {
118      get { return (ValueParameter<MultiAnalyzer>)Parameters[AnalyzerName]; }
119    }
120    #endregion
121
122    #region Properties
123    public IntValue Seed {
124      get { return SeedParameter.Value; }
125      set { SeedParameter.Value = value; }
126    }
127    public BoolValue SetSeedRandomly {
128      get { return SetSeedRandomlyParameter.Value; }
129      set { SetSeedRandomlyParameter.Value = value; }
130    }
131    public IMultiMoveGenerator MoveGenerator {
132      get { return MoveGeneratorParameter.Value; }
133      set { MoveGeneratorParameter.Value = value; }
134    }
135    public IMoveMaker MoveMaker {
136      get { return MoveMakerParameter.Value; }
137      set { MoveMakerParameter.Value = value; }
138    }
139    public ISingleObjectiveMoveEvaluator MoveEvaluator {
140      get { return MoveEvaluatorParameter.Value; }
141      set { MoveEvaluatorParameter.Value = value; }
142    }
143    public IDiscreteDoubleValueModifier AnnealingOperator {
144      get { return AnnealingOperatorParameter.Value; }
145      set { AnnealingOperatorParameter.Value = value; }
146    }
147    public IDiscreteDoubleValueModifier HeatingOperator {
148      get { return HeatingOperatorParameter.Value; }
149      set { HeatingOperatorParameter.Value = value; }
150    }
151    public IntValue MaximumIterations {
152      get { return MaximumIterationsParameter.Value; }
153      set { MaximumIterationsParameter.Value = value; }
154    }
155    public DoubleValue UpperTemperature {
156      get { return UpperTemperatureParameter.Value; }
157      set { UpperTemperatureParameter.Value = value; }
158    }
159    public DoubleValue LowerTemperature {
160      get { return LowerTemperatureParameter.Value; }
161      set { LowerTemperatureParameter.Value = value; }
162    }
163    public MultiAnalyzer Analyzer {
164      get { return AnalyzerParameter.Value; }
165      set { AnalyzerParameter.Value = value; }
166    }
167    public DoubleRange AcceptanceThreshold {
168      get { return ThresholdParameter.Value; }
169      set { ThresholdParameter.Value = value; }
170    }
171    public IntValue AcceptanceMemorySize {
172      get { return MemorySizeParameter.Value; }
173      set { MemorySizeParameter.Value = value; }
174    }
175    private RandomCreator RandomCreator {
176      get { return (RandomCreator)OperatorGraph.InitialOperator; }
177    }
178    private SolutionsCreator SolutionsCreator {
179      get { return (SolutionsCreator)RandomCreator.Successor; }
180    }
181    private SimulatedAnnealingMainLoop MainLoop {
182      get { return OperatorGraph.Iterate().OfType<SimulatedAnnealingMainLoop>().First(); }
183    }
184    #endregion
185
186    [StorableConstructor]
187    private SimulatedAnnealing(bool deserializing) : base(deserializing) { }
188    private SimulatedAnnealing(SimulatedAnnealing original, Cloner cloner)
189      : base(original, cloner) {
190      RegisterEventHandlers();
191    }
192    public SimulatedAnnealing()
193      : base() {
194      Parameters.Add(new ValueParameter<IntValue>(SeedName, "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
195      Parameters.Add(new ValueParameter<BoolValue>(SetSeedRandomlyName, "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
196      Parameters.Add(new ConstrainedValueParameter<IMultiMoveGenerator>(MoveGeneratorName, "The operator used to generate moves to the neighborhood of the current solution."));
197      Parameters.Add(new ConstrainedValueParameter<ISingleObjectiveMoveEvaluator>(MoveEvaluatorName, "The operator used to evaluate a move."));
198      Parameters.Add(new ConstrainedValueParameter<IMoveMaker>(MoveMakerName, "The operator used to perform a move."));
199      Parameters.Add(new ConstrainedValueParameter<IDiscreteDoubleValueModifier>(AnnealingOperatorName, "The operator used to cool the temperature."));
200      Parameters.Add(new OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier>(HeatingOperatorName, "The operator used to heat the temperature."));
201      Parameters.Add(new ValueParameter<IntValue>(MaximumIterationsName, "The maximum number of generations which should be processed.", new IntValue(10000)));
202      Parameters.Add(new ValueParameter<DoubleValue>(UpperTemperatureName, "The upper bound for the temperature.", new DoubleValue(100)));
203      Parameters.Add(new ValueParameter<DoubleValue>(LowerTemperatureName, "The lower bound for the temperature.", new DoubleValue(1e-6)));
204      Parameters.Add(new ValueParameter<MultiAnalyzer>(AnalyzerName, "The operator used to analyze each iteration.", new MultiAnalyzer()));
205      Parameters.Add(new ValueParameter<IntValue>(MemorySizeName, "The maximum size of the acceptance memory.", new IntValue(100)));
206      Parameters.Add(new ValueParameter<DoubleRange>(ThresholdName, "The threshold controls the temperature in case a heating operator is specified. If the average ratio of accepted moves goes below the start of the range the temperature is heated. If the the average ratio of accepted moves goes beyond the end of the range the temperature is cooled again.", new DoubleRange(0.05, 0.2)));
207
208      var randomCreator = new RandomCreator();
209      var solutionsCreator = new SolutionsCreator();
210      var variableCreator = new VariableCreator();
211      var startTemperatureAssigner = new Assigner();
212      var endTemperatureAssigner = new Assigner();
213      var temperatureAssigner = new Assigner();
214      var resultsCollector = new ResultsCollector();
215      var mainLoop = new SimulatedAnnealingMainLoop();
216      OperatorGraph.InitialOperator = randomCreator;
217
218      randomCreator.RandomParameter.ActualName = RandomName;
219      randomCreator.SeedParameter.ActualName = SeedParameter.Name;
220      randomCreator.SeedParameter.Value = null;
221      randomCreator.SetSeedRandomlyParameter.ActualName = SetSeedRandomlyParameter.Name;
222      randomCreator.SetSeedRandomlyParameter.Value = null;
223      randomCreator.Successor = solutionsCreator;
224
225      solutionsCreator.NumberOfSolutions = new IntValue(1);
226      solutionsCreator.Successor = variableCreator;
227
228      variableCreator.Name = "Initialize Variables";
229      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>(EvaluatedMovesName, new IntValue()));
230      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>(IterationsName, new IntValue(0)));
231      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>(TemperatureStartIndexName, new IntValue(0)));
232      variableCreator.CollectedValues.Add(new ValueParameter<BoolValue>(CoolingName, new BoolValue(true)));
233      variableCreator.Successor = startTemperatureAssigner;
234
235      startTemperatureAssigner.Name = "Assign Start Temperature";
236      startTemperatureAssigner.LeftSideParameter.ActualName = StartTemperatureName;
237      startTemperatureAssigner.RightSideParameter.ActualName = UpperTemperatureParameter.Name;
238      startTemperatureAssigner.Successor = endTemperatureAssigner;
239
240      endTemperatureAssigner.Name = "Assign End Temperature";
241      endTemperatureAssigner.LeftSideParameter.ActualName = EndTemperatureName;
242      endTemperatureAssigner.RightSideParameter.ActualName = LowerTemperatureParameter.Name;
243      endTemperatureAssigner.Successor = temperatureAssigner;
244
245      temperatureAssigner.Name = "Initialize Temperature";
246      temperatureAssigner.LeftSideParameter.ActualName = TemperatureName;
247      temperatureAssigner.RightSideParameter.ActualName = StartTemperatureName;
248      temperatureAssigner.Successor = resultsCollector;
249
250      resultsCollector.CopyValue = new BoolValue(false);
251      resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>(EvaluatedMovesName, null));
252      resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>(IterationsName, null));
253      resultsCollector.ResultsParameter.ActualName = ResultsName;
254      resultsCollector.Successor = mainLoop;
255     
256      mainLoop.AnalyzerParameter.ActualName = AnalyzerParameter.Name;
257      mainLoop.AnnealingOperatorParameter.ActualName = AnnealingOperatorParameter.Name;
258      mainLoop.MemorySizeParameter.ActualName = MemorySizeParameter.Name;
259      mainLoop.ThresholdParameter.ActualName = ThresholdParameter.Name;
260      mainLoop.CoolingParameter.ActualName = CoolingName;
261      mainLoop.EndTemperatureParameter.ActualName = EndTemperatureName;
262      mainLoop.EvaluatedMovesParameter.ActualName = EvaluatedMovesName;
263      mainLoop.HeatingOperatorParameter.ActualName = HeatingOperatorParameter.Name;
264      mainLoop.IterationsParameter.ActualName = IterationsName;
265      mainLoop.LowerTemperatureParameter.ActualName = LowerTemperatureParameter.Name;
266      mainLoop.MaximumIterationsParameter.ActualName = MaximumIterationsParameter.Name;
267      mainLoop.MoveEvaluatorParameter.ActualName = MoveEvaluatorParameter.Name;
268      mainLoop.MoveGeneratorParameter.ActualName = MoveGeneratorParameter.Name;
269      mainLoop.MoveMakerParameter.ActualName = MoveMakerParameter.Name;
270      mainLoop.RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
271      mainLoop.ResultsParameter.ActualName = ResultsName;
272      mainLoop.StartTemperatureParameter.ActualName = StartTemperatureName;
273      mainLoop.TemperatureStartIndexParameter.ActualName = TemperatureStartIndexName;
274      mainLoop.TemperatureParameter.ActualName = TemperatureName;
275      mainLoop.UpperTemperatureParameter.ActualName = UpperTemperatureParameter.Name;
276
277      foreach (var op in ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>().OrderBy(x => x.Name)) {
278        AnnealingOperatorParameter.ValidValues.Add(op);
279        HeatingOperatorParameter.ValidValues.Add((IDiscreteDoubleValueModifier)op.Clone());
280      }
281
282      UpdateAnalyzers();
283
284      Parameterize();
285
286      RegisterEventHandlers();
287    }
288
289    public override IDeepCloneable Clone(Cloner cloner) {
290      return new SimulatedAnnealing(this, cloner);
291    }
292
293    [StorableHook(HookType.AfterDeserialization)]
294    private void AfterDeserialization() {
295      RegisterEventHandlers();
296    }
297
298    private void RegisterEventHandlers() {
299      if (Problem != null) {
300        Problem.Evaluator.QualityParameter.ActualNameChanged += Evaluator_QualityParameter_ActualNameChanged;
301        foreach (var op in Problem.Operators.OfType<ISingleObjectiveMoveEvaluator>()) {
302          op.MoveQualityParameter.ActualNameChanged += MoveEvaluator_MoveQualityParameter_ActualNameChanged;
303        }
304      }
305      MoveGeneratorParameter.ValueChanged += MoveGeneratorParameter_ValueChanged;
306      MoveEvaluatorParameter.ValueChanged += MoveEvaluatorParameter_ValueChanged;
307    }
308
309    public override void Prepare() {
310      if (Problem != null && MoveGenerator != null && MoveMaker != null && MoveEvaluator != null)
311        base.Prepare();
312    }
313
314    #region Events
315    protected override void OnProblemChanged() {
316      foreach (var op in Problem.Operators.OfType<ISingleObjectiveMoveEvaluator>()) {
317        op.MoveQualityParameter.ActualNameChanged += MoveEvaluator_MoveQualityParameter_ActualNameChanged;
318      }
319      UpdateMoveGenerator();
320      UpdateMoveOperators();
321      UpdateAnalyzers();
322      Parameterize();
323      Problem.Evaluator.QualityParameter.ActualNameChanged += Evaluator_QualityParameter_ActualNameChanged;
324      base.OnProblemChanged();
325    }
326    protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) {
327      Parameterize();
328      base.Problem_SolutionCreatorChanged(sender, e);
329    }
330    protected override void Problem_EvaluatorChanged(object sender, EventArgs e) {
331      Parameterize();
332      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
333      base.Problem_EvaluatorChanged(sender, e);
334    }
335    protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
336      foreach (var op in Problem.Operators.OfType<ISingleObjectiveMoveEvaluator>()) {
337        op.MoveQualityParameter.ActualNameChanged -= MoveEvaluator_MoveQualityParameter_ActualNameChanged;
338        op.MoveQualityParameter.ActualNameChanged += MoveEvaluator_MoveQualityParameter_ActualNameChanged;
339      }
340      UpdateMoveGenerator();
341      UpdateMoveOperators();
342      UpdateAnalyzers();
343      Parameterize();
344      base.Problem_OperatorsChanged(sender, e);
345    }
346    private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
347      Parameterize();
348    }
349    private void MoveGeneratorParameter_ValueChanged(object sender, EventArgs e) {
350      UpdateMoveOperators();
351    }
352    private void MoveEvaluatorParameter_ValueChanged(object sender, EventArgs e) {
353      Parameterize();
354    }
355    private void MoveEvaluator_MoveQualityParameter_ActualNameChanged(object sender, EventArgs e) {
356      if (sender == MoveEvaluator) Parameterize();
357    }
358    #endregion
359
360    #region Helpers
361
362    private void UpdateMoveGenerator() {
363      var oldMoveGenerator = MoveGenerator;
364      var defaultMoveGenerator = Problem.Operators.OfType<IMultiMoveGenerator>().FirstOrDefault();
365     
366      MoveGeneratorParameter.ValidValues.Clear();
367
368      if (Problem != null) {
369        foreach (var generator in Problem.Operators.OfType<IMultiMoveGenerator>().OrderBy(x => x.Name))
370          MoveGeneratorParameter.ValidValues.Add(generator);
371      }
372
373      if (oldMoveGenerator != null) {
374        var newMoveGenerator = MoveGeneratorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveGenerator.GetType());
375        if (newMoveGenerator != null) MoveGenerator = newMoveGenerator;
376        else oldMoveGenerator = null;
377      }
378      if (oldMoveGenerator == null && defaultMoveGenerator != null)
379        MoveGenerator = defaultMoveGenerator;
380
381      UpdateMoveOperators();
382    }
383
384    private void UpdateMoveOperators() {
385      var oldMoveMaker = MoveMaker;
386      var oldMoveEvaluator = MoveEvaluator;
387
388      MoveMakerParameter.ValidValues.Clear();
389      MoveEvaluatorParameter.ValidValues.Clear();
390
391      if (MoveGenerator != null) {
392        var moveTypes = MoveGenerator.GetType().GetInterfaces().Where(x => typeof(IMoveOperator).IsAssignableFrom(x)).ToList();
393        foreach (var type in moveTypes.ToList()) {
394          if (moveTypes.Any(t => t != type && type.IsAssignableFrom(t)))
395            moveTypes.Remove(type);
396        }
397        var operators = Problem.Operators.Where(op => moveTypes.Any(m => m.IsInstanceOfType(op))).ToList();
398        var defaultMoveMaker = operators.OfType<IMoveMaker>().FirstOrDefault();
399        var defaultMoveEvaluator = operators.OfType<ISingleObjectiveMoveEvaluator>().FirstOrDefault();
400
401        foreach (var moveMaker in operators.OfType<IMoveMaker>().OrderBy(op => op.Name))
402          MoveMakerParameter.ValidValues.Add(moveMaker);
403
404        foreach (var moveEvaluator in operators.OfType<ISingleObjectiveMoveEvaluator>().OrderBy(op => op.Name))
405          MoveEvaluatorParameter.ValidValues.Add(moveEvaluator);
406
407        if (oldMoveMaker != null) {
408          var mm = MoveMakerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveMaker.GetType());
409          if (mm != null) MoveMaker = mm;
410          else oldMoveMaker = null;
411        }
412        if (oldMoveMaker == null && defaultMoveMaker != null)
413          MoveMaker = defaultMoveMaker;
414
415        if (oldMoveEvaluator != null) {
416          var me = MoveEvaluatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveEvaluator.GetType());
417          if (me != null) MoveEvaluator = me;
418          else oldMoveEvaluator = null;
419        }
420        if (oldMoveEvaluator == null & defaultMoveEvaluator != null)
421          MoveEvaluator = defaultMoveEvaluator;
422      }
423    }
424
425    private void UpdateAnalyzers() {
426      Analyzer.Operators.Clear();
427      if (Problem != null) {
428        foreach (var analyzer in Problem.Operators.OfType<IAnalyzer>()) {
429          foreach (var param in analyzer.Parameters.OfType<IScopeTreeLookupParameter>())
430            param.Depth = 0;
431          Analyzer.Operators.Add(analyzer, analyzer.EnabledByDefault);
432        }
433      }
434      var qualityAnalyzer = new QualityAnalyzer();
435      var temperatureAnalyzer = new SingleValueAnalyzer { Name = TemperatureAnalyzerName };
436      Analyzer.Operators.Add(qualityAnalyzer, qualityAnalyzer.EnabledByDefault);
437      Analyzer.Operators.Add(temperatureAnalyzer, temperatureAnalyzer.EnabledByDefault);
438    }
439
440    private void Parameterize() {
441
442      #region IStochasticOperator
443      if (Problem != null) {
444        foreach (var op in Problem.Operators.OfType<IStochasticOperator>()) {
445          op.RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
446          op.RandomParameter.Hidden = true;
447        }
448      }
449      #endregion
450
451      #region IIterationBasedOperator
452      if (Problem != null) {
453        foreach (var op in Problem.Operators.OfType<IIterationBasedOperator>()) {
454          op.IterationsParameter.ActualName = IterationsName;
455          op.IterationsParameter.Hidden = true;
456          op.MaximumIterationsParameter.ActualName = MaximumIterationsParameter.Name;
457          op.MaximumIterationsParameter.Hidden = true;
458        }
459      }
460      #endregion
461
462      #region Analyzers
463
464      foreach (var qualityAnalyzer in Analyzer.Operators.OfType<QualityAnalyzer>()) {
465        qualityAnalyzer.ResultsParameter.ActualName = ResultsName;
466        if (Problem != null) {
467          qualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
468          qualityAnalyzer.MaximizationParameter.Hidden = true;
469          qualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
470          qualityAnalyzer.QualityParameter.Depth = 0;
471          qualityAnalyzer.QualityParameter.Hidden = true;
472          qualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
473          qualityAnalyzer.BestKnownQualityParameter.Hidden = true;
474        } else {
475          qualityAnalyzer.MaximizationParameter.Hidden = false;
476          qualityAnalyzer.QualityParameter.Hidden = false;
477          qualityAnalyzer.BestKnownQualityParameter.Hidden = false;
478        }
479      }
480
481      var temperatureAnalyzer = Analyzer.Operators.OfType<SingleValueAnalyzer>().FirstOrDefault(x => x.Name == TemperatureAnalyzerName);
482      if (temperatureAnalyzer != null) {
483        temperatureAnalyzer.ResultsParameter.ActualName = ResultsName;
484        temperatureAnalyzer.ResultsParameter.Hidden = true;
485        temperatureAnalyzer.ValueParameter.ActualName = TemperatureName;
486        temperatureAnalyzer.ValueParameter.Hidden = true;
487        temperatureAnalyzer.ValuesParameter.ActualName = TemperatureChartName;
488        temperatureAnalyzer.ValuesParameter.Hidden = true;
489      }
490
491      #endregion
492
493      #region SolutionCreator
494      if (Problem != null) {
495        SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
496        SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
497      }
498      #endregion
499
500      #region Annealing/Reheating Operators
501      foreach (var op in AnnealingOperatorParameter.ValidValues) {
502        op.IndexParameter.ActualName = IterationsName;
503        op.IndexParameter.Hidden = true;
504        op.StartIndexParameter.Value = null;
505        op.StartIndexParameter.ActualName = TemperatureStartIndexName;
506        op.EndIndexParameter.ActualName = MaximumIterationsParameter.Name;
507        op.ValueParameter.ActualName = TemperatureName;
508        op.ValueParameter.Hidden = true;
509        op.StartValueParameter.ActualName = StartTemperatureName;
510        op.StartValueParameter.Hidden = true;
511        op.EndValueParameter.ActualName = LowerTemperatureParameter.Name;
512        op.EndValueParameter.Hidden = true;
513      }
514      foreach (var op in HeatingOperatorParameter.ValidValues) {
515        op.IndexParameter.ActualName = IterationsName;
516        op.IndexParameter.Hidden = true;
517        op.StartIndexParameter.Value = null;
518        op.StartIndexParameter.ActualName = TemperatureStartIndexName;
519        op.EndIndexParameter.ActualName = MaximumIterationsParameter.Name;
520        op.ValueParameter.ActualName = TemperatureName;
521        op.ValueParameter.Hidden = true;
522        op.StartValueParameter.ActualName = StartTemperatureName;
523        op.StartValueParameter.Hidden = true;
524        op.EndValueParameter.ActualName = UpperTemperatureParameter.Name;
525        op.EndValueParameter.Hidden = true;
526      }
527      #endregion
528
529      #region Move Operators
530      if (Problem != null) {
531        foreach (var op in Problem.Operators.OfType<IMultiMoveGenerator>()) {
532          op.SampleSizeParameter.Value = new IntValue(1);
533          op.SampleSizeParameter.Hidden = true;
534        }
535        foreach (var op in Problem.Operators.OfType<IMoveMaker>()) {
536          op.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
537          op.QualityParameter.Hidden = true;
538          if (MoveEvaluator != null) {
539            op.MoveQualityParameter.ActualName = MoveEvaluator.MoveQualityParameter.ActualName;
540            op.MoveQualityParameter.Hidden = true;
541          } else {
542            op.MoveQualityParameter.Hidden = false;
543          }
544        }
545        foreach (var op in Problem.Operators.OfType<ISingleObjectiveMoveEvaluator>()) {
546          op.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
547          op.QualityParameter.Hidden = true;
548        }
549      }
550      #endregion
551
552      #region MainLoop
553      if (Problem != null) {
554        MainLoop.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
555        MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
556        MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
557        if (MoveEvaluator != null)
558          MainLoop.MoveQualityParameter.ActualName = MoveEvaluator.MoveQualityParameter.ActualName;
559      }
560      #endregion
561
562    }
563    #endregion
564  }
565}
Note: See TracBrowser for help on using the repository browser.