1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2011 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;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Drawing;
|
---|
25 | using HeuristicLab.Collections;
|
---|
26 | using HeuristicLab.Common;
|
---|
27 | using HeuristicLab.Core;
|
---|
28 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
29 |
|
---|
30 | namespace HeuristicLab.Optimization {
|
---|
31 | [Item("Problem", "Represents the base class for a problem.")]
|
---|
32 | [StorableClass]
|
---|
33 | public abstract class Problem : ParameterizedNamedItem, IProblem {
|
---|
34 | public override Image ItemImage {
|
---|
35 | get { return HeuristicLab.Common.Resources.VSImageLibrary.Type; }
|
---|
36 | }
|
---|
37 |
|
---|
38 | [StorableConstructor]
|
---|
39 | protected Problem(bool deserializing) : base(deserializing) { }
|
---|
40 | protected Problem(Problem original, Cloner cloner)
|
---|
41 | : base(original, cloner) {
|
---|
42 | operators = cloner.Clone(original.operators);
|
---|
43 | RegisterEventHandlers();
|
---|
44 | }
|
---|
45 |
|
---|
46 | protected Problem()
|
---|
47 | : base() {
|
---|
48 | operators = new OperatorCollection();
|
---|
49 | RegisterEventHandlers();
|
---|
50 | }
|
---|
51 |
|
---|
52 | [StorableHook(HookType.AfterDeserialization)]
|
---|
53 | private void AfterDeserialization() {
|
---|
54 | RegisterEventHandlers();
|
---|
55 | }
|
---|
56 |
|
---|
57 | private void RegisterEventHandlers() {
|
---|
58 | Operators.ItemsAdded += new CollectionItemsChangedEventHandler<IOperator>(Operators_Changed);
|
---|
59 | Operators.ItemsRemoved += new CollectionItemsChangedEventHandler<IOperator>(Operators_Changed);
|
---|
60 | Operators.CollectionReset += new CollectionItemsChangedEventHandler<IOperator>(Operators_Changed);
|
---|
61 | }
|
---|
62 |
|
---|
63 | #region properties
|
---|
64 | private OperatorCollection operators;
|
---|
65 | [Storable(Name = "Operators")]
|
---|
66 | private IEnumerable<IOperator> StorableOperators {
|
---|
67 | get { return operators; }
|
---|
68 | set { operators = new OperatorCollection(value); }
|
---|
69 | }
|
---|
70 | protected OperatorCollection Operators {
|
---|
71 | get { return this.operators; }
|
---|
72 | }
|
---|
73 | IEnumerable<IOperator> IProblem.Operators { get { return operators; } }
|
---|
74 | #endregion
|
---|
75 |
|
---|
76 | #region events
|
---|
77 | private void Operators_Changed(object sender, EventArgs e) {
|
---|
78 | OnOperatorsChanged();
|
---|
79 | }
|
---|
80 | public event EventHandler OperatorsChanged;
|
---|
81 | protected virtual void OnOperatorsChanged() {
|
---|
82 | EventHandler handler = OperatorsChanged;
|
---|
83 | if (handler != null)
|
---|
84 | handler(this, EventArgs.Empty);
|
---|
85 | }
|
---|
86 |
|
---|
87 | public event EventHandler Reset;
|
---|
88 | protected virtual void OnReset() {
|
---|
89 | EventHandler handler = Reset;
|
---|
90 | if (handler != null)
|
---|
91 | handler(this, EventArgs.Empty);
|
---|
92 | }
|
---|
93 | #endregion
|
---|
94 | }
|
---|
95 | }
|
---|