Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Core/3.2/Interfaces/IOperator.cs @ 1847

Last change on this file since 1847 was 1847, checked in by gkronber, 15 years ago

Fixed #633 for the SequentialEngine by:

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