Example #1
0
        protected ErrorResult SyncRunCommand(MatlabCommand toRunCommand)
        {
            //SingleMatlabCommand toRunCommand = new SingleMatlabCommand(commandString);
            runCanceled = false;

            return(MatlabSyncProgram.RunMatlab(toRunCommand, true));
        }
Example #2
0
        /*public override void RunSync()
         * {
         *  if (!Directory.Exists(tempPath))
         *      Directory.CreateDirectory(tempPath);
         *  File.Delete(outputLogPath);
         *
         *  if(testWorkspace is CCTestWorkspace)
         *      RunCCTestCase();
         *  if (testWorkspace is SBTestWorkspace)
         *      RunSBTestCase();
         *
         *  MatlabCommand modelSettingsCommand = MatlabCommandBuilder.GetModelSettingsMatlabCommand(testWorkspace.modelSettings);
         *  modelSettingsCommand.SaveToMatlabScript(tempPath + "\\" + MatlabCommandBuilder.ModelSettingsScriptFileName + ".m");
         *  SyncRunMainScript();
         * }*/

        public override void RunAsync()
        {
            MatlabAsyncProgram.KillMatlab();
            matlabAsyncProgram = new MatlabAsyncProgram(testWorkspace.modelSettings.MatlabExePath);


            if (!Directory.Exists(tempPath))
            {
                Directory.CreateDirectory(tempPath);
            }
            File.Delete(outputLogPath);

            if (testWorkspace is CCTestWorkspace)
            {
                RunCCTestCase();
            }
            if (testWorkspace is SLTestWorkspace)
            {
                RunSBTestCase();
            }

            MatlabCommand modelSettingsCommand = MatlabCommandBuilder.GetModelSettingsMatlabCommand(testWorkspace.modelSettings);

            modelSettingsCommand.SaveToMatlabScript(tempPath + "\\" + MatlabCommandBuilder.ModelSettingsScriptFileName + ".m");
            AsyncRunMainScript();
        }
        public void RunMatlab(MatlabCommand matlabCommand, bool silentMode)
        {
            string  arguemntString = " -r \"" + matlabCommand.ToString() + "\"";
            Process process        = new Process();

            process.StartInfo.Arguments = arguemntString;
            process.StartInfo.FileName  = programPath;
            process.Start();
        }
Example #4
0
        public override ErrorResult RunSync()
        {
            RunExtractInfo();

            MatlabCommand modelSettingsCommand = MatlabCommandBuilder.GetModelSettingsMatlabCommand(testWorkspace.modelSettings);

            modelSettingsCommand.SaveToMatlabScript(tempPath + "\\" + MatlabCommandBuilder.ModelSettingsScriptFileName + ".m");
            return(SyncRunMainScript());
        }
Example #5
0
        public static ErrorResult RunMatlab(MatlabCommand matlabCommand, bool silentMode)
        {
            string commandString = matlabCommand.ToString();

            matlab.Visible = 0;
            string ans = matlab.Execute(commandString);

            return(new ErrorResult());
        }
Example #6
0
        public void TestCreateCommand_ValidArgs()
        {
            string        cmdText = "b=a*a";
            MatlabEngine  engine  = new MatlabEngine();
            MatlabCommand cmd     = engine.CreateCommand(cmdText);
            SingleStatementMatlabCommand theCmd = cmd as SingleStatementMatlabCommand;

            Assert.AreEqual(cmdText, theCmd.Input);
        }
        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();
        }
        //protected override void ReportResultsOnRunFinish(MatlabRunOutput matlabRunOutput)
        //{
        //    singleTestRunProgressListener.TestFinished(matlabRunOutput.CheckOutput());
        //}

        public override ErrorResult RunSync()
        {
            if (!Directory.Exists(tempPath))
            {
                Directory.CreateDirectory(tempPath);
            }
            File.Delete(outputLogPath);

            if (testWorkspace is SLTestWorkspace)
            {
                RunSLTestCase();
            }

            MatlabCommand modelSettingsCommand = MatlabCommandBuilder.GetModelSettingsMatlabCommand(testWorkspace.modelSettings);

            modelSettingsCommand.SaveToMatlabScript(tempPath + "\\" + MatlabCommandBuilder.ModelSettingsScriptFileName + ".m");
            return(SyncRunMainScript());
        }
Example #9
0
 private void _runScript(MatlabEngine engine, IEnumerable <string> script)
 {
     try
     {
         string        currentDir = Directory.GetCurrentDirectory();
         string        cdToDir    = string.Format("cd {0}", currentDir);
         MatlabCommand cmd        = engine.CreateCommand(cdToDir);
         cmd.Execute();
         MatlabCommand c = engine.CreateCommand(script);
         c.Execute();
         MatlabCommand close = engine.CreateCommand("fclose('all')");
         close.Execute();
     }
     catch (Exception e)
     {
         string err = "Error executing Matlab script. Ensure all variables have been provided " +
                      "and that the script functions within Matlab.";
         throw new AlgorithmException(err, e);
     }
 }
        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();
        }
Example #11
0
        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();
        }
Example #12
0
        public override ErrorResult RunSync()
        {
            MatlabCommand closeWindowsMatlabCommand = MatlabCommandBuilder.GetCloseWindowsMatlabCommand();

            return(SyncRunCommand(closeWindowsMatlabCommand));
        }
Example #13
0
        public override ErrorResult RunSync()
        {
            MatlabCommand highlightBlockCommand = MatlabCommandBuilder.GeHighlightBlcokMatlabCommand(blockPath);

            return(SyncRunCommand(highlightBlockCommand));
        }
Example #14
0
 public void TestCreateComplexCommand_ValidArgs()
 {
     IEnumerable <string> cmds   = new [] { "a=1+1" };
     MatlabEngine         engine = new MatlabEngine();
     MatlabCommand        cmd    = engine.CreateCommand(cmds);
 }