Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/04/18 22:33:26 (7 years ago)
Author:
abeham
Message:

#1614:

  • reverted r15603 by reverse merging
  • added expert system plugins from #2457
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/1614_GeneralizedQAP/HeuristicLab.Optimization/3.3/MetaOptimizers/TimeLimitRun.cs

    r15605 r15721  
    214214
    215215    private void Initialize() {
    216       timer = new System.Timers.Timer();
    217       timer.Interval = 50;
    218       timer.Elapsed += Timer_Elapsed;
    219216      if (algorithm != null) RegisterAlgorithmEvents();
    220217      snapshotTimes.ItemsAdded += snapshotTimes_Changed;
     
    258255    }
    259256
    260     private System.Timers.Timer timer;
    261 
    262     private void Timer_Elapsed(object sender, EventArgs e) {
    263       if (Algorithm.ExecutionState == ExecutionState.Started) {
    264         if (snapshotTimesIndex < SnapshotTimes.Count && ExecutionTime >= SnapshotTimes[snapshotTimesIndex]
    265           && !pausedForSnapshot) {
    266           pausedForSnapshot = true;
    267           Algorithm.Pause();
    268         }
    269         if (ExecutionTime >= MaximumExecutionTime && !pausedForTermination) {
    270           pausedForTermination = true;
    271           if (!pausedForSnapshot) Algorithm.Pause();
    272         }
    273       }
    274     }
    275 
    276257    #region Events
    277258    protected override void OnNameChanged() {
     
    292273      if (handler != null) handler(this, EventArgs.Empty);
    293274    }
    294     [Obsolete("Deprecated needs to be removed")]
    295275    public event EventHandler ExecutionTimeChanged;
     276    private void OnExecutionTimeChanged() {
     277      var handler = ExecutionTimeChanged;
     278      if (handler != null) handler(this, EventArgs.Empty);
     279    }
    296280    public event EventHandler Prepared;
    297281    private void OnPrepared() {
     
    301285    public event EventHandler Started;
    302286    private void OnStarted() {
    303       timer.Start();
    304287      var handler = Started;
    305288      if (handler != null) handler(this, EventArgs.Empty);
     
    307290    public event EventHandler Paused;
    308291    private void OnPaused() {
    309       timer.Stop();
    310292      var handler = Paused;
    311293      if (handler != null) handler(this, EventArgs.Empty);
     
    313295    public event EventHandler Stopped;
    314296    private void OnStopped() {
    315       timer.Stop();
    316297      var handler = Stopped;
    317298      if (handler != null) handler(this, EventArgs.Empty);
     
    327308    private void RegisterAlgorithmEvents() {
    328309      algorithm.ExceptionOccurred += Algorithm_ExceptionOccurred;
     310      algorithm.ExecutionTimeChanged += Algorithm_ExecutionTimeChanged;
    329311      algorithm.ExecutionStateChanged += Algorithm_ExecutionStateChanged;
    330312      algorithm.Paused += Algorithm_Paused;
     
    335317    private void DeregisterAlgorithmEvents() {
    336318      algorithm.ExceptionOccurred -= Algorithm_ExceptionOccurred;
     319      algorithm.ExecutionTimeChanged -= Algorithm_ExecutionTimeChanged;
    337320      algorithm.ExecutionStateChanged -= Algorithm_ExecutionStateChanged;
    338321      algorithm.Paused -= Algorithm_Paused;
     
    343326    private void Algorithm_ExceptionOccurred(object sender, EventArgs<Exception> e) {
    344327      OnExceptionOccurred(e.Value);
     328    }
     329    private void Algorithm_ExecutionTimeChanged(object sender, EventArgs e) {
     330      if (snapshotTimesIndex < SnapshotTimes.Count && ExecutionTime >= SnapshotTimes[snapshotTimesIndex]
     331        && !pausedForSnapshot) {
     332        pausedForSnapshot = true;
     333        Algorithm.Pause();
     334      }
     335      if (ExecutionTime >= MaximumExecutionTime && !pausedForTermination) {
     336        pausedForTermination = true;
     337        if (!pausedForSnapshot) Algorithm.Pause();
     338      }
     339      OnExecutionTimeChanged();
    345340    }
    346341    private void Algorithm_ExecutionStateChanged(object sender, EventArgs e) {
Note: See TracChangeset for help on using the changeset viewer.