Changeset 6103
- Timestamp:
- 05/03/11 11:04:02 (14 years ago)
- Location:
- trunk/sources
- Files:
-
- 2 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Common/3.3/HeuristicLab.Common-3.3.csproj
r5837 r6103 121 121 <Compile Include="Content\IStorableContent.cs" /> 122 122 <Compile Include="Constants.cs" /> 123 <Compile Include="ObjectExtensions.cs" /> 123 124 <Compile Include="DeepCloneable.cs" /> 124 125 <Compile Include="Content\IContent.cs" /> -
trunk/sources/HeuristicLab.Common/3.3/TypeExtensions.cs
r5445 r6103 21 21 22 22 using System; 23 using System.Collections.Generic; 24 using System.Reflection; 23 25 using System.Text; 24 26 … … 45 47 return sb.ToString(); 46 48 } 49 public static IEnumerable<FieldInfo> GetAllFields(this Type type) { 50 foreach(var field in type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) 51 yield return field; 52 53 foreach (var field in type.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)) 54 yield return field; 55 56 if (type.BaseType != null) { 57 foreach (var field in type.BaseType.GetAllFields()) 58 yield return field; 59 } 60 } 61 // http://stackoverflow.com/questions/457676/c-reflection-check-if-a-class-is-derived-from-a-generic-class 62 public static bool IsSubclassOfRawGeneric(this Type toCheck, Type generic) { 63 while (toCheck != typeof(object)) { 64 var cur = toCheck.IsGenericType ? toCheck.GetGenericTypeDefinition() : toCheck; 65 if (generic == cur) { 66 return true; 67 } 68 toCheck = toCheck.BaseType; // baseType is null when toCheck is an Interface 69 if (toCheck == null) 70 return false; 71 } 72 return false; 73 } 47 74 } 48 75 } -
trunk/sources/HeuristicLab.Core/3.3/HeuristicLab.Core-3.3.csproj
r5809 r6103 147 147 <Compile Include="Interfaces\IMultiOperator.cs" /> 148 148 <Compile Include="Interfaces\IFixedValueParameter.cs" /> 149 <Compile Include="Interfaces\IStatefulItem.cs" /> 149 150 <Compile Include="OperatorExecutionException.cs" /> 150 151 <Compile Include="Interfaces\IScopeTreeLookupParameter.cs" /> -
trunk/sources/HeuristicLab.Operators/3.3/Operator.cs
r5445 r6103 33 33 [Item("Operator", "Base class for operators.")] 34 34 [StorableClass] 35 public abstract class Operator : ParameterizedNamedItem, IOperator {35 public abstract class Operator : ParameterizedNamedItem, IOperator, IStatefulItem { 36 36 public override Image ItemImage { 37 37 get { … … 74 74 protected Operator(bool deserializing) 75 75 : base(deserializing) { 76 executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);76 InitializeState(); 77 77 } 78 78 protected Operator(Operator original, Cloner cloner) 79 79 : base(original, cloner) { 80 executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);80 InitializeState(); 81 81 this.breakpoint = original.breakpoint; 82 82 } 83 83 protected Operator() 84 84 : base() { 85 executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);85 InitializeState(); 86 86 breakpoint = false; 87 87 } 88 88 protected Operator(string name) 89 89 : base(name) { 90 executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);90 InitializeState(); 91 91 breakpoint = false; 92 92 } 93 93 protected Operator(string name, ParameterCollection parameters) 94 94 : base(name, parameters) { 95 executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);95 InitializeState(); 96 96 breakpoint = false; 97 97 } 98 98 protected Operator(string name, string description) 99 99 : base(name, description) { 100 executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);100 InitializeState(); 101 101 breakpoint = false; 102 102 } 103 103 protected Operator(string name, string description, ParameterCollection parameters) 104 104 : base(name, description, parameters) { 105 InitializeState(); 106 breakpoint = false; 107 } 108 109 public virtual void InitializeState() { 105 110 executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication); 106 breakpoint = false; 111 } 112 public virtual void ClearState() { 113 executionContexts = null; 107 114 } 108 115 -
trunk/sources/HeuristicLab.Optimization/3.3/Algorithms/Algorithm.cs
r5954 r6103 261 261 protected virtual void OnPrepared() { 262 262 ExecutionTime = TimeSpan.Zero; 263 foreach (IStatefulItem statefulObject in this.GetObjectGraphObjects().OfType<IStatefulItem>()) { 264 statefulObject.InitializeState(); 265 } 263 266 ExecutionState = ExecutionState.Prepared; 264 267 EventHandler handler = Prepared; … … 280 283 protected virtual void OnStopped() { 281 284 ExecutionState = ExecutionState.Stopped; 285 foreach (IStatefulItem statefulObject in this.GetObjectGraphObjects().OfType<IStatefulItem>()) { 286 statefulObject.ClearState(); 287 } 282 288 runsCounter++; 283 289 runs.Add(new Run(string.Format("{0} Run {1}", Name, runsCounter), this)); -
trunk/sources/HeuristicLab.Parameters/3.3/Parameter.cs
r5768 r6103 33 33 [Item("Parameter", "A base class for parameters.")] 34 34 [StorableClass] 35 public abstract class Parameter : NamedItem, IParameter {35 public abstract class Parameter : NamedItem, IParameter, IStatefulItem { 36 36 public override Image ItemImage { 37 37 get { … … 92 92 protected Parameter(bool deserializing) 93 93 : base(deserializing) { 94 cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication); 95 executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication); 94 InitializeState(); 96 95 } 97 96 protected Parameter(Parameter original, Cloner cloner) … … 99 98 dataType = original.dataType; 100 99 hidden = original.hidden; 101 cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication); 102 executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication); 100 InitializeState(); 103 101 } 104 102 protected Parameter() … … 106 104 dataType = typeof(IItem); 107 105 hidden = false; 108 cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication); 109 executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication); 106 InitializeState(); 110 107 } 111 108 protected Parameter(string name, Type dataType) … … 114 111 this.dataType = dataType; 115 112 hidden = false; 116 cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication); 117 executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication); 113 InitializeState(); 118 114 } 119 115 protected Parameter(string name, string description, Type dataType) … … 122 118 this.dataType = dataType; 123 119 hidden = false; 120 InitializeState(); 121 } 122 123 public virtual void InitializeState() { 124 124 cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication); 125 125 executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication); 126 } 127 public virtual void ClearState() { 128 cachedActualValues = null; 129 executionContexts = null; 126 130 } 127 131
Note: See TracChangeset
for help on using the changeset viewer.