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).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.