- Timestamp:
- 03/28/19 16:54:20 (6 years ago)
- Location:
- branches/2521_ProblemRefactoring
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring
- Property svn:mergeinfo changed
-
branches/2521_ProblemRefactoring/HeuristicLab.Optimization
- Property svn:mergeinfo changed
-
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/MetaOptimizers/BatchRun.cs
r16692 r16723 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 8Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 29 29 using HeuristicLab.Core; 30 30 using HeuristicLab.Data; 31 using H euristicLab.Persistence.Default.CompositeSerializers.Storable;31 using HEAL.Attic; 32 32 33 33 namespace HeuristicLab.Optimization { 34 [StorableType("3d385be2-5c83-43f2-a693-f984acac44f6")] 34 35 internal enum BatchRunAction { None, Prepare, Start, Pause, Stop }; 35 36 … … 39 40 [Item("Batch Run", "A run in which an optimizer is executed a given number of times.")] 40 41 [Creatable(CreatableAttribute.Categories.TestingAndAnalysis, Priority = 110)] 41 [Storable Class]42 [StorableType("E85407E0-18EC-4198-8321-9CF030FDF6D7")] 42 43 public sealed class BatchRun : NamedItem, IOptimizer, IStorableContent { 43 44 public string Filename { get; set; } … … 199 200 } 200 201 [StorableConstructor] 201 private BatchRun( bool deserializing) : base(deserializing) { }202 private BatchRun(StorableConstructorFlag _) : base(_) { } 202 203 [StorableHook(HookType.AfterDeserialization)] 203 204 private void AfterDeserialization() { -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/MetaOptimizers/Experiment.cs
r16692 r16723 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 8Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 29 29 using HeuristicLab.Common; 30 30 using HeuristicLab.Core; 31 using H euristicLab.Persistence.Default.CompositeSerializers.Storable;31 using HEAL.Attic; 32 32 33 33 namespace HeuristicLab.Optimization { … … 37 37 [Item("Experiment", "An experiment which contains multiple algorithms, batch runs or other experiments.")] 38 38 [Creatable(CreatableAttribute.Categories.TestingAndAnalysis, Priority = 100)] 39 [Storable Class]39 [StorableType("A8A4536B-54C1-4A17-AB58-A6006F7F394B")] 40 40 public sealed class Experiment : NamedItem, IOptimizer, IStorableContent { 41 41 public string Filename { get; set; } … … 161 161 } 162 162 [StorableConstructor] 163 private Experiment( bool deserializing) : base(deserializing) { }163 private Experiment(StorableConstructorFlag _) : base(_) { } 164 164 [StorableHook(HookType.AfterDeserialization)] 165 165 private void AfterDeserialization() { -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/MetaOptimizers/TimeLimitRun.cs
r16692 r16723 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 8Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 27 27 using System.Threading; 28 28 using System.Threading.Tasks; 29 using HEAL.Attic; 29 30 using HeuristicLab.Collections; 30 31 using HeuristicLab.Common; 31 32 using HeuristicLab.Common.Resources; 32 33 using HeuristicLab.Core; 33 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;34 34 35 35 namespace HeuristicLab.Optimization { … … 39 39 [Item("Timelimit Run", "A run in which an optimizer is executed a certain maximum time.")] 40 40 [Creatable(CreatableAttribute.Categories.TestingAndAnalysis, Priority = 115)] 41 [Storable Class]41 [StorableType("85A1AB82-689F-4925-B888-B3886707BE88")] 42 42 public sealed class TimeLimitRun : NamedItem, IOptimizer, IStorableContent, INotifyPropertyChanged { 43 43 public string Filename { get; set; } … … 62 62 if (maximumExecutionTime == value) return; 63 63 maximumExecutionTime = value; 64 OnPropertyChanged( "MaximumExecutionTime");64 OnPropertyChanged(nameof(MaximumExecutionTime)); 65 65 } 66 66 } … … 77 77 snapshotTimes.Sort(); 78 78 FindNextSnapshotTimeIndex(ExecutionTime); 79 OnPropertyChanged( "SnapshotTimes");79 OnPropertyChanged(nameof(SnapshotTimes)); 80 80 } 81 81 } … … 89 89 if (storeAlgorithmInEachSnapshot == value) return; 90 90 storeAlgorithmInEachSnapshot = value; 91 OnPropertyChanged( "StoreAlgorithmInEachSnapshot");91 OnPropertyChanged(nameof(StoreAlgorithmInEachSnapshot)); 92 92 } 93 93 } … … 100 100 if (snapshots == value) return; 101 101 snapshots = value; 102 OnPropertyChanged( "Snapshots");102 OnPropertyChanged(nameof(Snapshots)); 103 103 } 104 104 } 105 105 106 106 #region Inherited Properties 107 [Storable] 108 private ExecutionState executionState; 107 109 public ExecutionState ExecutionState { 108 get { return (Algorithm != null) ? Algorithm.ExecutionState : ExecutionState.Stopped; } 110 get { return executionState; } 111 private set { 112 if (executionState == value) return; 113 executionState = value; 114 OnExecutionStateChanged(); 115 OnPropertyChanged(nameof(ExecutionState)); 116 } 109 117 } 110 118 … … 119 127 set { 120 128 if (algorithm == value) return; 129 if (ExecutionState == ExecutionState.Started || ExecutionState == ExecutionState.Paused) 130 throw new InvalidOperationException("Cannot change algorithm while the TimeLimitRun is running or paused."); 121 131 if (algorithm != null) DeregisterAlgorithmEvents(); 122 132 algorithm = value; 133 if (algorithm != null) RegisterAlgorithmEvents(); 134 OnPropertyChanged(nameof(Algorithm)); 135 OnPropertyChanged(nameof(NestedOptimizers)); 123 136 if (algorithm != null) { 124 RegisterAlgorithmEvents(); 125 } 126 OnPropertyChanged("Algorithm"); 127 Prepare(); 137 if (algorithm.ExecutionState == ExecutionState.Started || algorithm.ExecutionState == ExecutionState.Paused) 138 throw new InvalidOperationException("Cannot assign a running or paused algorithm to a TimeLimitRun."); 139 Prepare(); 140 if (algorithm.ExecutionState == ExecutionState.Stopped) OnStopped(); 141 } else OnStopped(); 128 142 } 129 143 } … … 137 151 if (runs == value) return; 138 152 runs = value; 139 OnPropertyChanged( "Runs");153 OnPropertyChanged(nameof(Runs)); 140 154 } 141 155 } … … 152 166 153 167 [StorableConstructor] 154 private TimeLimitRun( bool deserializing) : base(deserializing) { }168 private TimeLimitRun(StorableConstructorFlag _) : base(_) { } 155 169 private TimeLimitRun(TimeLimitRun original, Cloner cloner) 156 170 : base(original, cloner) { … … 160 174 snapshots = cloner.Clone(original.snapshots); 161 175 storeAlgorithmInEachSnapshot = original.storeAlgorithmInEachSnapshot; 176 executionState = original.executionState; 162 177 algorithm = cloner.Clone(original.algorithm); 163 178 runs = cloner.Clone(original.runs); … … 169 184 name = ItemName; 170 185 description = ItemDescription; 186 executionState = ExecutionState.Stopped; 171 187 maximumExecutionTime = TimeSpan.FromMinutes(.5); 172 188 snapshotTimes = new ObservableList<TimeSpan>(new[] { … … 182 198 : base(name) { 183 199 description = ItemDescription; 200 executionState = ExecutionState.Stopped; 184 201 maximumExecutionTime = TimeSpan.FromMinutes(.5); 185 202 snapshotTimes = new ObservableList<TimeSpan>(new[] { … … 188 205 TimeSpan.FromSeconds(15) }); 189 206 snapshotTimesIndex = 0; 207 snapshots = new RunCollection(); 190 208 Runs = new RunCollection { OptimizerName = Name }; 191 209 Initialize(); … … 193 211 public TimeLimitRun(string name, string description) 194 212 : base(name, description) { 213 executionState = ExecutionState.Stopped; 195 214 maximumExecutionTime = TimeSpan.FromMinutes(.5); 196 215 snapshotTimes = new ObservableList<TimeSpan>(new[] { … … 199 218 TimeSpan.FromSeconds(15) }); 200 219 snapshotTimesIndex = 0; 220 snapshots = new RunCollection(); 201 221 Runs = new RunCollection { OptimizerName = Name }; 202 222 Initialize(); … … 211 231 private void AfterDeserialization() { 212 232 Initialize(); 233 // BackwardsCompatibility3.3 234 #region Backwards compatible code, remove with 3.4 235 if (Algorithm != null && executionState != Algorithm.ExecutionState) { 236 executionState = Algorithm.ExecutionState; 237 } else if (Algorithm == null) executionState = ExecutionState.Stopped; 238 #endregion 213 239 } 214 240 … … 236 262 } 237 263 public void Prepare(bool clearRuns) { 264 if (Algorithm == null) return; 238 265 Algorithm.Prepare(clearRuns); 239 266 } … … 280 307 public event EventHandler Prepared; 281 308 private void OnPrepared() { 309 ExecutionState = ExecutionState.Prepared; 282 310 var handler = Prepared; 283 311 if (handler != null) handler(this, EventArgs.Empty); … … 285 313 public event EventHandler Started; 286 314 private void OnStarted() { 315 ExecutionState = ExecutionState.Started; 287 316 var handler = Started; 288 317 if (handler != null) handler(this, EventArgs.Empty); … … 290 319 public event EventHandler Paused; 291 320 private void OnPaused() { 321 ExecutionState = ExecutionState.Paused; 292 322 var handler = Paused; 293 323 if (handler != null) handler(this, EventArgs.Empty); … … 295 325 public event EventHandler Stopped; 296 326 private void OnStopped() { 327 ExecutionState = ExecutionState.Stopped; 297 328 var handler = Stopped; 298 329 if (handler != null) handler(this, EventArgs.Empty); … … 300 331 public event EventHandler<EventArgs<Exception>> ExceptionOccurred; 301 332 private void OnExceptionOccurred(Exception exception) { 333 ExecutionState = ExecutionState.Paused; 302 334 var handler = ExceptionOccurred; 303 335 if (handler != null) handler(this, new EventArgs<Exception>(exception)); … … 309 341 algorithm.ExceptionOccurred += Algorithm_ExceptionOccurred; 310 342 algorithm.ExecutionTimeChanged += Algorithm_ExecutionTimeChanged; 311 algorithm.ExecutionStateChanged += Algorithm_ExecutionStateChanged;312 343 algorithm.Paused += Algorithm_Paused; 313 344 algorithm.Prepared += Algorithm_Prepared; … … 318 349 algorithm.ExceptionOccurred -= Algorithm_ExceptionOccurred; 319 350 algorithm.ExecutionTimeChanged -= Algorithm_ExecutionTimeChanged; 320 algorithm.ExecutionStateChanged -= Algorithm_ExecutionStateChanged;321 351 algorithm.Paused -= Algorithm_Paused; 322 352 algorithm.Prepared -= Algorithm_Prepared; … … 338 368 } 339 369 OnExecutionTimeChanged(); 340 }341 private void Algorithm_ExecutionStateChanged(object sender, EventArgs e) {342 OnExecutionStateChanged();343 370 } 344 371 private void Algorithm_Paused(object sender, EventArgs e) { … … 348 375 MakeSnapshot(); 349 376 FindNextSnapshotTimeIndex(ExecutionTime); 350 } 351 OnPaused(); 377 } else OnPaused(); 352 378 if (action == ExecutionState.Started) Algorithm.Start(); 353 379 else if (action == ExecutionState.Stopped) Algorithm.Stop(); … … 359 385 } 360 386 private void Algorithm_Started(object sender, EventArgs e) { 361 OnStarted(); 387 if (ExecutionState == ExecutionState.Prepared || ExecutionState == ExecutionState.Paused) 388 OnStarted(); 389 if (ExecutionState == ExecutionState.Stopped) 390 throw new InvalidOperationException("Algorithm was started although TimeLimitRun was in state Stopped."); 391 // otherwise the algorithm was just started after being snapshotted 362 392 } 363 393 private void Algorithm_Stopped(object sender, EventArgs e) { 364 var cloner = new Cloner(); 365 var algRun = cloner.Clone(Algorithm.Runs.Last()); 366 var clonedSnapshots = cloner.Clone(snapshots); 367 algRun.Results.Add("TimeLimitRunSnapshots", clonedSnapshots); 368 Runs.Add(algRun); 369 Algorithm.Runs.Clear(); 370 OnStopped(); 394 try { 395 var cloner = new Cloner(); 396 var algRun = cloner.Clone(Algorithm.Runs.Last()); 397 var clonedSnapshots = cloner.Clone(snapshots); 398 algRun.Results.Add("TimeLimitRunSnapshots", clonedSnapshots); 399 Runs.Add(algRun); 400 Algorithm.Runs.Clear(); 401 } finally { OnStopped(); } 371 402 } 372 403 #endregion … … 377 408 while (index < snapshotTimes.Count && snapshotTimes[index] <= reference) { 378 409 index++; 379 } ;410 } 380 411 snapshotTimesIndex = index; 381 412 }
Note: See TracChangeset
for help on using the changeset viewer.