Changeset 15327 for trunk/sources
- Timestamp:
- 08/17/17 12:51:06 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Optimization/3.3/MetaOptimizers/Experiment.cs
r15287 r15327 111 111 private bool experimentStarted = false; 112 112 private bool experimentStopped = false; 113 private ManualResetEventSlim allOptimizerFinished; // this indicates that all started optimizers have been paused or stopped 113 114 114 115 public Experiment() … … 195 196 experimentStarted = true; 196 197 experimentStopped = false; 198 allOptimizerFinished = new ManualResetEventSlim(false); 199 197 200 IOptimizer optimizer; 198 201 while ((optimizer = Optimizers.FirstOrDefault(x => (x.ExecutionState == ExecutionState.Prepared) || (x.ExecutionState == ExecutionState.Paused))) != null) { … … 201 204 if (ExecutionState == ExecutionState.Paused || ExecutionState == ExecutionState.Stopped) break; 202 205 } 206 207 allOptimizerFinished.Wait(); 203 208 } 204 209 public async Task StartAsync() { await StartAsync(CancellationToken.None); } … … 368 373 private void optimizer_Paused(object sender, EventArgs e) { 369 374 lock (locker) 370 if (Optimizers.All(x => x.ExecutionState != ExecutionState.Started)) OnPaused(); 375 if (Optimizers.All(x => x.ExecutionState != ExecutionState.Started)) { 376 OnPaused(); 377 allOptimizerFinished.Set(); 378 } 371 379 } 372 380 private void optimizer_Prepared(object sender, EventArgs e) { … … 381 389 lock (locker) { 382 390 if (experimentStopped) { 383 if (Optimizers.All(x => (x.ExecutionState == ExecutionState.Stopped) || (x.ExecutionState == ExecutionState.Prepared))) OnStopped(); 391 if (Optimizers.All(x => (x.ExecutionState == ExecutionState.Stopped) || (x.ExecutionState == ExecutionState.Prepared))) { 392 OnStopped(); 393 allOptimizerFinished.Set(); 394 } 384 395 } else { 385 396 if (experimentStarted && Optimizers.Any(x => (x.ExecutionState == ExecutionState.Prepared) || (x.ExecutionState == ExecutionState.Paused))) return; 386 else if (Optimizers.All(x => x.ExecutionState == ExecutionState.Stopped)) OnStopped(); 387 else if (Optimizers.Any(x => (x.ExecutionState == ExecutionState.Prepared) || (x.ExecutionState == ExecutionState.Paused)) && Optimizers.All(o => o.ExecutionState != ExecutionState.Started)) OnPaused(); 397 else if (Optimizers.All(x => x.ExecutionState == ExecutionState.Stopped)) { 398 OnStopped(); 399 allOptimizerFinished.Set(); 400 } else if (Optimizers.Any(x => (x.ExecutionState == ExecutionState.Prepared) || (x.ExecutionState == ExecutionState.Paused)) && Optimizers.All(o => o.ExecutionState != ExecutionState.Started)) { 401 OnPaused(); 402 allOptimizerFinished.Set(); 403 } 388 404 } 389 405 }
Note: See TracChangeset
for help on using the changeset viewer.