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 |
|
---|
22 | using System;
|
---|
23 | using System.Linq;
|
---|
24 | using HeuristicLab.Common;
|
---|
25 | using HeuristicLab.Core;
|
---|
26 | using HeuristicLab.Data;
|
---|
27 | using HeuristicLab.Optimization;
|
---|
28 | using HeuristicLab.Parameters;
|
---|
29 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
30 | using HeuristicLab.PluginInfrastructure;
|
---|
31 |
|
---|
32 | namespace 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 = "AlgorithmParameterConfiguration";
|
---|
40 | private const string ProblemParametersConfigurationParameterName = "ProblemParametersConfiguration";
|
---|
41 |
|
---|
42 | #region Parameter Properties
|
---|
43 | public ValueParameter<IAlgorithm> AlgorithmParameter {
|
---|
44 | get { return (ValueParameter<IAlgorithm>)Parameters[AlgorithmParameterName]; }
|
---|
45 | }
|
---|
46 | public ValueParameter<IItemList<ISingleObjectiveProblem>> ProblemsParameter {
|
---|
47 | get { return (ValueParameter<IItemList<ISingleObjectiveProblem>>)Parameters[ProblemsParameterName]; }
|
---|
48 | }
|
---|
49 | public ValueParameter<IValueConfiguration> AlgorithmParameterConfigurationParameter {
|
---|
50 | get { return (ValueParameter<IValueConfiguration>)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 IAlgorithm 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 IValueConfiguration 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()
|
---|
77 | : base() {
|
---|
78 | Parameters.Add(new ValueParameter<IAlgorithm>(AlgorithmParameterName, "The algorithm which's parameters should be optimized."));
|
---|
79 | Parameters.Add(new ValueParameter<IItemList<IProblem>>(ProblemsParameterName, "The problems that should be evaluated.", new ItemList<IProblem>()));
|
---|
80 | Parameters.Add(new ValueParameter<IValueConfiguration>(AlgorithmParameterConfigurationParameterName, "List of algorithm parameters that should be optimized."));
|
---|
81 | //Parameters.Add(new ValueParameter<IItemList<IParameterConfiguration>>(ProblemParametersConfigurationParameterName, "List of problem parameters that should be optimized.", new ItemList<IParameterConfiguration>()));
|
---|
82 |
|
---|
83 | Maximization = new BoolValue(false);
|
---|
84 | SolutionCreator = new RandomParameterConfigurationCreator();
|
---|
85 | Evaluator = new MetaOptimizationEvaluator();
|
---|
86 |
|
---|
87 | InitializeOperators();
|
---|
88 | RegisterParameterEvents();
|
---|
89 | ParameterizeSolutionCreator();
|
---|
90 | ParameterizeEvaluator();
|
---|
91 | ParameterizeOperators();
|
---|
92 | }
|
---|
93 |
|
---|
94 | [StorableConstructor]
|
---|
95 | private MetaOptimizationProblem(bool deserializing) : base(deserializing) { }
|
---|
96 | private MetaOptimizationProblem(MetaOptimizationProblem original, Cloner cloner) : base(original, cloner) {
|
---|
97 | // todo
|
---|
98 | this.RegisterParameterEvents();
|
---|
99 | }
|
---|
100 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
101 | return new MetaOptimizationProblem(this, cloner);
|
---|
102 | }
|
---|
103 |
|
---|
104 | #region Helpers
|
---|
105 | [StorableHook(HookType.AfterDeserialization)]
|
---|
106 | private void AfterDeserializationHook() {
|
---|
107 | RegisterParameterEvents();
|
---|
108 | }
|
---|
109 | private void RegisterParameterEvents() {
|
---|
110 | SolutionCreatorParameter.ValueChanged += new EventHandler(SolutionCreatorParameter_ValueChanged);
|
---|
111 | EvaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged);
|
---|
112 | Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
|
---|
113 | AlgorithmParameter.ValueChanged += new EventHandler(BaseLevelAlgorithmParameter_ValueChanged);
|
---|
114 | }
|
---|
115 | private void InitializeOperators() {
|
---|
116 | Operators.AddRange(ApplicationManager.Manager.GetInstances<IParameterConfigurationOperator>().Cast<IOperator>());
|
---|
117 | Operators.Add(new BestParameterConfigurationAnalyzer());
|
---|
118 | }
|
---|
119 | private void ParameterizeSolutionCreator() {
|
---|
120 | //SolutionCreator.ParametersToOptimize = this.ParametersToOptimize;
|
---|
121 |
|
---|
122 | }
|
---|
123 | private void ParameterizeEvaluator() {
|
---|
124 | ((MetaOptimizationEvaluator)Evaluator).ParameterConfigurationParameter.ActualName = ((RandomParameterConfigurationCreator)SolutionCreator).ValueConfigurationParameter.ActualName;
|
---|
125 | }
|
---|
126 | private void ParameterizeAnalyzer() {
|
---|
127 | //BestQualityAnalyzer.ResultsParameter.ActualName = "Results";
|
---|
128 | }
|
---|
129 | private void ParameterizeOperators() {
|
---|
130 |
|
---|
131 | }
|
---|
132 |
|
---|
133 | #endregion
|
---|
134 |
|
---|
135 | #region Events
|
---|
136 |
|
---|
137 | private void SolutionCreatorParameter_ValueChanged(object sender, EventArgs e) {
|
---|
138 | ParameterizeSolutionCreator();
|
---|
139 | ParameterizeEvaluator();
|
---|
140 | ParameterizeAnalyzer();
|
---|
141 | ParameterizeOperators();
|
---|
142 | OnSolutionCreatorChanged();
|
---|
143 | }
|
---|
144 | private void EvaluatorParameter_ValueChanged(object sender, EventArgs e) {
|
---|
145 | Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
|
---|
146 | ParameterizeEvaluator();
|
---|
147 | ParameterizeAnalyzer();
|
---|
148 | OnEvaluatorChanged();
|
---|
149 | }
|
---|
150 | private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
|
---|
151 | ParameterizeAnalyzer();
|
---|
152 | }
|
---|
153 | void BaseLevelAlgorithmParameter_ValueChanged(object sender, EventArgs e) {
|
---|
154 | if (Algorithm != null) {
|
---|
155 | Algorithm.ProblemChanged += new EventHandler(BaseLevelAlgorithm_ProblemChanged);
|
---|
156 | AlgorithmParameterConfiguration = new RootValueConfiguration(Algorithm, Algorithm.GetType());
|
---|
157 | }
|
---|
158 | BaseLevelAlgorithm_ProblemChanged(sender, e);
|
---|
159 | }
|
---|
160 |
|
---|
161 | void BaseLevelAlgorithm_ProblemChanged(object sender, EventArgs e) {
|
---|
162 | //ClearProblemParameters();
|
---|
163 | //if (Algorithm.Problem != null) {
|
---|
164 | // AddProblemParameters();
|
---|
165 | //}
|
---|
166 | }
|
---|
167 | #endregion
|
---|
168 | }
|
---|
169 | }
|
---|