Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Optimization/3.3/SingleObjectiveProblem.cs @ 2864

Last change on this file since 2864 was 2852, checked in by swagner, 14 years ago

Operator architecture refactoring (#95)

  • worked on algorithms
File size: 3.2 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.Drawing;
23using HeuristicLab.Core;
24using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
25using HeuristicLab.Parameters;
26using HeuristicLab.Data;
27using System;
28
29namespace 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}
Note: See TracBrowser for help on using the repository browser.