Changeset 11033 for branches/HeuristicLab.ExternalEvaluation Scientific/HeuristicLab.Problems.ExternalEvaluation.Matlab
- Timestamp:
- 06/23/14 16:56:04 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.ExternalEvaluation Scientific/HeuristicLab.Problems.ExternalEvaluation.Matlab/3.3/MatlabParameterVectorEvaluator.cs
r11028 r11033 22 22 using System; 23 23 using System.IO; 24 using System.Runtime.InteropServices; 24 25 using HeuristicLab.Common; 25 26 using HeuristicLab.Core; … … 67 68 68 69 public override void ClearState() { 69 matLabConnector.Execute("clear"); 70 //mkommend: necessary because matlabConnector.Quit() does not work 71 try { 72 matLabConnector.Execute("exit"); 73 } 74 catch (COMException) { } 75 finally { 76 matLabConnector = null; 77 } 78 70 79 changedDirectory = false; 71 executedInitializationScript = false;72 80 base.ClearState(); 73 81 } … … 75 83 private MLApp.MLApp matLabConnector; 76 84 private bool changedDirectory = false; 77 private bool executedInitializationScript = false;78 85 private readonly object locker = new object(); 79 86 80 87 public override IOperation Apply() { 81 88 lock (locker) { 82 83 if (matLabConnector == null) {84 Type matlabtype = Type.GetTypeFromProgID("matlab.application.single");85 matLabConnector = (MLApp.MLApp)Activator.CreateInstance(matlabtype);86 matLabConnector.Visible = 0;87 }88 string result;89 90 89 var initializationScript = MatlabInitializationScriptParameter.ActualValue; 91 90 if (!string.IsNullOrEmpty(initializationScript.Value) && !initializationScript.Exists()) … … 98 97 throw new FileNotFoundException(string.Format("The evaluation script \"{0}\" cannot be found.", evaluationScript.Value)); 99 98 100 if (!string.IsNullOrEmpty(initializationScript.Value) && !executedInitializationScript) { 101 var directoryName = Path.GetDirectoryName(initializationScript.Value); 102 result = matLabConnector.Execute(string.Format("cd '{0}'", directoryName)); 103 if (!string.IsNullOrEmpty(result)) throw new InvalidOperationException(result); 99 string result; 100 if (matLabConnector == null) { 101 Type matlabtype = Type.GetTypeFromProgID("matlab.application.single"); 102 matLabConnector = (MLApp.MLApp)Activator.CreateInstance(matlabtype); 103 matLabConnector.Visible = 0; 104 104 105 result = matLabConnector.Execute(Path.GetFileNameWithoutExtension(initializationScript.Value)); 106 if (!string.IsNullOrEmpty(result)) throw new InvalidOperationException(result); 105 if (!string.IsNullOrEmpty(initializationScript.Value)) { 106 var directoryName = Path.GetDirectoryName(initializationScript.Value); 107 if (string.IsNullOrEmpty(directoryName)) directoryName = Environment.CurrentDirectory; 108 result = matLabConnector.Execute(string.Format("cd '{0}'", directoryName)); 109 if (!string.IsNullOrEmpty(result)) throw new InvalidOperationException(result); 107 110 108 executedInitializationScript = true; 111 result = matLabConnector.Execute(Path.GetFileNameWithoutExtension(initializationScript.Value)); 112 if (!string.IsNullOrEmpty(result)) throw new InvalidOperationException(result); 113 } 109 114 } 110 115 111 116 if (!changedDirectory) { 112 117 var directoryName = Path.GetDirectoryName(evaluationScript.Value); 118 if (string.IsNullOrEmpty(directoryName)) directoryName = Environment.CurrentDirectory; 113 119 result = matLabConnector.Execute(string.Format("cd '{0}'", directoryName)); 114 120 if (!string.IsNullOrEmpty(result)) throw new InvalidOperationException(result);
Note: See TracChangeset
for help on using the changeset viewer.