Changeset 2834 for trunk/sources/HeuristicLab.Core/3.3
- Timestamp:
- 02/19/10 06:19:16 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Core/3.3
- Files:
-
- 3 added
- 7 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Core/3.3/Engine.cs
r2796 r2834 71 71 72 72 [Storable] 73 private IProblem problem;74 /// <summary>75 /// Gets or sets the current problem.76 /// </summary>77 public IProblem Problem {78 get { return problem; }79 set {80 if (value == null) throw new ArgumentNullException();81 if (value != problem) {82 problem = value;83 OnProblemChanged();84 Prepare();85 }86 }87 }88 89 [Storable]90 73 private TimeSpan executionTime; 91 74 /// <summary> … … 105 88 /// </summary> 106 89 [Storable] 107 private Stack<I ExecutionSequence> executionStack;90 private Stack<IOperation> executionStack; 108 91 /// <summary> 109 92 /// Gets the current execution stack. 110 93 /// </summary> 111 protected Stack<I ExecutionSequence> ExecutionStack {94 protected Stack<IOperation> ExecutionStack { 112 95 get { return executionStack; } 113 96 } … … 146 129 protected Engine() { 147 130 globalScope = new Scope("Global"); 148 problem = null; 149 executionStack = new Stack<IExecutionSequence>(); 131 executionStack = new Stack<IOperation>(); 150 132 OperatorGraph = new OperatorGraph(); 151 133 } … … 162 144 clone.OperatorGraph = (OperatorGraph)cloner.Clone(operatorGraph); 163 145 clone.globalScope = (Scope)cloner.Clone(globalScope); 164 clone.problem = (IProblem)cloner.Clone(problem);165 146 clone.executionTime = executionTime; 166 I ExecutionSequence[] contexts = executionStack.ToArray();147 IOperation[] contexts = executionStack.ToArray(); 167 148 for (int i = contexts.Length - 1; i >= 0; i--) 168 clone.executionStack.Push((I ExecutionSequence)cloner.Clone(contexts[i]));149 clone.executionStack.Push((IOperation)cloner.Clone(contexts[i])); 169 150 clone.running = running; 170 151 clone.canceled = canceled; … … 172 153 } 173 154 155 public void Prepare(IOperation initialOperation) { 156 canceled = false; 157 running = false; 158 globalScope.Clear(); 159 ExecutionTime = new TimeSpan(); 160 executionStack.Clear(); 161 if (initialOperation != null) 162 executionStack.Push(initialOperation); 163 OnPrepared(); 164 } 174 165 /// <inheritdoc/> 175 166 /// <remarks>Sets <c>myCanceled</c> and <c>myRunning</c> to <c>false</c>. The global scope is cleared, … … 178 169 /// Calls <see cref="OnPrepared"/>.</remarks> 179 170 public void Prepare() { 180 canceled = false; 181 running = false; 182 globalScope.Clear(); 183 ExecutionTime = new TimeSpan(); 184 executionStack.Clear(); 185 if ((OperatorGraph.InitialOperator != null) && (Problem != null)) 186 executionStack.Push(new ExecutionContext(null, OperatorGraph.InitialOperator, GlobalScope, Problem)); 187 OnPrepared(); 171 if (OperatorGraph.InitialOperator != null) 172 Prepare(new ExecutionContext(null, OperatorGraph.InitialOperator, GlobalScope)); 188 173 } 189 174 /// <inheritdoc/> … … 254 239 } 255 240 /// <summary> 256 /// Occurs when the problem was changed.257 /// </summary>258 public event EventHandler ProblemChanged;259 /// <summary>260 /// Fires a new <c>ProblemChanged</c> event.261 /// </summary>262 protected virtual void OnProblemChanged() {263 if (ProblemChanged != null)264 ProblemChanged(this, EventArgs.Empty);265 }266 /// <summary>267 241 /// Occurs when the execution time changed. 268 242 /// </summary> -
trunk/sources/HeuristicLab.Core/3.3/ExecutionContext.cs
r2796 r2834 21 21 22 22 using System; 23 using System.Collections.Generic; 24 using System.Text; 23 using HeuristicLab.Collections; 25 24 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 25 27 26 namespace HeuristicLab.Core { 28 public class ExecutionContext : DeepCloneable, IExecution Sequence{27 public class ExecutionContext : DeepCloneable, IExecutionContext, IAtomicOperation { 29 28 [Storable] 30 private ExecutionContext parent; 31 public ExecutionContext Parent { 29 private IParameterizedItem parameterizedItem; 30 31 [Storable] 32 private IExecutionContext parent; 33 public IExecutionContext Parent { 32 34 get { return parent; } 33 35 } 34 36 35 [Storable] 36 private IOperator op; 37 public IObservableKeyedCollection<string, IParameter> Parameters { 38 get { return parameterizedItem.Parameters; } 39 } 40 37 41 public IOperator Operator { 38 get { return op; }42 get { return parameterizedItem as IOperator; } 39 43 } 40 44 … … 45 49 } 46 50 47 [Storable]48 private IProblem problem;49 public IProblem Problem {50 get { return problem; }51 }52 53 51 private ExecutionContext() { 54 52 parent = null; 55 op= null;53 parameterizedItem = null; 56 54 scope = null; 57 problem = null;58 55 } 59 public ExecutionContext( ExecutionContext parent, IOperator op, IScope scope, IProblem problem) {60 if (( op == null) || (scope == null) || (problem== null)) throw new ArgumentNullException();56 public ExecutionContext(IExecutionContext parent, IParameterizedItem parameterizedItem, IScope scope) { 57 if ((parameterizedItem == null) || (scope == null)) throw new ArgumentNullException(); 61 58 this.parent = parent; 62 this. op = op;59 this.parameterizedItem = parameterizedItem; 63 60 this.scope = scope; 64 this.problem = problem;65 61 } 66 62 … … 68 64 ExecutionContext clone = new ExecutionContext(); 69 65 cloner.RegisterClonedObject(this, clone); 70 clone.parent = ( ExecutionContext)cloner.Clone(parent);71 clone. op = (IOperator)cloner.Clone(op);66 clone.parent = (IExecutionContext)cloner.Clone(parent); 67 clone.parameterizedItem = (IParameterizedItem)cloner.Clone(parameterizedItem); 72 68 clone.scope = (IScope)cloner.Clone(scope); 73 clone.problem = (IProblem)cloner.Clone(problem);74 69 return clone; 75 70 } 76 71 77 public ExecutionContext CreateContext(IOperator op) {78 return new ExecutionContext(parent, op, scope , problem);72 public IAtomicOperation CreateOperation(IOperator op) { 73 return new ExecutionContext(parent, op, scope); 79 74 } 80 public ExecutionContext CreateContext(IOperator op, IScope scope) {81 return new ExecutionContext(parent, op, scope , problem);75 public IAtomicOperation CreateOperation(IOperator op, IScope scope) { 76 return new ExecutionContext(parent, op, scope); 82 77 } 83 public ExecutionContext CreateChildContext(IOperator op) {84 return new ExecutionContext(this, op, scope , problem);78 public IAtomicOperation CreateChildOperation(IOperator op) { 79 return new ExecutionContext(this, op, scope); 85 80 } 86 public ExecutionContext CreateChildContext(IOperator op, IScope scope) {87 return new ExecutionContext(this, op, scope , problem);81 public IAtomicOperation CreateChildOperation(IOperator op, IScope scope) { 82 return new ExecutionContext(this, op, scope); 88 83 } 89 84 } -
trunk/sources/HeuristicLab.Core/3.3/HeuristicLab.Core-3.3.csproj
r2805 r2834 104 104 <Compile Include="ChangedEventArgs.cs" /> 105 105 <None Include="HeuristicLabCorePlugin.cs.frame" /> 106 <Compile Include="Interfaces\IParameterizedItem.cs" /> 107 <Compile Include="Interfaces\IAtomicOperation.cs" /> 108 <Compile Include="Interfaces\IExecutionContext.cs" /> 109 <Compile Include="Interfaces\IOperation.cs" /> 110 <Compile Include="OperationCollection.cs" /> 106 111 <Compile Include="ValueParameterCollection.cs" /> 107 <Compile Include="Interfaces\IProblem.cs" />108 <Compile Include="Interfaces\IExecutionSequence.cs" />109 112 <Compile Include="Interfaces\IValueLookupParameter.cs" /> 110 113 <Compile Include="Interfaces\IValueParameter.cs" /> … … 117 120 <Compile Include="Item.cs" /> 118 121 <Compile Include="NamedItem.cs" /> 119 <Compile Include="Problem.cs" />120 122 <Compile Include="OperatorGraph.cs" /> 121 123 <Compile Include="Interfaces\IParameter.cs" /> … … 128 130 <SubType>Code</SubType> 129 131 </Compile> 130 <Compile Include="ExecutionContextCollection.cs" />131 132 <Compile Include="ExecutionContext.cs" /> 132 133 <Compile Include="OperatorList.cs" /> -
trunk/sources/HeuristicLab.Core/3.3/Interfaces/IEngine.cs
r2796 r2834 38 38 /// </summary> 39 39 IScope GlobalScope { get; } 40 /// <summary>41 /// Gets the problem of the current instance.42 /// </summary>43 IProblem Problem { get; set; }44 40 45 41 /// <summary> … … 62 58 void Prepare(); 63 59 /// <summary> 60 /// Prepares the engine with a given initial operation. 61 /// </summary> 62 void Prepare(IOperation initialOperation); 63 /// <summary> 64 64 /// Executes the whole run. 65 65 /// </summary> … … 78 78 /// </summary> 79 79 event EventHandler OperatorGraphChanged; 80 /// <summary>81 /// Occurs when the problem was changed.82 /// </summary>83 event EventHandler ProblemChanged;84 80 /// <summary> 85 81 /// Occurs when the execution time was changed. -
trunk/sources/HeuristicLab.Core/3.3/Interfaces/IOperation.cs
r2829 r2834 20 20 #endregion 21 21 22 using System;23 using System.Collections.Generic;24 using System.ComponentModel;25 using System.Text;26 using System.Drawing;27 28 22 namespace HeuristicLab.Core { 29 23 /// <summary> 30 /// Interface which represents an execution context.24 /// Interface which represents an operation. 31 25 /// </summary> 32 public interface I ExecutionSequence: IDeepCloneable { }26 public interface IOperation : IDeepCloneable { } 33 27 } -
trunk/sources/HeuristicLab.Core/3.3/Interfaces/IOperator.cs
r2790 r2834 21 21 22 22 using System; 23 using System.Collections.Generic;24 using System.Text;25 using HeuristicLab.Common;26 using HeuristicLab.Collections;27 23 28 24 namespace HeuristicLab.Core { … … 31 27 /// a basic instruction of an algorithm. 32 28 /// </summary> 33 public interface IOperator : INamedItem { 34 IObservableKeyedCollection<string, IParameter> Parameters { get; } 35 29 public interface IOperator : INamedItem, IParameterizedItem { 36 30 /// <summary> 37 31 /// Gets or sets a boolean value whether the engine should stop here during the run. … … 44 38 /// <param name="scope">The scope where to execute the current instance.</param> 45 39 /// <returns>The next operation.</returns> 46 I ExecutionSequence Execute(ExecutionContext context);40 IOperation Execute(IExecutionContext context); 47 41 /// <summary> 48 42 /// Aborts the current operator. -
trunk/sources/HeuristicLab.Core/3.3/Interfaces/IParameter.cs
r2790 r2834 21 21 22 22 using System; 23 using System.Collections.Generic;24 using System.Text;25 using System.Xml;26 using HeuristicLab.Common;27 23 28 24 namespace HeuristicLab.Core { … … 30 26 Type DataType { get; } 31 27 IItem ActualValue { get; set; } 32 ExecutionContext ExecutionContext { get; set; }28 IExecutionContext ExecutionContext { get; set; } 33 29 } 34 30 } -
trunk/sources/HeuristicLab.Core/3.3/NamedItemCollection.cs
r2833 r2834 21 21 22 22 using System; 23 using System.Linq;24 23 using System.Collections.Generic; 25 24 using System.Drawing; 25 using System.Linq; 26 26 using HeuristicLab.Collections; 27 27 using HeuristicLab.Common; -
trunk/sources/HeuristicLab.Core/3.3/OperationCollection.cs
r2829 r2834 20 20 #endregion 21 21 22 using System;23 22 using System.Collections.Generic; 24 23 using System.Linq; 25 using System.Text;26 using System.Xml;27 24 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 25 29 26 namespace HeuristicLab.Core { 30 public class ExecutionContextCollection : DeepCloneable, IList<IExecutionSequence>, IExecutionSequence{27 public class OperationCollection : DeepCloneable, IList<IOperation>, IOperation { 31 28 [Storable] 32 private IList<I ExecutionSequence> contexts;29 private IList<IOperation> operations; 33 30 34 31 [Storable] … … 39 36 } 40 37 41 public ExecutionContextCollection() {42 contexts = new List<IExecutionSequence>();38 public OperationCollection() { 39 operations = new List<IOperation>(); 43 40 parallel = false; 44 41 } 45 public ExecutionContextCollection(IEnumerable<IExecutionSequence> collection) {46 contexts = new List<IExecutionSequence>(collection.Where(e => e != null));42 public OperationCollection(IEnumerable<IOperation> collection) { 43 operations = new List<IOperation>(collection.Where(e => e != null)); 47 44 parallel = false; 48 45 } 49 public ExecutionContextCollection(params IExecutionSequence[] list) {50 contexts = new List<IExecutionSequence>(list.Where(e => e != null));46 public OperationCollection(params IOperation[] list) { 47 operations = new List<IOperation>(list.Where(e => e != null)); 51 48 parallel = false; 52 49 } 53 50 54 51 public override IDeepCloneable Clone(Cloner cloner) { 55 ExecutionContextCollection clone = new ExecutionContextCollection();52 OperationCollection clone = new OperationCollection(this.Select(x => (IOperation)cloner.Clone(x))); 56 53 cloner.RegisterClonedObject(this, clone); 57 54 clone.parallel = parallel; 58 for (int i = 0; i < contexts.Count; i++)59 clone.contexts.Add((IExecutionSequence)cloner.Clone(contexts[i]));60 55 return clone; 61 56 } 62 57 63 #region IList<I ExecutionContext> Members64 public int IndexOf(I ExecutionSequenceitem) {65 return contexts.IndexOf(item);58 #region IList<IOperation> Members 59 public int IndexOf(IOperation item) { 60 return operations.IndexOf(item); 66 61 } 67 public void Insert(int index, I ExecutionSequenceitem) {68 if (item != null) contexts.Insert(index, item);62 public void Insert(int index, IOperation item) { 63 if (item != null) operations.Insert(index, item); 69 64 } 70 65 public void RemoveAt(int index) { 71 contexts.RemoveAt(index);66 operations.RemoveAt(index); 72 67 } 73 public I ExecutionSequencethis[int index] {74 get { return contexts[index]; }75 set { if (value != null) contexts[index] = value; }68 public IOperation this[int index] { 69 get { return operations[index]; } 70 set { if (value != null) operations[index] = value; } 76 71 } 77 72 #endregion 78 73 79 #region ICollection<I ExecutionContext> Members80 public void Add(I ExecutionSequenceitem) {81 if (item != null) contexts.Add(item);74 #region ICollection<IOperation> Members 75 public void Add(IOperation item) { 76 if (item != null) operations.Add(item); 82 77 } 83 78 public void Clear() { 84 contexts.Clear();79 operations.Clear(); 85 80 } 86 public bool Contains(I ExecutionSequenceitem) {87 return contexts.Contains(item);81 public bool Contains(IOperation item) { 82 return operations.Contains(item); 88 83 } 89 public void CopyTo(I ExecutionSequence[] array, int arrayIndex) {90 contexts.CopyTo(array, arrayIndex);84 public void CopyTo(IOperation[] array, int arrayIndex) { 85 operations.CopyTo(array, arrayIndex); 91 86 } 92 87 public int Count { 93 get { return contexts.Count; }88 get { return operations.Count; } 94 89 } 95 90 public bool IsReadOnly { 96 get { return contexts.IsReadOnly; }91 get { return operations.IsReadOnly; } 97 92 } 98 public bool Remove(I ExecutionSequenceitem) {99 return contexts.Remove(item);93 public bool Remove(IOperation item) { 94 return operations.Remove(item); 100 95 } 101 96 #endregion 102 97 103 #region IEnumerable<I ExecutionContext> Members104 public IEnumerator<I ExecutionSequence> GetEnumerator() {105 return contexts.GetEnumerator();98 #region IEnumerable<IOperation> Members 99 public IEnumerator<IOperation> GetEnumerator() { 100 return operations.GetEnumerator(); 106 101 } 107 102 #endregion … … 109 104 #region IEnumerable Members 110 105 System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { 111 return contexts.GetEnumerator();106 return operations.GetEnumerator(); 112 107 } 113 108 #endregion
Note: See TracChangeset
for help on using the changeset viewer.