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