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 |
|
---|
26 | namespace HeuristicLab.Core {
|
---|
27 | /// <summary>
|
---|
28 | /// Interface to represent an operator (e.g. GreaterThanComparator,...),
|
---|
29 | /// a basic instruction of an algorithm.
|
---|
30 | /// </summary>
|
---|
31 | public interface IOperator : IConstrainedItem {
|
---|
32 | /// <summary>
|
---|
33 | /// Gets or sets the name of the current instance.
|
---|
34 | /// </summary>
|
---|
35 | string Name { get; set; }
|
---|
36 | /// <summary>
|
---|
37 | /// Gets or sets the description of the current instance.
|
---|
38 | /// </summary>
|
---|
39 | string Description { get; }
|
---|
40 |
|
---|
41 | /// <summary>
|
---|
42 | /// Gets information whether the current operator has been canceled.
|
---|
43 | /// </summary>
|
---|
44 | bool Canceled { get; }
|
---|
45 | /// <summary>
|
---|
46 | /// Gets or sets a boolean value whether the engine should stop here during the run.
|
---|
47 | /// </summary>
|
---|
48 | bool Breakpoint { get; set; }
|
---|
49 |
|
---|
50 | /// <summary>
|
---|
51 | /// Gets a list of all sub operators.
|
---|
52 | /// </summary>
|
---|
53 | IList<IOperator> SubOperators { get; }
|
---|
54 | /// <summary>
|
---|
55 | /// Gets a collection of all variable (parameter) infos.
|
---|
56 | /// </summary>
|
---|
57 | ICollection<IVariableInfo> VariableInfos { get; }
|
---|
58 | /// <summary>
|
---|
59 | /// Gets a collection of all variables of the current operator.
|
---|
60 | /// </summary>
|
---|
61 | ICollection<IVariable> Variables { get; }
|
---|
62 |
|
---|
63 | /// <summary>
|
---|
64 | /// Adds the given sub operator to the current instance.
|
---|
65 | /// </summary>
|
---|
66 | /// <param name="op">The operator to add.</param>
|
---|
67 | void AddSubOperator(IOperator op);
|
---|
68 | /// <summary>
|
---|
69 | /// Adds the given sub operator to the current instance if all constraints can be fulfilled.
|
---|
70 | /// </summary>
|
---|
71 | /// <param name="op">The operator to add.</param>
|
---|
72 | /// <returns><c>true</c> if the operator could be added without violating constraints,
|
---|
73 | /// <c>false</c> otherwise.</returns>
|
---|
74 | bool TryAddSubOperator(IOperator op);
|
---|
75 | /// <summary>
|
---|
76 | /// Adds the given sub operator to the current instance if all constraints can be fulfilled.
|
---|
77 | /// </summary>
|
---|
78 | /// <param name="op">The operator to add.</param>
|
---|
79 | /// <param name="violatedConstraints">Output parameter; contains all constraints that could not be
|
---|
80 | /// fulfilled.</param>
|
---|
81 | /// <returns><c>true</c> if the operator could be added without violating constraints,
|
---|
82 | /// <c>false</c> otherwise.</returns>
|
---|
83 | bool TryAddSubOperator(IOperator op, out ICollection<IConstraint> violatedConstraints);
|
---|
84 | /// <summary>
|
---|
85 | /// Adds the given sub operator at a the specified <paramref name="index"/>.
|
---|
86 | /// </summary>
|
---|
87 | /// <param name="op">The operator to add.</param>
|
---|
88 | /// <param name="index">The position where to add the operator.</param>
|
---|
89 | void AddSubOperator(IOperator op, int index);
|
---|
90 | /// <summary>
|
---|
91 | /// Adds the given operator at the specified <paramref name="index"/> to the current instance
|
---|
92 | /// if all constraints can be fulfilled.
|
---|
93 | /// </summary>
|
---|
94 | /// <param name="op">The operator to add.</param>
|
---|
95 | /// <param name="index">The position where to add the operator.</param>
|
---|
96 | /// <returns><c>true</c> if the operator could be added without violating constraints,
|
---|
97 | /// <c>false</c> otherwise.</returns>
|
---|
98 | bool TryAddSubOperator(IOperator op, int index);
|
---|
99 | /// <summary>
|
---|
100 | /// Adds the given operator at the specified <paramref name="index"/> to the current instance
|
---|
101 | /// if all constraints can be fulfilled.
|
---|
102 | /// </summary>
|
---|
103 | /// <param name="op">The operator to add.</param>
|
---|
104 | /// <param name="index">The position where to add the operator.</param>
|
---|
105 | /// <param name="violatedConstraints">Output parameter; contains all constraints that could not be
|
---|
106 | /// fulfilled.</param>
|
---|
107 | /// <returns><c>true</c> if the operator could be added without violating constraints,
|
---|
108 | /// <c>false</c> otherwise.</returns>
|
---|
109 | bool TryAddSubOperator(IOperator op, int index, out ICollection<IConstraint> violatedConstraints);
|
---|
110 | /// <summary>
|
---|
111 | /// Removes a sub operator at the specified <paramref name="index"/>.
|
---|
112 | /// </summary>
|
---|
113 | /// <param name="index">The position where to delete the operator.</param>
|
---|
114 | void RemoveSubOperator(int index);
|
---|
115 | /// <summary>
|
---|
116 | /// Removes a sub operator at the specified <paramref name="index"/> if all constraint can be fulfilled.
|
---|
117 | /// </summary>
|
---|
118 | /// <param name="index">The position where to delete the operator.</param>
|
---|
119 | /// <returns><c>true</c> if the operator could be deleted without violating constraints,
|
---|
120 | /// <c>false</c> otherwise.</returns>
|
---|
121 | bool TryRemoveSubOperator(int index);
|
---|
122 | /// <summary>
|
---|
123 | /// Deletes the operator at the specified <paramref name="index"/>
|
---|
124 | /// if all constraints can be fulfilled.
|
---|
125 | /// </summary>
|
---|
126 | /// <param name="index">The position where to delete the operator.</param>
|
---|
127 | /// <param name="violatedConstraints">Output parameter; contains all constraints that could not be
|
---|
128 | /// fulfilled.</param>
|
---|
129 | /// <returns><c>true</c> if the operator could be deleted without violating constraints,
|
---|
130 | /// <c>false</c> otherwise.</returns>
|
---|
131 | bool TryRemoveSubOperator(int index, out ICollection<IConstraint> violatedConstraints);
|
---|
132 |
|
---|
133 | /// <summary>
|
---|
134 | /// Gets the variable info with the given <paramref name="formalName"/>.
|
---|
135 | /// </summary>
|
---|
136 | /// <param name="formalName">The formal name of the variable info.</param>
|
---|
137 | /// <returns>The variable info with the specified formal name.</returns>
|
---|
138 | IVariableInfo GetVariableInfo(string formalName);
|
---|
139 | /// <summary>
|
---|
140 | /// Adds the specified variable info to the current instance.
|
---|
141 | /// </summary>
|
---|
142 | /// <param name="variableInfo">The variable info to add.</param>
|
---|
143 | void AddVariableInfo(IVariableInfo variableInfo);
|
---|
144 | /// <summary>
|
---|
145 | /// Adds the specified variable info to the current instance, if all constraints can be fulfilled.
|
---|
146 | /// </summary>
|
---|
147 | /// <param name="variableInfo">The variable info to add.</param>
|
---|
148 | /// <returns><c>true</c> if the variable info could be added without violating constraints,
|
---|
149 | /// <c>false</c> otherwise.</returns>
|
---|
150 | bool TryAddVariableInfo(IVariableInfo variableInfo);
|
---|
151 | /// <summary>
|
---|
152 | /// Adds the specified variable info to the current instance, if all constraints can be fulfilled.
|
---|
153 | /// </summary>
|
---|
154 | /// <param name="variableInfo">The variable info to add.</param>
|
---|
155 | /// <param name="violatedConstraints">Output parameter; contains all constraints that could not be
|
---|
156 | /// fulfilled.</param>
|
---|
157 | /// <returns><c>true</c> if the variable info could be added without violating constraints,
|
---|
158 | /// <c>false</c> otherwise.</returns>
|
---|
159 | bool TryAddVariableInfo(IVariableInfo variableInfo, out ICollection<IConstraint> violatedConstraints);
|
---|
160 | /// <summary>
|
---|
161 | /// Removes the variable info with the given formal name.
|
---|
162 | /// </summary>
|
---|
163 | /// <param name="formalName">The formal name of the variable info to remove.</param>
|
---|
164 | void RemoveVariableInfo(string formalName);
|
---|
165 | /// <summary>
|
---|
166 | /// Deletes the variable info with the given formal name,
|
---|
167 | /// if all constraints can be fulfilled.
|
---|
168 | /// </summary>
|
---|
169 | /// <param name="formalName">The formal name of the variable info to remove.</param>
|
---|
170 | /// <returns><c>true</c> if the variable info could be deleted without violating constraints,
|
---|
171 | /// <c>false</c> otherwise.</returns>
|
---|
172 | bool TryRemoveVariableInfo(string formalName);
|
---|
173 | /// <summary>
|
---|
174 | /// Deletes the variable info with the given formal name,
|
---|
175 | /// if all constraints can be fulfilled.
|
---|
176 | /// </summary>
|
---|
177 | /// <param name="formalName">The formal name of the variable info to remove.</param>
|
---|
178 | /// <param name="violatedConstraints">Output parameter; contains all constraints that could not be
|
---|
179 | /// fulfilled.</param>
|
---|
180 | /// <returns><c>true</c> if the variable info could be deleted without violating constraints,
|
---|
181 | /// <c>false</c> otherwise.</returns>
|
---|
182 | bool TryRemoveVariableInfo(string formalName, out ICollection<IConstraint> violatedConstraints);
|
---|
183 |
|
---|
184 | /// <summary>
|
---|
185 | /// Gets a variable with the given <paramref name="name"/>.
|
---|
186 | /// </summary>
|
---|
187 | /// <param name="name">The name of the variable.</param>
|
---|
188 | /// <returns>The variable with the specified name.</returns>
|
---|
189 | IVariable GetVariable(string name);
|
---|
190 | /// <summary>
|
---|
191 | /// Adds the specified <paramref name="variable"/> to the current instance.
|
---|
192 | /// </summary>
|
---|
193 | /// <param name="variable">The variable to add.</param>
|
---|
194 | void AddVariable(IVariable variable);
|
---|
195 | /// <summary>
|
---|
196 | /// Adds the specified <paramref name="variable"/> to the current instance if all constraints can
|
---|
197 | /// be fulfilled.
|
---|
198 | /// </summary>
|
---|
199 | /// <param name="variable">The variable to add.</param>
|
---|
200 | /// <returns><c>true</c> if the variable could be added without violating constraints,
|
---|
201 | /// <c>false</c> otherwise.</returns>
|
---|
202 | bool TryAddVariable(IVariable variable);
|
---|
203 | /// <summary>
|
---|
204 | /// Adds the specified <paramref name="variable"/> to the current instance if all constraints can
|
---|
205 | /// be fulfilled.
|
---|
206 | /// </summary>
|
---|
207 | /// <param name="variable">The variable to add.</param>
|
---|
208 | /// <param name="violatedConstraints">Output parameter; contains all constraints that could
|
---|
209 | /// not be fulfillled.</param>
|
---|
210 | /// <returns><c>true</c> if the variable could be added without violating constraints,
|
---|
211 | /// <c>false</c> otherwise.</returns>
|
---|
212 | bool TryAddVariable(IVariable variable, out ICollection<IConstraint> violatedConstraints);
|
---|
213 | /// <summary>
|
---|
214 | /// Deletes the variable with the specified <paramref name="name"/>.
|
---|
215 | /// </summary>
|
---|
216 | /// <param name="name">The name of the variable to delete.</param>
|
---|
217 | void RemoveVariable(string name);
|
---|
218 | /// <summary>
|
---|
219 | /// Deletes the variable with the specified <paramref name="name"/> if all constraints can be
|
---|
220 | /// fulfilled.
|
---|
221 | /// </summary>
|
---|
222 | /// <param name="name">The name of the variable to remove.</param>
|
---|
223 | /// <returns><c>true</c> if the variable could be deleted without violating constraints,
|
---|
224 | /// <c>false</c> otherwise.</returns>
|
---|
225 | bool TryRemoveVariable(string name);
|
---|
226 | /// <summary>
|
---|
227 | /// Deletes the variable with the specified <paramref name="name"/> if all constraints can be
|
---|
228 | /// fulfilled.
|
---|
229 | /// </summary>
|
---|
230 | /// <param name="name">The name of the variable to remove.</param>
|
---|
231 | /// <param name="violatedConstraints">Output parameter; contains all constraints that could
|
---|
232 | /// not be fulfilled.</param>
|
---|
233 | /// <returns><c>true</c> if the variable could be deleted without violating constraints,
|
---|
234 | /// <c>false</c> otherwise.</returns>
|
---|
235 | bool TryRemoveVariable(string name, out ICollection<IConstraint> violatedConstraints);
|
---|
236 |
|
---|
237 | /// <inheritdoc cref="GetVariableValue(string, HeuristicLab.Core.IScope, bool)"/>
|
---|
238 | /// <typeparam name="T">The type of the value that is searched.</typeparam>
|
---|
239 | T GetVariableValue<T>(string formalName, IScope scope, bool recursiveLookup) where T : class, IItem;
|
---|
240 | /// <inheritdoc cref="GetVariableValue(string, HeuristicLab.Core.IScope, bool, bool)"/>
|
---|
241 | /// <typeparam name="T">The type of the value that is searched.</typeparam>
|
---|
242 | T GetVariableValue<T>(string formalName, IScope scope, bool recursiveLookup, bool throwOnError) where T : class, IItem;
|
---|
243 | /// <inheritdoc cref="GetVariableValue(System.String, IScope, bool, bool)"
|
---|
244 | /// select="summary"/>
|
---|
245 | /// <param name="formalName">The formal name of the variable info whose variable value is searched.</param>
|
---|
246 | /// <param name="scope">The scope where to look for the variable.</param>
|
---|
247 | /// <param name="recursiveLookup">Boolean value, whether also the parent scopes shall be searched if
|
---|
248 | /// the variable is not found in the specified <paramref name="scope"/>.</param>
|
---|
249 | /// <returns>The value of the searched variable or null if it is not found.</returns>
|
---|
250 | IItem GetVariableValue(string formalName, IScope scope, bool recursiveLookup);
|
---|
251 | /// <summary>
|
---|
252 | /// Gets the value of the variable in the specified <paramref name="scope"/>
|
---|
253 | /// whose variable(parameter) info has the specified <paramref name="formalName"/>.
|
---|
254 | /// </summary>
|
---|
255 | /// <param name="formalName">The formal name of the variable info whose variable value is searched.</param>
|
---|
256 | /// <param name="scope">The scope where to look for the variable.</param>
|
---|
257 | /// <param name="recursiveLookup">Boolean value, whether also the parent scopes shall be searched if
|
---|
258 | /// the variable is not found in the specified <paramref name="scope"/>.</param>
|
---|
259 | /// <param name="throwOnError">Boolean value, whether an exception shall be thrown, if the variable
|
---|
260 | /// cannot be found or just <c>null</c> shall be returned.</param>
|
---|
261 | /// <returns>The value of the searched variable (or null if the variable is not
|
---|
262 | /// found and <paramref name="throwOnError"/> is set to false).</returns>
|
---|
263 | IItem GetVariableValue(string formalName, IScope scope, bool recursiveLookup, bool throwOnError);
|
---|
264 |
|
---|
265 | /// <summary>
|
---|
266 | /// Executes the current instance on the specified <paramref name="scope"/>.
|
---|
267 | /// </summary>
|
---|
268 | /// <param name="scope">The scope where to execute the current instance.</param>
|
---|
269 | /// <returns>The next operation.</returns>
|
---|
270 | IOperation Execute(IScope scope);
|
---|
271 | /// <summary>
|
---|
272 | /// Aborts the current operator.
|
---|
273 | /// </summary>
|
---|
274 | void Abort();
|
---|
275 |
|
---|
276 | /// <summary>
|
---|
277 | /// Occurs when the name of the operator was changed.
|
---|
278 | /// </summary>
|
---|
279 | event EventHandler NameChanged;
|
---|
280 | /// <summary>
|
---|
281 | /// Occurs when the breakpoint flag of the current instance was changed.
|
---|
282 | /// </summary>
|
---|
283 | event EventHandler BreakpointChanged;
|
---|
284 | /// <summary>
|
---|
285 | /// Occurs when a sub operator has been added.
|
---|
286 | /// </summary>
|
---|
287 | event EventHandler<OperatorIndexEventArgs> SubOperatorAdded;
|
---|
288 | /// <summary>
|
---|
289 | /// Occurs when a sub operator has been deleted.
|
---|
290 | /// </summary>
|
---|
291 | event EventHandler<OperatorIndexEventArgs> SubOperatorRemoved;
|
---|
292 | /// <summary>
|
---|
293 | /// Occurs when a variable info has been added.
|
---|
294 | /// </summary>
|
---|
295 | event EventHandler<VariableInfoEventArgs> VariableInfoAdded;
|
---|
296 | /// <summary>
|
---|
297 | /// Occurs when a variable info has been deleted.
|
---|
298 | /// </summary>
|
---|
299 | event EventHandler<VariableInfoEventArgs> VariableInfoRemoved;
|
---|
300 | /// <summary>
|
---|
301 | /// Occurs when a variable has been added.
|
---|
302 | /// </summary>
|
---|
303 | event EventHandler<VariableEventArgs> VariableAdded;
|
---|
304 | /// <summary>
|
---|
305 | /// Occurs when a variable has been deleted.
|
---|
306 | /// </summary>
|
---|
307 | event EventHandler<VariableEventArgs> VariableRemoved;
|
---|
308 | /// <summary>
|
---|
309 | /// Occurs when the current instance is executed.
|
---|
310 | /// </summary>
|
---|
311 | event EventHandler Executed;
|
---|
312 | }
|
---|
313 | }
|
---|