Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Optimization/3.3/Problem.cs @ 2857

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

Operator architecture refactoring (#95)

  • worked on algorithms
File size: 4.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 System;
27using HeuristicLab.Common;
28
29namespace HeuristicLab.Optimization {
30  /// <summary>
31  /// A base class for optimization problems.
32  /// </summary>
33  [Item("Problem", "A base class for optimization problems.")]
34  [EmptyStorableClass]
35  public abstract class Problem : ParameterizedNamedItem, IProblem {
36    public override Image ItemImage {
37      get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Type; }
38    }
39
40    private IValueParameter<ISolutionCreator> SolutionCreatorParameter {
41      get { return (IValueParameter<ISolutionCreator>)Parameters["SolutionCreator"]; }
42    }
43    private IValueParameter<IEvaluator> EvaluatorParameter {
44      get { return (IValueParameter<IEvaluator>)Parameters["Evaluator"]; }
45    }
46    public ISolutionCreator SolutionCreator {
47      get { return SolutionCreatorParameter.Value; }
48      set { SolutionCreatorParameter.Value = value; }
49    }
50    public IEvaluator Evaluator {
51      get { return EvaluatorParameter.Value; }
52      set { EvaluatorParameter.Value = value; }
53    }
54
55    protected Problem()
56      : base() {
57      AddParameters();
58    }
59    protected Problem(string name)
60      : base(name) {
61      AddParameters();
62    }
63    protected Problem(string name, ParameterCollection parameters)
64      : base(name, parameters) {
65      AddParameters();
66    }
67    protected Problem(string name, string description)
68      : base(name, description) {
69      AddParameters();
70    }
71    protected Problem(string name, string description, ParameterCollection parameters)
72      : base(name, description, parameters) {
73      AddParameters();
74    }
75
76    private void AddParameters() {
77      ValueParameter<ISolutionCreator> solutionCreatorParameter = new ValueParameter<ISolutionCreator>("SolutionCreator", "The operator which should be used to create new solutions.");
78      solutionCreatorParameter.ValueChanged += new EventHandler(SolutionCreatorParameter_ValueChanged);
79      Parameters.Add(solutionCreatorParameter);
80
81      ValueParameter<IEvaluator> evaluatorParameter = new ValueParameter<IEvaluator>("Evaluator", "The operator which should be used to evaluate solutions.");
82      evaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged);
83      Parameters.Add(evaluatorParameter);
84    }
85
86    private void SolutionCreatorParameter_ValueChanged(object sender, EventArgs e) {
87      OnSolutionCreatorChanged();
88    }
89    private void EvaluatorParameter_ValueChanged(object sender, EventArgs e) {
90      OnEvaluatorChanged();
91    }
92
93    public event EventHandler SolutionCreatorChanged;
94    protected virtual void OnSolutionCreatorChanged() {
95      if (SolutionCreatorChanged != null)
96        SolutionCreatorChanged(this, EventArgs.Empty);
97    }
98    public event EventHandler EvaluatorChanged;
99    protected virtual void OnEvaluatorChanged() {
100      if (EvaluatorChanged != null)
101        EvaluatorChanged(this, EventArgs.Empty);
102    }
103    public event EventHandler<EventArgs<Type>> OperatorsChanged;
104    protected virtual void OnOperatorsChanged(Type operatorType) {
105      if (OperatorsChanged != null)
106        OperatorsChanged(this, new EventArgs<Type>(operatorType));
107    }
108  }
109}
Note: See TracBrowser for help on using the repository browser.