Changeset 3261 for trunk/sources/HeuristicLab.Optimization/3.3
- Timestamp:
- 04/04/10 00:03:13 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Optimization/3.3
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Optimization/3.3/Algorithm.cs
r3260 r3261 112 112 } 113 113 public void Start() { 114 OnStarted(); 114 115 Running = true; 115 116 Canceled = false; 116 OnStarted();117 117 } 118 118 public void Stop() { … … 157 157 public event EventHandler Stopped; 158 158 protected virtual void OnStopped() { 159 Canceled = false; 160 Running = false; 159 161 if (Stopped != null) 160 162 Stopped(this, EventArgs.Empty); 161 Canceled = false;162 Running = false;163 163 } 164 164 protected virtual void OnCanceledChanged() { } -
trunk/sources/HeuristicLab.Optimization/3.3/BatchRun.cs
r3260 r3261 142 142 } 143 143 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 } 145 150 } 146 151 public void Stop() { … … 186 191 if (Stopped != null) 187 192 Stopped(this, EventArgs.Empty); 188 canceled = false;189 Running = false;190 193 } 191 194 public event EventHandler<HeuristicLab.Common.EventArgs<Exception>> ExceptionOccurred; … … 195 198 } 196 199 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 } 197 205 private void DeregisterAlgorithmEvents() { 198 algorithm.RunningChanged -= new EventHandler(Algorithm_RunningChanged);199 206 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 223 211 private void Algorithm_ExceptionOccurred(object sender, HeuristicLab.Common.EventArgs<Exception> e) { 224 212 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 } 225 238 } 226 239 #endregion -
trunk/sources/HeuristicLab.Optimization/3.3/EngineAlgorithm.cs
r3260 r3261 216 216 Engine.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(Engine_ExceptionOccurred); 217 217 Engine.ExecutionTimeChanged += new EventHandler(Engine_ExecutionTimeChanged); 218 Engine.RunningChanged += new EventHandler(Engine_RunningChanged); 219 } 218 Engine.Stopped += new EventHandler(Engine_Stopped); 219 } 220 220 221 private void DeregisterEngineEvents() { 221 222 Engine.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(Engine_ExceptionOccurred); 222 223 Engine.ExecutionTimeChanged -= new EventHandler(Engine_ExecutionTimeChanged); 223 Engine. RunningChanged -= new EventHandler(Engine_RunningChanged);224 Engine.Stopped -= new EventHandler(Engine_Stopped); 224 225 } 225 226 … … 230 231 OnExecutionTimeChanged(); 231 232 } 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(); 234 235 } 235 236 }
Note: See TracChangeset
for help on using the changeset viewer.