Changeset 8975 for branches/RuntimeOptimizer
- Timestamp:
- 11/29/12 11:31:44 (12 years ago)
- Location:
- branches/RuntimeOptimizer
- Files:
-
- 3 added
- 2 deleted
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/RuntimeOptimizer/HeuristicLab.MainForm.WindowsForms/3.3/HeuristicLab.MainForm.WindowsForms-3.3.csproj
r8618 r8975 126 126 <DependentUpon>DragOverTabControl.cs</DependentUpon> 127 127 </Compile> 128 <Compile Include="Dialogs\DefineArithmeticProgressionDialog.cs"> 129 <SubType>Form</SubType> 130 </Compile> 131 <Compile Include="Dialogs\DefineArithmeticProgressionDialog.Designer.cs"> 132 <DependentUpon>DefineArithmeticProgressionDialog.cs</DependentUpon> 133 </Compile> 128 134 <Compile Include="Plugin.cs" /> 129 135 <Compile Include="Views\AsynchronousContentView.cs"> … … 254 260 </BootstrapperPackage> 255 261 </ItemGroup> 262 <ItemGroup /> 256 263 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> 257 264 <!-- To modify your build process, add your task inside one of the targets below and uncomment it. -
branches/RuntimeOptimizer/HeuristicLab.Optimization.Views/3.3/TimeLimitRunView.Designer.cs
r8961 r8975 51 51 this.openFileDialog = new System.Windows.Forms.OpenFileDialog(); 52 52 this.snapshotButton = new System.Windows.Forms.Button(); 53 this.sequenceButton = new System.Windows.Forms.Button(); 53 54 ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit(); 54 55 this.tabControl.SuspendLayout(); … … 135 136 this.snapshotsTextBox.Location = new System.Drawing.Point(69, 52); 136 137 this.snapshotsTextBox.Name = "snapshotsTextBox"; 137 this.snapshotsTextBox.Size = new System.Drawing.Size( 259, 20);138 this.snapshotsTextBox.Size = new System.Drawing.Size(175, 20); 138 139 this.snapshotsTextBox.TabIndex = 6; 139 140 this.snapshotsTextBox.Validating += new System.ComponentModel.CancelEventHandler(this.snapshotsTextBox_Validating); … … 286 287 this.snapshotButton.Click += new System.EventHandler(this.snapshotButton_Click); 287 288 // 289 // sequenceButton 290 // 291 this.sequenceButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); 292 this.sequenceButton.Location = new System.Drawing.Point(250, 50); 293 this.sequenceButton.Name = "sequenceButton"; 294 this.sequenceButton.Size = new System.Drawing.Size(75, 23); 295 this.sequenceButton.TabIndex = 16; 296 this.sequenceButton.Text = "Sequence..."; 297 this.sequenceButton.UseVisualStyleBackColor = true; 298 this.sequenceButton.Click += new System.EventHandler(this.sequenceButton_Click); 299 // 288 300 // TimeLimitRunView 289 301 // 290 302 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit; 303 this.Controls.Add(this.sequenceButton); 291 304 this.Controls.Add(this.snapshotButton); 292 305 this.Controls.Add(this.tabControl); … … 314 327 this.Controls.SetChildIndex(this.startButton, 0); 315 328 this.Controls.SetChildIndex(this.snapshotButton, 0); 329 this.Controls.SetChildIndex(this.sequenceButton, 0); 316 330 ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit(); 317 331 this.tabControl.ResumeLayout(false); … … 342 356 private System.Windows.Forms.OpenFileDialog openFileDialog; 343 357 private System.Windows.Forms.Button snapshotButton; 358 private System.Windows.Forms.Button sequenceButton; 344 359 } 345 360 } -
branches/RuntimeOptimizer/HeuristicLab.Optimization.Views/3.3/TimeLimitRunView.cs
r8961 r8975 114 114 protected override void SetEnabledStateOfExecutableButtons() { 115 115 base.SetEnabledStateOfExecutableButtons(); 116 snapshotButton.Enabled = Content != null && (Content.ExecutionState == ExecutionState.Started || Content.ExecutionState == ExecutionState.Paused);116 snapshotButton.Enabled = Content != null && Content.Algorithm != null && Content.ExecutionState == ExecutionState.Paused; 117 117 } 118 118 … … 290 290 private void snapshotButton_Click(object sender, EventArgs e) { 291 291 Content.Snapshot(); 292 } 293 294 private void sequenceButton_Click(object sender, EventArgs e) { 295 using (var dialog = new DefineArithmeticProgressionDialog(false, 1, Content.MaximumExecutionTime.TotalSeconds, 1)) { 296 if (dialog.ShowDialog() == DialogResult.OK) { 297 Content.SnapshotTimes = new ObservableList<TimeSpan>(dialog.Values.Select(TimeSpan.FromSeconds)); 298 } 299 } 292 300 } 293 301 #endregion -
branches/RuntimeOptimizer/HeuristicLab.Optimization/3.3/MetaOptimizers/BatchRun.cs
r8955 r8975 175 175 repetitions = 10; 176 176 repetitionsCounter = 0; 177 Runs = new RunCollection { AlgorithmName = Name };177 Runs = new RunCollection { OptimizerName = Name }; 178 178 } 179 179 public BatchRun(string name) … … 185 185 repetitions = 10; 186 186 repetitionsCounter = 0; 187 Runs = new RunCollection { AlgorithmName = Name };187 Runs = new RunCollection { OptimizerName = Name }; 188 188 } 189 189 public BatchRun(string name, string description) … … 194 194 repetitions = 10; 195 195 repetitionsCounter = 0; 196 Runs = new RunCollection { AlgorithmName = Name };196 Runs = new RunCollection { OptimizerName = Name }; 197 197 } 198 198 [StorableConstructor] … … 237 237 batchRunAction = BatchRunAction.Prepare; 238 238 // a race-condition may occur when the optimizer has changed the state by itself in the meantime 239 try { Optimizer.Prepare(clearRuns); } 240 catch (InvalidOperationException) { } 239 try { Optimizer.Prepare(clearRuns); } catch (InvalidOperationException) { } 241 240 } else { 242 241 ExecutionState = ExecutionState.Stopped; … … 250 249 if (Optimizer.ExecutionState == ExecutionState.Stopped) Optimizer.Prepare(); 251 250 // a race-condition may occur when the optimizer has changed the state by itself in the meantime 252 try { Optimizer.Start(); } 253 catch (InvalidOperationException) { } 251 try { Optimizer.Start(); } catch (InvalidOperationException) { } 254 252 } 255 253 public void Pause() { … … 260 258 if (Optimizer.ExecutionState != ExecutionState.Started) return; 261 259 // a race-condition may occur when the optimizer has changed the state by itself in the meantime 262 try { Optimizer.Pause(); } 263 catch (InvalidOperationException) { } 260 try { Optimizer.Pause(); } catch (InvalidOperationException) { } 264 261 } 265 262 public void Stop() { … … 273 270 } 274 271 // a race-condition may occur when the optimizer has changed the state by itself in the meantime 275 try { Optimizer.Stop(); } 276 catch (InvalidOperationException) { } 272 try { Optimizer.Stop(); } catch (InvalidOperationException) { } 277 273 } 278 274 … … 280 276 protected override void OnNameChanged() { 281 277 base.OnNameChanged(); 282 runs. AlgorithmName = Name;278 runs.OptimizerName = Name; 283 279 } 284 280 -
branches/RuntimeOptimizer/HeuristicLab.Optimization/3.3/MetaOptimizers/Experiment.cs
r8955 r8975 117 117 executionTime = TimeSpan.Zero; 118 118 optimizers = new OptimizerList(); 119 Runs = new RunCollection { AlgorithmName = Name };119 Runs = new RunCollection { OptimizerName = Name }; 120 120 Initialize(); 121 121 } … … 126 126 executionTime = TimeSpan.Zero; 127 127 optimizers = new OptimizerList(); 128 Runs = new RunCollection { AlgorithmName = Name };128 Runs = new RunCollection { OptimizerName = Name }; 129 129 Initialize(); 130 130 } … … 134 134 executionTime = TimeSpan.Zero; 135 135 optimizers = new OptimizerList(); 136 Runs = new RunCollection { AlgorithmName = Name };136 Runs = new RunCollection { OptimizerName = Name }; 137 137 Initialize(); 138 138 } … … 180 180 foreach (IOptimizer optimizer in Optimizers.Where(x => x.ExecutionState != ExecutionState.Started)) { 181 181 // a race-condition may occur when the optimizer has changed the state by itself in the meantime 182 try { optimizer.Prepare(clearRuns); } 183 catch (InvalidOperationException) { } 182 try { optimizer.Prepare(clearRuns); } catch (InvalidOperationException) { } 184 183 } 185 184 } … … 194 193 if (optimizer != null) { 195 194 // a race-condition may occur when the optimizer has changed the state by itself in the meantime 196 try { optimizer.Start(); } 197 catch (InvalidOperationException) { } 195 try { optimizer.Start(); } catch (InvalidOperationException) { } 198 196 } 199 197 } … … 207 205 foreach (IOptimizer optimizer in Optimizers.Where(x => x.ExecutionState == ExecutionState.Started)) { 208 206 // a race-condition may occur when the optimizer has changed the state by itself in the meantime 209 try { optimizer.Pause(); } 210 catch (InvalidOperationException) { } 207 try { optimizer.Pause(); } catch (InvalidOperationException) { } 211 208 } 212 209 } … … 221 218 foreach (var optimizer in Optimizers.Where(x => (x.ExecutionState == ExecutionState.Started) || (x.ExecutionState == ExecutionState.Paused))) { 222 219 // a race-condition may occur when the optimizer has changed the state by itself in the meantime 223 try { optimizer.Stop(); } 224 catch (InvalidOperationException) { } 220 try { optimizer.Stop(); } catch (InvalidOperationException) { } 225 221 } 226 222 } else { … … 232 228 protected override void OnNameChanged() { 233 229 base.OnNameChanged(); 234 Runs. AlgorithmName = Name;230 Runs.OptimizerName = Name; 235 231 } 236 232 -
branches/RuntimeOptimizer/HeuristicLab.Optimization/3.3/MetaOptimizers/TimeLimitRun.cs
r8961 r8975 25 25 using System.Drawing; 26 26 using System.Linq; 27 using System.Threading;28 27 using System.Threading.Tasks; 29 using System.Timers;30 28 using HeuristicLab.Collections; 31 29 using HeuristicLab.Common; … … 33 31 using HeuristicLab.Core; 34 32 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 35 using Timer = System.Timers.Timer;36 33 37 34 namespace HeuristicLab.Optimization { … … 56 53 #endregion 57 54 58 private Timer snapTimer, runTimer; 59 private readonly ManualResetEvent algorithmStarted = new ManualResetEvent(false); 60 private readonly ManualResetEvent algorithmPaused = new ManualResetEvent(false); 61 private readonly ManualResetEvent algorithmStopped = new ManualResetEvent(false); 62 [Storable] 63 private bool snapshotTimesDirty; 55 private bool pausedForSnapshot = false; 56 private bool pausedForTermination = false; 64 57 65 58 [Storable] … … 70 63 if (maximumExecutionTime == value) return; 71 64 maximumExecutionTime = value; 72 runTimer.Interval = (maximumExecutionTime - ExecutionTime).TotalMilliseconds;73 65 OnPropertyChanged("MaximumExecutionTime"); 74 66 } … … 84 76 if (snapshotTimes == value) return; 85 77 snapshotTimes = value; 86 snapshotTimesDirty = true; 78 snapshotTimes.Sort(); 79 FindNextSnapshotTimeIndex(ExecutionTime); 87 80 OnPropertyChanged("SnapshotTimes"); 88 81 } … … 131 124 if (algorithm != null) { 132 125 RegisterAlgorithmEvents(); 133 if (algorithm.ExecutionState == ExecutionState.Started) algorithmStarted.Set();134 else algorithmStarted.Reset();135 if (algorithm.ExecutionState == ExecutionState.Paused) algorithmPaused.Set();136 else algorithmPaused.Reset();137 if (algorithm.ExecutionState == ExecutionState.Stopped) algorithmStopped.Set();138 else algorithmStopped.Reset();139 126 } 140 127 OnPropertyChanged("Algorithm"); … … 173 160 snapshotTimesIndex = original.snapshotTimesIndex; 174 161 snapshots = cloner.Clone(original.snapshots); 175 snapshotTimesDirty = original.snapshotTimesDirty;176 162 storeAlgorithmInEachSnapshot = original.storeAlgorithmInEachSnapshot; 177 163 algorithm = cloner.Clone(original.algorithm); 178 164 runs = cloner.Clone(original.runs); 179 180 snapTimer = new Timer() {181 AutoReset = original.snapTimer.AutoReset,182 Interval = original.snapTimer.Interval183 };184 runTimer = new Timer() {185 AutoReset = original.runTimer.AutoReset,186 Interval = original.runTimer.Interval187 };188 if (original.algorithm != null && original.algorithm.ExecutionState == ExecutionState.Started)189 algorithmStarted.Set();190 if (original.algorithm != null && original.algorithm.ExecutionState == ExecutionState.Paused)191 algorithmPaused.Set();192 if (original.algorithm != null && original.algorithm.ExecutionState == ExecutionState.Stopped)193 algorithmStopped.Set();194 165 195 166 Initialize(); … … 199 170 name = ItemName; 200 171 description = ItemDescription; 201 maximumExecutionTime = TimeSpan.FromMinutes( 1);172 maximumExecutionTime = TimeSpan.FromMinutes(.5); 202 173 snapshotTimes = new ObservableList<TimeSpan>(new[] { 203 174 TimeSpan.FromSeconds(5), 204 175 TimeSpan.FromSeconds(10), 205 TimeSpan.FromSeconds( 30) });176 TimeSpan.FromSeconds(15) }); 206 177 snapshotTimesIndex = 0; 207 snapTimer = new Timer() {208 AutoReset = false,209 Enabled = false,210 Interval = 100211 };212 runTimer = new Timer() {213 AutoReset = false,214 Enabled = false,215 Interval = MaximumExecutionTime.TotalMilliseconds216 };217 178 snapshots = new RunCollection(); 218 Runs = new RunCollection { AlgorithmName = Name };179 Runs = new RunCollection { OptimizerName = Name }; 219 180 Initialize(); 220 181 } … … 222 183 : base(name) { 223 184 description = ItemDescription; 224 maximumExecutionTime = TimeSpan.FromMinutes( 1);185 maximumExecutionTime = TimeSpan.FromMinutes(.5); 225 186 snapshotTimes = new ObservableList<TimeSpan>(new[] { 226 187 TimeSpan.FromSeconds(5), 227 188 TimeSpan.FromSeconds(10), 228 TimeSpan.FromSeconds( 30) });189 TimeSpan.FromSeconds(15) }); 229 190 snapshotTimesIndex = 0; 230 snapTimer = new Timer() { 231 AutoReset = false, 232 Enabled = false, 233 Interval = 100 234 }; 235 snapshots = new RunCollection(); 236 runTimer = new Timer() { 237 AutoReset = false, 238 Enabled = false, 239 Interval = MaximumExecutionTime.TotalMilliseconds 240 }; 241 Runs = new RunCollection { AlgorithmName = Name }; 191 Runs = new RunCollection { OptimizerName = Name }; 242 192 Initialize(); 243 193 } 244 194 public TimeLimitRun(string name, string description) 245 195 : base(name, description) { 246 maximumExecutionTime = TimeSpan.FromMinutes( 1);196 maximumExecutionTime = TimeSpan.FromMinutes(.5); 247 197 snapshotTimes = new ObservableList<TimeSpan>(new[] { 248 198 TimeSpan.FromSeconds(5), 249 199 TimeSpan.FromSeconds(10), 250 TimeSpan.FromSeconds( 30) });200 TimeSpan.FromSeconds(15) }); 251 201 snapshotTimesIndex = 0; 252 snapTimer = new Timer() { 253 AutoReset = false, 254 Enabled = false, 255 Interval = 100 256 }; 257 snapshots = new RunCollection(); 258 runTimer = new Timer() { 259 AutoReset = false, 260 Enabled = false, 261 Interval = MaximumExecutionTime.TotalMilliseconds 262 }; 263 Runs = new RunCollection { AlgorithmName = Name }; 202 Runs = new RunCollection { OptimizerName = Name }; 264 203 Initialize(); 265 204 } … … 272 211 [StorableHook(HookType.AfterDeserialization)] 273 212 private void AfterDeserialization() { 274 // the timers will not be serialized275 snapTimer = new Timer() {276 AutoReset = false,277 Enabled = false,278 Interval = 100279 };280 runTimer = new Timer() {281 AutoReset = false,282 Enabled = false,283 Interval = double.MaxValue284 };285 if (Algorithm != null && Algorithm.ExecutionState == ExecutionState.Started)286 algorithmStarted.Set();287 else algorithmStarted.Reset();288 if (Algorithm != null && Algorithm.ExecutionState == ExecutionState.Paused)289 algorithmPaused.Set();290 else algorithmPaused.Reset();291 if (Algorithm != null && Algorithm.ExecutionState == ExecutionState.Stopped)292 algorithmStopped.Set();293 else algorithmStopped.Reset();294 213 Initialize(); 295 214 } … … 302 221 snapshotTimes.ItemsReplaced += snapshotTimes_Changed; 303 222 snapshotTimes.CollectionReset += snapshotTimes_Changed; 304 snapTimer.Elapsed += snapshotTimer_Elapsed; 305 runTimer.Elapsed += runTimer_Elapsed; 306 } 307 308 private void snapshotTimes_Changed(object sender, EventArgs e) { 309 snapshotTimesDirty = true; 310 } 311 312 private readonly object snapshotLock = new object(); 313 private void snapshotTimer_Elapsed(object sender, ElapsedEventArgs e) { 314 snapTimer.Stop(); 315 lock (snapshotLock) { 316 try { 317 if (Algorithm == null) return; 318 if (ExecutionState != ExecutionState.Started) return; 319 320 var execTime = ExecutionTime; 321 if (snapshotTimesIndex < SnapshotTimes.Count && 322 SnapshotTimes[snapshotTimesIndex] <= execTime) { 323 DoSnapshot(); 324 snapshotTimesIndex++; 325 try { 326 Algorithm.Start(); 327 algorithmStarted.WaitOne(); 328 } catch (InvalidOperationException) { } 329 } 330 } catch { } 331 snapTimer.Start(); 332 } 333 } 334 335 private void runTimer_Elapsed(object sender, ElapsedEventArgs e) { 336 snapTimer.Stop(); 337 lock (snapshotLock) { 338 try { 339 Algorithm.Stop(); 340 algorithmStopped.WaitOne(); 341 } catch (InvalidOperationException) { } 342 } 343 } 223 } 224 225 private void snapshotTimes_Changed(object sender, CollectionItemsChangedEventArgs<IndexedItem<TimeSpan>> e) { 226 if (e.Items.Any()) snapshotTimes.Sort(); 227 FindNextSnapshotTimeIndex(ExecutionTime); 228 } 229 230 public void Snapshot() { 231 if (Algorithm == null || Algorithm.ExecutionState != ExecutionState.Paused) throw new InvalidOperationException("Snapshot not allowed in execution states other than Paused"); 232 Task.Factory.StartNew(MakeSnapshot); 233 } 234 235 public void Prepare() { 236 Prepare(false); 237 } 238 public void Prepare(bool clearRuns) { 239 Algorithm.Prepare(clearRuns); 240 } 241 public void Start() { 242 Algorithm.Start(); 243 } 244 public void Pause() { 245 Algorithm.Pause(); 246 } 247 public void Stop() { 248 Algorithm.Stop(); 249 } 250 251 #region Events 252 protected override void OnNameChanged() { 253 base.OnNameChanged(); 254 runs.OptimizerName = Name; 255 } 256 257 public event PropertyChangedEventHandler PropertyChanged; 258 private void OnPropertyChanged(string property) { 259 var handler = PropertyChanged; 260 if (handler != null) handler(this, new PropertyChangedEventArgs(property)); 261 } 262 263 #region IExecutable Events 264 public event EventHandler ExecutionStateChanged; 265 private void OnExecutionStateChanged() { 266 var handler = ExecutionStateChanged; 267 if (handler != null) handler(this, EventArgs.Empty); 268 } 269 public event EventHandler ExecutionTimeChanged; 270 private void OnExecutionTimeChanged() { 271 var handler = ExecutionTimeChanged; 272 if (handler != null) handler(this, EventArgs.Empty); 273 } 274 public event EventHandler Prepared; 275 private void OnPrepared() { 276 var handler = Prepared; 277 if (handler != null) handler(this, EventArgs.Empty); 278 } 279 public event EventHandler Started; 280 private void OnStarted() { 281 var handler = Started; 282 if (handler != null) handler(this, EventArgs.Empty); 283 } 284 public event EventHandler Paused; 285 private void OnPaused() { 286 var handler = Paused; 287 if (handler != null) handler(this, EventArgs.Empty); 288 } 289 public event EventHandler Stopped; 290 private void OnStopped() { 291 var handler = Stopped; 292 if (handler != null) handler(this, EventArgs.Empty); 293 } 294 public event EventHandler<EventArgs<Exception>> ExceptionOccurred; 295 private void OnExceptionOccurred(Exception exception) { 296 var handler = ExceptionOccurred; 297 if (handler != null) handler(this, new EventArgs<Exception>(exception)); 298 } 299 #endregion 300 301 #region Algorithm Events 302 private void RegisterAlgorithmEvents() { 303 algorithm.ExceptionOccurred += Algorithm_ExceptionOccurred; 304 algorithm.ExecutionTimeChanged += Algorithm_ExecutionTimeChanged; 305 algorithm.ExecutionStateChanged += Algorithm_ExecutionStateChanged; 306 algorithm.Paused += Algorithm_Paused; 307 algorithm.Prepared += Algorithm_Prepared; 308 algorithm.Started += Algorithm_Started; 309 algorithm.Stopped += Algorithm_Stopped; 310 } 311 private void DeregisterAlgorithmEvents() { 312 algorithm.ExceptionOccurred -= Algorithm_ExceptionOccurred; 313 algorithm.ExecutionTimeChanged -= Algorithm_ExecutionTimeChanged; 314 algorithm.ExecutionStateChanged -= Algorithm_ExecutionStateChanged; 315 algorithm.Paused -= Algorithm_Paused; 316 algorithm.Prepared -= Algorithm_Prepared; 317 algorithm.Started -= Algorithm_Started; 318 algorithm.Stopped -= Algorithm_Stopped; 319 } 320 private void Algorithm_ExceptionOccurred(object sender, EventArgs<Exception> e) { 321 OnExceptionOccurred(e.Value); 322 } 323 private void Algorithm_ExecutionTimeChanged(object sender, EventArgs e) { 324 if (snapshotTimesIndex < SnapshotTimes.Count && ExecutionTime >= SnapshotTimes[snapshotTimesIndex] 325 && !pausedForSnapshot) { 326 pausedForSnapshot = true; 327 Algorithm.Pause(); 328 } 329 if (ExecutionTime >= MaximumExecutionTime && !pausedForTermination) { 330 pausedForTermination = true; 331 if (!pausedForSnapshot) Algorithm.Pause(); 332 } 333 OnExecutionTimeChanged(); 334 } 335 private void Algorithm_ExecutionStateChanged(object sender, EventArgs e) { 336 OnExecutionStateChanged(); 337 } 338 private void Algorithm_Paused(object sender, EventArgs e) { 339 var action = pausedForTermination ? ExecutionState.Stopped : (pausedForSnapshot ? ExecutionState.Started : ExecutionState.Paused); 340 if (pausedForSnapshot || pausedForTermination) { 341 pausedForSnapshot = pausedForTermination = false; 342 MakeSnapshot(); 343 snapshotTimesIndex++; 344 } 345 OnPaused(); 346 if (action == ExecutionState.Started) Algorithm.Start(); 347 else if (action == ExecutionState.Stopped) Algorithm.Stop(); 348 } 349 private void Algorithm_Prepared(object sender, EventArgs e) { 350 snapshotTimesIndex = 0; 351 snapshots.Clear(); 352 OnPrepared(); 353 } 354 private void Algorithm_Started(object sender, EventArgs e) { 355 OnStarted(); 356 } 357 private void Algorithm_Stopped(object sender, EventArgs e) { 358 var cloner = new Cloner(); 359 var algRun = cloner.Clone(Algorithm.Runs.Last()); 360 var clonedSnapshots = cloner.Clone(snapshots); 361 try { 362 algRun.Results.Add("Snapshots", clonedSnapshots); 363 } catch (ArgumentException ex) { // Snapshots already exists 364 // TODO strategy? 365 } 366 Runs.Add(algRun); 367 Algorithm.Runs.Clear(); 368 OnStopped(); 369 } 370 #endregion 371 #endregion 344 372 345 373 private void FindNextSnapshotTimeIndex(TimeSpan reference) { … … 349 377 }; 350 378 snapshotTimesIndex = index; 351 }352 353 private void DoSnapshot() {354 lock (snapshotLock) {355 var wasPaused = Algorithm.ExecutionState == ExecutionState.Paused;356 var error = false;357 try {358 Algorithm.Pause();359 algorithmPaused.WaitOne();360 } catch (InvalidOperationException) {361 error = true;362 }363 if (error && ExecutionState != ExecutionState.Paused) return; // Algorithm is either stopped or prepared364 365 MakeSnapshot();366 if (!wasPaused) {367 try {368 Algorithm.Start();369 algorithmStarted.WaitOne();370 } catch (InvalidOperationException) { }371 }372 }373 379 } 374 380 … … 397 403 snapshots.Add(run); 398 404 } 399 400 public void Snapshot() {401 Task.Factory.StartNew(DoSnapshot);402 }403 404 public void Prepare() {405 Prepare(false);406 }407 public void Prepare(bool clearRuns) {408 Algorithm.Prepare(clearRuns);409 }410 public void Start() {411 Algorithm.Start();412 }413 public void Pause() {414 Algorithm.Pause();415 }416 public void Stop() {417 Algorithm.Stop();418 }419 420 #region Events421 protected override void OnNameChanged() {422 base.OnNameChanged();423 runs.AlgorithmName = Name;424 }425 426 public event PropertyChangedEventHandler PropertyChanged;427 private void OnPropertyChanged(string property) {428 var handler = PropertyChanged;429 if (handler != null) handler(this, new PropertyChangedEventArgs(property));430 }431 432 #region IExecutable Events433 public event EventHandler ExecutionStateChanged;434 private void OnExecutionStateChanged() {435 var handler = ExecutionStateChanged;436 if (handler != null) handler(this, EventArgs.Empty);437 }438 public event EventHandler ExecutionTimeChanged;439 private void OnExecutionTimeChanged() {440 var handler = ExecutionTimeChanged;441 if (handler != null) handler(this, EventArgs.Empty);442 }443 public event EventHandler Prepared;444 private void OnPrepared() {445 var handler = Prepared;446 if (handler != null) handler(this, EventArgs.Empty);447 }448 public event EventHandler Started;449 private void OnStarted() {450 var handler = Started;451 if (handler != null) handler(this, EventArgs.Empty);452 }453 public event EventHandler Paused;454 private void OnPaused() {455 var handler = Paused;456 if (handler != null) handler(this, EventArgs.Empty);457 }458 public event EventHandler Stopped;459 private void OnStopped() {460 var handler = Stopped;461 if (handler != null) handler(this, EventArgs.Empty);462 }463 public event EventHandler<EventArgs<Exception>> ExceptionOccurred;464 private void OnExceptionOccurred(Exception exception) {465 var handler = ExceptionOccurred;466 if (handler != null) handler(this, new EventArgs<Exception>(exception));467 }468 #endregion469 470 #region Algorithm Events471 private void RegisterAlgorithmEvents() {472 algorithm.ExceptionOccurred += Algorithm_ExceptionOccurred;473 algorithm.ExecutionTimeChanged += Algorithm_ExecutionTimeChanged;474 algorithm.ExecutionStateChanged += Algorithm_ExecutionStateChanged;475 algorithm.Paused += Algorithm_Paused;476 algorithm.Prepared += Algorithm_Prepared;477 algorithm.Started += Algorithm_Started;478 algorithm.Stopped += Algorithm_Stopped;479 }480 private void DeregisterAlgorithmEvents() {481 algorithm.ExceptionOccurred -= Algorithm_ExceptionOccurred;482 algorithm.ExecutionTimeChanged -= Algorithm_ExecutionTimeChanged;483 algorithm.ExecutionStateChanged -= Algorithm_ExecutionStateChanged;484 algorithm.Paused -= Algorithm_Paused;485 algorithm.Prepared -= Algorithm_Prepared;486 algorithm.Started -= Algorithm_Started;487 algorithm.Stopped -= Algorithm_Stopped;488 }489 private void Algorithm_ExceptionOccurred(object sender, EventArgs<Exception> e) {490 OnExceptionOccurred(e.Value);491 }492 private void Algorithm_ExecutionTimeChanged(object sender, EventArgs e) {493 OnExecutionTimeChanged();494 }495 private void Algorithm_ExecutionStateChanged(object sender, EventArgs e) {496 OnExecutionStateChanged();497 }498 private void Algorithm_Paused(object sender, EventArgs e) {499 algorithmStarted.Reset();500 algorithmPaused.Set();501 algorithmStopped.Reset();502 OnPaused();503 }504 private void Algorithm_Prepared(object sender, EventArgs e) {505 algorithmStarted.Reset();506 algorithmPaused.Reset();507 algorithmStopped.Reset();508 snapTimer.Stop();509 runTimer.Stop();510 snapshotTimesIndex = 0;511 snapshots.Clear();512 OnPrepared();513 }514 private void Algorithm_Started(object sender, EventArgs e) {515 algorithmStarted.Set();516 algorithmPaused.Reset();517 algorithmStopped.Reset();518 var execTime = ExecutionTime;519 if (snapshotTimesDirty) {520 SnapshotTimes.Sort();521 snapshotTimesDirty = false; // sort will mark it dirty again522 FindNextSnapshotTimeIndex(execTime);523 }524 runTimer.Interval = (MaximumExecutionTime - execTime).TotalMilliseconds;525 snapTimer.Start();526 runTimer.Start();527 OnStarted();528 }529 private void Algorithm_Stopped(object sender, EventArgs e) {530 algorithmStarted.Reset();531 algorithmPaused.Reset();532 algorithmStopped.Set();533 lock (snapshotLock) {534 snapTimer.Stop();535 runTimer.Stop();536 MakeSnapshot();537 }538 var cloner = new Cloner();539 var algRun = cloner.Clone(Algorithm.Runs.Last());540 var clonedSnapshots = cloner.Clone(snapshots);541 try {542 algRun.Results.Add("Snapshots", clonedSnapshots);543 } catch (ArgumentException ex) {544 // TODO strategy?545 }546 Runs.Add(algRun);547 Algorithm.Runs.Clear();548 OnStopped();549 }550 #endregion551 #endregion552 405 } 553 406 } -
branches/RuntimeOptimizer/HeuristicLab.Optimizer/3.3/CreateExperimentDialog.cs
r8474 r8975 30 30 using HeuristicLab.Core; 31 31 using HeuristicLab.Data; 32 using HeuristicLab.MainForm.WindowsForms; 32 33 using HeuristicLab.Optimization; 33 34 using HeuristicLab.Parameters; -
branches/RuntimeOptimizer/HeuristicLab.Optimizer/3.3/HeuristicLab.Optimizer-3.3.csproj
r8780 r8975 128 128 <EmbeddedResource Include="Documents\RAPGA_JSSP.hl" /> 129 129 <None Include="Plugin.cs.frame" /> 130 <Compile Include="DefineArithmeticProgressionDialog.cs">131 <SubType>Form</SubType>132 </Compile>133 <Compile Include="DefineArithmeticProgressionDialog.Designer.cs">134 <DependentUpon>DefineArithmeticProgressionDialog.cs</DependentUpon>135 </Compile>136 130 <Compile Include="OptimizerSingleDocumentMainForm.cs"> 137 131 <SubType>Form</SubType>
Note: See TracChangeset
for help on using the changeset viewer.