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 System;
|
---|
27 |
|
---|
28 | namespace 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 | }
|
---|