Changeset 2757 for trunk/sources
- Timestamp:
- 02/08/10 03:43:36 (15 years ago)
- Location:
- trunk/sources
- Files:
-
- 8 added
- 15 deleted
- 38 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Core/3.3/Engine.cs
r2687 r2757 93 93 /// </summary> 94 94 [Storable] 95 private Stack< ExecutionContext> executionStack;95 private Stack<IExecutionContext> executionStack; 96 96 /// <summary> 97 97 /// Gets the current execution stack. 98 98 /// </summary> 99 protected Stack< ExecutionContext> ExecutionStack {99 protected Stack<IExecutionContext> ExecutionStack { 100 100 get { return executionStack; } 101 101 } … … 135 135 protected Engine() { 136 136 globalScope = new Scope("Global"); 137 executionStack = new Stack< ExecutionContext>();137 executionStack = new Stack<IExecutionContext>(); 138 138 OperatorGraph = new OperatorGraph(); 139 139 } … … 151 151 clone.globalScope = (Scope)cloner.Clone(globalScope); 152 152 clone.executionTime = executionTime; 153 ExecutionContext[] contexts = executionStack.ToArray();153 IExecutionContext[] contexts = executionStack.ToArray(); 154 154 for (int i = contexts.Length - 1; i >= 0; i--) 155 clone.executionStack.Push(( ExecutionContext)cloner.Clone(contexts[i]));155 clone.executionStack.Push((IExecutionContext)cloner.Clone(contexts[i])); 156 156 clone.running = running; 157 157 clone.canceled = canceled; -
trunk/sources/HeuristicLab.Core/3.3/ExecutionContext.cs
r2687 r2757 26 26 27 27 namespace HeuristicLab.Core { 28 public class ExecutionContext : DeepCloneable {28 public class ExecutionContext : DeepCloneable, IExecutionContext { 29 29 [Storable] 30 30 private ExecutionContext parent; -
trunk/sources/HeuristicLab.Core/3.3/ExecutionContextCollection.cs
r2664 r2757 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Linq; 24 25 using System.Text; 25 26 using System.Xml; … … 27 28 28 29 namespace HeuristicLab.Core { 29 public class ExecutionContextCollection : DeepCloneable, IList< ExecutionContext>{30 public class ExecutionContextCollection : DeepCloneable, IList<IExecutionContext>, IExecutionContext { 30 31 [Storable] 31 private IList< ExecutionContext> contexts;32 private IList<IExecutionContext> contexts; 32 33 33 34 [Storable] … … 39 40 40 41 public ExecutionContextCollection() { 41 contexts = new List< ExecutionContext>();42 contexts = new List<IExecutionContext>(); 42 43 parallel = false; 43 44 } 44 public ExecutionContextCollection(IEnumerable< ExecutionContext> collection) {45 contexts = new List< ExecutionContext>(collection);45 public ExecutionContextCollection(IEnumerable<IExecutionContext> collection) { 46 contexts = new List<IExecutionContext>(collection.Where(e => e != null)); 46 47 parallel = false; 47 48 } 48 public ExecutionContextCollection(params ExecutionContext[] list) {49 contexts = new List< ExecutionContext>(list);49 public ExecutionContextCollection(params IExecutionContext[] list) { 50 contexts = new List<IExecutionContext>(list.Where(e => e != null)); 50 51 parallel = false; 51 52 } … … 56 57 clone.parallel = parallel; 57 58 for (int i = 0; i < contexts.Count; i++) 58 clone.contexts.Add(( ExecutionContext)cloner.Clone(contexts[i]));59 clone.contexts.Add((IExecutionContext)cloner.Clone(contexts[i])); 59 60 return clone; 60 61 } 61 62 62 #region IList< ExecutionContext> Members63 public int IndexOf( ExecutionContext item) {63 #region IList<IExecutionContext> Members 64 public int IndexOf(IExecutionContext item) { 64 65 return contexts.IndexOf(item); 65 66 } 66 public void Insert(int index, ExecutionContext item) {67 contexts.Insert(index, item);67 public void Insert(int index, IExecutionContext item) { 68 if (item != null) contexts.Insert(index, item); 68 69 } 69 70 public void RemoveAt(int index) { 70 71 contexts.RemoveAt(index); 71 72 } 72 public ExecutionContext this[int index] {73 public IExecutionContext this[int index] { 73 74 get { return contexts[index]; } 74 set { contexts[index] = value; }75 set { if (value != null) contexts[index] = value; } 75 76 } 76 77 #endregion 77 78 78 #region ICollection< ExecutionContext> Members79 public void Add( ExecutionContext item) {80 contexts.Add(item);79 #region ICollection<IExecutionContext> Members 80 public void Add(IExecutionContext item) { 81 if (item != null) contexts.Add(item); 81 82 } 82 83 public void Clear() { 83 84 contexts.Clear(); 84 85 } 85 public bool Contains( ExecutionContext item) {86 public bool Contains(IExecutionContext item) { 86 87 return contexts.Contains(item); 87 88 } 88 public void CopyTo( ExecutionContext[] array, int arrayIndex) {89 public void CopyTo(IExecutionContext[] array, int arrayIndex) { 89 90 contexts.CopyTo(array, arrayIndex); 90 91 } … … 95 96 get { return contexts.IsReadOnly; } 96 97 } 97 public bool Remove( ExecutionContext item) {98 public bool Remove(IExecutionContext item) { 98 99 return contexts.Remove(item); 99 100 } 100 101 #endregion 101 102 102 #region IEnumerable< ExecutionContext> Members103 public IEnumerator< ExecutionContext> GetEnumerator() {103 #region IEnumerable<IExecutionContext> Members 104 public IEnumerator<IExecutionContext> GetEnumerator() { 104 105 return contexts.GetEnumerator(); 105 106 } -
trunk/sources/HeuristicLab.Core/3.3/HeuristicLab.Core-3.3.csproj
r2756 r2757 104 104 <Compile Include="ChangedEventArgs.cs" /> 105 105 <None Include="HeuristicLabCorePlugin.cs.frame" /> 106 <Compile Include="Interfaces\IExecutionContext.cs" /> 106 107 <Compile Include="Interfaces\IValueLookupParameter.cs" /> 107 108 <Compile Include="Interfaces\IValueParameter.cs" /> -
trunk/sources/HeuristicLab.Core/3.3/Interfaces/IOperator.cs
r2653 r2757 44 44 /// <param name="scope">The scope where to execute the current instance.</param> 45 45 /// <returns>The next operation.</returns> 46 ExecutionContextCollectionExecute(ExecutionContext context);46 IExecutionContext Execute(ExecutionContext context); 47 47 /// <summary> 48 48 /// Aborts the current operator. -
trunk/sources/HeuristicLab.Core/3.3/Interfaces/IParameter.cs
r2740 r2757 29 29 public interface IParameter : INamedItem { 30 30 Type DataType { get; } 31 IItem ActualValue { get; set; } 31 32 ExecutionContext ExecutionContext { get; set; } 32 33 } -
trunk/sources/HeuristicLab.Core/3.3/ItemArray.cs
r2746 r2757 29 29 using HeuristicLab.Common.Resources; 30 30 using HeuristicLab.Collections; 31 32 31 33 32 namespace HeuristicLab.Core { -
trunk/sources/HeuristicLab.Data.Views/3.3/HeuristicLab.Data.Views-3.3.csproj
r2754 r2757 58 58 </Compile> 59 59 <None Include="HeuristicLabDataViewsPlugin.cs.frame" /> 60 <Compile Include="ComparisonDataView.cs"> 61 <SubType>UserControl</SubType> 62 </Compile> 63 <Compile Include="ComparisonDataView.Designer.cs"> 64 <DependentUpon>ComparisonDataView.cs</DependentUpon> 65 </Compile> 60 66 <Compile Include="StringConvertibleDataView.cs"> 61 67 <SubType>UserControl</SubType> -
trunk/sources/HeuristicLab.Data/3.3/BoolData.cs
r2694 r2757 31 31 [Item("BoolData", "Represents a boolean value.")] 32 32 [Creatable("Test")] 33 public sealed class BoolData : ValueTypeData<bool>, I StringConvertibleData {33 public sealed class BoolData : ValueTypeData<bool>, IComparable, IStringConvertibleData { 34 34 public BoolData() : base() { } 35 35 public BoolData(bool value) : base(value) { } … … 39 39 cloner.RegisterClonedObject(this, clone); 40 40 return clone; 41 } 42 43 public int CompareTo(object obj) { 44 BoolData other = obj as BoolData; 45 if (other != null) 46 return Value.CompareTo(other.Value); 47 else 48 return Value.CompareTo(obj); 41 49 } 42 50 -
trunk/sources/HeuristicLab.Data/3.3/DateTimeData.cs
r2694 r2757 32 32 [Item("DateTimeData", "Represents a date and time value.")] 33 33 [Creatable("Test")] 34 public sealed class DateTimeData : ValueTypeData<DateTime>, I StringConvertibleData {34 public sealed class DateTimeData : ValueTypeData<DateTime>, IComparable, IStringConvertibleData { 35 35 public DateTimeData() : base() { } 36 36 public DateTimeData(DateTime value) : base(value) { } … … 44 44 public override string ToString() { 45 45 return Value.ToString("o"); // round-trip format 46 } 47 48 public int CompareTo(object obj) { 49 DateTimeData other = obj as DateTimeData; 50 if (other != null) 51 return Value.CompareTo(other.Value); 52 else 53 return Value.CompareTo(obj); 46 54 } 47 55 -
trunk/sources/HeuristicLab.Data/3.3/DoubleData.cs
r2694 r2757 31 31 [Item("DoubleData", "Represents a double value.")] 32 32 [Creatable("Test")] 33 public sealed class DoubleData : ValueTypeData<double>, I StringConvertibleData {33 public sealed class DoubleData : ValueTypeData<double>, IComparable, IStringConvertibleData { 34 34 public DoubleData() : base() { } 35 35 public DoubleData(double value) : base(value) { } … … 43 43 public override string ToString() { 44 44 return Value.ToString("r"); // round-trip format 45 } 46 47 public int CompareTo(object obj) { 48 DoubleData other = obj as DoubleData; 49 if (other != null) 50 return Value.CompareTo(other.Value); 51 else 52 return Value.CompareTo(obj); 45 53 } 46 54 -
trunk/sources/HeuristicLab.Data/3.3/HeuristicLab.Data-3.3.csproj
r2754 r2757 106 106 <Compile Include="BoolMatrixData.cs" /> 107 107 <None Include="HeuristicLabDataPlugin.cs.frame" /> 108 <Compile Include="Comparison.cs" /> 109 <Compile Include="ComparisonData.cs" /> 108 110 <Compile Include="StringMatrixData.cs" /> 109 111 <Compile Include="StringArrayData.cs" /> -
trunk/sources/HeuristicLab.Data/3.3/IntData.cs
r2694 r2757 31 31 [Item("IntData", "Represents an integer value.")] 32 32 [Creatable("Test")] 33 public sealed class IntData : ValueTypeData<int>, I StringConvertibleData {33 public sealed class IntData : ValueTypeData<int>, IComparable, IStringConvertibleData { 34 34 public IntData() : base() { } 35 35 public IntData(int value) : base(value) { } … … 39 39 cloner.RegisterClonedObject(this, clone); 40 40 return clone; 41 } 42 43 public int CompareTo(object obj) { 44 IntData other = obj as IntData; 45 if (other != null) 46 return Value.CompareTo(other.Value); 47 else 48 return Value.CompareTo(obj); 41 49 } 42 50 -
trunk/sources/HeuristicLab.Data/3.3/StringData.cs
r2694 r2757 31 31 [Item("StringData", "Represents a string.")] 32 32 [Creatable("Test")] 33 public sealed class StringData : Item, I StringConvertibleData {33 public sealed class StringData : Item, IComparable, IStringConvertibleData { 34 34 [Storable] 35 35 private string value; … … 63 63 } 64 64 65 public int CompareTo(object obj) { 66 StringData other = obj as StringData; 67 if (other != null) 68 return Value.CompareTo(other.Value); 69 else 70 return Value.CompareTo(obj); 71 } 72 65 73 #region IStringConvertibleData Members 66 74 bool IStringConvertibleData.Validate(string value, out string errorMessage) { -
trunk/sources/HeuristicLab.Data/3.3/TimeSpanData.cs
r2694 r2757 31 31 [Item("TimeSpanData", "Represents a duration of time.")] 32 32 [Creatable("Test")] 33 public sealed class TimeSpanData : ValueTypeData<TimeSpan>, I StringConvertibleData {33 public sealed class TimeSpanData : ValueTypeData<TimeSpan>, IComparable, IStringConvertibleData { 34 34 public TimeSpanData() : base() { } 35 35 public TimeSpanData(TimeSpan value) : base(value) { } … … 39 39 cloner.RegisterClonedObject(this, clone); 40 40 return clone; 41 } 42 43 public int CompareTo(object obj) { 44 TimeSpanData other = obj as TimeSpanData; 45 if (other != null) 46 return Value.CompareTo(other.Value); 47 else 48 return Value.CompareTo(obj); 41 49 } 42 50 -
trunk/sources/HeuristicLab.Data/3.3/ValueTypeData.cs
r2694 r2757 24 24 using System.Text; 25 25 using System.Xml; 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; 27 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; -
trunk/sources/HeuristicLab.Operators/3.3/CombinedOperator.cs
r2740 r2757 68 68 } 69 69 70 public override ExecutionContextCollectionApply() {71 ExecutionContextCollection next = base.Apply();70 public override IExecutionContext Apply() { 71 ExecutionContextCollection next = new ExecutionContextCollection(base.Apply()); 72 72 if (operatorGraph.InitialOperator != null) 73 73 next.Insert(0, new ExecutionContext(ExecutionContext, operatorGraph.InitialOperator, ExecutionContext.Scope)); -
trunk/sources/HeuristicLab.Operators/3.3/ConditionalBranch.cs
r1530 r2757 23 23 using System.Collections.Generic; 24 24 using System.Text; 25 using System.Xml; 25 26 using HeuristicLab.Core; 26 27 using HeuristicLab.Data; 28 using HeuristicLab.Parameters; 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 30 28 31 namespace HeuristicLab.Operators { 29 32 /// <summary> 30 /// Branch of (one or)two operators whose executions depend on a specificcondition.33 /// A branch of two operators whose executions depend on a condition. 31 34 /// </summary> 32 public class ConditionalBranch : OperatorBase { 33 /// <inheritdoc select="summary"/> 34 public override string Description { 35 get { return @"ConditionalBranch expects to have 1 or 2 sub-operators. 36 It will return the 1st sub-operator if ""Condition"" is true and the 2nd sub-operator if ""Condition"" equals to false. 37 38 In case a 2nd sub-operator does not exist and ""Condition"" would equal to false, Conditional Branch will not return a new operation."; } 35 [Item("ConditionalBranch", "A branch of two operators whose executions depend on a boolean condition.")] 36 [Creatable("Test")] 37 [EmptyStorableClass] 38 public class ConditionalBranch : SingleSuccessorOperator { 39 public LookupParameter<BoolData> ConditionParameter { 40 get { return (LookupParameter<BoolData>)Parameters["Condition"]; } 41 } 42 protected OperatorParameter TrueBranchParameter { 43 get { return (OperatorParameter)Parameters["TrueBranch"]; } 44 } 45 protected OperatorParameter FalseBranchParameter { 46 get { return (OperatorParameter)Parameters["FalseBranch"]; } 47 } 48 public IOperator TrueBranch { 49 get { return TrueBranchParameter.Value; } 50 set { TrueBranchParameter.Value = value; } 51 } 52 public IOperator FalseBranch { 53 get { return FalseBranchParameter.Value; } 54 set { FalseBranchParameter.Value = value; } 39 55 } 40 56 41 /// <summary>42 /// Initializes a new instance of <see cref="ConditionalBranch"/> with one variable info43 /// (<c>Condition</c>).44 /// </summary>45 57 public ConditionalBranch() 46 58 : base() { 47 AddVariableInfo(new VariableInfo("Condition", "A boolean variable that decides the branch", typeof(BoolData), VariableKind.In)); 59 Parameters.Add(new LookupParameter<BoolData>("Condition", "A boolean variable which defines which branch is executed.")); 60 Parameters.Add(new OperatorParameter("TrueBranch", "The operator which is executed if the condition is true.")); 61 Parameters.Add(new OperatorParameter("FalseBranch", "The operator which is executed if the condition is false.")); 48 62 } 49 63 50 /// <summary> 51 /// Applies the operator of branch one under a specific condition on the given 52 /// <paramref name="scope"/>, or - if existent - operator of branch two if the condition could not 53 /// be fulfilled. 54 /// </summary> 55 /// <param name="scope">The scope to apply the operators on.</param> 56 /// <returns>A new <see cref="AtomicOperation"/> with either operator 1 or operator 2 applied 57 /// to the given <paramref name="scope"/> or <c>null</c>.</returns> 58 public override IOperation Apply(IScope scope) { 59 BoolData resultData = GetVariableValue<BoolData>("Condition", scope, true); 60 bool result = resultData.Data; 61 62 if ((result) && (SubOperators.Count > 0) && (SubOperators[0] != null)) 63 return new AtomicOperation(SubOperators[0], scope); 64 else if ((!result) && (SubOperators.Count > 1) && (SubOperators[1] != null)) 65 return new AtomicOperation(SubOperators[1], scope); 66 return null; 64 public override IExecutionContext Apply() { 65 ExecutionContextCollection next = new ExecutionContextCollection(base.Apply()); 66 if (ConditionParameter.ActualValue.Value) { 67 if (TrueBranch != null) next.Insert(0, new ExecutionContext(ExecutionContext.Parent, TrueBranch, ExecutionContext.Scope)); 68 } else { 69 if (FalseBranch != null) next.Insert(0, new ExecutionContext(ExecutionContext.Parent, FalseBranch, ExecutionContext.Scope)); 70 } 71 return next; 67 72 } 68 73 } -
trunk/sources/HeuristicLab.Operators/3.3/Counter.cs
r2756 r2757 39 39 get { return (LookupParameter<IntData>)Parameters["Value"]; } 40 40 } 41 public ValueLookupParameter<IntData> IncrementPara neter {41 public ValueLookupParameter<IntData> IncrementParameter { 42 42 get { return (ValueLookupParameter<IntData>)Parameters["Increment"]; } 43 43 } 44 44 public IntData Increment { 45 get { return IncrementPara neter.Value; }46 set { IncrementPara neter.Value = value; }45 get { return IncrementParameter.Value; } 46 set { IncrementParameter.Value = value; } 47 47 } 48 48 … … 53 53 } 54 54 55 public override ExecutionContextCollectionApply() {55 public override IExecutionContext Apply() { 56 56 if (ValueParameter.ActualValue == null) ValueParameter.ActualValue = new IntData(); 57 ValueParameter.ActualValue.Value += IncrementPara neter.ActualValue.Value;57 ValueParameter.ActualValue.Value += IncrementParameter.ActualValue.Value; 58 58 return base.Apply(); 59 59 } -
trunk/sources/HeuristicLab.Operators/3.3/DoubleCounter.cs
r1530 r2757 25 25 using HeuristicLab.Core; 26 26 using HeuristicLab.Data; 27 using HeuristicLab.Parameters; 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 29 28 30 namespace HeuristicLab.Operators { 29 31 /// <summary> 30 /// Class to add a specified interval to a double value.32 /// Operator which increments a double variable. 31 33 /// </summary> 32 public class DoubleCounter : OperatorBase { 33 /// <summary> 34 /// Gets the description of the current instance. 35 /// </summary> 36 public override string Description { 37 get { return @"Adds a given interval to a double value"; } 34 [Item("DoubleCounter", "An operator which increments a double variable.")] 35 [EmptyStorableClass] 36 [Creatable("Test")] 37 public sealed class DoubleCounter : SingleSuccessorOperator { 38 public LookupParameter<DoubleData> ValueParameter { 39 get { return (LookupParameter<DoubleData>)Parameters["Value"]; } 40 } 41 public ValueLookupParameter<DoubleData> IncrementParameter { 42 get { return (ValueLookupParameter<DoubleData>)Parameters["Increment"]; } 43 } 44 public DoubleData Increment { 45 get { return IncrementParameter.Value; } 46 set { IncrementParameter.Value = value; } 38 47 } 39 48 40 /// <summary>41 /// Initializes a new instance of <see cref="DoubleCounter"/>, including two variable infos42 /// (<c>Value</c> and <c>Interval</c>).43 /// </summary>44 49 public DoubleCounter() 45 50 : base() { 46 AddVariableInfo(new VariableInfo("Value", "Counter value", typeof(DoubleData), VariableKind.In | VariableKind.Out));47 AddVariableInfo(new VariableInfo("Interval", "Interval value", typeof(DoubleData), VariableKind.In));51 Parameters.Add(new LookupParameter<DoubleData>("Value", "The value which should be incremented.")); 52 Parameters.Add(new ValueLookupParameter<DoubleData>("Increment", "The increment which is added to the value.", new DoubleData(1))); 48 53 } 49 54 50 /// <summary> 51 /// Adds to a double value of the given <paramref name="scope"/> a specified interval. 52 /// </summary> 53 /// <param name="scope">The scope whose variable should be incremented.</param> 54 /// <returns><c>null</c>.</returns> 55 public override IOperation Apply(IScope scope) { 56 DoubleData value = GetVariableValue<DoubleData>("Value", scope, true); 57 double interval = GetVariableValue<DoubleData>("Interval", scope, true).Data; 58 value.Data += interval; 59 return null; 55 public override IExecutionContext Apply() { 56 if (ValueParameter.ActualValue == null) ValueParameter.ActualValue = new DoubleData(); 57 ValueParameter.ActualValue.Value += IncrementParameter.ActualValue.Value; 58 return base.Apply(); 60 59 } 61 60 } -
trunk/sources/HeuristicLab.Operators/3.3/HeuristicLab.Operators-3.3.csproj
r2754 r2757 87 87 <Compile Include="CombinedOperator.cs" /> 88 88 <None Include="HeuristicLabOperatorsPlugin.cs.frame" /> 89 <Compile Include="ConditionalBranch.cs" /> 90 <Compile Include="Comparator.cs" /> 91 <Compile Include="ScopeCleaner.cs" /> 92 <Compile Include="SubScopesRemover.cs" /> 93 <Compile Include="SubScopesSorter.cs" /> 94 <Compile Include="DoubleCounter.cs" /> 95 <Compile Include="ParallelProcessor.cs" /> 96 <Compile Include="UniformParallelSubScopesProcessor.cs" /> 97 <Compile Include="UniformSequentialSubScopesProcessor.cs" /> 98 <Compile Include="ValueCollector.cs" /> 89 99 <Compile Include="MultipleSuccessorsOperator.cs" /> 90 100 <Compile Include="Counter.cs" /> … … 97 107 <Compile Include="SequentialProcessor.cs" /> 98 108 <Compile Include="SingleSuccessorOperator.cs" /> 109 <Compile Include="SubScopesCreater.cs" /> 110 <Compile Include="VariableInjector.cs"> 111 <SubType>Code</SubType> 112 </Compile> 99 113 </ItemGroup> 100 114 <ItemGroup> -
trunk/sources/HeuristicLab.Operators/3.3/Operator.cs
r2740 r2757 61 61 } 62 62 63 [Storable] 64 private ExecutionContext executionContext; 65 protected ExecutionContext ExecutionContext { 66 get { return executionContext; } 67 private set { 68 if (value != executionContext) { 69 executionContext = value; 70 OnExecutionContextChanged(); 71 } 72 } 73 } 74 63 75 /// <summary> 64 76 /// Flag whether the current instance has been canceled. … … 68 80 protected bool Canceled { 69 81 get { return canceled; } 82 private set { 83 if (value != canceled) { 84 canceled = value; 85 OnCanceledChanged(); 86 } 87 } 70 88 } 71 89 … … 82 100 } 83 101 } 84 }85 86 [Storable]87 private ExecutionContext executionContext;88 protected ExecutionContext ExecutionContext {89 get { return executionContext; }90 102 } 91 103 … … 118 130 119 131 /// <inheritdoc/> 120 public virtual ExecutionContextCollectionExecute(ExecutionContext context) {132 public virtual IExecutionContext Execute(ExecutionContext context) { 121 133 try { 122 canceled = false;123 executionContext = context;134 Canceled = false; 135 ExecutionContext = context; 124 136 foreach (IParameter param in Parameters) 125 137 param.ExecutionContext = context; 126 ExecutionContextCollectionnext = Apply();138 IExecutionContext next = Apply(); 127 139 OnExecuted(); 128 140 return next; … … 131 143 foreach (IParameter param in Parameters) 132 144 param.ExecutionContext = null; 133 context = null;145 ExecutionContext = null; 134 146 } 135 147 } 136 148 /// <inheritdoc/> 137 149 /// <remarks>Sets property <see cref="Canceled"/> to <c>true</c>.</remarks> 138 public v irtual void Abort() {139 canceled = true;150 public void Abort() { 151 Canceled = true; 140 152 } 141 153 /// <summary> … … 144 156 /// <param name="scope">The scope where to execute the operator</param> 145 157 /// <returns><c>null</c>.</returns> 146 public virtual ExecutionContextCollection Apply() { 147 return new ExecutionContextCollection(); 148 } 158 public abstract IExecutionContext Apply(); 149 159 160 protected virtual void OnExecutionContextChanged() { } 161 protected virtual void OnCanceledChanged() { } 150 162 /// <inheritdoc/> 151 163 public event EventHandler BreakpointChanged; -
trunk/sources/HeuristicLab.Operators/3.3/ParallelProcessor.cs
r1530 r2757 23 23 using System.Collections.Generic; 24 24 using System.Text; 25 using System.Xml; 26 using HeuristicLab.Collections; 25 27 using HeuristicLab.Core; 26 28 using HeuristicLab.Data; 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 30 28 31 namespace HeuristicLab.Operators { 29 32 /// <summary> 30 /// Performs <c>n</c> operators on the given scope; operations can be executedin parallel.33 /// Operator which executes multiple operators in parallel. 31 34 /// </summary> 32 public class ParallelProcessor : OperatorBase { 33 /// <inheritdoc select="summary"/> 34 public override string Description { 35 get { return @"TODO\r\nOperator description still missing ..."; } 35 [Item("ParallelProcessor", "An operator which executes multiple operators in parallel.")] 36 [Creatable("Test")] 37 [EmptyStorableClass] 38 public sealed class ParallelProcessor : MultipleSuccessorsOperator { 39 public ParallelProcessor() 40 : base() { 36 41 } 37 42 38 /// <summary> 39 /// Applies <c>n</c> operators on the given <paramref name="scope"/>. 40 /// </summary> 41 /// <param name="scope">The scope to apply the operators on.</param> 42 /// <returns>A new <see cref="CompositeOperation"/> with the <c>n</c> operators applied 43 /// to the given <paramref name="scope"/> with the <c>ExecuteInParallel</c> set to <c>true</c>.</returns> 44 public override IOperation Apply(IScope scope) { 45 CompositeOperation next = new CompositeOperation(); 46 next.ExecuteInParallel = true; 47 for (int i = 0; i < SubOperators.Count; i++) 48 next.AddOperation(new AtomicOperation(SubOperators[i], scope)); 43 public override IExecutionContext Apply() { 44 ExecutionContextCollection next = new ExecutionContextCollection(); 45 for (int i = 0; i < Successors.Count; i++) { 46 if (Successors[i] != null) 47 next.Add(new ExecutionContext(ExecutionContext.Parent, Successors[i], ExecutionContext.Scope)); 48 } 49 next.Parallel = true; 49 50 return next; 50 51 } -
trunk/sources/HeuristicLab.Operators/3.3/ScopeCleaner.cs
r1530 r2757 24 24 using System.Text; 25 25 using HeuristicLab.Core; 26 using HeuristicLab.Data; 26 using HeuristicLab.Parameters; 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 28 28 29 namespace HeuristicLab.Operators { 29 30 /// <summary> 30 /// Operator that removes all variables in the given scope and deletes also all subscopes.31 /// An operator which removes all variables and sub-scopes from the current scope. 31 32 /// </summary> 32 public class ScopeCleaner : OperatorBase { 33 /// <inheritdoc select="summary"/> 34 public override string Description { 35 get { return @"Removes all variables in the current scope and deletes all subscopes"; } 33 [Item("ScopeCleaner", "An operator which removes all variables and sub-scopes from the current scope.")] 34 [EmptyStorableClass] 35 [Creatable("Test")] 36 public sealed class ScopeCleaner : SingleSuccessorOperator { 37 private ScopeParameter CurrentScopeParameter { 38 get { return (ScopeParameter)Parameters["CurrentScope"]; } 39 } 40 public IScope CurrentScope { 41 get { return CurrentScopeParameter.ActualValue; } 36 42 } 37 43 38 /// <summary>39 /// Deletes all variable and sub scopes from the given <paramref name="scope"/>.40 /// </summary>41 /// <remarks>Calls <see cref="IScope.Clear"/> of interface <see cref="IScope"/>.</remarks>42 /// <param name="scope">The scope to clear.</param> 43 /// <returns><c>null</c>.</returns>44 public override IOperation Apply(IScope scope) {45 scope.Clear();46 return null;44 public ScopeCleaner() 45 : base() { 46 Parameters.Add(new ScopeParameter("CurrentScope", "The current scope whose variables and sub-scopes should be removed.")); 47 } 48 49 public override IExecutionContext Apply() { 50 CurrentScope.Variables.Clear(); 51 CurrentScope.SubScopes.Clear(); 52 return base.Apply(); 47 53 } 48 54 } -
trunk/sources/HeuristicLab.Operators/3.3/SequentialProcessor.cs
r2740 r2757 41 41 } 42 42 43 public override ExecutionContextCollectionApply() {43 public override IExecutionContext Apply() { 44 44 ExecutionContextCollection next = new ExecutionContextCollection(); 45 for (int i = 0; i < Successors.Count; i++) 46 next.Add(new ExecutionContext(ExecutionContext.Parent, Successors[i], ExecutionContext.Scope)); 45 for (int i = 0; i < Successors.Count; i++) { 46 if (Successors[i] != null) 47 next.Add(new ExecutionContext(ExecutionContext.Parent, Successors[i], ExecutionContext.Scope)); 48 } 47 49 return next; 48 50 } -
trunk/sources/HeuristicLab.Operators/3.3/SingleSuccessorOperator.cs
r2740 r2757 49 49 } 50 50 51 public override ExecutionContextCollectionApply() {51 public override IExecutionContext Apply() { 52 52 if (Successor != null) 53 return new ExecutionContext Collection(new ExecutionContext(ExecutionContext.Parent, Successor, ExecutionContext.Scope));53 return new ExecutionContext(ExecutionContext.Parent, Successor, ExecutionContext.Scope); 54 54 else 55 return n ew ExecutionContextCollection();55 return null; 56 56 } 57 57 } -
trunk/sources/HeuristicLab.Operators/3.3/SubScopesCreater.cs
r1530 r2757 25 25 using HeuristicLab.Core; 26 26 using HeuristicLab.Data; 27 using HeuristicLab.Parameters; 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 29 28 30 namespace HeuristicLab.Operators { 29 31 /// <summary> 30 /// Operator to create sub scopes in a givenscope.32 /// An operator which adds new and empty sub-scopes to the current scope. 31 33 /// </summary> 32 public class SubScopesCreater : OperatorBase { 33 /// <inheritdoc select="summary"/> 34 public override string Description { 35 get { return @"TODO\r\nOperator description still missing ..."; } 34 [Item("SubScopesCreater", "An operator which adds new and empty sub-scopes to the current scope.")] 35 [EmptyStorableClass] 36 [Creatable("Test")] 37 public class SubScopesCreater : SingleSuccessorOperator { 38 public ValueLookupParameter<IntData> NumberOfSubScopesParameter { 39 get { return (ValueLookupParameter<IntData>)Parameters["NumberOfSubScopes"]; } 40 } 41 protected ScopeParameter CurrentScopeParameter { 42 get { return (ScopeParameter)Parameters["CurrentScope"]; } 43 } 44 public IScope CurrentScope { 45 get { return CurrentScopeParameter.ActualValue; } 36 46 } 37 47 38 /// <summary>39 /// Initializes a new instance of <see cref="SubScopesCreater"/> with one variable info (<c>SubScopes</c>).40 /// </summary>41 48 public SubScopesCreater() 42 49 : base() { 43 AddVariableInfo(new VariableInfo("SubScopes", "Number of sub-scopes", typeof(IntData), VariableKind.In)); 50 Parameters.Add(new ValueLookupParameter<IntData>("NumberOfSubScopes", "The number of new and empty sub-scopes which should be added to the current scope.")); 51 Parameters.Add(new ScopeParameter("CurrentScope", "The current scope to which the new and empty sub-scopes are added.")); 44 52 } 45 53 46 /// <summary> 47 /// Creates a specified number of sub scopes in the given <paramref name="scope"/>. 48 /// </summary> 49 /// <param name="scope">The scope where to create the sub scopes.</param> 50 /// <returns><c>null</c>.</returns> 51 public override IOperation Apply(IScope scope) { 52 IntData count = GetVariableValue<IntData>("SubScopes", scope, true); 53 54 for (int i = 0; i < count.Data; i++) 55 scope.AddSubScope(new Scope(i.ToString())); 56 57 return null; 54 public override IExecutionContext Apply() { 55 int n = NumberOfSubScopesParameter.ActualValue.Value; 56 for (int i = 0; i < n; i++) 57 CurrentScope.SubScopes.Add(new Scope(i.ToString())); 58 return base.Apply(); 58 59 } 59 60 } -
trunk/sources/HeuristicLab.Operators/3.3/SubScopesRemover.cs
r1530 r2757 25 25 using HeuristicLab.Core; 26 26 using HeuristicLab.Data; 27 using HeuristicLab.Parameters; 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 29 28 30 namespace HeuristicLab.Operators { 29 31 /// <summary> 30 /// Removes one specified or - if nothing specified - all operators from the givenscope.32 /// An operator which removes one specified or (if not specified) all sub-scopes from the current scope. 31 33 /// </summary> 32 public class SubScopesRemover : OperatorBase { 33 /// <inheritdoc select="summary"/> 34 public override string Description { 35 get { 36 return @"This operator either removes the subscope specified in the variable SubScopeIndex or if this variable is absent, removes all subscopes."; 37 } 34 [Item("SubScopesRemover", "An operator which removes one specified or (if not specified) all sub-scopes from the current scope.")] 35 [EmptyStorableClass] 36 [Creatable("Test")] 37 public class SubScopesRemover : SingleSuccessorOperator { 38 public ValueLookupParameter<IntData> SubScopeIndexParameter { 39 get { return (ValueLookupParameter<IntData>)Parameters["SubScopeIndex"]; } 40 } 41 protected ScopeParameter CurrentScopeParameter { 42 get { return (ScopeParameter)Parameters["CurrentScope"]; } 43 } 44 public IScope CurrentScope { 45 get { return CurrentScopeParameter.ActualValue; } 38 46 } 39 47 40 /// <summary>41 /// Initializes a new instance of <see cref="SubScopesRemover"/> with one variable info42 /// (<c>SubScopeIndex</c>).43 /// </summary>44 48 public SubScopesRemover() 45 49 : base() { 46 AddVariableInfo(new VariableInfo("SubScopeIndex", "(Optional) the index of the subscope to remove", typeof(IntData), VariableKind.In)); 50 Parameters.Add(new ValueLookupParameter<IntData>("SubScopeIndex", "The index of the sub-scope which should be removed. If this parameter has no value, all sub-scopes of the current scope are removed.")); 51 Parameters.Add(new ScopeParameter("CurrentScope", "The current scope from which one or all sub-scopes should be removed.")); 47 52 } 48 53 49 /// <summary> 50 /// Removes one sub scope with a specified index from the given <paramref name="scope"/>, or if no 51 /// index has been specified, all sub scopes are removed. 52 /// </summary> 53 /// <exception cref="InvalidOperationException">Thrown when no sub scope with the specified index 54 /// exists.</exception> 55 /// <param name="scope">The scope whose sub scope(s) to remove.</param> 56 /// <returns><c>null</c>.</returns> 57 public override IOperation Apply(IScope scope) { 58 IntData index = GetVariableValue<IntData>("SubScopeIndex", scope, true, false); 59 if (index == null) { // remove all scopes 60 while (scope.SubScopes.Count > 0) { 61 scope.RemoveSubScope(scope.SubScopes[0]); 62 } 63 } else { 64 if (index.Data < 0 && index.Data >= scope.SubScopes.Count) throw new InvalidOperationException("ERROR: no scope with index " + index.Data + " exists"); 65 scope.RemoveSubScope(scope.SubScopes[index.Data]); 66 } 67 return null; 54 public override IExecutionContext Apply() { 55 IntData index = SubScopeIndexParameter.ActualValue; 56 if (index != null) 57 CurrentScope.SubScopes.RemoveAt(index.Value); 58 else 59 CurrentScope.SubScopes.Clear(); 60 return base.Apply(); 68 61 } 69 62 } -
trunk/sources/HeuristicLab.Operators/3.3/UniformParallelSubScopesProcessor.cs
r1530 r2757 23 23 using System.Collections.Generic; 24 24 using System.Text; 25 using System.Xml; 25 26 using HeuristicLab.Core; 26 using HeuristicLab.Data; 27 using HeuristicLab.Parameters; 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 29 28 30 namespace HeuristicLab.Operators { 29 31 /// <summary> 30 /// Performs the same operator on all <c>n</c> existing sub scopes of a given scope; 31 /// operations can be executed in parallel. 32 /// An operator which applies a specified operator on all sub-scopes of the current scope in parallel. 32 33 /// </summary> 33 public class UniformParallelSubScopesProcessor : OperatorBase { 34 /// <inheritdoc select="summary"/> 35 public override string Description { 36 get { return @"TODO\r\nOperator description still missing ..."; } 34 [Item("UniformParallelSubScopesProcessor", "An operator which applies a specified operator on all sub-scopes of the current scope in parallel.")] 35 [Creatable("Test")] 36 [EmptyStorableClass] 37 public sealed class UniformParallelSubScopesProcessor : SingleSuccessorOperator { 38 private OperatorParameter OperatorParameter { 39 get { return (OperatorParameter)Parameters["Operator"]; } 40 } 41 public IOperator Operator { 42 get { return OperatorParameter.Value; } 43 set { OperatorParameter.Value = value; } 37 44 } 38 45 39 /// <summary> 40 /// Applies one operator on all the sub scopes of the given <paramref name="scope"/>. 41 /// </summary> 42 /// <param name="scope">The scope on whose sub scopes the operator is applied.</param> 43 /// <returns>A new <see cref="CompositeOperation"/> with one operator and all sub scopes and 44 /// the <c>ExecuteInParallel</c> flag set to <c>true</c>.</returns> 45 public override IOperation Apply(IScope scope) { 46 CompositeOperation next = new CompositeOperation(); 47 next.ExecuteInParallel = true; 48 for (int i = 0; i < scope.SubScopes.Count; i++) 49 next.AddOperation(new AtomicOperation(SubOperators[0], scope.SubScopes[i])); 46 public UniformParallelSubScopesProcessor() 47 : base() { 48 Parameters.Add(new OperatorParameter("Operator", "The operator which should be applied on all sub-scopes of the current scope in parallel.")); 49 } 50 51 public override IExecutionContext Apply() { 52 ExecutionContextCollection next = new ExecutionContextCollection(base.Apply()); 53 if (Operator != null) { 54 ExecutionContextCollection inner = new ExecutionContextCollection(); 55 inner.Parallel = true; 56 for (int i = 0; i < ExecutionContext.Scope.SubScopes.Count; i++) 57 inner.Add(new ExecutionContext(ExecutionContext.Parent, Operator, ExecutionContext.Scope.SubScopes[i])); 58 next.Insert(0, inner); 59 } 50 60 return next; 51 61 } -
trunk/sources/HeuristicLab.Operators/3.3/UniformSequentialSubScopesProcessor.cs
r1530 r2757 23 23 using System.Collections.Generic; 24 24 using System.Text; 25 using System.Xml; 25 26 using HeuristicLab.Core; 26 using HeuristicLab.Data; 27 using HeuristicLab.Parameters; 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 29 28 30 namespace HeuristicLab.Operators { 29 31 /// <summary> 30 /// Performs the same operator on all existing sub scopes of a given scope, 31 /// must be executed sequentially. 32 /// An operator which applies a specified operator sequentially on all sub-scopes of the current scope. 32 33 /// </summary> 33 public class UniformSequentialSubScopesProcessor : OperatorBase { 34 /// <inheritdoc select="summary"/> 35 public override string Description { 36 get { return @"TODO\r\nOperator description still missing ..."; } 34 [Item("UniformSequentialSubScopesProcessor", "An operator which applies a specified operator sequentially on all sub-scopes of the current scope.")] 35 [Creatable("Test")] 36 [EmptyStorableClass] 37 public sealed class UniformSequentialSubScopesProcessor : SingleSuccessorOperator { 38 private OperatorParameter OperatorParameter { 39 get { return (OperatorParameter)Parameters["Operator"]; } 40 } 41 public IOperator Operator { 42 get { return OperatorParameter.Value; } 43 set { OperatorParameter.Value = value; } 37 44 } 38 45 39 /// <summary> 40 /// Applies one operator on all the sub scopes of the given <paramref name="scope"/>. 41 /// </summary> 42 /// <param name="scope">The scope on whose sub scopes the operator is applied.</param> 43 /// <returns>A new <see cref="CompositeOperation"/> with one operator and all sub scopes.</returns> 44 public override IOperation Apply(IScope scope) { 45 CompositeOperation next = new CompositeOperation(); 46 for (int i = 0; i < scope.SubScopes.Count; i++) 47 next.AddOperation(new AtomicOperation(SubOperators[0], scope.SubScopes[i])); 46 public UniformSequentialSubScopesProcessor() 47 : base() { 48 Parameters.Add(new OperatorParameter("Operator", "The operator which should be applied sequentially on all sub-scopes of the current scope.")); 49 } 50 51 public override IExecutionContext Apply() { 52 ExecutionContextCollection next = new ExecutionContextCollection(base.Apply()); 53 if (Operator != null) { 54 ExecutionContextCollection inner = new ExecutionContextCollection(); 55 for (int i = 0; i < ExecutionContext.Scope.SubScopes.Count; i++) 56 inner.Add(new ExecutionContext(ExecutionContext.Parent, Operator, ExecutionContext.Scope.SubScopes[i])); 57 next.Insert(0, inner); 58 } 48 59 return next; 49 60 } -
trunk/sources/HeuristicLab.Operators/3.3/VariableInjector.cs
r2526 r2757 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Linq; 24 25 using System.Text; 25 26 using System.Xml; 27 using HeuristicLab.Collections; 26 28 using HeuristicLab.Core; 29 using HeuristicLab.Parameters; 27 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 31 29 32 namespace HeuristicLab.Operators { 30 33 /// <summary> 31 /// Class to inject local variables into thescope.34 /// An operator which collects the actual values of parameters and clones them into the current scope. 32 35 /// </summary> 33 public class VariableInjector : OperatorBase { 34 35 private Dictionary<IVariable, IVariableInfo> variableVariableInfoTable; 36 private Dictionary<IVariableInfo, IVariable> variableInfoVariableTable; 37 38 /// <inheritdoc select="summary"/> 39 public override string Description { 40 get { return @"TODO\r\nOperator description still missing ..."; } 36 [Item("VariableInjector", "An operator which collects the actual values of parameters and clones them into the current scope.")] 37 [Creatable("Test")] 38 [EmptyStorableClass] 39 public class VariableInjector : ValueCollector { 40 protected ScopeParameter CurrentScopeParameter { 41 get { return (ScopeParameter)Parameters["CurrentScope"]; } 42 } 43 public IScope CurrentScope { 44 get { return CurrentScopeParameter.ActualValue; } 41 45 } 42 46 43 /// <summary>44 /// Initializes a new instance of <see cref="VariableInjector"/>.45 /// </summary>46 47 public VariableInjector() 47 48 : base() { 48 variableVariableInfoTable = new Dictionary<IVariable, IVariableInfo>(); 49 variableInfoVariableTable = new Dictionary<IVariableInfo, IVariable>(); 49 Parameters.Add(new ScopeParameter("CurrentScope", "The current scope into which the parameter values are cloned.")); 50 50 } 51 51 52 /// <summary> 53 /// Clones the current instance (deep clone). 54 /// </summary> 55 /// <remarks>Deep clone performed with <see cref="cloner.Clone"/> of helper class 56 /// <see cref="Auxiliary"/>.</remarks> 57 /// <param name="clonedObjects">Dictionary of all already cloned objects. (Needed to avoid cycles.)</param> 58 /// <returns>The cloned object as <see cref="VariableInjector"/>.</returns> 59 public override IItem Clone(ICloner cloner) { 60 VariableInjector clone = new VariableInjector(); 61 cloner.RegisterClonedObject(this, clone); 62 clone.Name = Name; 63 foreach (IVariable variable in Variables) 64 clone.AddVariable((IVariable)cloner.Clone(variable)); 65 return clone; 52 public override IExecutionContext Apply() { 53 IVariable var; 54 foreach (IParameter param in CollectedValues) { 55 CurrentScope.Variables.TryGetValue(param.Name, out var); 56 if (var != null) 57 var.Value = (IItem)param.ActualValue.Clone(); 58 else 59 CurrentScope.Variables.Add(new Variable(param.Name, (IItem)param.ActualValue.Clone())); 60 } 61 return base.Apply(); 66 62 } 67 68 /// <summary>69 /// Adds the specified <paramref name="variable"/> to the current instance to get injected.70 /// </summary>71 /// <param name="variable">The variable to add.</param>72 /// <remarks>Calls private method <see cref="CreateVariableInfo"/> and <see cref="OperatorBase.AddVariable"/>73 /// of base class <see cref="OperatorBase"/>.</remarks>74 public override void AddVariable(IVariable variable) {75 base.AddVariable(variable);76 CreateVariableInfo(variable);77 }78 79 /// <summary>80 /// Removes a variable with the specified <paramref name="name"/> from the current injector.81 /// </summary>82 /// <remarks>Calls private method <see cref="DeleteVariableInfo"/> and <see cref="OperatorBase.RemoveVariable"/>83 /// of base class <see cref="OperatorBase"/>.</remarks>84 /// <param name="name">The name of the </param>85 public override void RemoveVariable(string name) {86 DeleteVariableInfo(name);87 base.RemoveVariable(name);88 }89 90 /// <summary>91 /// Adds the specified variables to the given <paramref name="scope"/> (and removes them first,92 /// if they already exist in the current scope).93 /// </summary>94 /// <param name="scope">The scope where to inject the variables.</param>95 /// <returns><c>null</c>.</returns>96 public override IOperation Apply(IScope scope) {97 foreach (IVariable variable in Variables) {98 if (scope.GetVariable(variable.Name) != null)99 scope.RemoveVariable(variable.Name);100 scope.AddVariable((IVariable)variable.Clone());101 }102 return null;103 }104 105 [Storable]106 private KeyValuePair<Dictionary<IVariableInfo, IVariable>, Dictionary<IVariable, IVariableInfo>> VariableMappingPersistence {107 get {108 return new KeyValuePair<Dictionary<IVariableInfo, IVariable>, Dictionary<IVariable, IVariableInfo>>(109 variableInfoVariableTable, variableVariableInfoTable);110 }111 set {112 variableInfoVariableTable = value.Key;113 variableVariableInfoTable = value.Value;114 foreach (var pair in variableInfoVariableTable) {115 pair.Key.ActualNameChanged += new EventHandler(VariableInfo_ActualNameChanged);116 pair.Value.NameChanged += new EventHandler(Variable_NameChanged);117 }118 }119 }120 121 private void CreateVariableInfo(IVariable variable) {122 IVariableInfo info = new VariableInfo(Guid.NewGuid().ToString(), "Injected variable", variable.Value.GetType(), VariableKind.New);123 info.ActualName = variable.Name;124 AddVariableInfo(info);125 variableVariableInfoTable.Add(variable, info);126 variableInfoVariableTable.Add(info, variable);127 info.ActualNameChanged += new EventHandler(VariableInfo_ActualNameChanged);128 variable.NameChanged += new EventHandler(Variable_NameChanged);129 }130 private void DeleteVariableInfo(string name) {131 IVariable variable = GetVariable(name);132 if (variable != null) {133 IVariableInfo info = variableVariableInfoTable[variable];134 RemoveVariableInfo(info.FormalName);135 variableVariableInfoTable.Remove(variable);136 variableInfoVariableTable.Remove(info);137 info.ActualNameChanged -= new EventHandler(VariableInfo_ActualNameChanged);138 variable.NameChanged -= new EventHandler(Variable_NameChanged);139 }140 }141 142 #region VariableInfo and Variable Events143 private void VariableInfo_ActualNameChanged(object sender, EventArgs e) {144 IVariableInfo info = (IVariableInfo)sender;145 IVariable variable = variableInfoVariableTable[info];146 variable.Name = info.ActualName;147 }148 private void Variable_NameChanged(object sender, EventArgs e) {149 IVariable variable = (IVariable)sender;150 IVariableInfo info = variableVariableInfoTable[variable];151 info.ActualName = variable.Name;152 }153 #endregion154 63 } 155 64 } -
trunk/sources/HeuristicLab.Parameters/3.3/LookupParameter.cs
r2756 r2757 32 32 /// A parameter whose value is retrieved from the scope. 33 33 /// </summary> 34 [Item("LookupParameter<T>", "A parameter whose value is retrieved from thescope.")]34 [Item("LookupParameter<T>", "A parameter whose value is retrieved from or written to a scope.")] 35 35 public class LookupParameter<T> : Parameter, ILookupParameter<T> where T : class, IItem { 36 36 [Storable] … … 46 46 } 47 47 } 48 public T ActualValue {49 get { return GetActualValue(); }48 public new T ActualValue { 49 get { return (T)GetActualValue(); } 50 50 set { SetActualValue(value); } 51 51 } … … 80 80 return scope != null ? scope.Variables[actualName] : null; 81 81 } 82 protected virtual TGetActualValue() {82 protected override IItem GetActualValue() { 83 83 string name = TranslateName(Name, ExecutionContext); 84 84 IVariable var = LookupVariable(name); … … 95 95 return null; 96 96 } 97 protected virtual void SetActualValue(T value) { 97 protected override void SetActualValue(IItem value) { 98 T val = value as T; 99 if (val == null) 100 throw new InvalidOperationException( 101 string.Format("Type mismatch. Value is not a \"{0}\".", 102 typeof(T).GetPrettyName()) 103 ); 98 104 string name = TranslateName(Name, ExecutionContext); 99 105 IVariable var = LookupVariable(name); 100 if (var != null) var.Value = val ue;101 else ExecutionContext.Scope.Variables.Add(new Variable(name, val ue));106 if (var != null) var.Value = val; 107 else ExecutionContext.Scope.Variables.Add(new Variable(name, val)); 102 108 } 103 109 -
trunk/sources/HeuristicLab.Parameters/3.3/Parameter.cs
r2756 r2757 45 45 get { return dataType; } 46 46 } 47 public IItem ActualValue { 48 get { return GetActualValue(); } 49 set { SetActualValue(value); } 50 } 47 51 [Storable] 48 52 private ExecutionContext executionContext; 49 53 public ExecutionContext ExecutionContext { 50 54 get { return executionContext; } 51 set { executionContext = value; } 55 set { 56 if (value != executionContext) { 57 executionContext = value; 58 OnExecutionContextChanged(); 59 } 60 } 52 61 } 53 62 … … 77 86 return string.Format("{0} ({1})", Name, DataType.Name); 78 87 } 88 89 protected abstract IItem GetActualValue(); 90 protected abstract void SetActualValue(IItem value); 91 92 protected virtual void OnExecutionContextChanged() { } 79 93 } 80 94 } -
trunk/sources/HeuristicLab.Parameters/3.3/ScopeParameter.cs
r2756 r2757 35 35 [Creatable("Test")] 36 36 public class ScopeParameter : Parameter { 37 public IScopeValue {37 public new IScope ActualValue { 38 38 get { return ExecutionContext.Scope; } 39 39 } … … 52 52 return string.Format("{0} ({1})", Name, DataType.Name); 53 53 } 54 55 protected override IItem GetActualValue() { 56 return ExecutionContext.Scope; 57 } 58 protected override void SetActualValue(IItem value) { 59 throw new NotSupportedException("The actual value of a ScopeParameter cannot be set. It is always the current scope."); 60 } 54 61 } 55 62 } -
trunk/sources/HeuristicLab.Parameters/3.3/SubScopesLookupParameter.cs
r2756 r2757 32 32 /// A generic parameter representing instances of type T which are collected from the sub-scopes of the current scope. 33 33 /// </summary> 34 [Item("SubScopesLookupParameter<T>", "A generic parameter representing instances of type T which are collected from the sub-scopes of the current scope.")]34 [Item("SubScopesLookupParameter<T>", "A generic parameter representing instances of type T which are collected from or written to the sub-scopes of the current scope.")] 35 35 public class SubScopesLookupParameter<T> : Parameter, ILookupParameter<T> where T : class, IItem { 36 36 [Storable] … … 47 47 } 48 48 49 public T[] ActualValues{50 get { return GetActualValues(); }51 set { SetActualValue s(value); }49 public new ItemArray<T> ActualValue { 50 get { return (ItemArray<T>)GetActualValue(); } 51 set { SetActualValue(value); } 52 52 } 53 53 54 54 public SubScopesLookupParameter() 55 : base("Anonymous", typeof( T)) {55 : base("Anonymous", typeof(ItemArray<T>)) { 56 56 actualName = Name; 57 57 } 58 58 public SubScopesLookupParameter(string name) 59 : base(name, typeof( T)) {59 : base(name, typeof(ItemArray<T>)) { 60 60 actualName = Name; 61 61 } 62 62 public SubScopesLookupParameter(string name, string description) 63 : base(name, description, typeof( T)) {63 : base(name, description, typeof(ItemArray<T>)) { 64 64 actualName = Name; 65 65 } … … 75 75 } 76 76 77 protected virtual T[] GetActualValues() {77 protected override IItem GetActualValue() { 78 78 string name = LookupParameter<T>.TranslateName(Name, ExecutionContext); 79 79 IScope scope = ExecutionContext.Scope; 80 T[] values = new T[scope.SubScopes.Count];80 ItemArray<T> values = new ItemArray<T>(scope.SubScopes.Count); 81 81 IVariable var; 82 82 T value; … … 97 97 return values; 98 98 } 99 protected virtual void SetActualValues(T[] values) { 99 protected override void SetActualValue(IItem value) { 100 ItemArray<T> values = value as ItemArray<T>; 101 if (values == null) 102 throw new InvalidOperationException( 103 string.Format("Type mismatch. Value is not a \"{0}\".", 104 typeof(ItemArray<T>).GetPrettyName()) 105 ); 106 100 107 string name = LookupParameter<T>.TranslateName(Name, ExecutionContext); 101 108 IScope scope = ExecutionContext.Scope; -
trunk/sources/HeuristicLab.Parameters/3.3/ValueLookupParameter.cs
r2756 r2757 32 32 /// A parameter whose value is either defined it the parameter itself or is retrieved from the scope. 33 33 /// </summary> 34 [Item("ValueLookupParameter<T>", "A parameter whose value is either defined it the parameter itself or is retrieved from thescope.")]34 [Item("ValueLookupParameter<T>", "A parameter whose value is either defined it the parameter itself or is retrieved from or written to a scope.")] 35 35 public class ValueLookupParameter<T> : Parameter, IValueLookupParameter<T> where T : class, IItem { 36 36 [Storable] … … 61 61 } 62 62 63 public T ActualValue {64 get { return GetActualValue(); }63 public new T ActualValue { 64 get { return (T)GetActualValue(); } 65 65 set { SetActualValue(value); } 66 66 } … … 137 137 return scope != null ? scope.Variables[actualName] : null; 138 138 } 139 protected virtual TGetActualValue() {139 protected override IItem GetActualValue() { 140 140 string name; 141 141 // try to get local value from context stack … … 157 157 return null; 158 158 } 159 protected virtual void SetActualValue(T value) { 159 protected override void SetActualValue(IItem value) { 160 T val = value as T; 161 if (val == null) 162 throw new InvalidOperationException( 163 string.Format("Type mismatch. Value is not a \"{0}\".", 164 typeof(T).GetPrettyName()) 165 ); 166 // try to get local value from context stack 160 167 string name; 161 // try to get local value from context stack162 168 IValueParameter<T> param = GetParameter(out name); 163 if (param != null) param.Value = val ue;169 if (param != null) param.Value = val; 164 170 else { // try to get variable from scope 165 171 IVariable var = LookupVariable(name); 166 if (var != null) var.Value = val ue;172 if (var != null) var.Value = val; 167 173 else ExecutionContext.Scope.Variables.Add(new Variable(name, value)); 168 174 } -
trunk/sources/HeuristicLab.Parameters/3.3/ValueParameter.cs
r2756 r2757 24 24 using System.Text; 25 25 using System.Xml; 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; 27 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 45 46 } 46 47 } 48 } 49 public new T ActualValue { 50 get { return Value; } 51 set { Value = value; } 47 52 } 48 53 … … 75 80 } 76 81 82 protected override IItem GetActualValue() { 83 return Value; 84 } 85 protected override void SetActualValue(IItem value) { 86 T val = value as T; 87 if (val == null) 88 throw new InvalidOperationException( 89 string.Format("Type mismatch. Value is not a \"{0}\".", 90 typeof(T).GetPrettyName()) 91 ); 92 Value = val; 93 } 94 77 95 public event EventHandler ValueChanged; 78 96 private void OnValueChanged() { -
trunk/sources/HeuristicLab.SequentialEngine/3.3/SequentialEngine.cs
r2664 r2757 57 57 protected override void ProcessNextOperator() { 58 58 currentOperator = null; 59 ExecutionContext context = ExecutionStack.Pop(); 60 ExecutionContextCollection next = null; 59 IExecutionContext next = ExecutionStack.Pop(); 60 ExecutionContextCollection coll = next as ExecutionContextCollection; 61 while (coll != null) { 62 for (int i = coll.Count - 1; i >= 0; i--) 63 ExecutionStack.Push(coll[i]); 64 next = ExecutionStack.Pop(); 65 coll = next as ExecutionContextCollection; 66 } 67 ExecutionContext context = next as ExecutionContext; 61 68 try { 62 69 currentOperator = context.Operator; 63 next = context.Operator.Execute(context);70 ExecutionStack.Push(context.Operator.Execute(context)); 64 71 currentOperator = null; 65 72 } … … 69 76 OnExceptionOccurred(ex); 70 77 } 71 if (next != null) {72 for (int i = next.Count - 1; i >= 0; i--)73 ExecutionStack.Push(next[i]);74 }75 78 if (context.Operator.Breakpoint) 76 79 Stop();
Note: See TracChangeset
for help on using the changeset viewer.