Changeset 15382 for stable/HeuristicLab.Optimization/3.3/MetaOptimizers
- Timestamp:
- 09/27/17 10:32:21 (7 years ago)
- Location:
- stable
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 15327,15339
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Optimization
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Optimization merged: 15327,15339
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Optimization/3.3/MetaOptimizers/Experiment.cs
r15292 r15382 111 111 private bool experimentStarted = false; 112 112 private bool experimentStopped = false; 113 private readonly ManualResetEventSlim allOptimizerFinished = new ManualResetEventSlim(false); // this indicates that all started optimizers have been paused or stopped 113 114 114 115 public Experiment() … … 191 192 if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused)) 192 193 throw new InvalidOperationException(string.Format("Start not allowed in execution state \"{0}\".", ExecutionState)); 193 if ( Optimizers.Count == 0) return;194 if (!Optimizers.Any(x => x.ExecutionState == ExecutionState.Prepared || x.ExecutionState == ExecutionState.Paused)) return; 194 195 195 196 experimentStarted = true; 196 197 experimentStopped = false; 198 allOptimizerFinished.Reset(); 197 199 IOptimizer optimizer; 198 while ((optimizer = Optimizers.FirstOrDefault(x => (x.ExecutionState == ExecutionState.Prepared) || (x.ExecutionState == ExecutionState.Paused))) != null) {200 while ((optimizer = Optimizers.FirstOrDefault(x => x.ExecutionState == ExecutionState.Prepared || x.ExecutionState == ExecutionState.Paused)) != null) { 199 201 // a race-condition may occur when the optimizer has changed the state by itself in the meantime 200 202 try { optimizer.Start(cancellationToken); } catch (InvalidOperationException) { } 201 203 if (ExecutionState == ExecutionState.Paused || ExecutionState == ExecutionState.Stopped) break; 202 204 } 205 allOptimizerFinished.Wait(); 203 206 } 204 207 public async Task StartAsync() { await StartAsync(CancellationToken.None); } … … 266 269 private void OnPaused() { 267 270 ExecutionState = ExecutionState.Paused; 271 allOptimizerFinished.Set(); 268 272 EventHandler handler = Paused; 269 273 if (handler != null) handler(this, EventArgs.Empty); … … 272 276 private void OnStopped() { 273 277 ExecutionState = ExecutionState.Stopped; 278 allOptimizerFinished.Set(); 274 279 EventHandler handler = Stopped; 275 280 if (handler != null) handler(this, EventArgs.Empty);
Note: See TracChangeset
for help on using the changeset viewer.