Free cookie consent management tool by TermsFeed Policy Generator

Changeset 15216 for branches


Ignore:
Timestamp:
07/12/17 19:49:03 (7 years ago)
Author:
jkarder
Message:

#2258: reset startPending if an exception is thrown before OnStarted is called

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/CrossValidation.cs

    r15212 r15216  
    281281      }
    282282
    283       if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused))
    284         throw new InvalidOperationException(string.Format("Start not allowed in execution state \"{0}\".", ExecutionState));
    285 
    286       if (Algorithm == null) return;
    287       //create cloned algorithms
    288       if (clonedAlgorithms.Count == 0) {
    289         int testSamplesCount = (SamplesEnd.Value - SamplesStart.Value) / Folds.Value;
    290 
    291         for (int i = 0; i < Folds.Value; i++) {
    292           IAlgorithm clonedAlgorithm = (IAlgorithm)algorithm.Clone();
    293           clonedAlgorithm.Name = algorithm.Name + " Fold " + i;
    294           IDataAnalysisProblem problem = clonedAlgorithm.Problem as IDataAnalysisProblem;
    295           ISymbolicDataAnalysisProblem symbolicProblem = problem as ISymbolicDataAnalysisProblem;
    296 
    297           int testStart = (i * testSamplesCount) + SamplesStart.Value;
    298           int testEnd = (i + 1) == Folds.Value ? SamplesEnd.Value : (i + 1) * testSamplesCount + SamplesStart.Value;
    299 
    300           problem.ProblemData.TrainingPartition.Start = SamplesStart.Value;
    301           problem.ProblemData.TrainingPartition.End = SamplesEnd.Value;
    302           problem.ProblemData.TestPartition.Start = testStart;
    303           problem.ProblemData.TestPartition.End = testEnd;
    304           DataAnalysisProblemData problemData = problem.ProblemData as DataAnalysisProblemData;
    305           if (problemData != null) {
    306             problemData.TrainingPartitionParameter.Hidden = false;
    307             problemData.TestPartitionParameter.Hidden = false;
     283      try {
     284        if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused))
     285          throw new InvalidOperationException(string.Format("Start not allowed in execution state \"{0}\".", ExecutionState));
     286
     287        if (Algorithm == null) return;
     288        //create cloned algorithms
     289        if (clonedAlgorithms.Count == 0) {
     290          int testSamplesCount = (SamplesEnd.Value - SamplesStart.Value) / Folds.Value;
     291
     292          for (int i = 0; i < Folds.Value; i++) {
     293            IAlgorithm clonedAlgorithm = (IAlgorithm)algorithm.Clone();
     294            clonedAlgorithm.Name = algorithm.Name + " Fold " + i;
     295            IDataAnalysisProblem problem = clonedAlgorithm.Problem as IDataAnalysisProblem;
     296            ISymbolicDataAnalysisProblem symbolicProblem = problem as ISymbolicDataAnalysisProblem;
     297
     298            int testStart = (i * testSamplesCount) + SamplesStart.Value;
     299            int testEnd = (i + 1) == Folds.Value ? SamplesEnd.Value : (i + 1) * testSamplesCount + SamplesStart.Value;
     300
     301            problem.ProblemData.TrainingPartition.Start = SamplesStart.Value;
     302            problem.ProblemData.TrainingPartition.End = SamplesEnd.Value;
     303            problem.ProblemData.TestPartition.Start = testStart;
     304            problem.ProblemData.TestPartition.End = testEnd;
     305            DataAnalysisProblemData problemData = problem.ProblemData as DataAnalysisProblemData;
     306            if (problemData != null) {
     307              problemData.TrainingPartitionParameter.Hidden = false;
     308              problemData.TestPartitionParameter.Hidden = false;
     309            }
     310
     311            if (symbolicProblem != null) {
     312              symbolicProblem.FitnessCalculationPartition.Start = SamplesStart.Value;
     313              symbolicProblem.FitnessCalculationPartition.End = SamplesEnd.Value;
     314            }
     315            clonedAlgorithm.Prepare();
     316            clonedAlgorithms.Add(clonedAlgorithm);
    308317          }
    309 
    310           if (symbolicProblem != null) {
    311             symbolicProblem.FitnessCalculationPartition.Start = SamplesStart.Value;
    312             symbolicProblem.FitnessCalculationPartition.End = SamplesEnd.Value;
    313           }
    314           clonedAlgorithm.Prepare();
    315           clonedAlgorithms.Add(clonedAlgorithm);
    316         }
    317       }
    318 
    319       OnStarted();
     318        }
     319
     320        OnStarted();
     321      } finally {
     322        if (startPending) startPending = false;
     323      }
     324
    320325      availableWorkers = new SemaphoreSlim(NumberOfWorkers.Value, NumberOfWorkers.Value);
    321326      allAlgorithmsFinished = new ManualResetEventSlim(false);
Note: See TracChangeset for help on using the changeset viewer.