Free cookie consent management tool by TermsFeed Policy Generator

source: branches/sluengo/HeuristicLab.Problems.TradeRules/Problem/TradeRulesAbstractProblem.cs @ 12341

Last change on this file since 12341 was 9262, checked in by sluengo, 12 years ago
File size: 5.3 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.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Data;
27using HeuristicLab.Optimization;
28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30using HeuristicLab.Problems.DataAnalysis.Symbolic;
31using HeuristicLab.Problems.DataAnalysis;
32
33namespace HeuristicLab.Problems.TradeRules
34{
35    [StorableClass]
36    public abstract class TradeRulesAbstractProblem<T, U, V> : TradeAnalysisProblem<T, U, V>, ISingleObjectiveHeuristicOptimizationProblem
37        where T : class,IDataAnalysisProblemData
38        where U : class, ISymbolicDataAnalysisSingleObjectiveEvaluator<T>
39        where V : class, ISymbolicDataAnalysisSolutionCreator
40    {
41        private const string MaximizationParameterName = "Maximization";
42        private const string BestKnownQualityParameterName = "BestKnownQuality";
43
44        #region parameter properties
45        public IFixedValueParameter<BoolValue> MaximizationParameter
46        {
47            get { return (IFixedValueParameter<BoolValue>)Parameters[MaximizationParameterName]; }
48        }
49        IParameter ISingleObjectiveHeuristicOptimizationProblem.MaximizationParameter
50        {
51            get { return MaximizationParameter; }
52        }
53        public IFixedValueParameter<DoubleValue> BestKnownQualityParameter
54        {
55            get { return (IFixedValueParameter<DoubleValue>)Parameters[BestKnownQualityParameterName]; }
56        }
57        IParameter ISingleObjectiveHeuristicOptimizationProblem.BestKnownQualityParameter
58        {
59            get { return BestKnownQualityParameter; }
60        }
61        #endregion
62
63        #region properties
64        public BoolValue Maximization
65        {
66            get { return MaximizationParameter.Value; }
67        }
68        public DoubleValue BestKnownQuality
69        {
70            get { return BestKnownQualityParameter.Value; }
71        }
72        ISingleObjectiveEvaluator ISingleObjectiveHeuristicOptimizationProblem.Evaluator
73        {
74            get { return Evaluator; }
75        }
76        #endregion
77
78        [StorableConstructor]
79        protected TradeRulesAbstractProblem(bool deserializing) : base(deserializing) { }
80        protected TradeRulesAbstractProblem(TradeRulesAbstractProblem<T, U, V> original, Cloner cloner)
81            : base(original, cloner)
82        {
83            RegisterEventHandler();
84            MaximizationParameter.Hidden = true;
85        }
86
87        public TradeRulesAbstractProblem(T problemData, U evaluator, V solutionCreator)
88            : base(problemData, evaluator, solutionCreator)
89        {
90            Parameters.Add(new FixedValueParameter<BoolValue>(MaximizationParameterName, "Set to false if the problem should be minimized."));
91            Parameters.Add(new FixedValueParameter<DoubleValue>(BestKnownQualityParameterName, "The quality of the best known solution of this problem."));
92
93            MaximizationParameter.Hidden = true;
94            InitializeOperators();
95            RegisterEventHandler();
96        }
97
98        [StorableHook(HookType.AfterDeserialization)]
99        private void AfterDeserialization()
100        {
101            RegisterEventHandler();
102        }
103
104        private void InitializeOperators()
105        {
106            Operators.Add(new SymbolicDataAnalysisAlleleFrequencyAnalyzer());
107            ParameterizeOperators();
108        }
109
110        private void RegisterEventHandler()
111        {
112            Evaluator.QualityParameter.ActualNameChanged += new EventHandler(QualityParameter_ActualNameChanged);
113        }
114
115        protected override void OnEvaluatorChanged()
116        {
117            base.OnEvaluatorChanged();
118            Evaluator.QualityParameter.ActualNameChanged += new EventHandler(QualityParameter_ActualNameChanged);
119            Maximization.Value = base.Evaluator.Maximization;
120            ParameterizeOperators();
121        }
122
123        private void QualityParameter_ActualNameChanged(object sender, EventArgs e)
124        {
125            ParameterizeOperators();
126        }
127
128        protected override void ParameterizeOperators()
129        {
130            base.ParameterizeOperators();
131
132            foreach (var op in Operators.OfType<ISymbolicDataAnalysisSingleObjectiveAnalyzer>())
133            {
134                op.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
135                op.MaximizationParameter.ActualName = MaximizationParameterName;
136            }
137        }
138    }
139}
Note: See TracBrowser for help on using the repository browser.