private void generationWorker_DoWork(object sender, DoWorkEventArgs e) { try { this.Exception = null; isRunning = false; fm = e.Argument as StepFaultModel; ExecutionInstance currentTestProject = fm.ExecutionInstance; string message = null; fm.ExecutionEngine.AcquireProcess(); // Sets up the environment of the execution engine fm.ExecutionInstance = currentTestProject; fm.SetUpEnvironment(); passedDuration = 0.0; estimatedDuration = fm.GetEstimatedDuration("RandomExploration").TotalMilliseconds; aTimer = new System.Timers.Timer(100); aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent); aTimer.Enabled = true; aTimer.AutoReset = true; isRunning = true; message = (string)fm.Run("RandomExploration"); // Tears down the environment fm.TearDownEnvironment(false); // Relinquishes control of the execution engine fm.ExecutionEngine.RelinquishProcess(); aTimer.Enabled = false; if (message.ToLower().Contains("success")) { e.Result = true; } else { e.Result = false; this.Exception = new FM4CCException(message); } } catch(TargetInvocationException) { e.Result = false; } }
private void singleStateWorker_DoWork(object sender, DoWorkEventArgs e) { try { this.Exception = null; isRunning = false; if (SelectedRegions == null) throw new FM4CCException("Search regions not set"); aTimer = new System.Timers.Timer(100); aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent); aTimer.Enabled = true; aTimer.AutoReset = true; fm = e.Argument as StepFaultModel; ExecutionInstance currentTestProject = fm.ExecutionInstance; string message = null; fm.ExecutionEngine.AcquireProcess(); // Sets up the environment of the execution engine fm.ExecutionInstance = currentTestProject; fm.SetUpEnvironment(); e.Result = true; int i = 0; foreach (DataGridHeatPoint region in SelectedRegions) { int requirementIndex = 1; switch (region.Requirement) { case "Stability": requirementIndex = 1; break; case "Precision": requirementIndex = 2; break; case "Smoothness": requirementIndex = 3; break; case "Responsiveness": requirementIndex = 4; break; case "Steadiness": requirementIndex = 5; break; case "NormalizedSmoothness": // the normalization is performed in the parser requirementIndex = 3; break; } fm.SetSearchParameters(requirementIndex, region.InitialDesiredRegion, region.FinalDesiredRegion, region.ContainedHeatPoint, (string)fm.FaultModelConfiguration.GetValue("OptimizationAlgorithm")); isRunning = true; message = (string)fm.Run("WorstCaseSearch"); if (!message.ToLower().Contains("success")) { if (!message.ToLower().Contains("fitting error")) { e.Result = false; this.Exception = new FM4CCException(message); break; } else { string chosenRegressionFunction = fm.ExecutionEngine.GetVariable("ChosenRegressionFunction"); double rmse = fm.ExecutionEngine.GetVariable("BestRMSE"); double qualityThreshold = fm.ExecutionEngine.GetVariable("RegressionQualityThreshold"); string bestRegressionFunction = fm.ExecutionEngine.GetVariable("BestRegressionFunction"); // use the worst point found while computing the training set fm.ExecutionEngine.ExecuteCommand("tmpVar = TrainingSet.Input(worstObjectiveFunctions(1,1),:)"); double[,] bestPoint = fm.ExecutionEngine.GetVariable("tmpVar"); Logger("Step Fault Model - Accelerated worst case computation for " + region.Requirement + " failed. Unable to fit data to regressed model, falling back to doing simple Simulated Annealing. Best regression function was " + bestRegressionFunction + " (RMSE: " + rmse.ToString() + ", Threshold: " + qualityThreshold.ToString() + ")."); fm.SetSearchParameters(requirementIndex, region.InitialDesiredRegion, region.FinalDesiredRegion, new StepHeatPoint(bestPoint[0,0], bestPoint[0,1], 0.0, 0.0, false), "SimulatedAnnealing"); message = (string)fm.Run("WorstCaseSearch"); } } else { string chosenRegressionFunction = fm.ExecutionEngine.GetVariable("ChosenRegressionFunction"); double rmse = fm.ExecutionEngine.GetVariable("BestRMSE"); double qualityThreshold = fm.ExecutionEngine.GetVariable("RegressionQualityThreshold"); Logger("Step Fault Model - Accelerated worst case computation successful for " + region.Requirement + ". Regression function " + chosenRegressionFunction + " selected (RMSE: " + rmse.ToString() + ", Threshold: " + qualityThreshold.ToString() + ")."); } i++; this.ReportProgress((int)((double)i / SelectedRegions.Count * 100.0)); string worstPointFile = Path.GetDirectoryName(fm.ExecutionInstance.GetValue("SUTPath")) + "\\ControllerTesterResults\\SingleStateSearch\\SingleStateSearch_WorstCase.csv"; if (region.Requirement != "NormalizedSmoothness") { ProcessWorstCaseResults(region, worstPointFile, fm.ToString(), requirementIndex); } else { ProcessWorstCaseResults(region, worstPointFile, fm.ToString(), 6); } } aTimer.Enabled = false; // Tears down the environment fm.TearDownEnvironment(false); // Relinquishes control of the execution engine fm.ExecutionEngine.RelinquishProcess(); } catch (TargetInvocationException) { e.Result = false; } }