Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3261


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

Continued work on algorithm batch processing (#947).

Location:
trunk/sources
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Core.Views/3.3/EngineView.cs

    r3260 r3261  
    6060    protected override void DeregisterContentEvents() {
    6161      Content.Prepared -= new EventHandler(Content_Prepared);
    62       Content.Started -= new EventHandler(Content_Started);
    63       Content.Stopped -= new EventHandler(Content_Stopped);
     62      Content.RunningChanged -= new EventHandler(Content_RunningChanged);
    6463      Content.ExecutionTimeChanged -= new EventHandler(Content_ExecutionTimeChanged);
    6564      Content.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred);
     
    7473      base.RegisterContentEvents();
    7574      Content.Prepared += new EventHandler(Content_Prepared);
    76       Content.Started += new EventHandler(Content_Started);
    77       Content.Stopped += new EventHandler(Content_Stopped);
     75      Content.RunningChanged += new EventHandler(Content_RunningChanged);
    7876      Content.ExecutionTimeChanged += new EventHandler(Content_ExecutionTimeChanged);
    7977      Content.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred);
     
    102100        Invoke(new EventHandler(Content_Prepared), sender, e);
    103101      else {
     102        executionTimeCounter = 0;
    104103        UpdateExecutionTimeTextBox();
    105104        Log("Engine prepared");
    106105      }
    107106    }
    108     protected virtual void Content_Started(object sender, EventArgs e) {
    109       executionTimeCounter = 0;
     107    protected virtual void Content_RunningChanged(object sender, EventArgs e) {
    110108      if (InvokeRequired)
    111         Invoke(new EventHandler(Content_Started), sender, e);
     109        Invoke(new EventHandler(Content_RunningChanged), sender, e);
    112110      else {
    113111        UpdateExecutionTimeTextBox();
    114         Log("Engine started");
    115       }
    116     }
    117     protected virtual void Content_Stopped(object sender, EventArgs e) {
    118       if (InvokeRequired)
    119         Invoke(new EventHandler(Content_Stopped), sender, e);
    120       else {
    121         UpdateExecutionTimeTextBox();
    122         if (Content.Finished) Log("Engine finished");
     112        if (Content.Running) Log("Engine started");
     113        else if (Content.Finished) Log("Engine finished");
    123114        else Log("Engine stopped");
    124115      }
  • trunk/sources/HeuristicLab.Core/3.3/Engine.cs

    r3226 r3261  
    142142    /// of class <see cref="ThreadPool"/>.</remarks>
    143143    public void Start() {
    144       Running = true;
    145       Canceled = false;
    146144      ThreadPool.QueueUserWorkItem(new WaitCallback(Run), null);
    147145    }
     
    150148    /// of class <see cref="ThreadPool"/>.</remarks>
    151149    public void Step() {
    152       Running = true;
    153       Canceled = false;
    154150      ThreadPool.QueueUserWorkItem(new WaitCallback(RunStep), null);
    155151    }
     
    162158    private void Run(object state) {
    163159      OnStarted();
     160      Running = true;
     161      Canceled = false;
    164162      DateTime start = DateTime.Now;
    165163      DateTime end;
     
    171169      }
    172170      ExecutionTime += DateTime.Now - start;
     171      Canceled = false;
     172      Running = false;
    173173      OnStopped();
    174174    }
    175175    private void RunStep(object state) {
    176176      OnStarted();
     177      Running = true;
     178      Canceled = false;
    177179      DateTime start = DateTime.Now;
    178180      if ((!Canceled) && (!Finished))
    179181        ProcessNextOperator();
    180182      ExecutionTime += DateTime.Now - start;
     183      Canceled = false;
     184      Running = false;
    181185      OnStopped();
    182186    }
     
    241245      if (Stopped != null)
    242246        Stopped(this, EventArgs.Empty);
    243       Canceled = false;
    244       Running = false;
    245247    }
    246248    protected virtual void OnCanceledChanged() { }
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/AlgorithmView.cs

    r3260 r3261  
    7878      Content.Prepared -= new EventHandler(Content_Prepared);
    7979      Content.ProblemChanged -= new EventHandler(Content_ProblemChanged);
    80       Content.Started -= new EventHandler(Content_Started);
    81       Content.Stopped -= new EventHandler(Content_Stopped);
     80      Content.RunningChanged -= new EventHandler(Content_RunningChanged);
    8281      base.DeregisterContentEvents();
    8382    }
     
    8887      Content.Prepared += new EventHandler(Content_Prepared);
    8988      Content.ProblemChanged += new EventHandler(Content_ProblemChanged);
    90       Content.Started += new EventHandler(Content_Started);
    91       Content.Stopped += new EventHandler(Content_Stopped);
     89      Content.RunningChanged += new EventHandler(Content_RunningChanged);
    9290    }
    9391
     
    127125        Invoke(new EventHandler(Content_Prepared), sender, e);
    128126      else {
     127        executionTimeCounter = 0;
    129128        resultsView.Content = Content.Results.AsReadOnly();
    130129        startButton.Enabled = !Content.Finished;
     
    141140      }
    142141    }
    143     protected virtual void Content_Started(object sender, EventArgs e) {
    144       executionTimeCounter = 0;
    145       if (InvokeRequired)
    146         Invoke(new EventHandler(Content_Started), sender, e);
     142    protected virtual void Content_RunningChanged(object sender, EventArgs e) {
     143      if (InvokeRequired)
     144        Invoke(new EventHandler(Content_RunningChanged), sender, e);
    147145      else {
    148         SaveEnabled = false;
    149         parameterCollectionView.Enabled = false;
    150         newProblemButton.Enabled = openProblemButton.Enabled = saveProblemButton.Enabled = false;
    151         problemViewHost.Enabled = false;
    152         resultsView.Enabled = false;
    153         startButton.Enabled = false;
    154         stopButton.Enabled = true;
    155         resetButton.Enabled = false;
    156         UpdateExecutionTimeTextBox();
    157       }
    158     }
    159     protected virtual void Content_Stopped(object sender, EventArgs e) {
    160       if (InvokeRequired)
    161         Invoke(new EventHandler(Content_Stopped), sender, e);
    162       else {
    163         SaveEnabled = true;
    164         parameterCollectionView.Enabled = true;
    165         newProblemButton.Enabled = openProblemButton.Enabled = saveProblemButton.Enabled = true;
    166         problemViewHost.Enabled = true;
    167         resultsView.Enabled = true;
    168         startButton.Enabled = !Content.Finished;
    169         stopButton.Enabled = false;
    170         resetButton.Enabled = true;
     146        SaveEnabled = !Content.Running;
     147        parameterCollectionView.Enabled = !Content.Running;
     148        newProblemButton.Enabled = openProblemButton.Enabled = saveProblemButton.Enabled = !Content.Running;
     149        problemViewHost.Enabled = !Content.Running;
     150        resultsView.Enabled = !Content.Running;
     151        startButton.Enabled = !Content.Running && !Content.Finished;
     152        stopButton.Enabled = Content.Running;
     153        resetButton.Enabled = !Content.Running;
    171154        UpdateExecutionTimeTextBox();
    172155      }
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/BatchRunView.Designer.cs

    r3260 r3261  
    171171      this.startButton.Size = new System.Drawing.Size(24, 24);
    172172      this.startButton.TabIndex = 7;
    173       this.toolTip.SetToolTip(this.startButton, "Start/Resume Algorithm");
     173      this.toolTip.SetToolTip(this.startButton, "Start/Resume Batch Run");
    174174      this.startButton.UseVisualStyleBackColor = true;
    175175      this.startButton.Click += new System.EventHandler(this.startButton_Click);
     
    183183      this.stopButton.Size = new System.Drawing.Size(24, 24);
    184184      this.stopButton.TabIndex = 8;
    185       this.toolTip.SetToolTip(this.stopButton, "Pause Algorithm");
     185      this.toolTip.SetToolTip(this.stopButton, "Pause Batch Run");
    186186      this.stopButton.UseVisualStyleBackColor = true;
    187187      this.stopButton.Click += new System.EventHandler(this.stopButton_Click);
     
    195195      this.resetButton.Size = new System.Drawing.Size(24, 24);
    196196      this.resetButton.TabIndex = 9;
    197       this.toolTip.SetToolTip(this.resetButton, "Reset Algorithm");
     197      this.toolTip.SetToolTip(this.resetButton, "Reset Batch Run");
    198198      this.resetButton.UseVisualStyleBackColor = true;
    199199      this.resetButton.Click += new System.EventHandler(this.resetButton_Click);
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/BatchRunView.cs

    r3260 r3261  
    6262      Content.Prepared -= new EventHandler(Content_Prepared);
    6363      Content.AlgorithmChanged -= new EventHandler(Content_AlgorithmChanged);
    64       Content.Started -= new EventHandler(Content_Started);
    65       Content.Stopped -= new EventHandler(Content_Stopped);
    6664      Content.RepetitionsChanged -= new EventHandler(Content_RepetitionsChanged);
     65      Content.RunningChanged -= new EventHandler(Content_RunningChanged);
    6766      base.DeregisterContentEvents();
    6867    }
     
    7372      Content.Prepared += new EventHandler(Content_Prepared);
    7473      Content.AlgorithmChanged += new EventHandler(Content_AlgorithmChanged);
    75       Content.Started += new EventHandler(Content_Started);
    76       Content.Stopped += new EventHandler(Content_Stopped);
    7774      Content.RepetitionsChanged += new EventHandler(Content_RepetitionsChanged);
     75      Content.RunningChanged += new EventHandler(Content_RunningChanged);
    7876    }
    7977
     
    128126      }
    129127    }
    130     private void Content_Started(object sender, EventArgs e) {
    131       if (InvokeRequired)
    132         Invoke(new EventHandler(Content_Started), sender, e);
    133       else {
    134         SaveEnabled = false;
    135         repetitionsNumericUpDown.Enabled = false;
    136         newAlgorithmButton.Enabled = openAlgorithmButton.Enabled = saveAlgorithmButton.Enabled = false;
    137         startButton.Enabled = false;
    138         stopButton.Enabled = true;
    139         resetButton.Enabled = false;
    140         UpdateExecutionTimeTextBox();
    141       }
    142     }
    143     private void Content_Stopped(object sender, EventArgs e) {
    144       if (InvokeRequired)
    145         Invoke(new EventHandler(Content_Stopped), sender, e);
    146       else {
    147         SaveEnabled = true;
    148         repetitionsNumericUpDown.Enabled = true;
    149         newAlgorithmButton.Enabled = openAlgorithmButton.Enabled = saveAlgorithmButton.Enabled = true;
    150         startButton.Enabled = !Content.Finished;
    151         stopButton.Enabled = false;
    152         resetButton.Enabled = true;
     128    private void Content_RunningChanged(object sender, EventArgs e) {
     129      if (InvokeRequired)
     130        Invoke(new EventHandler(Content_RunningChanged), sender, e);
     131      else {
     132        SaveEnabled = !Content.Running;
     133        repetitionsNumericUpDown.Enabled = !Content.Running;
     134        newAlgorithmButton.Enabled = openAlgorithmButton.Enabled = saveAlgorithmButton.Enabled = !Content.Running;
     135        startButton.Enabled = !Content.Running && !Content.Finished;
     136        stopButton.Enabled = Content.Running;
     137        resetButton.Enabled = !Content.Running;
    153138        UpdateExecutionTimeTextBox();
    154139      }
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/EngineAlgorithmView.cs

    r3214 r3261  
    9898    }
    9999
    100     protected override void Content_Started(object sender, EventArgs e) {
     100    protected override void Content_RunningChanged(object sender, EventArgs e) {
    101101      if (InvokeRequired)
    102         Invoke(new EventHandler(Content_Started), sender, e);
     102        Invoke(new EventHandler(Content_RunningChanged), sender, e);
    103103      else {
    104         createUserDefinedAlgorithmButton.Enabled = false;
    105         engineComboBox.Enabled = false;
    106         engineViewHost.Enabled = false;
    107         base.Content_Started(sender, e);
    108       }
    109     }
    110     protected override void Content_Stopped(object sender, EventArgs e) {
    111       if (InvokeRequired)
    112         Invoke(new EventHandler(Content_Stopped), sender, e);
    113       else {
    114         createUserDefinedAlgorithmButton.Enabled = true;
    115         engineComboBox.Enabled = true;
    116         engineViewHost.Enabled = true;
    117         base.Content_Stopped(sender, e);
     104        createUserDefinedAlgorithmButton.Enabled = !Content.Running;
     105        engineComboBox.Enabled = !Content.Running;
     106        engineViewHost.Enabled = !Content.Running;
     107        base.Content_RunningChanged(sender, e);
    118108      }
    119109    }
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/UserDefinedAlgorithmView.cs

    r3177 r3261  
    7575    }
    7676
    77     protected override void Content_Started(object sender, EventArgs e) {
     77    protected override void Content_RunningChanged(object sender, EventArgs e) {
    7878      if (InvokeRequired)
    79         Invoke(new EventHandler(Content_Started), sender, e);
     79        Invoke(new EventHandler(Content_RunningChanged), sender, e);
    8080      else {
    81         newOperatorGraphButton.Enabled = openOperatorGraphButton.Enabled = saveOperatorGraphButton.Enabled = false;
    82         operatorGraphViewHost.Enabled = false;
    83         globalScopeView.Enabled = false;
    84         base.Content_Started(sender, e);
    85       }
    86     }
    87     protected override void Content_Stopped(object sender, EventArgs e) {
    88       if (InvokeRequired)
    89         Invoke(new EventHandler(Content_Stopped), sender, e);
    90       else {
    91         newOperatorGraphButton.Enabled = openOperatorGraphButton.Enabled = saveOperatorGraphButton.Enabled = true;
    92         operatorGraphViewHost.Enabled = true;
    93         globalScopeView.Enabled = true;
    94         base.Content_Stopped(sender, e);
     81        newOperatorGraphButton.Enabled = openOperatorGraphButton.Enabled = saveOperatorGraphButton.Enabled = !Content.Running;
     82        operatorGraphViewHost.Enabled = !Content.Running;
     83        globalScopeView.Enabled = !Content.Running;
     84        base.Content_RunningChanged(sender, e);
    9585      }
    9686    }
  • 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.