- Timestamp:
- 06/25/17 16:21:48 (7 years ago)
- Location:
- stable
- Files:
-
- 32 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 14517,14523,14527
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Algorithms.DataAnalysis
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Algorithms.DataAnalysis merged: 14523
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/BaselineClassifiers/OneR.cs
r14186 r15061 22 22 using System.Collections.Generic; 23 23 using System.Linq; 24 using System.Threading; 24 25 using HeuristicLab.Common; 25 26 using HeuristicLab.Core; … … 58 59 } 59 60 60 protected override void Run( ) {61 protected override void Run(CancellationToken cancellationToken) { 61 62 var solution = CreateOneRSolution(Problem.ProblemData, MinBucketSizeParameter.Value.Value); 62 63 Results.Add(new Result("OneR solution", "The 1R classifier.", solution)); -
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/BaselineClassifiers/ZeroR.cs
r14186 r15061 21 21 22 22 using System.Linq; 23 using System.Threading; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; … … 49 50 } 50 51 51 protected override void Run( ) {52 protected override void Run(CancellationToken cancellationToken) { 52 53 var solution = CreateZeroRSolution(Problem.ProblemData); 53 54 Results.Add(new Result("ZeroR solution", "The simplest possible classifier, ZeroR always predicts the majority class.", solution)); -
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/FixedDataAnalysisAlgorithm.cs
r14186 r15061 21 21 22 22 using System; 23 using System.Threading;24 using System.Threading.Tasks;25 23 using HeuristicLab.Common; 26 24 using HeuristicLab.Optimization; … … 30 28 namespace HeuristicLab.Algorithms.DataAnalysis { 31 29 [StorableClass] 32 public abstract class FixedDataAnalysisAlgorithm<T> : Algorithm, 33 IDataAnalysisAlgorithm<T>, 34 IStorableContent 35 where T : class, IDataAnalysisProblem { 36 public string Filename { get; set; } 37 30 public abstract class FixedDataAnalysisAlgorithm<T> : BasicAlgorithm where T : class, IDataAnalysisProblem { 38 31 #region Properties 39 32 public override Type ProblemType { … … 44 37 set { base.Problem = value; } 45 38 } 46 [Storable]47 private ResultCollection results;48 public override ResultCollection Results {49 get { return results; }50 }51 39 #endregion 52 40 53 p rivate DateTime lastUpdateTime;41 public override bool SupportsPause { get { return false; } } 54 42 55 43 [StorableConstructor] 56 44 protected FixedDataAnalysisAlgorithm(bool deserializing) : base(deserializing) { } 57 protected FixedDataAnalysisAlgorithm(FixedDataAnalysisAlgorithm<T> original, Cloner cloner) 58 : base(original, cloner) { 59 results = cloner.Clone(original.Results); 60 } 61 public FixedDataAnalysisAlgorithm() 62 : base() { 63 results = new ResultCollection(); 64 } 65 66 public override void Prepare() { 67 if (Problem != null) base.Prepare(); 68 results.Clear(); 69 OnPrepared(); 70 } 71 72 public override void Start() { 73 base.Start(); 74 var cancellationTokenSource = new CancellationTokenSource(); 75 76 OnStarted(); 77 Task task = Task.Factory.StartNew(Run, cancellationTokenSource.Token, cancellationTokenSource.Token); 78 task.ContinueWith(t => { 79 try { 80 t.Wait(); 81 } 82 catch (AggregateException ex) { 83 try { 84 ex.Flatten().Handle(x => x is OperationCanceledException); 85 } 86 catch (AggregateException remaining) { 87 if (remaining.InnerExceptions.Count == 1) OnExceptionOccurred(remaining.InnerExceptions[0]); 88 else OnExceptionOccurred(remaining); 89 } 90 } 91 cancellationTokenSource.Dispose(); 92 cancellationTokenSource = null; 93 OnStopped(); 94 }); 95 } 96 private void Run(object state) { 97 CancellationToken cancellationToken = (CancellationToken)state; 98 lastUpdateTime = DateTime.UtcNow; 99 System.Timers.Timer timer = new System.Timers.Timer(250); 100 timer.AutoReset = true; 101 timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed); 102 timer.Start(); 103 try { 104 Run(); 105 } 106 finally { 107 timer.Elapsed -= new System.Timers.ElapsedEventHandler(timer_Elapsed); 108 timer.Stop(); 109 ExecutionTime += DateTime.UtcNow - lastUpdateTime; 110 } 111 112 cancellationToken.ThrowIfCancellationRequested(); 113 } 114 protected abstract void Run(); 115 #region Events 116 protected override void OnProblemChanged() { 117 Problem.Reset += new EventHandler(Problem_Reset); 118 base.OnProblemChanged(); 119 } 120 private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { 121 System.Timers.Timer timer = (System.Timers.Timer)sender; 122 timer.Enabled = false; 123 DateTime now = DateTime.UtcNow; 124 ExecutionTime += now - lastUpdateTime; 125 lastUpdateTime = now; 126 timer.Enabled = true; 127 } 128 #endregion 45 protected FixedDataAnalysisAlgorithm(FixedDataAnalysisAlgorithm<T> original, Cloner cloner) : base(original, cloner) { } 46 public FixedDataAnalysisAlgorithm() : base() { } 129 47 130 48 } -
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/GBM/GradientBoostingRegressionAlgorithm.cs
r14186 r15061 44 44 [StorableClass] 45 45 [Creatable(CreatableAttribute.Categories.DataAnalysisRegression, Priority = 350)] 46 public class GradientBoostingRegressionAlgorithm : BasicAlgorithm { 47 public override Type ProblemType { 48 get { return typeof(IRegressionProblem); } 49 } 50 51 public new IRegressionProblem Problem { 52 get { return (IRegressionProblem)base.Problem; } 53 set { base.Problem = value; } 54 } 46 public class GradientBoostingRegressionAlgorithm : FixedDataAnalysisAlgorithm<IRegressionProblem> { 55 47 56 48 #region ParameterNames -
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesAlgorithm.cs
r14961 r15061 38 38 [StorableClass] 39 39 [Creatable(CreatableAttribute.Categories.DataAnalysisRegression, Priority = 125)] 40 public class GradientBoostedTreesAlgorithm : BasicAlgorithm { 41 public override Type ProblemType { 42 get { return typeof(IRegressionProblem); } 43 } 44 public new IRegressionProblem Problem { 45 get { return (IRegressionProblem)base.Problem; } 46 set { base.Problem = value; } 47 } 48 40 public class GradientBoostedTreesAlgorithm : FixedDataAnalysisAlgorithm<IRegressionProblem> { 49 41 #region ParameterNames 50 42 private const string IterationsParameterName = "Iterations"; -
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/LinearDiscriminantAnalysis.cs
r14795 r15061 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using System.Threading; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; … … 59 60 60 61 #region Fisher LDA 61 protected override void Run( ) {62 protected override void Run(CancellationToken cancellationToken) { 62 63 var solution = CreateLinearDiscriminantAnalysisSolution(Problem.ProblemData); 63 64 Results.Add(new Result(LinearDiscriminantAnalysisSolutionResultName, "The linear discriminant analysis.", solution)); -
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/LinearRegression.cs
r14795 r15061 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using System.Threading; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; … … 60 61 61 62 #region linear regression 62 protected override void Run( ) {63 protected override void Run(CancellationToken cancellationToken) { 63 64 double rmsError, cvRmsError; 64 65 var solution = CreateLinearRegressionSolution(Problem.ProblemData, out rmsError, out cvRmsError); -
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/MultinomialLogitClassification.cs
r14186 r15061 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using System.Threading; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; … … 57 58 58 59 #region logit classification 59 protected override void Run( ) {60 protected override void Run(CancellationToken cancellationToken) { 60 61 double rmsError, relClassError; 61 62 var solution = CreateLogitClassificationSolution(Problem.ProblemData, out rmsError, out relClassError); -
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/MctsSymbolicRegression/MctsSymbolicRegressionAlgorithm.cs
r15060 r15061 38 38 [StorableClass] 39 39 [Creatable(CreatableAttribute.Categories.DataAnalysisRegression, Priority = 250)] 40 public class MctsSymbolicRegressionAlgorithm : BasicAlgorithm { 41 public override Type ProblemType { 42 get { return typeof(IRegressionProblem); } 43 } 44 public new IRegressionProblem Problem { 45 get { return (IRegressionProblem)base.Problem; } 46 set { base.Problem = value; } 47 } 40 public class MctsSymbolicRegressionAlgorithm : FixedDataAnalysisAlgorithm<IRegressionProblem> { 48 41 49 42 #region ParameterNames -
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourClassification.cs
r14308 r15061 22 22 using System; 23 23 using System.Linq; 24 using System.Threading; 24 25 using HeuristicLab.Common; 25 26 using HeuristicLab.Core; … … 91 92 92 93 #region nearest neighbour 93 protected override void Run( ) {94 protected override void Run(CancellationToken cancellationToken) { 94 95 double[] weights = null; 95 96 if (Weights != null) weights = Weights.CloneAsArray(); -
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourRegression.cs
r14308 r15061 21 21 22 22 using System; 23 using System.Threading; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; … … 92 93 93 94 #region nearest neighbour 94 protected override void Run( ) {95 protected override void Run(CancellationToken cancellationToken) { 95 96 double[] weights = null; 96 97 if (Weights != null) weights = Weights.CloneAsArray(); -
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkClassification.cs
r14186 r15061 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using System.Threading; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; … … 168 169 169 170 #region neural network 170 protected override void Run( ) {171 protected override void Run(CancellationToken cancellationToken) { 171 172 double rmsError, avgRelError, relClassError; 172 173 var solution = CreateNeuralNetworkClassificationSolution(Problem.ProblemData, HiddenLayers, NodesInFirstHiddenLayer, NodesInSecondHiddenLayer, Decay, Restarts, out rmsError, out avgRelError, out relClassError); -
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkEnsembleClassification.cs
r14186 r15061 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using System.Threading; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; … … 154 155 155 156 #region neural network ensemble 156 protected override void Run( ) {157 protected override void Run(CancellationToken cancellationToken) { 157 158 double rmsError, avgRelError, relClassError; 158 159 var solution = CreateNeuralNetworkEnsembleClassificationSolution(Problem.ProblemData, EnsembleSize, HiddenLayers, NodesInFirstHiddenLayer, NodesInSecondHiddenLayer, Decay, Restarts, out rmsError, out avgRelError, out relClassError); -
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkEnsembleRegression.cs
r14186 r15061 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using System.Threading; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; … … 154 155 155 156 #region neural network ensemble 156 protected override void Run( ) {157 protected override void Run(CancellationToken cancellationToken) { 157 158 double rmsError, avgRelError; 158 159 var solution = CreateNeuralNetworkEnsembleRegressionSolution(Problem.ProblemData, EnsembleSize, HiddenLayers, NodesInFirstHiddenLayer, NodesInSecondHiddenLayer, Decay, Restarts, out rmsError, out avgRelError); -
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkRegression.cs
r14186 r15061 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using System.Threading; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; … … 170 171 171 172 #region neural network 172 protected override void Run( ) {173 protected override void Run(CancellationToken cancellationToken) { 173 174 double rmsError, avgRelError; 174 175 var solution = CreateNeuralNetworkRegressionSolution(Problem.ProblemData, HiddenLayers, NodesInFirstHiddenLayer, NodesInSecondHiddenLayer, Decay, Restarts, out rmsError, out avgRelError); -
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/NonlinearRegression/NonlinearRegression.cs
r14564 r15061 22 22 using System; 23 23 using System.Linq; 24 using System.Threading; 24 25 using HeuristicLab.Analysis; 25 26 using HeuristicLab.Common; … … 157 158 158 159 #region nonlinear regression 159 protected override void Run( ) {160 protected override void Run(CancellationToken cancellationToken) { 160 161 IRegressionSolution bestSolution = null; 161 162 if (InitializeParametersRandomly) { -
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestClassification.cs
r14186 r15061 20 20 #endregion 21 21 22 using System.Threading; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; … … 132 133 133 134 #region random forest 134 protected override void Run( ) {135 protected override void Run(CancellationToken cancellationToken) { 135 136 double rmsError, relClassificationError, outOfBagRmsError, outOfBagRelClassificationError; 136 137 if (SetSeedRandomly) Seed = new System.Random().Next(); -
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestRegression.cs
r14186 r15061 20 20 #endregion 21 21 22 using System.Threading; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; … … 131 132 132 133 #region random forest 133 protected override void Run( ) {134 protected override void Run(CancellationToken cancellationToken) { 134 135 double rmsError, avgRelError, outOfBagRmsError, outOfBagAvgRelError; 135 136 if (SetSeedRandomly) Seed = new System.Random().Next(); -
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/SupportVectorMachine/SupportVectorClassification.cs
r14186 r15061 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using System.Threading; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; … … 143 144 144 145 #region support vector classification 145 protected override void Run( ) {146 protected override void Run(CancellationToken cancellationToken) { 146 147 IClassificationProblemData problemData = Problem.ProblemData; 147 148 IEnumerable<string> selectedInputVariables = problemData.AllowedInputVariables; -
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/SupportVectorMachine/SupportVectorRegression.cs
r14186 r15061 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using System.Threading; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; … … 151 152 152 153 #region support vector regression 153 protected override void Run( ) {154 protected override void Run(CancellationToken cancellationToken) { 154 155 IRegressionProblemData problemData = Problem.ProblemData; 155 156 IEnumerable<string> selectedInputVariables = problemData.AllowedInputVariables; -
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/TimeSeries/AutoregressiveModeling.cs
r14186 r15061 22 22 using System; 23 23 using System.Linq; 24 using System.Threading; 24 25 using HeuristicLab.Common; 25 26 using HeuristicLab.Core; … … 63 64 } 64 65 65 protected override void Run( ) {66 protected override void Run(CancellationToken cancellationToken) { 66 67 double rmsError, cvRmsError; 67 68 var solution = CreateAutoRegressiveSolution(Problem.ProblemData, TimeOffset, out rmsError, out cvRmsError); -
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/kMeans/KMeansClustering.cs
r14186 r15061 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using System.Threading; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; … … 77 78 78 79 #region k-Means clustering 79 protected override void Run( ) {80 protected override void Run(CancellationToken cancellationToken) { 80 81 var solution = CreateKMeansSolution(Problem.ProblemData, K.Value, Restarts.Value); 81 82 Results.Add(new Result(KMeansSolutionResultName, "The k-Means clustering solution.", solution)); -
stable/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/HillClimber.cs
r14186 r15061 48 48 49 49 private const string IterationsParameterName = "Iterations"; 50 private const string BestQualityResultName = "Best quality"; 51 private const string IterationsResultName = "Iterations"; 50 52 51 53 public override Type ProblemType { 52 54 get { return typeof(BinaryProblem); } 53 55 } 56 57 public override bool SupportsPause { get { return false; } } 58 54 59 public new BinaryProblem Problem { 55 60 get { return (BinaryProblem)base.Problem; } … … 65 70 set { IterationsParameter.Value.Value = value; } 66 71 } 72 73 #region ResultsProperties 74 private double ResultsBestQuality { 75 get { return ((DoubleValue)Results[BestQualityResultName].Value).Value; } 76 set { ((DoubleValue)Results[BestQualityResultName].Value).Value = value; } 77 } 78 private int ResultsIterations { 79 get { return ((IntValue)Results[IterationsResultName].Value).Value; } 80 set { ((IntValue)Results[IterationsResultName].Value).Value = value; } 81 } 82 #endregion 67 83 68 84 [StorableConstructor] … … 80 96 Parameters.Add(new FixedValueParameter<IntValue>(IterationsParameterName, "", new IntValue(100))); 81 97 } 98 99 100 protected override void Initialize(CancellationToken cancellationToken) { 101 Results.Add(new Result(BestQualityResultName, new DoubleValue(double.NaN))); 102 Results.Add(new Result(IterationsResultName, new IntValue(0))); 103 base.Initialize(cancellationToken); 104 } 82 105 protected override void Run(CancellationToken cancellationToken) { 83 var BestQuality = new DoubleValue(double.NaN);84 Results.Add(new Result("Best quality", BestQuality));85 for (int iteration = 0; iteration < Iterations; iteration++) { 106 while (ResultsIterations < Iterations) { 107 cancellationToken.ThrowIfCancellationRequested(); 108 86 109 var solution = new BinaryVector(Problem.Length); 87 110 for (int i = 0; i < solution.Length; i++) { … … 92 115 93 116 fitness = ImproveToLocalOptimum(Problem, solution, fitness, random); 94 if (double.IsNaN( BestQuality.Value) || Problem.IsBetter(fitness, BestQuality.Value)) {95 BestQuality.Value= fitness;117 if (double.IsNaN(ResultsBestQuality) || Problem.IsBetter(fitness, ResultsBestQuality)) { 118 ResultsBestQuality = fitness; 96 119 } 120 121 ResultsIterations++; 97 122 } 98 123 } -
stable/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/ParameterlessPopulationPyramid.cs
r14186 r15061 56 56 57 57 // Tracks all solutions in Pyramid for quick membership checks 58 private HashSet<BinaryVector> seen = new HashSet<BinaryVector>(new EnumerableBoolEqualityComparer());58 private readonly HashSet<BinaryVector> seen = new HashSet<BinaryVector>(new EnumerableBoolEqualityComparer()); 59 59 60 60 #region ParameterNames … … 152 152 } 153 153 #endregion 154 155 public override bool SupportsPause { get { return true; } } 154 156 155 157 [StorableConstructor] … … 213 215 } 214 216 215 protected override void Run(CancellationToken cancellationToken) {217 protected override void Initialize(CancellationToken cancellationToken) { 216 218 // Set up the algorithm 217 219 if (SetSeedRandomly) Seed = new System.Random().Next(); … … 242 244 Results.Add(new Result("Stored Solutions", table)); 243 245 246 base.Initialize(cancellationToken); 247 } 248 249 protected override void Run(CancellationToken cancellationToken) { 244 250 // Loop until iteration limit reached or canceled. 245 for (ResultsIterations = 0; ResultsIterations < MaximumIterations; ResultsIterations++) {251 while (ResultsIterations < MaximumIterations) { 246 252 double fitness = double.NaN; 247 253 248 254 try { 249 255 fitness = iterate(); 256 ResultsIterations++; 250 257 cancellationToken.ThrowIfCancellationRequested(); 251 258 } finally { -
stable/HeuristicLab.Optimization
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Optimization merged: 14517,14523
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Optimization.Views
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Optimization.Views merged: 14517,14523
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Optimization.Views/3.3/BasicAlgorithmView.cs
r14186 r15061 36 36 protected override void SetEnabledStateOfControls() { 37 37 base.SetEnabledStateOfControls(); 38 pauseButton.Enabled = false;38 pauseButton.Enabled &= Content != null && Content.SupportsPause; 39 39 } 40 40 41 41 protected override void SetEnabledStateOfExecutableButtons() { 42 42 base.SetEnabledStateOfExecutableButtons(); 43 pauseButton.Enabled = false;43 pauseButton.Enabled &= Content != null && Content.SupportsPause; 44 44 } 45 45 } -
stable/HeuristicLab.Optimization/3.3/Algorithms/BasicAlgorithm.cs
r14186 r15061 24 24 using System.Threading.Tasks; 25 25 using HeuristicLab.Common; 26 using HeuristicLab.Core; 26 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 28 … … 29 30 [StorableClass] 30 31 public abstract class BasicAlgorithm : Algorithm, IStorableContent { 32 33 private bool pausePending; 34 private DateTime lastUpdateTime; 35 31 36 public string Filename { get; set; } 32 37 38 public abstract bool SupportsPause { get; } 39 33 40 [Storable] 34 private ResultCollection results; 41 private bool initialized; 42 [Storable] 43 private readonly ResultCollection results; 35 44 public override ResultCollection Results { 36 45 get { return results; } … … 58 67 base.Prepare(); 59 68 results.Clear(); 69 initialized = false; 60 70 OnPrepared(); 61 71 } … … 64 74 base.Start(); 65 75 CancellationTokenSource = new CancellationTokenSource(); 76 pausePending = false; 77 OnStarted(); 66 78 67 OnStarted(); 68 Task task = Task.Factory.StartNew(Run, cancellationTokenSource.Token, cancellationTokenSource.Token); 79 Task task = Task.Factory.StartNew(Run, CancellationTokenSource.Token, CancellationTokenSource.Token); 69 80 task.ContinueWith(t => { 70 81 try { 71 82 t.Wait(); 72 } catch (AggregateException ex) { 83 } 84 catch (AggregateException ex) { 73 85 try { 74 86 ex.Flatten().Handle(x => x is OperationCanceledException); 75 } catch (AggregateException remaining) { 87 } 88 catch (AggregateException remaining) { 76 89 if (remaining.InnerExceptions.Count == 1) OnExceptionOccurred(remaining.InnerExceptions[0]); 77 90 else OnExceptionOccurred(remaining); … … 80 93 CancellationTokenSource.Dispose(); 81 94 CancellationTokenSource = null; 82 OnStopped(); 95 if (pausePending) OnPaused(); 96 else OnStopped(); 83 97 }); 84 98 } 85 99 86 100 public override void Pause() { 87 throw new NotSupportedException("Pause is not supported in basic algorithms."); 101 // CancellationToken.ThrowIfCancellationRequested() must be called from within the Run method, otherwise pause does nothing 102 // alternatively check the IsCancellationRequested property of the cancellation token 103 if (!SupportsPause) 104 throw new NotSupportedException("Pause is not supported by this algorithm."); 105 106 base.Pause(); 107 pausePending = true; 108 CancellationTokenSource.Cancel(); 88 109 } 89 110 … … 92 113 // alternatively check the IsCancellationRequested property of the cancellation token 93 114 base.Stop(); 94 CancellationTokenSource.Cancel(); 115 if (ExecutionState == ExecutionState.Paused) OnStopped(); 116 else CancellationTokenSource.Cancel(); 95 117 } 96 118 97 98 private DateTime lastUpdateTime;99 119 private void Run(object state) { 100 120 CancellationToken cancellationToken = (CancellationToken)state; … … 105 125 timer.Start(); 106 126 try { 127 if (!initialized) 128 Initialize(cancellationToken); 129 initialized = true; 107 130 Run(cancellationToken); 108 } finally { 131 } 132 finally { 109 133 timer.Elapsed -= new System.Timers.ElapsedEventHandler(timer_Elapsed); 110 134 timer.Stop(); … … 113 137 } 114 138 139 protected virtual void Initialize(CancellationToken cancellationToken) { } 115 140 protected abstract void Run(CancellationToken cancellationToken); 116 141 -
stable/HeuristicLab.Tests
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Tests merged: 14527
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Tests/HeuristicLab.Algorithms.ParameterlessPopulationPyramid-3.3/ParameterlessPopulationPyramidTest.cs
r14186 r15061 39 39 PrivateObject hidden = new PrivateObject(solver); 40 40 try { 41 hidden.Invoke("Run", new CancellationToken()); 41 var ct = new CancellationToken(); 42 hidden.Invoke("Initialize", ct); 43 hidden.Invoke("Run", ct); 42 44 } catch (OperationCanceledException) { 43 45 // Ignore
Note: See TracChangeset
for help on using the changeset viewer.