Free cookie consent management tool by TermsFeed Policy Generator

Changeset 15382 for stable


Ignore:
Timestamp:
09/27/17 10:32:21 (7 years ago)
Author:
pfleck
Message:

#2823 merged r15327, r15339 to stable

Location:
stable
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Optimization

  • stable/HeuristicLab.Optimization/3.3/MetaOptimizers/Experiment.cs

    r15292 r15382  
    111111    private bool experimentStarted = false;
    112112    private bool experimentStopped = false;
     113    private readonly ManualResetEventSlim allOptimizerFinished = new ManualResetEventSlim(false); // this indicates that all started optimizers have been paused or stopped
    113114
    114115    public Experiment()
     
    191192      if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused))
    192193        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;
    194195
    195196      experimentStarted = true;
    196197      experimentStopped = false;
     198      allOptimizerFinished.Reset();
    197199      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) {
    199201        // a race-condition may occur when the optimizer has changed the state by itself in the meantime
    200202        try { optimizer.Start(cancellationToken); } catch (InvalidOperationException) { }
    201203        if (ExecutionState == ExecutionState.Paused || ExecutionState == ExecutionState.Stopped) break;
    202204      }
     205      allOptimizerFinished.Wait();
    203206    }
    204207    public async Task StartAsync() { await StartAsync(CancellationToken.None); }
     
    266269    private void OnPaused() {
    267270      ExecutionState = ExecutionState.Paused;
     271      allOptimizerFinished.Set();
    268272      EventHandler handler = Paused;
    269273      if (handler != null) handler(this, EventArgs.Empty);
     
    272276    private void OnStopped() {
    273277      ExecutionState = ExecutionState.Stopped;
     278      allOptimizerFinished.Set();
    274279      EventHandler handler = Stopped;
    275280      if (handler != null) handler(this, EventArgs.Empty);
Note: See TracChangeset for help on using the changeset viewer.