Changeset 3280 for trunk/sources/HeuristicLab.Optimization/3.3
- Timestamp:
- 04/07/10 05:22:33 (14 years ago)
- Location:
- trunk/sources/HeuristicLab.Optimization/3.3
- Files:
-
- 1 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Optimization/3.3/Algorithm.cs
r3275 r3280 64 64 } 65 65 66 [Storable] 66 67 private IProblem problem; 67 [Storable]68 private IProblem ProblemPersistence {69 get { return problem; }70 set {71 if (problem != null) DeregisterProblemEvents();72 problem = value;73 if (problem != null) RegisterProblemEvents();74 }75 }76 68 public IProblem Problem { 77 69 get { return problem; } … … 91 83 92 84 [Storable] 85 protected int runsCounter; 86 87 [Storable] 93 88 private RunCollection runs; 94 89 public RunCollection Runs { … … 100 95 executionState = ExecutionState.Stopped; 101 96 executionTime = TimeSpan.Zero; 97 runsCounter = 0; 102 98 runs = new RunCollection(); 103 99 } … … 106 102 executionState = ExecutionState.Stopped; 107 103 executionTime = TimeSpan.Zero; 104 runsCounter = 0; 108 105 runs = new RunCollection(); 109 106 } … … 112 109 executionState = ExecutionState.Stopped; 113 110 executionTime = TimeSpan.Zero; 111 runsCounter = 0; 114 112 runs = new RunCollection(); 115 113 } … … 118 116 executionState = ExecutionState.Stopped; 119 117 executionTime = TimeSpan.Zero; 118 runsCounter = 0; 120 119 runs = new RunCollection(); 121 120 } … … 124 123 executionState = ExecutionState.Stopped; 125 124 executionTime = TimeSpan.Zero; 126 runs = new RunCollection(); 125 runsCounter = 0; 126 runs = new RunCollection(); 127 } 128 internal Algorithm(Algorithm algorithm, Cloner cloner) 129 : base(algorithm.Name, algorithm.Description, (ParameterCollection)cloner.Clone(algorithm.Parameters)) { 130 executionState = algorithm.executionState; 131 executionTime = algorithm.executionTime; 132 problem = (IProblem)cloner.Clone(algorithm.problem); 133 runsCounter = algorithm.runsCounter; 134 runs = (RunCollection)cloner.Clone(algorithm.runs); 135 Initialize(); 136 } 137 [StorableConstructor] 138 protected Algorithm(bool deserializing) : base(deserializing) { } 139 140 [StorableHook(HookType.AfterDeserialization)] 141 private void Initialize() { 142 if (problem != null) RegisterProblemEvents(); 127 143 } 128 144 129 145 public override IDeepCloneable Clone(Cloner cloner) { 146 if (ExecutionState == ExecutionState.Started) throw new InvalidOperationException(string.Format("Clone not allowed in execution state \"{0}\".", ExecutionState)); 130 147 Algorithm clone = (Algorithm)base.Clone(cloner); 131 148 clone.executionState = executionState; 132 149 clone.executionTime = executionTime; 133 clone.Problem = (IProblem)cloner.Clone(problem); 150 clone.problem = (IProblem)cloner.Clone(problem); 151 clone.runsCounter = runsCounter; 134 152 clone.runs = (RunCollection)cloner.Clone(runs); 153 clone.Initialize(); 135 154 return clone; 136 155 } … … 143 162 if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused) && (ExecutionState != ExecutionState.Stopped)) 144 163 throw new InvalidOperationException(string.Format("Prepare not allowed in execution state \"{0}\".", ExecutionState)); 145 if (clearRuns) runs.Clear(); 164 if (clearRuns) { 165 runsCounter = 0; 166 runs.Clear(); 167 } 146 168 Prepare(); 147 169 } … … 165 187 public virtual void CollectResultValues(IDictionary<string, IItem> values) { 166 188 foreach (IResult result in Results) 167 values.Add(result.Name, result.Value != null ? (IItem)result.Value.Clone() : null);189 values.Add(result.Name, result.Value); 168 190 } 169 191 … … 205 227 public event EventHandler Stopped; 206 228 protected virtual void OnStopped() { 207 Run run = new Run("Run (" + ExecutionTime.ToString() + ")");208 CollectParameterValues(run.Parameters);209 CollectResultValues(run.Results);210 runs.Add(run);211 229 ExecutionState = ExecutionState.Stopped; 230 runsCounter++; 231 runs.Add(new Run(string.Format("{0} Run {1} ({2})", Name, runsCounter, ExecutionTime), this)); 212 232 EventHandler handler = Stopped; 213 233 if (handler != null) handler(this, EventArgs.Empty); -
trunk/sources/HeuristicLab.Optimization/3.3/BatchRun.cs
r3276 r3280 66 66 } 67 67 68 [Storable] 68 69 private IAlgorithm algorithm; 69 [Storable]70 private IAlgorithm AlgorithmPersistence {71 get { return algorithm; }72 set {73 if (algorithm != null) DeregisterAlgorithmEvents();74 algorithm = value;75 if (algorithm != null) RegisterAlgorithmEvents();76 }77 }78 70 public IAlgorithm Algorithm { 79 71 get { return algorithm; } … … 113 105 public BatchRun() 114 106 : base() { 107 name = ItemName; 108 description = ItemDescription; 115 109 executionState = ExecutionState.Stopped; 116 110 executionTime = TimeSpan.Zero; … … 119 113 stopPending = false; 120 114 } 121 public BatchRun(string name) : base(name) { 115 public BatchRun(string name) 116 : base(name) { 117 description = ItemDescription; 122 118 executionState = ExecutionState.Stopped; 123 119 executionTime = TimeSpan.Zero; … … 126 122 stopPending = false; 127 123 } 128 public BatchRun(string name, string description) : base(name, description) { 124 public BatchRun(string name, string description) 125 : base(name, description) { 129 126 executionState = ExecutionState.Stopped; 130 127 executionTime = TimeSpan.Zero; … … 133 130 stopPending = false; 134 131 } 132 [StorableConstructor] 133 private BatchRun(bool deserializing) 134 : base(deserializing) { 135 stopPending = false; 136 } 137 138 [StorableHook(HookType.AfterDeserialization)] 139 private void Initialize() { 140 if (algorithm != null) RegisterAlgorithmEvents(); 141 } 135 142 136 143 public override IDeepCloneable Clone(Cloner cloner) { 144 if (ExecutionState == ExecutionState.Started) throw new InvalidOperationException(string.Format("Clone not allowed in execution state \"{0}\".", ExecutionState)); 137 145 BatchRun clone = (BatchRun)base.Clone(cloner); 138 146 clone.executionState = executionState; 139 147 clone.executionTime = executionTime; 140 clone. Algorithm = (IAlgorithm)cloner.Clone(algorithm);148 clone.algorithm = (IAlgorithm)cloner.Clone(algorithm); 141 149 clone.repetitions = repetitions; 142 150 clone.runs = (RunCollection)cloner.Clone(runs); 143 151 clone.stopPending = stopPending; 152 clone.Initialize(); 144 153 return clone; 145 154 } … … 234 243 algorithm.Started += new EventHandler(Algorithm_Started); 235 244 algorithm.Stopped += new EventHandler(Algorithm_Stopped); 236 algorithm.Runs.CollectionReset += new CollectionItemsChangedEventHandler< Run>(Algorithm_Runs_CollectionReset);237 algorithm.Runs.ItemsAdded += new CollectionItemsChangedEventHandler< Run>(Algorithm_Runs_ItemsAdded);238 algorithm.Runs.ItemsRemoved += new CollectionItemsChangedEventHandler< Run>(Algorithm_Runs_ItemsRemoved);245 algorithm.Runs.CollectionReset += new CollectionItemsChangedEventHandler<IRun>(Algorithm_Runs_CollectionReset); 246 algorithm.Runs.ItemsAdded += new CollectionItemsChangedEventHandler<IRun>(Algorithm_Runs_ItemsAdded); 247 algorithm.Runs.ItemsRemoved += new CollectionItemsChangedEventHandler<IRun>(Algorithm_Runs_ItemsRemoved); 239 248 } 240 249 private void DeregisterAlgorithmEvents() { … … 245 254 algorithm.Started -= new EventHandler(Algorithm_Started); 246 255 algorithm.Stopped -= new EventHandler(Algorithm_Stopped); 247 algorithm.Runs.CollectionReset -= new CollectionItemsChangedEventHandler< Run>(Algorithm_Runs_CollectionReset);248 algorithm.Runs.ItemsAdded -= new CollectionItemsChangedEventHandler< Run>(Algorithm_Runs_ItemsAdded);249 algorithm.Runs.ItemsRemoved -= new CollectionItemsChangedEventHandler< Run>(Algorithm_Runs_ItemsRemoved);256 algorithm.Runs.CollectionReset -= new CollectionItemsChangedEventHandler<IRun>(Algorithm_Runs_CollectionReset); 257 algorithm.Runs.ItemsAdded -= new CollectionItemsChangedEventHandler<IRun>(Algorithm_Runs_ItemsAdded); 258 algorithm.Runs.ItemsRemoved -= new CollectionItemsChangedEventHandler<IRun>(Algorithm_Runs_ItemsRemoved); 250 259 } 251 260 private void Algorithm_ExceptionOccurred(object sender, EventArgs<Exception> e) { … … 277 286 } 278 287 } 279 private void Algorithm_Runs_CollectionReset(object sender, CollectionItemsChangedEventArgs< Run> e) {288 private void Algorithm_Runs_CollectionReset(object sender, CollectionItemsChangedEventArgs<IRun> e) { 280 289 Runs.RemoveRange(e.OldItems); 281 290 Runs.AddRange(e.Items); 282 291 } 283 private void Algorithm_Runs_ItemsAdded(object sender, CollectionItemsChangedEventArgs< Run> e) {292 private void Algorithm_Runs_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IRun> e) { 284 293 Runs.AddRange(e.Items); 285 294 } 286 private void Algorithm_Runs_ItemsRemoved(object sender, CollectionItemsChangedEventArgs< Run> e) {295 private void Algorithm_Runs_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IRun> e) { 287 296 Runs.RemoveRange(e.Items); 288 297 } -
trunk/sources/HeuristicLab.Optimization/3.3/EngineAlgorithm.cs
r3275 r3280 34 34 [StorableClass] 35 35 public abstract class EngineAlgorithm : Algorithm { 36 [Storable] 36 37 private OperatorGraph operatorGraph; 37 [Storable]38 private OperatorGraph OperatorGraphPersistence {39 get { return operatorGraph; }40 set {41 if (operatorGraph != null) operatorGraph.InitialOperatorChanged -= new EventHandler(OperatorGraph_InitialOperatorChanged);42 operatorGraph = value;43 if (operatorGraph != null) operatorGraph.InitialOperatorChanged += new EventHandler(OperatorGraph_InitialOperatorChanged);44 }45 }46 38 protected OperatorGraph OperatorGraph { 47 39 get { return operatorGraph; } … … 49 41 if (value == null) throw new ArgumentNullException(); 50 42 if (value != operatorGraph) { 51 if (operatorGraph != null)operatorGraph.InitialOperatorChanged -= new EventHandler(OperatorGraph_InitialOperatorChanged);43 operatorGraph.InitialOperatorChanged -= new EventHandler(OperatorGraph_InitialOperatorChanged); 52 44 operatorGraph = value; 53 if (operatorGraph != null)operatorGraph.InitialOperatorChanged += new EventHandler(OperatorGraph_InitialOperatorChanged);45 operatorGraph.InitialOperatorChanged += new EventHandler(OperatorGraph_InitialOperatorChanged); 54 46 OnOperatorGraphChanged(); 55 47 Prepare(); … … 64 56 } 65 57 58 [Storable] 66 59 private IEngine engine; 67 [Storable]68 private IEngine EnginePersistence {69 get { return engine; }70 set {71 if (engine != null) DeregisterEngineEvents();72 engine = value;73 if (engine != null) RegisterEngineEvents();74 }75 }76 60 public IEngine Engine { 77 61 get { return engine; } … … 97 81 globalScope = new Scope("Global Scope"); 98 82 globalScope.Variables.Add(new Variable("Results", new ResultCollection())); 99 OperatorGraph = new OperatorGraph();100 Initialize Engine();83 operatorGraph = new OperatorGraph(); 84 Initialize(); 101 85 } 102 86 protected EngineAlgorithm(string name) … … 104 88 globalScope = new Scope("Global Scope"); 105 89 globalScope.Variables.Add(new Variable("Results", new ResultCollection())); 106 OperatorGraph = new OperatorGraph();107 Initialize Engine();90 operatorGraph = new OperatorGraph(); 91 Initialize(); 108 92 } 109 93 protected EngineAlgorithm(string name, ParameterCollection parameters) … … 111 95 globalScope = new Scope("Global Scope"); 112 96 globalScope.Variables.Add(new Variable("Results", new ResultCollection())); 113 OperatorGraph = new OperatorGraph();114 Initialize Engine();97 operatorGraph = new OperatorGraph(); 98 Initialize(); 115 99 } 116 100 protected EngineAlgorithm(string name, string description) … … 118 102 globalScope = new Scope("Global Scope"); 119 103 globalScope.Variables.Add(new Variable("Results", new ResultCollection())); 120 OperatorGraph = new OperatorGraph();121 Initialize Engine();104 operatorGraph = new OperatorGraph(); 105 Initialize(); 122 106 } 123 107 protected EngineAlgorithm(string name, string description, ParameterCollection parameters) … … 125 109 globalScope = new Scope("Global Scope"); 126 110 globalScope.Variables.Add(new Variable("Results", new ResultCollection())); 127 OperatorGraph = new OperatorGraph(); 128 InitializeEngine(); 129 } 130 131 private void InitializeEngine() { 132 if (ApplicationManager.Manager != null) { 111 operatorGraph = new OperatorGraph(); 112 Initialize(); 113 } 114 internal EngineAlgorithm(EngineAlgorithm algorithm, Cloner cloner) 115 : base(algorithm, cloner) { 116 globalScope = (IScope)cloner.Clone(algorithm.globalScope); 117 operatorGraph = (OperatorGraph)cloner.Clone(algorithm.operatorGraph); 118 engine = (IEngine)cloner.Clone(algorithm.engine); 119 Initialize(); 120 } 121 [StorableConstructor] 122 protected EngineAlgorithm(bool deserializing) : base(deserializing) { } 123 124 [StorableHook(HookType.AfterDeserialization)] 125 private void Initialize() { 126 operatorGraph.InitialOperatorChanged += new EventHandler(OperatorGraph_InitialOperatorChanged); 127 if ((engine == null) && (ApplicationManager.Manager != null)) { 133 128 var types = ApplicationManager.Manager.GetTypes(typeof(IEngine)); 134 129 Type t = types.FirstOrDefault(x => x.Name.Equals("SequentialEngine")); 135 130 if (t == null) t = types.FirstOrDefault(); 136 if (t != null) Engine = (IEngine)Activator.CreateInstance(t); 137 } 131 if (t != null) engine = (IEngine)Activator.CreateInstance(t); 132 } 133 if (engine != null) RegisterEngineEvents(); 138 134 } 139 135 … … 141 137 EngineAlgorithm clone = (EngineAlgorithm)base.Clone(cloner); 142 138 clone.globalScope = (IScope)cloner.Clone(globalScope); 143 clone.Engine = (IEngine)cloner.Clone(engine); 144 clone.OperatorGraph = (OperatorGraph)cloner.Clone(operatorGraph); 139 clone.engine = (IEngine)cloner.Clone(engine); 140 clone.operatorGraph = (OperatorGraph)cloner.Clone(operatorGraph); 141 clone.Initialize(); 145 142 return clone; 146 143 } 147 144 148 145 public UserDefinedAlgorithm CreateUserDefinedAlgorithm() { 149 UserDefinedAlgorithm algorithm = new UserDefinedAlgorithm(Name, Description); 150 Cloner cloner = new Cloner(); 151 foreach (IParameter param in Parameters) 152 algorithm.Parameters.Add((IParameter)cloner.Clone(param)); 153 algorithm.Problem = (IProblem)cloner.Clone(Problem); 154 algorithm.Engine = (IEngine)cloner.Clone(engine); 155 algorithm.OperatorGraph = (OperatorGraph)cloner.Clone(operatorGraph); 156 return algorithm; 146 return new UserDefinedAlgorithm(this, new Cloner()); 157 147 } 158 148 -
trunk/sources/HeuristicLab.Optimization/3.3/Experiment.cs
r3276 r3280 62 62 } 63 63 64 [Storable] 64 65 private OptimizerList optimizers; 65 [Storable]66 66 public OptimizerList Optimizers { 67 67 get { return optimizers; } 68 private set {69 if (optimizers != value) {70 if (optimizers != null) DeregisterOptimizersEvents();71 optimizers = value;72 if (optimizers != null) RegisterOptimizersEvents();73 foreach (IOptimizer optimizer in optimizers)74 RegisterOptimizerEvents(optimizer);75 }76 }77 68 } 78 69 … … 87 78 public Experiment() 88 79 : base() { 80 name = ItemName; 81 description = ItemDescription; 89 82 executionState = ExecutionState.Stopped; 90 83 executionTime = TimeSpan.Zero; 91 Optimizers = new OptimizerList();84 optimizers = new OptimizerList(); 92 85 runs = new RunCollection(); 93 86 stopPending = false; 94 } 95 public Experiment(string name) : base(name) { 87 Initialize(); 88 } 89 public Experiment(string name) 90 : base(name) { 91 description = ItemDescription; 96 92 executionState = ExecutionState.Stopped; 97 93 executionTime = TimeSpan.Zero; 98 Optimizers = new OptimizerList();94 optimizers = new OptimizerList(); 99 95 runs = new RunCollection(); 100 96 stopPending = false; 101 } 102 public Experiment(string name, string description) : base(name, description) { 97 Initialize(); 98 } 99 public Experiment(string name, string description) 100 : base(name, description) { 103 101 executionState = ExecutionState.Stopped; 104 102 executionTime = TimeSpan.Zero; 105 Optimizers = new OptimizerList();103 optimizers = new OptimizerList(); 106 104 runs = new RunCollection(); 107 105 stopPending = false; 106 Initialize(); 107 } 108 [StorableConstructor] 109 private Experiment(bool deserializing) 110 : base(deserializing) { 111 stopPending = false; 112 } 113 114 [StorableHook(HookType.AfterDeserialization)] 115 private void Initialize() { 116 RegisterOptimizersEvents(); 117 foreach (IOptimizer optimizer in optimizers) 118 RegisterOptimizerEvents(optimizer); 108 119 } 109 120 110 121 public override IDeepCloneable Clone(Cloner cloner) { 122 if (ExecutionState == ExecutionState.Started) throw new InvalidOperationException(string.Format("Clone not allowed in execution state \"{0}\".", ExecutionState)); 111 123 Experiment clone = (Experiment)base.Clone(cloner); 112 124 clone.executionState = executionState; 113 125 clone.executionTime = executionTime; 114 clone. Optimizers = (OptimizerList)cloner.Clone(optimizers);126 clone.optimizers = (OptimizerList)cloner.Clone(optimizers); 115 127 clone.runs = (RunCollection)cloner.Clone(runs); 116 128 clone.stopPending = stopPending; 129 clone.Initialize(); 117 130 return clone; 118 131 } … … 244 257 optimizer.Started += new EventHandler(optimizer_Started); 245 258 optimizer.Stopped += new EventHandler(optimizer_Stopped); 246 optimizer.Runs.CollectionReset += new CollectionItemsChangedEventHandler< Run>(optimizer_Runs_CollectionReset);247 optimizer.Runs.ItemsAdded += new CollectionItemsChangedEventHandler< Run>(optimizer_Runs_ItemsAdded);248 optimizer.Runs.ItemsRemoved += new CollectionItemsChangedEventHandler< Run>(optimizer_Runs_ItemsRemoved);259 optimizer.Runs.CollectionReset += new CollectionItemsChangedEventHandler<IRun>(optimizer_Runs_CollectionReset); 260 optimizer.Runs.ItemsAdded += new CollectionItemsChangedEventHandler<IRun>(optimizer_Runs_ItemsAdded); 261 optimizer.Runs.ItemsRemoved += new CollectionItemsChangedEventHandler<IRun>(optimizer_Runs_ItemsRemoved); 249 262 } 250 263 private void DeregisterOptimizerEvents(IOptimizer optimizer) { … … 255 268 optimizer.Started -= new EventHandler(optimizer_Started); 256 269 optimizer.Stopped -= new EventHandler(optimizer_Stopped); 257 optimizer.Runs.CollectionReset -= new CollectionItemsChangedEventHandler< Run>(optimizer_Runs_CollectionReset);258 optimizer.Runs.ItemsAdded -= new CollectionItemsChangedEventHandler< Run>(optimizer_Runs_ItemsAdded);259 optimizer.Runs.ItemsRemoved -= new CollectionItemsChangedEventHandler< Run>(optimizer_Runs_ItemsRemoved);270 optimizer.Runs.CollectionReset -= new CollectionItemsChangedEventHandler<IRun>(optimizer_Runs_CollectionReset); 271 optimizer.Runs.ItemsAdded -= new CollectionItemsChangedEventHandler<IRun>(optimizer_Runs_ItemsAdded); 272 optimizer.Runs.ItemsRemoved -= new CollectionItemsChangedEventHandler<IRun>(optimizer_Runs_ItemsRemoved); 260 273 } 261 274 private void optimizer_ExceptionOccurred(object sender, EventArgs<Exception> e) { … … 287 300 } 288 301 } 289 private void optimizer_Runs_CollectionReset(object sender, CollectionItemsChangedEventArgs< Run> e) {302 private void optimizer_Runs_CollectionReset(object sender, CollectionItemsChangedEventArgs<IRun> e) { 290 303 Runs.RemoveRange(e.OldItems); 291 304 Runs.AddRange(e.Items); 292 305 } 293 private void optimizer_Runs_ItemsAdded(object sender, CollectionItemsChangedEventArgs< Run> e) {306 private void optimizer_Runs_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IRun> e) { 294 307 Runs.AddRange(e.Items); 295 308 } 296 private void optimizer_Runs_ItemsRemoved(object sender, CollectionItemsChangedEventArgs< Run> e) {309 private void optimizer_Runs_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IRun> e) { 297 310 Runs.RemoveRange(e.Items); 298 311 } -
trunk/sources/HeuristicLab.Optimization/3.3/HeuristicLab.Optimization-3.3.csproj
r3274 r3280 87 87 <Compile Include="Algorithm.cs" /> 88 88 <Compile Include="BatchRun.cs" /> 89 <Compile Include="Interfaces\IRun.cs" /> 89 90 <Compile Include="OptimizerList.cs" /> 90 91 <Compile Include="Experiment.cs" /> -
trunk/sources/HeuristicLab.Optimization/3.3/Run.cs
r3275 r3280 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using HeuristicLab.Core; … … 30 31 [Item("Run", "The parameters and results of an algorithm run.")] 31 32 [StorableClass] 32 public sealed class Run : NamedItem { 33 public override bool CanChangeName { 34 get { return false; } 33 public sealed class Run : NamedItem, IRun { 34 [Storable] 35 private IAlgorithm algorithm; 36 public IAlgorithm Algorithm { 37 get { return algorithm; } 35 38 } 36 public override bool CanChangeDescription {37 get { return false; }38 }39 40 39 [Storable] 41 40 private Dictionary<string, IItem> parameters; … … 50 49 51 50 public Run() 52 : base("Anonymous") { 51 : base() { 52 name = ItemName; 53 description = ItemDescription; 54 algorithm = null; 53 55 parameters = new Dictionary<string, IItem>(); 54 56 results = new Dictionary<string, IItem>(); 55 57 } 56 public Run(string name) 58 public Run(IAlgorithm algorithm) 59 : base() { 60 if (algorithm == null) throw new ArgumentNullException(); 61 name = algorithm.Name + " Run (" + algorithm.ExecutionTime.ToString() + ")"; 62 description = ItemDescription; 63 Initialize((IAlgorithm)algorithm.Clone()); 64 } 65 public Run(string name, IAlgorithm algorithm) 57 66 : base(name) { 67 if (algorithm == null) throw new ArgumentNullException(); 68 description = ItemDescription; 69 Initialize((IAlgorithm)algorithm.Clone()); 70 } 71 public Run(string name, string description, IAlgorithm algorithm) 72 : base(name, description) { 73 if (algorithm == null) throw new ArgumentNullException(); 74 Initialize((IAlgorithm)algorithm.Clone()); 75 } 76 77 private void Initialize(IAlgorithm algorithm) { 78 this.algorithm = algorithm; 58 79 parameters = new Dictionary<string, IItem>(); 59 80 results = new Dictionary<string, IItem>(); 60 } 61 public Run(string name, string description) 62 : base(name, description) { 63 parameters = new Dictionary<string, IItem>(); 64 results = new Dictionary<string, IItem>(); 81 this.algorithm.CollectParameterValues(parameters); 82 this.algorithm.CollectResultValues(results); 65 83 } 66 84 67 85 public override IDeepCloneable Clone(Cloner cloner) { 68 Run clone = new Run(Name, Description);69 clone r.RegisterClonedObject(this, clone);86 Run clone = (Run)base.Clone(cloner); 87 clone.algorithm = (IAlgorithm)cloner.Clone(algorithm); 70 88 foreach (string key in parameters.Keys) 71 89 clone.parameters.Add(key, (IItem)cloner.Clone(parameters[key])); -
trunk/sources/HeuristicLab.Optimization/3.3/RunCollection.cs
r3274 r3280 28 28 [StorableClass] 29 29 [Item("RunCollection", "Represents a collection of runs.")] 30 public class RunCollection : ItemCollection< Run> {30 public class RunCollection : ItemCollection<IRun> { 31 31 public RunCollection() : base() { } 32 32 public RunCollection(int capacity) : base(capacity) { } 33 public RunCollection(IEnumerable< Run> collection) : base(collection) { }33 public RunCollection(IEnumerable<IRun> collection) : base(collection) { } 34 34 35 35 public override IDeepCloneable Clone(Cloner cloner) { 36 RunCollection clone = new RunCollection(this.Select(x => ( Run)cloner.Clone(x)));36 RunCollection clone = new RunCollection(this.Select(x => (IRun)cloner.Clone(x))); 37 37 cloner.RegisterClonedObject(this, clone); 38 38 return clone; -
trunk/sources/HeuristicLab.Optimization/3.3/UserDefinedAlgorithm.cs
r3262 r3280 52 52 public UserDefinedAlgorithm(string name) : base(name) { } 53 53 public UserDefinedAlgorithm(string name, string description) : base(name, description) { } 54 internal UserDefinedAlgorithm(EngineAlgorithm algorithm, Cloner cloner) : base(algorithm, cloner) { } 55 [StorableConstructor] 56 private UserDefinedAlgorithm(bool deserializing) : base(deserializing) { } 54 57 55 58 public event EventHandler OperatorGraphChanged;
Note: See TracChangeset
for help on using the changeset viewer.