- Timestamp:
- 07/17/13 13:38:25 (11 years ago)
- Location:
- branches/HeuristicLab.ExternalEvaluation Scientific
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.ExternalEvaluation Scientific/HeuristicLab.Problems.ExternalEvaluation.Matlab/3.3/MatlabParameterOptimizationProblem.cs
r9690 r9715 39 39 get { return (IFixedValueParameter<StringValue>)Parameters[QualityVariableParameterName]; } 40 40 } 41 public IFixedValueParameter<TextFile > MatlabEvaluationScriptParameter {42 get { return (IFixedValueParameter<TextFile >)Parameters[MatlabEvaluationScriptParameterName]; }41 public IFixedValueParameter<TextFileValue> MatlabEvaluationScriptParameter { 42 get { return (IFixedValueParameter<TextFileValue>)Parameters[MatlabEvaluationScriptParameterName]; } 43 43 } 44 44 #endregion … … 49 49 set { QualityVariableParameter.Value.Value = value; } 50 50 } 51 public TextFile MatlabEvaluationScript {51 public TextFileValue MatlabEvaluationScript { 52 52 get { return MatlabEvaluationScriptParameter.Value; } 53 53 } … … 66 66 : base(new MatlabParameterVectorEvaluator()) { 67 67 Parameters.Add(new FixedValueParameter<StringValue>(QualityVariableParameterName, "The name of the quality variable of the SciLab script.", new StringValue("quality"))); 68 Parameters.Add(new FixedValueParameter<TextFile >(MatlabEvaluationScriptParameterName, "The path to the Matlab evaluation script.", new TextFile()));68 Parameters.Add(new FixedValueParameter<TextFileValue>(MatlabEvaluationScriptParameterName, "The path to the Matlab evaluation script.", new TextFileValue())); 69 69 70 70 MatlabEvaluationScript.FileDialogFilter = @"Matlab Scripts|*.m|All files|*.*"; -
branches/HeuristicLab.ExternalEvaluation Scientific/HeuristicLab.Problems.ExternalEvaluation.Matlab/3.3/MatlabParameterVectorEvaluator.cs
r9698 r9715 22 22 using System; 23 23 using System.IO; 24 using System.Linq;25 24 using HeuristicLab.Common; 26 25 using HeuristicLab.Core; … … 42 41 get { return (ILookupParameter<StringValue>)Parameters[QualityVariableParameterName]; } 43 42 } 44 public ILookupParameter<TextFile > MatlabEvaluationScriptParameter {45 get { return (ILookupParameter<TextFile >)Parameters[MatlabEvaluationScriptParameterName]; }43 public ILookupParameter<TextFileValue> MatlabEvaluationScriptParameter { 44 get { return (ILookupParameter<TextFileValue>)Parameters[MatlabEvaluationScriptParameterName]; } 46 45 } 47 public IFixedValueParameter<TextFile > InitializationScriptParameter {48 get { return (IFixedValueParameter<TextFile >)Parameters[InitializationScriptParameterName]; }46 public IFixedValueParameter<TextFileValue> InitializationScriptParameter { 47 get { return (IFixedValueParameter<TextFileValue>)Parameters[InitializationScriptParameterName]; } 49 48 } 50 49 #endregion 51 50 52 public TextFile InitializationScript {51 public TextFileValue InitializationScript { 53 52 get { return InitializationScriptParameter.Value; } 54 53 } … … 66 65 : base() { 67 66 Parameters.Add(new LookupParameter<StringValue>(QualityVariableParameterName, "The name of the quality variable of the Matlab script.")); 68 Parameters.Add(new LookupParameter<TextFile >(MatlabEvaluationScriptParameterName, "The path to the Matlab evaluation script."));69 Parameters.Add(new FixedValueParameter<TextFile >(InitializationScriptParameterName, "The path to a Matlab script the should be execute before the evaluation starts.", new TextFile()));67 Parameters.Add(new LookupParameter<TextFileValue>(MatlabEvaluationScriptParameterName, "The path to the Matlab evaluation script.")); 68 Parameters.Add(new FixedValueParameter<TextFileValue>(InitializationScriptParameterName, "The path to a Matlab script the should be execute before the evaluation starts.", new TextFileValue())); 70 69 } 71 70 71 [StorableHook(HookType.AfterDeserialization)] 72 private void AfterDeserialization() { 73 InitializeState(); 74 } 72 75 73 private MLApp. IMLApp matLabConnector;76 private MLApp.MLApp matLabConnector; 74 77 public override void InitializeState() { 75 78 base.InitializeState(); 79 changedDirectory = false; 76 80 77 Type matlabtype = Type.GetTypeFromProgID("matlab.application.single"); 78 matLabConnector = (MLApp.IMLApp)Activator.CreateInstance(matlabtype); 81 if (matLabConnector == null) { 82 Type matlabtype = Type.GetTypeFromProgID("matlab.application.single"); 83 matLabConnector = (MLApp.MLApp)Activator.CreateInstance(matlabtype); 84 matLabConnector.Visible = 0; 85 } 79 86 80 87 if (string.IsNullOrEmpty(InitializationScript.Value)) return; 81 88 if (!InitializationScript.Exists()) throw new FileNotFoundException(string.Format("The initialization script \"{0}\" cannot be found.", InitializationScript.Value)); 82 string result = matLabConnector.Execute(string.Format("run({0});", InitializationScript.Value)); 83 //if (result != 0) ThrowSciLabException(InitializationScript.Value, result); 89 90 string initScript = InitializationScript.Value; 91 string result = matLabConnector.Execute("cd " + Path.GetDirectoryName(initScript)); 92 if (!string.IsNullOrEmpty(result)) throw new InvalidOperationException(result); 93 94 result = matLabConnector.Execute(Path.GetFileNameWithoutExtension(initScript)); 95 if (!string.IsNullOrEmpty(result)) throw new InvalidOperationException(result); 84 96 } 85 97 86 98 public override void ClearState() { 99 matLabConnector.Execute("clear"); 100 changedDirectory = false; 87 101 base.ClearState(); 88 matLabConnector.Quit();89 102 } 90 103 104 private bool changedDirectory = false; 91 105 private readonly object locker = new object(); 92 106 public override IOperation Apply() { … … 97 111 lock (locker) { 98 112 string result; 113 string script = evaluationScript.Value; 114 115 if (!changedDirectory) { 116 result = matLabConnector.Execute("cd " + Path.GetDirectoryName(script)); 117 if (!string.IsNullOrEmpty(result)) throw new InvalidOperationException(result); 118 changedDirectory = true; 119 } 120 99 121 var parameterVector = ParameterVectorParameter.ActualValue; 100 122 var parameterNames = ParameterNamesParameter.ActualValue; 101 if (parameterNames.Any(string.IsNullOrEmpty)) throw new ArgumentException("Not all parameter names are provided.");102 123 103 124 for (int i = 0; i < ProblemSizeParameter.ActualValue.Value; i++) { … … 105 126 } 106 127 107 string script = MatlabEvaluationScriptParameter.ActualValue.Value; 108 result = matLabConnector.Execute(string.Format("run({0});", script)); 109 //if (result != 0) ThrowSciLabException(script, result); 128 result = matLabConnector.Execute(Path.GetFileNameWithoutExtension(script)); 129 if (!string.IsNullOrEmpty(result)) throw new InvalidOperationException(result); 110 130 111 131 string qualityVariableName = QualityVariableParameter.ActualValue.Value; 112 132 var quality = matLabConnector.GetVariable(qualityVariableName, "base"); 113 //if (values == null) throw new InvalidOperationException(string.Format("Could not find the variable \"{0}\" in the Scilab workspace, that should hold the quality value.", qualityVariableName));114 133 115 134 if (double.IsNaN(quality)) quality = double.MaxValue; … … 120 139 } 121 140 } 122 123 //private void ThrowSciLabException(string fileName, int errorCode) {124 // const string code = "errorMsg = lasterror();";125 // int result = DotNetScilab.Scilab.Instance.SendScilabJob(code);126 // if (result != 0) throw new InvalidOperationException(string.Format("An error occured during the execution of the Scilab script {0}.", fileName));127 128 // string errorMessage = DotNetScilab.Scilab.Instance.readNamedMatrixOfString("errorMsg")[0];129 130 // string message = string.Format("The error {1} occured during the execution of the Scilab script {0}. \r\n\r\n {2}", fileName, errorCode, errorMessage);131 // throw new InvalidOperationException(message);132 //}133 141 } 134 142 } 143 -
branches/HeuristicLab.ExternalEvaluation Scientific/HeuristicLab.Problems.ExternalEvaluation.Scilab/3.3/ScilabParameterOptimizationProblem.cs
r9688 r9715 39 39 get { return (IFixedValueParameter<StringValue>)Parameters[QualityVariableParameterName]; } 40 40 } 41 public IFixedValueParameter<TextFile > ScilabEvaluationScriptParameter {42 get { return (IFixedValueParameter<TextFile >)Parameters[ScilabEvaluationScriptParameterName]; }41 public IFixedValueParameter<TextFileValue> ScilabEvaluationScriptParameter { 42 get { return (IFixedValueParameter<TextFileValue>)Parameters[ScilabEvaluationScriptParameterName]; } 43 43 } 44 44 #endregion … … 49 49 set { QualityVariableParameter.Value.Value = value; } 50 50 } 51 public TextFile ScilabEvaluationScript {51 public TextFileValue ScilabEvaluationScript { 52 52 get { return ScilabEvaluationScriptParameter.Value; } 53 53 } … … 66 66 : base(new ScilabParameterVectorEvaluator()) { 67 67 Parameters.Add(new FixedValueParameter<StringValue>(QualityVariableParameterName, "The name of the quality variable of the Scilab script.", new StringValue("quality"))); 68 Parameters.Add(new FixedValueParameter<TextFile >(ScilabEvaluationScriptParameterName, "The path to the Scilab evaluation script.", new TextFile()));68 Parameters.Add(new FixedValueParameter<TextFileValue>(ScilabEvaluationScriptParameterName, "The path to the Scilab evaluation script.", new TextFileValue())); 69 69 70 70 ScilabEvaluationScript.FileDialogFilter = @"Scilab Scripts|*.sce|All files|*.*"; -
branches/HeuristicLab.ExternalEvaluation Scientific/HeuristicLab.Problems.ExternalEvaluation.Scilab/3.3/ScilabParameterVectorEvaluator.cs
r9698 r9715 42 42 get { return (ILookupParameter<StringValue>)Parameters[QualityVariableParameterName]; } 43 43 } 44 public ILookupParameter<TextFile > ScilabEvaluationScriptParameter {45 get { return (ILookupParameter<TextFile >)Parameters[ScilabEvaluationScriptParameterName]; }44 public ILookupParameter<TextFileValue> ScilabEvaluationScriptParameter { 45 get { return (ILookupParameter<TextFileValue>)Parameters[ScilabEvaluationScriptParameterName]; } 46 46 } 47 public IFixedValueParameter<TextFile > InitializationScriptParameter {48 get { return (IFixedValueParameter<TextFile >)Parameters[InitializationScriptParameterName]; }47 public IFixedValueParameter<TextFileValue> InitializationScriptParameter { 48 get { return (IFixedValueParameter<TextFileValue>)Parameters[InitializationScriptParameterName]; } 49 49 } 50 50 #endregion 51 51 52 public TextFile InitializationScript {52 public TextFileValue InitializationScript { 53 53 get { return InitializationScriptParameter.Value; } 54 54 } … … 66 66 : base() { 67 67 Parameters.Add(new LookupParameter<StringValue>(QualityVariableParameterName, "The name of the quality variable of the Scilab script.")); 68 Parameters.Add(new LookupParameter<TextFile>(ScilabEvaluationScriptParameterName, "The path to the Scilab evaluation script.")); 69 Parameters.Add(new FixedValueParameter<TextFile>(InitializationScriptParameterName, "The path to a Scilab script the should be execute before the evaluation starts.", new TextFile())); 68 Parameters.Add(new LookupParameter<TextFileValue>(ScilabEvaluationScriptParameterName, "The path to the Scilab evaluation script.")); 69 Parameters.Add(new FixedValueParameter<TextFileValue>(InitializationScriptParameterName, "The path to a Scilab script the should be execute before the evaluation starts.", new TextFileValue())); 70 } 71 72 [StorableHook(HookType.AfterDeserialization)] 73 private void AfterDeserialization() { 74 InitializeState(); 70 75 } 71 76
Note: See TracChangeset
for help on using the changeset viewer.