Free cookie consent management tool by TermsFeed Policy Generator

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

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

Operator architecture refactoring (#95)

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