1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2008 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.Text;
|
---|
25 | using System.Xml;
|
---|
26 | using HeuristicLab.Persistence.Default.Decomposers.Storable;
|
---|
27 |
|
---|
28 | namespace HeuristicLab.Core {
|
---|
29 | /// <summary>
|
---|
30 | /// Representation of a group of operators (can also include subgroups).
|
---|
31 | /// </summary>
|
---|
32 | public class OperatorGroup : StorableBase, IOperatorGroup {
|
---|
33 |
|
---|
34 | [Storable]
|
---|
35 | private string myName;
|
---|
36 | /// <summary>
|
---|
37 | /// Gets or sets the name of the current operator group.
|
---|
38 | /// </summary>
|
---|
39 | /// <remarks>Calls <see cref="OnNameChanged"/> in the setter.</remarks>
|
---|
40 | public string Name {
|
---|
41 | get { return myName; }
|
---|
42 | set {
|
---|
43 | if (myName != value) {
|
---|
44 | myName = value;
|
---|
45 | OnNameChanged();
|
---|
46 | }
|
---|
47 | }
|
---|
48 | }
|
---|
49 |
|
---|
50 | [Storable]
|
---|
51 | private List<IOperatorGroup> mySubGroups;
|
---|
52 | /// <summary>
|
---|
53 | /// Gets all subgroups of the current instance.
|
---|
54 | /// <note type="caution"> The subgroups are returned read-only.</note>
|
---|
55 | /// </summary>
|
---|
56 | public ICollection<IOperatorGroup> SubGroups {
|
---|
57 | get { return mySubGroups.AsReadOnly(); }
|
---|
58 | }
|
---|
59 |
|
---|
60 | [Storable]
|
---|
61 | private List<IOperator> myOperators;
|
---|
62 | /// <summary>
|
---|
63 | /// Gets all operators of the current instance.
|
---|
64 | /// <note type="caution"> The operators are returned read-only.</note>
|
---|
65 | /// </summary>
|
---|
66 | public ICollection<IOperator> Operators {
|
---|
67 | get { return myOperators.AsReadOnly(); }
|
---|
68 | }
|
---|
69 |
|
---|
70 | /// <summary>
|
---|
71 | /// Initializes a new instance of <see cref="OperatorGroup"/> having "Anonymous" as name.
|
---|
72 | /// </summary>
|
---|
73 | public OperatorGroup() {
|
---|
74 | myName = "Anonymous";
|
---|
75 | mySubGroups = new List<IOperatorGroup>();
|
---|
76 | myOperators = new List<IOperator>();
|
---|
77 | }
|
---|
78 |
|
---|
79 | /// <summary>
|
---|
80 | /// Clones the current instance (deep clone).
|
---|
81 | /// </summary>
|
---|
82 | /// <remarks>Deep clone with <see cref="Auxiliary.Clone"/> method of helper class
|
---|
83 | /// <see cref="Auxiliary"/>.</remarks>
|
---|
84 | /// <param name="clonedObjects">Dictionary of all already cloned objects. (Needed to avoid cycles.)</param>
|
---|
85 | /// <returns>The cloned object as <see cref="OperatorGroup"/>.</returns>
|
---|
86 | public override object Clone(IDictionary<Guid, object> clonedObjects) {
|
---|
87 | OperatorGroup clone = (OperatorGroup)base.Clone(clonedObjects);
|
---|
88 | clone.myName = Name;
|
---|
89 | foreach (IOperatorGroup group in SubGroups)
|
---|
90 | clone.AddSubGroup((IOperatorGroup)Auxiliary.Clone(group, clonedObjects));
|
---|
91 | foreach (IOperator op in Operators)
|
---|
92 | clone.AddOperator((IOperator)Auxiliary.Clone(op, clonedObjects));
|
---|
93 | return clone;
|
---|
94 | }
|
---|
95 |
|
---|
96 | /// <summary>
|
---|
97 | /// Adds the given subgroup (<paramref name="group"/>) to the current instance.
|
---|
98 | /// </summary>
|
---|
99 | /// <param name="group">The subgroup to add.</param>
|
---|
100 | public virtual void AddSubGroup(IOperatorGroup group) {
|
---|
101 | mySubGroups.Add(group);
|
---|
102 | }
|
---|
103 | /// <summary>
|
---|
104 | /// Removes the given subgroup (<paramref name="group"/>) from the current instance.
|
---|
105 | /// </summary>
|
---|
106 | /// <param name="group">The subgroup to remove.</param>
|
---|
107 | public virtual void RemoveSubGroup(IOperatorGroup group) {
|
---|
108 | mySubGroups.Remove(group);
|
---|
109 | }
|
---|
110 | /// <summary>
|
---|
111 | /// Ads the given operator <paramref name="op"/> to the current instance.
|
---|
112 | /// </summary>
|
---|
113 | /// <param name="op">The operator to add.</param>
|
---|
114 | public virtual void AddOperator(IOperator op) {
|
---|
115 | myOperators.Add(op);
|
---|
116 | }
|
---|
117 | /// <summary>
|
---|
118 | /// Removes the given operator <paramref name="op"/> from the current instance.
|
---|
119 | /// </summary>
|
---|
120 | /// <param name="op">The operator to remove.</param>
|
---|
121 | public virtual void RemoveOperator(IOperator op) {
|
---|
122 | myOperators.Remove(op);
|
---|
123 | }
|
---|
124 |
|
---|
125 | /// <summary>
|
---|
126 | /// Occurs when the name of the operator was changed.
|
---|
127 | /// </summary>
|
---|
128 | public event EventHandler NameChanged;
|
---|
129 | /// <summary>
|
---|
130 | /// Fires a new <c>NameChanged</c> event.
|
---|
131 | /// </summary>
|
---|
132 | protected virtual void OnNameChanged() {
|
---|
133 | if (NameChanged != null) {
|
---|
134 | NameChanged(this, new EventArgs());
|
---|
135 | }
|
---|
136 | }
|
---|
137 | }
|
---|
138 | }
|
---|