Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/04/10 00:03:13 (14 years ago)
Author:
swagner
Message:

Continued work on algorithm batch processing (#947).

Location:
trunk/sources/HeuristicLab.Optimization/3.3
Files:
3 edited

Legend:

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

    r3260 r3261  
    112112    }
    113113    public void Start() {
     114      OnStarted();
    114115      Running = true;
    115116      Canceled = false;
    116       OnStarted();
    117117    }
    118118    public void Stop() {
     
    157157    public event EventHandler Stopped;
    158158    protected virtual void OnStopped() {
     159      Canceled = false;
     160      Running = false;
    159161      if (Stopped != null)
    160162        Stopped(this, EventArgs.Empty);
    161       Canceled = false;
    162       Running = false;
    163163    }
    164164    protected virtual void OnCanceledChanged() { }
  • trunk/sources/HeuristicLab.Optimization/3.3/BatchRun.cs

    r3260 r3261  
    142142    }
    143143    public void Start() {
    144       if (Algorithm != null) Algorithm.Start();
     144      if (Algorithm != null) {
     145        OnStarted();
     146        Running = true;
     147        canceled = false;
     148        Algorithm.Start();
     149      }
    145150    }
    146151    public void Stop() {
     
    186191      if (Stopped != null)
    187192        Stopped(this, EventArgs.Empty);
    188       canceled = false;
    189       Running = false;
    190193    }
    191194    public event EventHandler<HeuristicLab.Common.EventArgs<Exception>> ExceptionOccurred;
     
    195198    }
    196199
     200    private void RegisterAlgorithmEvents() {
     201      algorithm.ExceptionOccurred += new EventHandler<HeuristicLab.Common.EventArgs<Exception>>(Algorithm_ExceptionOccurred);
     202      algorithm.Started += new EventHandler(Algorithm_Started);
     203      algorithm.Stopped += new EventHandler(Algorithm_Stopped);
     204    }
    197205    private void DeregisterAlgorithmEvents() {
    198       algorithm.RunningChanged -= new EventHandler(Algorithm_RunningChanged);
    199206      algorithm.ExceptionOccurred -= new EventHandler<HeuristicLab.Common.EventArgs<Exception>>(Algorithm_ExceptionOccurred);
    200     }
    201 
    202     private void RegisterAlgorithmEvents() {
    203       algorithm.RunningChanged += new EventHandler(Algorithm_RunningChanged);
    204       algorithm.ExceptionOccurred += new EventHandler<HeuristicLab.Common.EventArgs<Exception>>(Algorithm_ExceptionOccurred);
    205     }
    206 
    207     private void Algorithm_RunningChanged(object sender, EventArgs e) {
    208       if (Algorithm.Running) {
    209         Running = true;
    210         OnStarted();
    211       } else {
    212         if (!canceled) {
    213           ExecutionTime += Algorithm.ExecutionTime;
    214           runs.Add(new Run("Run " + Algorithm.ExecutionTime.ToString(), Algorithm));
    215           Algorithm.Prepare();
    216           if (runs.Count < repetitions) Algorithm.Start();
    217           else OnStopped();
    218         } else {
    219           OnStopped();
    220         }
    221       }
    222     }
     207      algorithm.Started -= new EventHandler(Algorithm_Started);
     208      algorithm.Stopped -= new EventHandler(Algorithm_Stopped);
     209    }
     210
    223211    private void Algorithm_ExceptionOccurred(object sender, HeuristicLab.Common.EventArgs<Exception> e) {
    224212      OnExceptionOccurred(e.Value);
     213    }
     214    private void Algorithm_Started(object sender, EventArgs e) {
     215      if (!Running) {
     216        OnStarted();
     217        Running = true;
     218        canceled = false;
     219      }
     220    }
     221    private void Algorithm_Stopped(object sender, EventArgs e) {
     222      if (!canceled) {
     223        ExecutionTime += Algorithm.ExecutionTime;
     224        runs.Add(new Run("Run " + Algorithm.ExecutionTime.ToString(), Algorithm));
     225        Algorithm.Prepare();
     226
     227        if (runs.Count < repetitions)
     228          Algorithm.Start();
     229        else {
     230          Running = false;
     231          OnStopped();
     232        }
     233      } else {
     234        canceled = false;
     235        Running = false;
     236        OnStopped();
     237      }
    225238    }
    226239    #endregion
  • trunk/sources/HeuristicLab.Optimization/3.3/EngineAlgorithm.cs

    r3260 r3261  
    216216      Engine.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(Engine_ExceptionOccurred);
    217217      Engine.ExecutionTimeChanged += new EventHandler(Engine_ExecutionTimeChanged);
    218       Engine.RunningChanged += new EventHandler(Engine_RunningChanged);
    219     }
     218      Engine.Stopped += new EventHandler(Engine_Stopped);
     219    }
     220
    220221    private void DeregisterEngineEvents() {
    221222      Engine.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(Engine_ExceptionOccurred);
    222223      Engine.ExecutionTimeChanged -= new EventHandler(Engine_ExecutionTimeChanged);
    223       Engine.RunningChanged -= new EventHandler(Engine_RunningChanged);
     224      Engine.Stopped -= new EventHandler(Engine_Stopped);
    224225    }
    225226
     
    230231      OnExecutionTimeChanged();
    231232    }
    232     private void Engine_RunningChanged(object sender, EventArgs e) {
    233       if (!Engine.Running) OnStopped();
     233    private void Engine_Stopped(object sender, EventArgs e) {
     234      OnStopped();
    234235    }
    235236  }
Note: See TracChangeset for help on using the changeset viewer.