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.Drawing;
|
---|
23 | using HeuristicLab.Core;
|
---|
24 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
25 | using HeuristicLab.Parameters;
|
---|
26 | using HeuristicLab.Data;
|
---|
27 | using System;
|
---|
28 |
|
---|
29 | namespace HeuristicLab.Optimization {
|
---|
30 | /// <summary>
|
---|
31 | /// A base class for single-objective optimization problems.
|
---|
32 | /// </summary>
|
---|
33 | [Item("SingleObjectiveProblem", "A base class for single-objective optimization problems.")]
|
---|
34 | [EmptyStorableClass]
|
---|
35 | public abstract class SingleObjectiveProblem : Problem, ISingleObjectiveProblem {
|
---|
36 | private ValueParameter<BoolData> MaximizationParameter {
|
---|
37 | get { return (ValueParameter<BoolData>)Parameters["Maximization"]; }
|
---|
38 | }
|
---|
39 | public BoolData Maximization {
|
---|
40 | get { return MaximizationParameter.Value; }
|
---|
41 | set { MaximizationParameter.Value = value; }
|
---|
42 | }
|
---|
43 | public new ISingleObjectiveEvaluator Evaluator {
|
---|
44 | get { return (ISingleObjectiveEvaluator)base.Evaluator; }
|
---|
45 | set { base.Evaluator = value; }
|
---|
46 | }
|
---|
47 |
|
---|
48 | protected SingleObjectiveProblem()
|
---|
49 | : base() {
|
---|
50 | AddParameters();
|
---|
51 | }
|
---|
52 | protected SingleObjectiveProblem(string name)
|
---|
53 | : base(name) {
|
---|
54 | AddParameters();
|
---|
55 | }
|
---|
56 | protected SingleObjectiveProblem(string name, ParameterCollection parameters)
|
---|
57 | : base(name, parameters) {
|
---|
58 | AddParameters();
|
---|
59 | }
|
---|
60 | protected SingleObjectiveProblem(string name, string description)
|
---|
61 | : base(name, description) {
|
---|
62 | AddParameters();
|
---|
63 | }
|
---|
64 | protected SingleObjectiveProblem(string name, string description, ParameterCollection parameters)
|
---|
65 | : base(name, description, parameters) {
|
---|
66 | AddParameters();
|
---|
67 | }
|
---|
68 |
|
---|
69 | private void AddParameters() {
|
---|
70 | ValueParameter<BoolData> maximizationParameter = new ValueParameter<BoolData>("Maximization", "True if the problem is a maximization problem, otherwise false.", new BoolData(true));
|
---|
71 | maximizationParameter.ValueChanged += new System.EventHandler(MaximizationParameter_ValueChanged);
|
---|
72 | Parameters.Add(maximizationParameter);
|
---|
73 | }
|
---|
74 |
|
---|
75 | private void MaximizationParameter_ValueChanged(object sender, System.EventArgs e) {
|
---|
76 | OnMaximizationChanged();
|
---|
77 | }
|
---|
78 |
|
---|
79 | public event EventHandler MaximizationChanged;
|
---|
80 | protected virtual void OnMaximizationChanged() {
|
---|
81 | if (MaximizationChanged != null)
|
---|
82 | MaximizationChanged(this, EventArgs.Empty);
|
---|
83 | }
|
---|
84 | }
|
---|
85 | }
|
---|