Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/MetaOptimizationProblem.cs @ 5087

Last change on this file since 5087 was 5087, checked in by cneumuel, 14 years ago

#1215

  • enabled multiple problems
  • enabled n repetitions
  • improved results output
  • reduced memory footprint significantly
  • removed viewhost icons for less screen space waste
File size: 7.6 KB
Line 
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.Linq;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Data;
27using HeuristicLab.Optimization;
28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30using HeuristicLab.PluginInfrastructure;
31
32namespace HeuristicLab.Problems.MetaOptimization {
33  [Item("Meta Optimization Problem", "Represents a Meta Optimization Problem.")]
34  [Creatable("Problems")]
35  [StorableClass]
36  public sealed class MetaOptimizationProblem : SingleObjectiveProblem<IMetaOptimizationEvaluator, IParameterConfigurationCreator> {
37    private const string AlgorithmParameterName = "Algorithm";
38    private const string ProblemsParameterName = "Problems";
39    private const string AlgorithmParameterConfigurationParameterName = "InitialParameterConfigurationTree";
40    //private const string ProblemParametersConfigurationParameterName = "ProblemParametersConfiguration";
41
42    #region Parameter Properties
43    public IValueParameter<EngineAlgorithm> AlgorithmParameter {
44      get { return (ValueParameter<EngineAlgorithm>)Parameters[AlgorithmParameterName]; }
45    }
46    public IValueParameter<IItemList<ISingleObjectiveProblem>> ProblemsParameter {
47      get { return (ValueParameter<IItemList<ISingleObjectiveProblem>>)Parameters[ProblemsParameterName]; }
48    }
49    public IValueParameter<ParameterConfigurationTree> AlgorithmParameterConfigurationParameter {
50      get { return (ValueParameter<ParameterConfigurationTree>)Parameters[AlgorithmParameterConfigurationParameterName]; }
51    }
52    //public ValueParameter<IItemList<IParameterConfiguration>> ProblemParametersConfigurationParameter {
53    //  get { return (ValueParameter<IItemList<IParameterConfiguration>>)Parameters[ProblemParametersConfigurationParameterName]; }
54    //}
55    #endregion
56
57    #region Properties
58    public EngineAlgorithm Algorithm {
59      get { return AlgorithmParameter.Value; }
60      set { AlgorithmParameter.Value = value; }
61    }
62    public IItemList<ISingleObjectiveProblem> Problems {
63      get { return ProblemsParameter.Value; }
64      set { ProblemsParameter.Value = value; }
65    }
66    public ParameterConfigurationTree AlgorithmParameterConfiguration {
67      get { return AlgorithmParameterConfigurationParameter.Value; }
68      set { AlgorithmParameterConfigurationParameter.Value = value; }
69    }
70    //public IItemList<IParameterConfiguration> ProblemParametersConfiguration {
71    //  get { return ProblemParametersConfigurationParameter.Value; }
72    //  set { ProblemParametersConfigurationParameter.Value = value; }
73    //}
74    #endregion
75
76    public MetaOptimizationProblem() : base() {
77      Parameters.Add(new ValueParameter<EngineAlgorithm>(AlgorithmParameterName, "The algorithm which's parameters should be optimized."));
78      Parameters.Add(new ValueParameter<IItemList<ISingleObjectiveProblem>>(ProblemsParameterName, "The problems that should be evaluated.", new ItemList<ISingleObjectiveProblem>()));
79      Parameters.Add(new ValueParameter<ParameterConfigurationTree>(AlgorithmParameterConfigurationParameterName, "List of algorithm parameters that should be optimized."));
80      //Parameters.Add(new ValueParameter<IItemList<IParameterConfiguration>>(ProblemParametersConfigurationParameterName, "List of problem parameters that should be optimized.", new ItemList<IParameterConfiguration>()));
81     
82      Maximization = new BoolValue(false);
83      SolutionCreator = new RandomParameterConfigurationCreator();
84      Evaluator = new MetaOptimizationEvaluator();
85
86      InitializeOperators();
87      RegisterParameterEvents();
88      ParameterizeSolutionCreator();
89      ParameterizeEvaluator();
90      ParameterizeOperators();
91    }
92
93    [StorableConstructor]
94    private MetaOptimizationProblem(bool deserializing) : base(deserializing) { }
95    private MetaOptimizationProblem(MetaOptimizationProblem original, Cloner cloner) : base(original, cloner) {
96      // todo
97      this.RegisterParameterEvents();
98    }
99    public override IDeepCloneable Clone(Cloner cloner) {
100      return new MetaOptimizationProblem(this, cloner);
101    }
102
103    #region Helpers
104    [StorableHook(HookType.AfterDeserialization)]
105    private void AfterDeserializationHook() {
106      RegisterParameterEvents();
107    }
108    private void RegisterParameterEvents() {
109      SolutionCreatorParameter.ValueChanged += new EventHandler(SolutionCreatorParameter_ValueChanged);
110      EvaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged);
111      Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
112      AlgorithmParameter.ValueChanged += new EventHandler(BaseLevelAlgorithmParameter_ValueChanged);
113    }
114    private void InitializeOperators() {
115      Operators.AddRange(ApplicationManager.Manager.GetInstances<IParameterConfigurationOperator>().Cast<IOperator>());
116      Operators.Add(new BestParameterConfigurationAnalyzer());
117    }
118    private void ParameterizeSolutionCreator() {
119      //SolutionCreator.ParametersToOptimize = this.ParametersToOptimize;
120     
121    }
122    private void ParameterizeEvaluator() {
123      ((MetaOptimizationEvaluator)Evaluator).ParameterConfigurationParameter.ActualName = ((RandomParameterConfigurationCreator)SolutionCreator).ParameterConfigurationParameter.ActualName;
124    }
125    private void ParameterizeAnalyzer() {
126      //BestQualityAnalyzer.ResultsParameter.ActualName = "Results";
127    }
128    private void ParameterizeOperators() {
129     
130    }
131
132    #endregion
133
134    #region Events
135
136    private void SolutionCreatorParameter_ValueChanged(object sender, EventArgs e) {
137      ParameterizeSolutionCreator();
138      ParameterizeEvaluator();
139      ParameterizeAnalyzer();
140      ParameterizeOperators();
141      OnSolutionCreatorChanged();
142    }
143    private void EvaluatorParameter_ValueChanged(object sender, EventArgs e) {
144      Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
145      ParameterizeEvaluator();
146      ParameterizeAnalyzer();
147      OnEvaluatorChanged();
148    }
149    private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
150      ParameterizeAnalyzer();
151    }
152    void BaseLevelAlgorithmParameter_ValueChanged(object sender, EventArgs e) {
153      AlgorithmParameterConfiguration = new ParameterConfigurationTree(Algorithm);
154
155      //Algorithm.ProblemChanged += new EventHandler(BaseLevelAlgorithm_ProblemChanged); // when to deregister?
156      //BaseLevelAlgorithm_ProblemChanged(sender, e);
157    }
158
159    void BaseLevelAlgorithm_ProblemChanged(object sender, EventArgs e) {
160      //if (Algorithm != null && Algorithm.Problem != null) {
161      //  AlgorithmParameterConfiguration = new ParameterConfigurationTree(Algorithm);
162      //}
163    }
164    #endregion
165  }
166}
Note: See TracBrowser for help on using the repository browser.