Changeset 776 for trunk/sources/HeuristicLab.Core/EngineBase.cs
- Timestamp:
- 11/19/08 12:12:39 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Core/EngineBase.cs
r47 r776 27 27 28 28 namespace HeuristicLab.Core { 29 /// <summary> 30 /// Base class to represent an engine, which is an interpreter, holding the code, the data and 31 /// the actual state, which is the runtime stack and a pointer onto the next operation. It represents 32 /// one execution and can handle parallel executions. 33 /// </summary> 29 34 public abstract class EngineBase : ItemBase, IEngine { 35 /// <summary> 36 /// Field of the current instance that represent the operator graph. 37 /// </summary> 30 38 protected IOperatorGraph myOperatorGraph; 39 /// <summary> 40 /// Gets the current operator graph. 41 /// </summary> 31 42 public IOperatorGraph OperatorGraph { 32 43 get { return myOperatorGraph; } 33 44 } 45 /// <summary> 46 /// Field of the current instance that represent the global scope. 47 /// </summary> 34 48 protected IScope myGlobalScope; 49 /// <summary> 50 /// Gets the current global scope. 51 /// </summary> 35 52 public IScope GlobalScope { 36 53 get { return myGlobalScope; } … … 38 55 39 56 private TimeSpan myExecutionTime; 57 /// <summary> 58 /// Gets or sets the execution time. 59 /// </summary> 60 /// <remarks>Calls <see cref="OnExecutionTimeChanged"/> in the setter.</remarks> 40 61 public TimeSpan ExecutionTime { 41 62 get { return myExecutionTime; } … … 46 67 } 47 68 69 /// <summary> 70 /// Field of the current instance that represent the execution stack. 71 /// </summary> 48 72 protected Stack<IOperation> myExecutionStack; 73 /// <summary> 74 /// Gets the current execution stack. 75 /// </summary> 49 76 public Stack<IOperation> ExecutionStack { 50 77 get { return myExecutionStack; } 51 78 } 79 80 /// <summary> 81 /// Flag of the current instance whether it is currently running. 82 /// </summary> 52 83 protected bool myRunning; 84 /// <summary> 85 /// Gets information whether the instance is currently running. 86 /// </summary> 53 87 public bool Running { 54 88 get { return myRunning; } 55 89 } 90 91 /// <summary> 92 /// Flag of the current instance whether it is canceled. 93 /// </summary> 56 94 protected bool myCanceled; 95 /// <summary> 96 /// Gets information whether the instance is currently canceled. 97 /// </summary> 57 98 public bool Canceled { 58 99 get { return myCanceled; } 59 100 } 101 /// <summary> 102 /// Gets information whether the instance has already terminated. 103 /// </summary> 60 104 public virtual bool Terminated { 61 105 get { return ExecutionStack.Count == 0; } 62 106 } 63 107 108 /// <summary> 109 /// Initializes a new instance of <see cref="EngineBase"/> with a new global scope. 110 /// </summary> 111 /// <remarks>Calls <see cref="Reset"/>.</remarks> 64 112 protected EngineBase() { 65 113 myOperatorGraph = new OperatorGraph(); … … 69 117 } 70 118 119 /// <summary> 120 /// Clones the current instance (deep clone). 121 /// </summary> 122 /// <remarks>Deep clone through <see cref="Auxiliary.Clone"/> method of helper class 123 /// <see cref="Auxiliary"/>.</remarks> 124 /// <param name="clonedObjects">Dictionary of all already clone objects. (Needed to avoid cycles.)</param> 125 /// <returns>The cloned object as <see cref="EngineBase"/>.</returns> 71 126 public override object Clone(IDictionary<Guid, object> clonedObjects) { 72 127 EngineBase clone = (EngineBase)base.Clone(clonedObjects); … … 84 139 } 85 140 141 /// <inheritdoc/> 142 /// <remarks>Calls <see cref="ThreadPool.QueueUserWorkItem(System.Threading.WaitCallback, object)"/> 143 /// of class <see cref="ThreadPool"/>.</remarks> 86 144 public virtual void Execute() { 87 145 myRunning = true; … … 89 147 ThreadPool.QueueUserWorkItem(new WaitCallback(Run), null); 90 148 } 149 /// <inheritdoc/> 150 /// <remarks>Calls <see cref="ThreadPool.QueueUserWorkItem(System.Threading.WaitCallback, object)"/> 151 /// of class <see cref="ThreadPool"/>.</remarks> 91 152 public virtual void ExecuteSteps(int steps) { 92 153 myRunning = true; … … 94 155 ThreadPool.QueueUserWorkItem(new WaitCallback(Run), steps); 95 156 } 157 /// <inheritdoc/> 158 /// <remarks>Calls <see cref="ThreadPool.QueueUserWorkItem(System.Threading.WaitCallback, object)"/> 159 /// of class <see cref="ThreadPool"/>.</remarks> 96 160 public void ExecuteStep() { 97 161 ExecuteSteps(1); 98 162 } 163 /// <inheritdoc/> 164 /// <remarks>Sets the protected flag <c>myCanceled</c> to <c>true</c>.</remarks> 99 165 public virtual void Abort() { 100 166 myCanceled = true; 101 167 } 168 /// <inheritdoc/> 169 /// <remarks>Sets <c>myCanceled</c> and <c>myRunning</c> to <c>false</c>. The global scope is cleared, 170 /// the execution time is reseted, the execution stack is cleared and a new <see cref="AtomicOperation"/> 171 /// with the initial operator is added. <br/> 172 /// Calls <see cref="OnInitialized"/>.</remarks> 102 173 public virtual void Reset() { 103 174 myCanceled = false; … … 142 213 } 143 214 215 /// <summary> 216 /// Performs the next operation. 217 /// </summary> 144 218 protected abstract void ProcessNextOperation(); 145 219 220 /// <summary> 221 /// Occurs when the current instance is initialized. 222 /// </summary> 146 223 public event EventHandler Initialized; 224 /// <summary> 225 /// Fires a new <c>Initialized</c> event. 226 /// </summary> 147 227 protected virtual void OnInitialized() { 148 228 if (Initialized != null) 149 229 Initialized(this, new EventArgs()); 150 230 } 231 /// <summary> 232 /// Occurs when an operation is executed. 233 /// </summary> 151 234 public event EventHandler<OperationEventArgs> OperationExecuted; 235 /// <summary> 236 /// Fires a new <c>OperationExecuted</c> event. 237 /// </summary> 238 /// <param name="operation">The operation that has been executed.</param> 152 239 protected virtual void OnOperationExecuted(IOperation operation) { 153 240 if (OperationExecuted != null) 154 241 OperationExecuted(this, new OperationEventArgs(operation)); 155 242 } 243 /// <summary> 244 /// Occurs when an exception occured during the execution. 245 /// </summary> 156 246 public event EventHandler<ExceptionEventArgs> ExceptionOccurred; 247 /// <summary> 248 /// Aborts the execution and fires a new <c>ExceptionOccurred</c> event. 249 /// </summary> 250 /// <param name="exception">The exception that was thrown.</param> 157 251 protected virtual void OnExceptionOccurred(Exception exception) { 158 252 Abort(); … … 160 254 ExceptionOccurred(this, new ExceptionEventArgs(exception)); 161 255 } 256 /// <summary> 257 /// Occurs when the execution time changed. 258 /// </summary> 162 259 public event EventHandler ExecutionTimeChanged; 260 /// <summary> 261 /// Fires a new <c>ExecutionTimeChanged</c> event. 262 /// </summary> 163 263 protected virtual void OnExecutionTimeChanged() { 164 264 if (ExecutionTimeChanged != null) 165 265 ExecutionTimeChanged(this, new EventArgs()); 166 266 } 267 /// <summary> 268 /// Occurs when the execution is finished. 269 /// </summary> 167 270 public event EventHandler Finished; 271 /// <summary> 272 /// Fires a new <c>Finished</c> event. 273 /// </summary> 168 274 protected virtual void OnFinished() { 169 275 if (Finished != null) … … 172 278 173 279 #region Persistence Methods 280 /// <summary> 281 /// Saves the current instance as <see cref="XmlNode"/> in the specified <paramref name="document"/>. 282 /// </summary> 283 /// <remarks>Calls <see cref="StorableBase.GetXmlNode"/> of base class <see cref="ItemBase"/>.<br/> 284 /// A quick overview how the single elements of the current instance are saved: 285 /// <list type="bullet"> 286 /// <item> 287 /// <term>Operator graph: </term> 288 /// <description>Saved as a child node with the tag name <c>OperatorGraph</c>.</description> 289 /// </item> 290 /// <item> 291 /// <term>Global scope: </term> 292 /// <description>Saved as a child node with the tag name <c>GlobalScope</c>.</description> 293 /// </item> 294 /// <item> 295 /// <term>Execution stack: </term> 296 /// <description>A child node is created with the tag name <c>ExecutionStack</c>. Beyond this child node 297 /// all operations of the execution stack are saved as child nodes.</description> 298 /// </item> 299 /// <item> 300 /// <term>Execution time: </term> 301 /// <description>Saved as a child node with the tag name <c>ExecutionTime</c>, where the execution 302 /// time is saved as string in the node's inner text.</description> 303 /// </item> 304 /// </list></remarks> 305 /// <param name="name">The (tag)name of the <see cref="XmlNode"/>.</param> 306 /// <param name="document">The <see cref="XmlDocument"/> where to save the data.</param> 307 /// <param name="persistedObjects">The dictionary of all already persisted objects. (Needed to avoid cycles.)</param> 308 /// <returns>The saved <see cref="XmlNode"/>.</returns> 174 309 public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid,IStorable> persistedObjects) { 175 310 XmlNode node = base.GetXmlNode(name, document, persistedObjects); … … 190 325 return node; 191 326 } 327 /// <summary> 328 /// Loads the persisted instance from the specified <paramref name="node"/>. 329 /// </summary> 330 /// <remarks>See <see cref="GetXmlNode"/> to get information on how the instance must be saved. <br/> 331 /// Calls <see cref="StorableBase.Populate"/> of base class <see cref="ItemBase"/>.</remarks> 332 /// <param name="node">The <see cref="XmlNode"/> where the engine is saved.</param> 333 /// <param name="restoredObjects">The dictionary of all already restored objects. 334 /// (Needed to avoid cycles.)</param> 192 335 public override void Populate(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) { 193 336 base.Populate(node, restoredObjects);
Note: See TracChangeset
for help on using the changeset viewer.