Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/15/11 14:15:43 (13 years ago)
Author:
mkommend
Message:

#1573, #1574: Decoupled execution states of Experiment and BatchRun with the nested optimizers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Optimization/3.3/BatchRun.cs

    r6534 r6767  
    147147    }
    148148
    149     private bool stopPending;
     149    private bool batchRunStarted = false;
     150    private bool batchRunPaused = false;
     151    private bool batchRunStopped = false;
    150152
    151153    public BatchRun()
     
    158160      repetitionsCounter = 0;
    159161      Runs = new RunCollection();
    160       stopPending = false;
    161162    }
    162163    public BatchRun(string name)
     
    168169      repetitionsCounter = 0;
    169170      Runs = new RunCollection();
    170       stopPending = false;
    171171    }
    172172    public BatchRun(string name, string description)
     
    177177      repetitionsCounter = 0;
    178178      Runs = new RunCollection();
    179       stopPending = false;
    180179    }
    181180    [StorableConstructor]
    182     private BatchRun(bool deserializing)
    183       : base(deserializing) {
    184       stopPending = false;
    185     }
     181    private BatchRun(bool deserializing) : base(deserializing) { }
    186182    [StorableHook(HookType.AfterDeserialization)]
    187183    private void AfterDeserialization() {
     
    197193      repetitionsCounter = original.repetitionsCounter;
    198194      runs = cloner.Clone(original.runs);
    199       stopPending = original.stopPending;
     195      batchRunStarted = original.batchRunStarted;
     196      batchRunPaused = original.batchRunPaused;
     197      batchRunStopped = original.batchRunStopped;
    200198      Initialize();
    201199    }
     
    227225      if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused))
    228226        throw new InvalidOperationException(string.Format("Start not allowed in execution state \"{0}\".", ExecutionState));
    229       if (Optimizer != null) Optimizer.Start();
     227      if (Optimizer == null) return;
     228
     229      batchRunStarted = true;
     230      batchRunPaused = false;
     231      batchRunStopped = false;
     232      if (Optimizer.ExecutionState != ExecutionState.Prepared) Optimizer.Prepare();
     233      Optimizer.Start();
    230234    }
    231235    public void Pause() {
    232236      if (ExecutionState != ExecutionState.Started)
    233237        throw new InvalidOperationException(string.Format("Pause not allowed in execution state \"{0}\".", ExecutionState));
    234       if ((Optimizer != null) && (Optimizer.ExecutionState == ExecutionState.Started))
    235         Optimizer.Pause();
     238      if (Optimizer == null) return;
     239      if (Optimizer.ExecutionState != ExecutionState.Started) return;
     240
     241      batchRunStarted = false;
     242      batchRunPaused = true;
     243      batchRunStopped = false;
     244      Optimizer.Pause();
    236245    }
    237246    public void Stop() {
    238247      if ((ExecutionState != ExecutionState.Started) && (ExecutionState != ExecutionState.Paused))
    239248        throw new InvalidOperationException(string.Format("Stop not allowed in execution state \"{0}\".", ExecutionState));
    240       stopPending = true;
    241       if ((Optimizer != null) &&
    242           ((Optimizer.ExecutionState == ExecutionState.Started) || (Optimizer.ExecutionState == ExecutionState.Paused)))
    243         Optimizer.Stop();
     249      if (Optimizer == null) return;
     250      if (Optimizer.ExecutionState != ExecutionState.Started && Optimizer.ExecutionState != ExecutionState.Paused) return;
     251      batchRunStarted = false;
     252      batchRunPaused = false;
     253      batchRunStopped = true;
     254      Optimizer.Stop();
    244255    }
    245256
     
    324335    }
    325336    private void Optimizer_Paused(object sender, EventArgs e) {
    326       OnPaused();
     337      if (ExecutionState == ExecutionState.Started) {
     338        batchRunStarted = false;
     339        batchRunPaused = true;
     340        batchRunStopped = false;
     341        OnPaused();
     342      }
    327343    }
    328344    private void Optimizer_Prepared(object sender, EventArgs e) {
    329       if ((ExecutionState == ExecutionState.Paused) || (ExecutionState == ExecutionState.Stopped))
     345      if (ExecutionState == ExecutionState.Stopped || !batchRunStarted) {
    330346        OnPrepared();
     347      }
    331348    }
    332349    private void Optimizer_Started(object sender, EventArgs e) {
    333       stopPending = false;
    334350      if (ExecutionState != ExecutionState.Started)
    335351        OnStarted();
     
    338354      repetitionsCounter++;
    339355
    340       if (!stopPending && (repetitionsCounter < repetitions)) {
     356      if (batchRunStopped) OnStopped();
     357      else if (repetitionsCounter >= repetitions) OnStopped();
     358      else if (batchRunPaused) OnPaused();
     359      else if (batchRunStarted) {
    341360        Optimizer.Prepare();
    342361        Optimizer.Start();
    343       } else {
    344         OnStopped();
    345       }
     362      } else OnStopped();
    346363    }
    347364    private void Optimizer_Runs_CollectionReset(object sender, CollectionItemsChangedEventArgs<IRun> e) {
Note: See TracChangeset for help on using the changeset viewer.