Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/26/17 09:45:36 (7 years ago)
Author:
jkarder
Message:

#2258: refactored async methods

  • synchronously called IExecutables are now executed in the caller's thread
  • removed old synchronization code from unit tests
Location:
branches/Async/HeuristicLab.Tests
Files:
1 deleted
7 edited

Legend:

Unmodified
Added
Removed
  • branches/Async/HeuristicLab.Tests/HeuristicLab-3.3/CollectObjectGraphTest.cs

    r12012 r15065  
    2424using System.Diagnostics;
    2525using System.Linq;
    26 using System.Threading;
    2726using System.Threading.Tasks;
    2827using HeuristicLab.Algorithms.GeneticAlgorithm;
     
    112111        algs.Add(ga);
    113112
    114         var cancellationTokenSource = new CancellationTokenSource();
    115         ga.StartSync(cancellationTokenSource.Token);
     113        ga.Start();
    116114        sw.Stop();
    117115        TestContext.WriteLine("{0}: {1} ", i, sw.Elapsed);
     
    144142          var sw = new Stopwatch();
    145143          sw.Start();
    146           ga.StartSync(new CancellationToken());
     144          ga.Start();
    147145          sw.Stop();
    148146          Console.WriteLine("{0}; Objects after execution: {1}", ga.Name, ga.GetObjectGraphObjects().Count());
  • branches/Async/HeuristicLab.Tests/HeuristicLab-3.3/GeneticAlgorithmTest.cs

    r12012 r15065  
    2121
    2222using System;
    23 using System.Threading;
    2423using HeuristicLab.Algorithms.GeneticAlgorithm;
    2524using HeuristicLab.Common;
     
    3938    }
    4039
    41     private EventWaitHandle trigger = new AutoResetEvent(false);
    4240    private Exception ex;
    4341
     
    4947      GeneticAlgorithm ga = (GeneticAlgorithm)XmlParser.Deserialize(@"Test Resources\GA_TSP.hl");
    5048      ga.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(ga_ExceptionOccurred);
    51       ga.Stopped += new EventHandler(ga_Stopped);
    5249      ga.SetSeedRandomly.Value = false;
    5350      ga.Seed.Value = 0;
     
    5552      ga.Prepare();
    5653      ga.Start();
    57       trigger.WaitOne();
    5854      if (ex != null) throw ex;
    5955
     
    8076      ex = e.Value;
    8177    }
    82 
    83     private void ga_Stopped(object sender, EventArgs e) {
    84       trigger.Set();
    85     }
    8678  }
    8779}
  • branches/Async/HeuristicLab.Tests/HeuristicLab.Algorithms.DataAnalysis-3.4/GaussianProcessRegressionTest.cs

    r12012 r15065  
    2222using System;
    2323using System.Linq;
    24 using System.Threading;
    2524using HeuristicLab.Common;
    2625using HeuristicLab.Problems.DataAnalysis;
     
    3938    }
    4039
    41     private EventWaitHandle trigger = new AutoResetEvent(false);
    4240    private Exception ex;
    4341
     
    6563
    6664      alg.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(cv_ExceptionOccurred);
    67       alg.Stopped += new EventHandler(cv_Stopped);
    6865
    6966      alg.Prepare();
    7067      alg.Start();
    71       trigger.WaitOne();
    7268      if (ex != null) throw ex;
    7369
     
    7874      ex = e.Value;
    7975    }
    80 
    81     private void cv_Stopped(object sender, EventArgs e) {
    82       trigger.Set();
    83     }
    8476  }
    8577}
  • branches/Async/HeuristicLab.Tests/HeuristicLab.Algorithms.DataAnalysis-3.4/GradientBoostingTest.cs

    r13157 r15065  
    11using System;
    22using System.Linq;
    3 using System.Threading;
    43using HeuristicLab.Data;
    5 using HeuristicLab.Optimization;
    64using HeuristicLab.Problems.DataAnalysis;
    75using Microsoft.VisualStudio.TestTools.UnitTesting;
     
    182180      #endregion
    183181
    184       RunAlgorithm(gbt);
     182      gbt.Start();
    185183
    186184      Console.WriteLine(gbt.ExecutionTime);
     
    210208      #endregion
    211209
    212       RunAlgorithm(gbt);
     210      gbt.Start();
    213211
    214212      Console.WriteLine(gbt.ExecutionTime);
     
    238236      #endregion
    239237
    240       RunAlgorithm(gbt);
     238      gbt.Start();
    241239
    242240      Console.WriteLine(gbt.ExecutionTime);
    243241      Assert.AreEqual(0.061954221604374943, ((DoubleValue)gbt.Results["Loss (train)"].Value).Value, 1E-6);
    244242      Assert.AreEqual(0.06316303473499961, ((DoubleValue)gbt.Results["Loss (test)"].Value).Value, 1E-6);
    245     }
    246 
    247     // same as in SamplesUtil
    248     private void RunAlgorithm(IAlgorithm a) {
    249       var trigger = new EventWaitHandle(false, EventResetMode.ManualReset);
    250       Exception ex = null;
    251       a.Stopped += (src, e) => { trigger.Set(); };
    252       a.ExceptionOccurred += (src, e) => { ex = e.Value; trigger.Set(); };
    253       a.Prepare();
    254       a.Start();
    255       trigger.WaitOne();
    256 
    257       Assert.AreEqual(ex, null);
    258243    }
    259244
  • branches/Async/HeuristicLab.Tests/HeuristicLab.Algorithms.DataAnalysis-3.4/SupportVectorMachineTest.cs

    r12012 r15065  
    2323using System.Collections.Generic;
    2424using System.Linq;
    25 using System.Threading;
    2625using HeuristicLab.Algorithms.DataAnalysis;
    2726using HeuristicLab.Common;
     
    5049    }
    5150
    52     private EventWaitHandle trigger = new AutoResetEvent(false);
    5351    private Exception ex;
    5452
     
    7169
    7270      cv.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(cv_ExceptionOccurred);
    73       cv.Stopped += new EventHandler(cv_Stopped);
    7471
    7572      cv.Prepare();
    7673      cv.Start();
    77       trigger.WaitOne();
    7874      if (ex != null) throw ex;
    7975
     
    10298      ex = e.Value;
    10399    }
    104 
    105     private void cv_Stopped(object sender, EventArgs e) {
    106       trigger.Set();
    107     }
    108100  }
    109101}
  • branches/Async/HeuristicLab.Tests/HeuristicLab.Scripting-3.3/Script Sources/GUIAutomationScriptSource.cs

    r11789 r15065  
    1 using System;
    2 using System.Linq;
    3 using System.Threading;
     1using System.Linq;
    42using System.Windows.Forms;
    53
    64using HeuristicLab.Algorithms.GeneticAlgorithm;
    7 using HeuristicLab.Core;
    85using HeuristicLab.MainForm;
    96using HeuristicLab.MainForm.WindowsForms;
     
    1310
    1411public class GUIAutomationScript : HeuristicLab.Scripting.CSharpScriptBase {
    15   readonly ManualResetEvent mutex = new ManualResetEvent(false);
    16 
    1712  public override void Main() {
    1813    var ga = new GeneticAlgorithm {
     
    2722      ga.PopulationSize.Value *= 2;
    2823    }
    29 
    30     experiment.ExecutionStateChanged += OnExecutionStateChanged;
    3124    experiment.Start();
    32     mutex.WaitOne();
    3325
    3426    vars.experiment = experiment;
     
    3931    bubbleChart.Controls.OfType<ComboBox>().Single(x => x.Name == "xAxisComboBox").SelectedItem = "PopulationSize";
    4032  }
    41 
    42   private void OnExecutionStateChanged(object sender, EventArgs e) {
    43     if (((IExecutable)sender).ExecutionState == ExecutionState.Stopped)
    44       mutex.Set();
    45   }
    4633}
  • branches/Async/HeuristicLab.Tests/HeuristicLab.Tests.csproj

    r13266 r15065  
    428428  <ItemGroup>
    429429    <Compile Include="AssemblyInitializer.cs" />
    430     <Compile Include="HeuristicLab-3.3\AlgorithmExtensions.cs" />
    431430    <Compile Include="HeuristicLab-3.3\CloningConstructorTest.cs" />
    432431    <Compile Include="HeuristicLab-3.3\CollectObjectGraphTest.cs" />
Note: See TracChangeset for help on using the changeset viewer.