Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 6593 was 5954, checked in by mkommend, 14 years ago

#1462: Added algorithms and problems folder to HeuristicLab.Optimization.

File size: 3.2 KB
RevLine 
[4323]1#region License Information
2/* HeuristicLab
[5445]3 * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[4323]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;
23using System.Collections.Generic;
24using System.Drawing;
25using HeuristicLab.Collections;
26using HeuristicLab.Common;
27using HeuristicLab.Core;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29
[4564]30namespace HeuristicLab.Optimization {
[4596]31  [Item("Problem", "Represents the base class for a problem.")]
[4323]32  [StorableClass]
[5809]33  public abstract class Problem : ParameterizedNamedItem, IProblem {
[4323]34    public override Image ItemImage {
[5287]35      get { return HeuristicLab.Common.Resources.VSImageLibrary.Type; }
[4323]36    }
37
38    [StorableConstructor]
39    protected Problem(bool deserializing) : base(deserializing) { }
[5809]40    protected Problem(Problem original, Cloner cloner)
[4722]41      : base(original, cloner) {
42      operators = cloner.Clone(original.operators);
43      RegisterEventHandlers();
44    }
45
[4323]46    protected Problem()
47      : base() {
[4564]48      operators = new OperatorCollection();
[4563]49      RegisterEventHandlers();
[4323]50    }
51
52    [StorableHook(HookType.AfterDeserialization)]
53    private void AfterDeserialization() {
[4563]54      RegisterEventHandlers();
[4323]55    }
56
[4563]57    private void RegisterEventHandlers() {
[4323]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
[4564]64    private OperatorCollection operators;
[4563]65    [Storable(Name = "Operators")]
[4323]66    private IEnumerable<IOperator> StorableOperators {
67      get { return operators; }
[4564]68      set { operators = new OperatorCollection(value); }
[4323]69    }
[4564]70    protected OperatorCollection Operators {
[4323]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}
Note: See TracBrowser for help on using the repository browser.