private void RunSLTestCase() { SLTestWorkspace slTestWorkspace = (SLTestWorkspace)testWorkspace; CompositeMatlabCommand mainScriptCommand = new CompositeMatlabCommand(); mainScriptCommand.LoadFromMatlabScript(templatePath + "\\SingleTestCaseRun.m"); mainScriptCommand.ReplaceInTemplate("[MiLTester_CodeRootVal]", codePath); mainScriptCommand.ReplaceInTemplate("[MiLTester_DsrdOutNo]", slTestCase.dsrdOutNo.ToString()); mainScriptCommand.ReplaceInTemplate("[MiLTester_DsrdTCNo]", slTestCase.dsrdTCNo.ToString()); mainScriptCommand.ReplaceInTemplate("[MiLTester_FilesDirectory]", slTestCase.filesDir); mainScriptCommand.ReplaceInTemplate("[MiLTester_TestSuiteFilepath]", slTestCase.testSuiteDir); mainScriptCommand.ReplaceInTemplate("[MiLTester_SimulationTimeVal]", testWorkspace.GetSimulationTime().ToString()); mainScriptCommand.ReplaceInTemplate("[MiLTester_SimulationStepTimesVal]", "0.01"); mainScriptCommand.ReplaceInTemplate("[MiLTester_ModelComltName]", testWorkspace.modelSettings.GetSimulinkModelNameWithNoExtension()); mainScriptCommand.ReplaceInTemplate("[MiLTester_SimulinkModelPathVal]", testWorkspace.modelSettings.SimulinkModelPath); /*mainScriptCommand.ReplaceInTemplate("[MiLTester_InitialDesiredVal]", ccTestCase.initialDesired.ToString()); * mainScriptCommand.ReplaceInTemplate("[MiLTester_FinalDesiredVal]", ccTestCase.finalDesired.ToString()); * mainScriptCommand.ReplaceInTemplate("[MiLTester_DesiredValueVar]", ccTestWorkspace.GetDesiredValueVariable().parameterName); * mainScriptCommand.ReplaceInTemplate("[MiLTester_ActualValueVar]", ccTestWorkspace.GetActualValueVariable().parameterName); * mainScriptCommand.ReplaceInTemplate("[MiLTester_CalibrationVariablesNamesVar]", ccTestWorkspace.GetCalibrationVariableNamesStr()); * mainScriptCommand.ReplaceInTemplate("[MiLTester_CalibrationVariablesValuesVal]", ccTestWorkspace.GetCalibrationVariableValuesStr());*/ mainScriptCommand.SaveToMatlabScript(tempPath + "\\" + MatlabCommandBuilder.MainScriptFileName + ".m"); }
public static MatlabCommand GetCloseWindowsMatlabCommand() { CompositeMatlabCommand psc = new CompositeMatlabCommand(); psc.AddCommand(new SingleMatlabCommand("bdclose('all')")); return(psc); }
public static MatlabCommand GeHighlightBlcokMatlabCommand(string simBlockPath) { CompositeMatlabCommand psc = new CompositeMatlabCommand(); psc.AddCommand(new SingleMatlabCommand("hilite_system('" + simBlockPath + "')")); return(psc); }
protected ErrorResult SyncRunMainScript() { CompositeMatlabCommand toRunCommand = new CompositeMatlabCommand(); toRunCommand.AddCommand(new SingleMatlabCommand("addpath('" + tempPath + "')")); toRunCommand.AddCommand(new SingleMatlabCommand("run('" + MatlabCommandBuilder.MainScriptFileName + "')")); runCanceled = false; return(MatlabSyncProgram.RunMatlab(toRunCommand, true)); }
public void TestExecute_ValidSession() { IEnumerable <string> cmds = new[] { "a=1", "b=a*2", "c=b*b" }; MLAppClass matlab = MatlabTestInstance.Instance; MatlabSession session = new MatlabSession(matlab); CompositeMatlabCommand cmd = new CompositeMatlabCommand(session, cmds); cmd.Execute(); Assert.IsFalse(cmd.Outputs.Any(x => x == null)); }
public void TestExecute_InvalidSession() { MLAppClass matlab = MatlabTestInstance.Instance; MatlabSession session = new MatlabSession(matlab); CompositeMatlabCommand cmd = new CompositeMatlabCommand(session, new string[] {}); session.Valid = false; cmd.Execute(); }
private void RunExtractInfo() { CompositeMatlabCommand mainScriptCommand = new CompositeMatlabCommand(); mainScriptCommand.LoadFromMatlabScript(templatePath + "\\ExtractInfo.m"); mainScriptCommand.ReplaceInTemplate("[MiLTester_CodeRootVal]", codePath); mainScriptCommand.ReplaceInTemplate("[MiLTester_SimulinkModelNameVal]", testWorkspace.modelSettings.GetSimulinkModelNameWithNoExtension()); mainScriptCommand.ReplaceInTemplate("[MiLTester_SimulinkModelDirVal]", testWorkspace.modelSettings.GetSimulinkModelDirectory()); mainScriptCommand.SaveToMatlabScript(tempPath + "\\" + MatlabCommandBuilder.MainScriptFileName + ".m"); }
protected void AsyncRunMainScript() { CompositeMatlabCommand toRunCommand = new CompositeMatlabCommand(); toRunCommand.AddCommand(new SingleMatlabCommand("addpath('" + tempPath + "')")); toRunCommand.AddCommand(new SingleMatlabCommand("run('" + MatlabCommandBuilder.MainScriptFileName + "')")); runCanceled = false; Thread finishWaitThread = new Thread(this.FinishWaitFunction); finishWaitThread.Start(); matlabAsyncProgram.RunMatlab(toRunCommand, true); }
public override void RunAsync() { MatlabAsyncProgram.KillMatlab(); CCTestWorkspace ccTestWorkspace = (CCTestWorkspace)testWorkspace; if (Directory.Exists(tempPath)) { Directory.Delete(tempPath, true); } Directory.CreateDirectory(tempPath); File.Delete(outputLogPath); MatlabCommand modelSettingsCommand = MatlabCommandBuilder.GetModelSettingsMatlabCommand(ccTestWorkspace.modelSettings); modelSettingsCommand.SaveToMatlabScript(tempPath + "\\" + MatlabCommandBuilder.ModelSettingsScriptFileName + ".m"); CompositeMatlabCommand mainScriptCommand = new CompositeMatlabCommand(); mainScriptCommand.LoadFromMatlabScript(templatePath + "\\RandomExploration\\RandomExplorationRun-Common.m"); CompositeMatlabCommand GenerateNewValueCommand = new CompositeMatlabCommand(); if (ccTestWorkspace.advancedCCSettings.randomExplorationAlgorithm == RandomExplorationAlgorithmsEnum.RandomSearch) { GenerateNewValueCommand.LoadFromMatlabScript(templatePath + "\\RandomExploration\\RandomExplorationRun-RandomSearchGenerateValues.m"); } else if (ccTestWorkspace.advancedCCSettings.randomExplorationAlgorithm == RandomExplorationAlgorithmsEnum.AdaptiveRandomSearch) { GenerateNewValueCommand.LoadFromMatlabScript(templatePath + "\\RandomExploration\\RandomExplorationRun-AdaptiveRandomSearchGenerateNewValues.m"); GenerateNewValueCommand.ReplaceInTemplate("[NumCandidatePointsInAdaptiveRandomVal]", "5"); } mainScriptCommand.ReplaceInTemplate("[MiLTester_GenerateNewValuesCode]", GenerateNewValueCommand); mainScriptCommand.ReplaceInTemplate("[MiLTester_CodeRootVal]", codePath); mainScriptCommand.ReplaceInTemplate("[MiLTester_SimulationTimeVal]", testWorkspace.GetSimulationTime().ToString()); mainScriptCommand.ReplaceInTemplate("[MiLTester_SimulinkModelPathVal]", testWorkspace.modelSettings.SimulinkModelPath); mainScriptCommand.ReplaceInTemplate("[MiLTester_DesiredValueVar]", ccTestWorkspace.GetDesiredValueVariable().parameterName); mainScriptCommand.ReplaceInTemplate("[MiLTester_ActualValueVar]", ccTestWorkspace.GetActualValueVariable().parameterName); mainScriptCommand.ReplaceInTemplate("[MiLTester_MinAlgorithmIterationsVal]", ccTestWorkspace.GetRandomExplorationMinAlgorithmIterations().ToString()); mainScriptCommand.ReplaceInTemplate("[MiLTester_MaxAlgorithmIterationsVal]", ccTestWorkspace.GetRandomExplorationMaxAlgorithmIterations().ToString()); mainScriptCommand.ReplaceInTemplate("[MiLTester_NumberOfPointsInEachRegionVal]", ccTestWorkspace.ccSettings.numberOfPointsInEachRegion.ToString()); mainScriptCommand.ReplaceInTemplate("[MiLTester_HeatMapDiagramDivisionFactorVal]", ccTestWorkspace.ccSettings.heatMapDiagramDivisionFactor.ToString()); mainScriptCommand.ReplaceInTemplate("[MiLTester_RangeStartVal]", ccTestWorkspace.GetDesiredValueVariable().from.ToString()); mainScriptCommand.ReplaceInTemplate("[MiLTester_RangeStopVal]", ccTestWorkspace.GetDesiredValueVariable().to.ToString()); mainScriptCommand.ReplaceInTemplate("[MiLTester_CalibrationVariablesNamesVar]", ccTestWorkspace.GetCalibrationVariableNamesStr()); mainScriptCommand.ReplaceInTemplate("[MiLTester_CalibrationVariablesMinimumsVal]", ccTestWorkspace.GetCalibrationVariableMinimumsStr()); mainScriptCommand.ReplaceInTemplate("[MiLTester_CalibrationVariablesMaximumsVal]", ccTestWorkspace.GetCalibrationVariableMaximumsStr()); mainScriptCommand.SaveToMatlabScript(tempPath + "\\" + MatlabCommandBuilder.MainScriptFileName + ".m"); AsyncRunMainScript(); }
public static MatlabCommand GetModelSettingsMatlabCommand(ModelSettings modelSettings) { CompositeMatlabCommand psc = new CompositeMatlabCommand(); for (int i = 0; i < modelSettings.MatlabScriptsPaths.Count; ++i) { psc.AddCommand(new SingleMatlabCommand("run('" + modelSettings.MatlabScriptsPaths[i] + "')")); } for (int i = 0; i < modelSettings.MatlabPaths.Count; ++i) { psc.AddCommand(new SingleMatlabCommand("addpath('" + modelSettings.MatlabPaths[i] + "')")); } return(psc); }
public static MatlabCommand GetCCParametersMatlabCommand(List <TestParameter> ccTestParameters) { CompositeMatlabCommand mcc = new CompositeMatlabCommand(); for (int i = 0; i < ccTestParameters.Count; ++i) { mcc.AddCommand(new SingleMatlabCommand(ccTestParameters[i].parameterName)); if (ccTestParameters[i].parameteresType == ParameteresType.DesiredVariable || ccTestParameters[i].parameteresType == ParameteresType.ActualVariable) { mcc.AddCommand(new SingleMatlabCommand(ccTestParameters[i].parameterName + ".time")); mcc.AddCommand(new SingleMatlabCommand(ccTestParameters[i].parameterName + ".signals")); mcc.AddCommand(new SingleMatlabCommand(ccTestParameters[i].parameterName + ".signals.values")); } } return(mcc); }
private void RunCCTestCase() { CCTestWorkspace ccTestWorkspace = (CCTestWorkspace)testWorkspace; CompositeMatlabCommand mainScriptCommand = new CompositeMatlabCommand(); mainScriptCommand.LoadFromMatlabScript(templatePath + "\\SingleTestRun.m"); mainScriptCommand.ReplaceInTemplate("[MiLTester_CodeRootVal]", codePath); mainScriptCommand.ReplaceInTemplate("[MiLTester_SimulationTimeVal]", testWorkspace.GetSimulationTime().ToString()); mainScriptCommand.ReplaceInTemplate("[MiLTester_SimulinkModelPathVal]", testWorkspace.modelSettings.SimulinkModelPath); mainScriptCommand.ReplaceInTemplate("[MiLTester_InitialDesiredVal]", ccTestCase.initialDesired.ToString()); mainScriptCommand.ReplaceInTemplate("[MiLTester_FinalDesiredVal]", ccTestCase.finalDesired.ToString()); mainScriptCommand.ReplaceInTemplate("[MiLTester_DesiredValueVar]", ccTestWorkspace.GetDesiredValueVariable().parameterName); mainScriptCommand.ReplaceInTemplate("[MiLTester_ActualValueVar]", ccTestWorkspace.GetActualValueVariable().parameterName); mainScriptCommand.ReplaceInTemplate("[MiLTester_CalibrationVariablesNamesVar]", ccTestWorkspace.GetCalibrationVariableNamesStr()); mainScriptCommand.ReplaceInTemplate("[MiLTester_CalibrationVariablesValuesVal]", ccTestWorkspace.GetCalibrationVariableValuesStr()); mainScriptCommand.SaveToMatlabScript(tempPath + "\\" + MatlabCommandBuilder.MainScriptFileName + ".m"); }
public override void RunAsync() { MatlabAsyncProgram.KillMatlab(); matlabAsyncProgram = new MatlabAsyncProgram(testWorkspace.modelSettings.MatlabExePath); SLTestWorkspace slTestWorkspace = (SLTestWorkspace)testWorkspace; //if (Directory.Exists(tempPath)) // Directory.Delete(tempPath,true); //Directory.CreateDirectory(tempPath); //File.Delete(outputLogPath); MatlabCommand modelSettingsCommand = MatlabCommandBuilder.GetModelSettingsMatlabCommand(slTestWorkspace.modelSettings); modelSettingsCommand.SaveToMatlabScript(tempPath + "\\" + MatlabCommandBuilder.ModelSettingsScriptFileName + ".m"); CompositeMatlabCommand mainScriptCommand = new CompositeMatlabCommand(); mainScriptCommand.LoadFromMatlabScript(templatePath + "\\SLTestGeneration\\SLTestGenerationRun.m"); mainScriptCommand.ReplaceInTemplate("[MiLTester_CodeRootVal]", codePath); mainScriptCommand.ReplaceInTemplate("[MiLTester_ModelComltName]", testWorkspace.modelSettings.GetSimulinkModelNameWithNoExtension()); mainScriptCommand.ReplaceInTemplate("[MiLTester_SimulinkModelPathVal]", testWorkspace.modelSettings.GetSimulinkModelDirectory()); mainScriptCommand.SaveToMatlabScript(tempPath + "\\" + MatlabCommandBuilder.MainScriptFileName + ".m"); AsyncRunMainScript(); }
public void RunSingleStateSearchInRegion(HeatMapRegion heatMapRegion) { MatlabAsyncProgram.KillMatlab(); matlabAsyncProgram = new MatlabAsyncProgram(testWorkspace.modelSettings.MatlabExePath); CCTestWorkspace ccTestWorkspace = (CCTestWorkspace)testWorkspace; if (!Directory.Exists(tempPath)) { Directory.CreateDirectory(tempPath); } File.Delete(outputLogPath); MatlabCommand modelSettingsCommand = MatlabCommandBuilder.GetModelSettingsMatlabCommand(ccTestWorkspace.modelSettings); modelSettingsCommand.SaveToMatlabScript(tempPath + "\\" + MatlabCommandBuilder.ModelSettingsScriptFileName + ".m"); CompositeMatlabCommand mainScriptCommand = new CompositeMatlabCommand(); mainScriptCommand.LoadFromMatlabScript(templatePath + "\\SingleStateSearch\\SingleStateSearch-Common.m"); CompositeMatlabCommand GenerateNewValuesCommand = new CompositeMatlabCommand(); CompositeMatlabCommand ReplaceValuesCommand = new CompositeMatlabCommand(); if (ccTestWorkspace.advancedCCSettings.singelStateSearchAlgorithm == SingelStateSearchAlgorithmsEnum.RandomSearch) { GenerateNewValuesCommand.LoadFromMatlabScript(templatePath + "\\SingleStateSearch\\RandomSearch\\SingleStateSearch-RandomSearchGenerateValues.m"); ReplaceValuesCommand.LoadFromMatlabScript(templatePath + "\\SingleStateSearch\\RandomSearch\\SingleStateSearch-RandomSearchReplaceValues.m"); } else if (ccTestWorkspace.advancedCCSettings.singelStateSearchAlgorithm == SingelStateSearchAlgorithmsEnum.HillClimbing) { GenerateNewValuesCommand.LoadFromMatlabScript(templatePath + "\\SingleStateSearch\\HillClimbing\\SingleStateSearch-HillClimbingGenerateValues.m"); GenerateNewValuesCommand.ReplaceInTemplate("[MiLTester_EASigmalVal]", ccTestWorkspace.GetSigmaForSingleStateSearch().ToString()); ReplaceValuesCommand.LoadFromMatlabScript(templatePath + "\\SingleStateSearch\\HillClimbing\\SingleStateSearch-HillClimbingReplaceValues.m"); } else if (ccTestWorkspace.advancedCCSettings.singelStateSearchAlgorithm == SingelStateSearchAlgorithmsEnum.HCRR) { GenerateNewValuesCommand.LoadFromMatlabScript(templatePath + "\\SingleStateSearch\\HCRR\\SingleStateSearch-HillClimbingGenerateValues.m"); GenerateNewValuesCommand.ReplaceInTemplate("[MiLTester_EASigmalVal]", ccTestWorkspace.GetSigmaForSingleStateSearch().ToString()); ReplaceValuesCommand.LoadFromMatlabScript(templatePath + "\\SingleStateSearch\\HCRR\\SingleStateSearch-HillClimbingReplaceValues.m"); } else if (ccTestWorkspace.advancedCCSettings.singelStateSearchAlgorithm == SingelStateSearchAlgorithmsEnum.SimulatedAnnealing) { GenerateNewValuesCommand.LoadFromMatlabScript(templatePath + "\\SingleStateSearch\\SimulatedAnnealing\\SingleStateSearch-SimulatedAnnealingGenerateValues.m"); GenerateNewValuesCommand.ReplaceInTemplate("[MiLTester_EASigmalVal]", ccTestWorkspace.GetSigmaForSingleStateSearch().ToString()); ReplaceValuesCommand.LoadFromMatlabScript(templatePath + "\\SingleStateSearch\\SimulatedAnnealing\\SingleStateSearch-SimulatedAnnealingReplaceValues.m"); ReplaceValuesCommand.ReplaceInTemplate("[MiLTester_AnnealingScheduleVal]", ccTestWorkspace.GetAnnealingScheduleForSingleStateSearch().ToString()); } mainScriptCommand.ReplaceInTemplate("[MiLTester_GenerateNewValuesCode]", GenerateNewValuesCommand); mainScriptCommand.ReplaceInTemplate("[MiLTester_ReplaceValuesCode]", ReplaceValuesCommand); mainScriptCommand.ReplaceInTemplate("[MiLTester_CodeRootVal]", codePath); mainScriptCommand.ReplaceInTemplate("[MiLTester_SimulationTimeVal]", testWorkspace.GetSimulationTime().ToString()); mainScriptCommand.ReplaceInTemplate("[MiLTester_SimulinkModelPathVal]", testWorkspace.modelSettings.SimulinkModelPath); mainScriptCommand.ReplaceInTemplate("[MiLTester_SearchVariablesCntVal]", ccTestWorkspace.GetSearchVariablesCnt().ToString()); mainScriptCommand.ReplaceInTemplate("[MiLTester_RegionWidthRangeStartVal]", heatMapRegion.xStart.ToString()); mainScriptCommand.ReplaceInTemplate("[MiLTester_RegionWidthRangeStopVal]", heatMapRegion.xEnd.ToString()); mainScriptCommand.ReplaceInTemplate("[MiLTester_RegionHeightRangeStartVal]", heatMapRegion.yStart.ToString()); mainScriptCommand.ReplaceInTemplate("[MiLTester_RegionHeightRangeStopVal]", heatMapRegion.yEnd.ToString()); mainScriptCommand.ReplaceInTemplate("[MiLTester_WorstPointFromRandomExplorationInitialDesiredVal]", heatMapRegion.worstCasePointFromRandomExploration.x.ToString()); mainScriptCommand.ReplaceInTemplate("[MiLTester_WorstPointFromRandomExplorationFinalDesiredVal]", heatMapRegion.worstCasePointFromRandomExploration.y.ToString()); mainScriptCommand.ReplaceInTemplate("[MiLTester_AlgorithmRoundsVal]", ccTestWorkspace.advancedCCSettings.algorithmRounds.ToString()); mainScriptCommand.ReplaceInTemplate("[MiLTester_AlgorithmIterationsVal]", ccTestWorkspace.advancedCCSettings.algorithmIterations.ToString()); mainScriptCommand.ReplaceInTemplate("[MiLTester_SelectedObjectiveFunction]", heatMapRegion.requirementName); mainScriptCommand.ReplaceInTemplate("[MiLTester_DesiredValueVar]", ccTestWorkspace.GetDesiredValueVariable().parameterName); mainScriptCommand.ReplaceInTemplate("[MiLTester_ActualValueVar]", ccTestWorkspace.GetActualValueVariable().parameterName); mainScriptCommand.ReplaceInTemplate("[MiLTester_RegionWidthIndexVal]", heatMapRegion.indexX.ToString()); mainScriptCommand.ReplaceInTemplate("[MiLTester_RegionHeightIndexVal]", heatMapRegion.indexY.ToString()); mainScriptCommand.ReplaceInTemplate("[MiLTester_RangeStartVal]", ccTestWorkspace.GetDesiredValueVariable().from.ToString()); mainScriptCommand.ReplaceInTemplate("[MiLTester_RangeStopVal]", ccTestWorkspace.GetDesiredValueVariable().to.ToString()); mainScriptCommand.ReplaceInTemplate("[MiLTester_AnnealingStartTemprature]", ccTestWorkspace.GetAnnealingStartTemprature().ToString()); mainScriptCommand.SaveToMatlabScript(tempPath + "\\" + MatlabCommandBuilder.MainScriptFileName + ".m"); AsyncRunMainScript(); }
public void TestConstructor_NullCommand() { MLAppClass matlab = MatlabTestInstance.Instance; MatlabSession session = new MatlabSession(matlab); CompositeMatlabCommand cmd = new CompositeMatlabCommand(session, null); }
public void TestConstructor_NullSession() { CompositeMatlabCommand cmd = new CompositeMatlabCommand(null, new string[] {}); }