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