public RunWindow(SineFaultModel faultModel, Action<string> logFunction) { InitializeComponent(); this.log = logFunction; this.faultModel = faultModel; this.EnableDWMDropShadow = true; }
private void generationWorker_DoWork(object sender, DoWorkEventArgs e) { try { this.Exception = null; isRunning = false; fm = e.Argument as SineFaultModel; 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 SineFaultModel; 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; } fm.SetSearchParameters(requirementIndex, region.FrequencyRegion, region.DesiredRegion, region.ContainedHeatPoint, (string)fm.FaultModelConfiguration.GetValue("OptimizationAlgorithm")); isRunning = true; if (Double.IsInfinity(region.ContainedHeatPoint.Intensity)) { i++; this.ReportProgress((int)((double)i / SelectedRegions.Count * 100.0)); continue; } 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("Sine 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.FrequencyRegion, region.DesiredRegion, new SineHeatPoint(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("Sine 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"; ProcessWorstCaseResults(region, worstPointFile, fm.ToString()); } aTimer.Enabled = false; // Tears down the environment fm.TearDownEnvironment(false); // Relinquishes control of the execution engine fm.ExecutionEngine.RelinquishProcess(); } catch (TargetInvocationException) { e.Result = false; } }