Index: /branches/HeuristicLab.ExternalEvaluation Scientific/HeuristicLab.Problems.ExternalEvaluation.Matlab/3.3/MatlabParameterOptimizationProblem.cs
===================================================================
--- /branches/HeuristicLab.ExternalEvaluation Scientific/HeuristicLab.Problems.ExternalEvaluation.Matlab/3.3/MatlabParameterOptimizationProblem.cs	(revision 9714)
+++ /branches/HeuristicLab.ExternalEvaluation Scientific/HeuristicLab.Problems.ExternalEvaluation.Matlab/3.3/MatlabParameterOptimizationProblem.cs	(revision 9715)
@@ -39,6 +39,6 @@
       get { return (IFixedValueParameter<StringValue>)Parameters[QualityVariableParameterName]; }
     }
-    public IFixedValueParameter<TextFile> MatlabEvaluationScriptParameter {
-      get { return (IFixedValueParameter<TextFile>)Parameters[MatlabEvaluationScriptParameterName]; }
+    public IFixedValueParameter<TextFileValue> MatlabEvaluationScriptParameter {
+      get { return (IFixedValueParameter<TextFileValue>)Parameters[MatlabEvaluationScriptParameterName]; }
     }
     #endregion
@@ -49,5 +49,5 @@
       set { QualityVariableParameter.Value.Value = value; }
     }
-    public TextFile MatlabEvaluationScript {
+    public TextFileValue MatlabEvaluationScript {
       get { return MatlabEvaluationScriptParameter.Value; }
     }
@@ -66,5 +66,5 @@
       : base(new MatlabParameterVectorEvaluator()) {
       Parameters.Add(new FixedValueParameter<StringValue>(QualityVariableParameterName, "The name of the quality variable of the SciLab script.", new StringValue("quality")));
-      Parameters.Add(new FixedValueParameter<TextFile>(MatlabEvaluationScriptParameterName, "The path to the Matlab evaluation script.", new TextFile()));
+      Parameters.Add(new FixedValueParameter<TextFileValue>(MatlabEvaluationScriptParameterName, "The path to the Matlab evaluation script.", new TextFileValue()));
 
       MatlabEvaluationScript.FileDialogFilter = @"Matlab Scripts|*.m|All files|*.*";
Index: /branches/HeuristicLab.ExternalEvaluation Scientific/HeuristicLab.Problems.ExternalEvaluation.Matlab/3.3/MatlabParameterVectorEvaluator.cs
===================================================================
--- /branches/HeuristicLab.ExternalEvaluation Scientific/HeuristicLab.Problems.ExternalEvaluation.Matlab/3.3/MatlabParameterVectorEvaluator.cs	(revision 9714)
+++ /branches/HeuristicLab.ExternalEvaluation Scientific/HeuristicLab.Problems.ExternalEvaluation.Matlab/3.3/MatlabParameterVectorEvaluator.cs	(revision 9715)
@@ -22,5 +22,4 @@
 using System;
 using System.IO;
-using System.Linq;
 using HeuristicLab.Common;
 using HeuristicLab.Core;
@@ -42,13 +41,13 @@
       get { return (ILookupParameter<StringValue>)Parameters[QualityVariableParameterName]; }
     }
-    public ILookupParameter<TextFile> MatlabEvaluationScriptParameter {
-      get { return (ILookupParameter<TextFile>)Parameters[MatlabEvaluationScriptParameterName]; }
+    public ILookupParameter<TextFileValue> MatlabEvaluationScriptParameter {
+      get { return (ILookupParameter<TextFileValue>)Parameters[MatlabEvaluationScriptParameterName]; }
     }
-    public IFixedValueParameter<TextFile> InitializationScriptParameter {
-      get { return (IFixedValueParameter<TextFile>)Parameters[InitializationScriptParameterName]; }
+    public IFixedValueParameter<TextFileValue> InitializationScriptParameter {
+      get { return (IFixedValueParameter<TextFileValue>)Parameters[InitializationScriptParameterName]; }
     }
     #endregion
 
-    public TextFile InitializationScript {
+    public TextFileValue InitializationScript {
       get { return InitializationScriptParameter.Value; }
     }
@@ -66,27 +65,42 @@
       : base() {
       Parameters.Add(new LookupParameter<StringValue>(QualityVariableParameterName, "The name of the quality variable of the Matlab script."));
-      Parameters.Add(new LookupParameter<TextFile>(MatlabEvaluationScriptParameterName, "The path to the Matlab evaluation script."));
-      Parameters.Add(new FixedValueParameter<TextFile>(InitializationScriptParameterName, "The path to a Matlab script the should be execute before the evaluation starts.", new TextFile()));
+      Parameters.Add(new LookupParameter<TextFileValue>(MatlabEvaluationScriptParameterName, "The path to the Matlab evaluation script."));
+      Parameters.Add(new FixedValueParameter<TextFileValue>(InitializationScriptParameterName, "The path to a Matlab script the should be execute before the evaluation starts.", new TextFileValue()));
     }
 
+    [StorableHook(HookType.AfterDeserialization)]
+    private void AfterDeserialization() {
+      InitializeState();
+    }
 
-    private MLApp.IMLApp matLabConnector;
+    private MLApp.MLApp matLabConnector;
     public override void InitializeState() {
       base.InitializeState();
+      changedDirectory = false;
 
-      Type matlabtype = Type.GetTypeFromProgID("matlab.application.single");
-      matLabConnector = (MLApp.IMLApp)Activator.CreateInstance(matlabtype);
+      if (matLabConnector == null) {
+        Type matlabtype = Type.GetTypeFromProgID("matlab.application.single");
+        matLabConnector = (MLApp.MLApp)Activator.CreateInstance(matlabtype);
+        matLabConnector.Visible = 0;
+      }
 
       if (string.IsNullOrEmpty(InitializationScript.Value)) return;
       if (!InitializationScript.Exists()) throw new FileNotFoundException(string.Format("The initialization script \"{0}\" cannot be found.", InitializationScript.Value));
-      string result = matLabConnector.Execute(string.Format("run({0});", InitializationScript.Value));
-      //if (result != 0) ThrowSciLabException(InitializationScript.Value, result);
+
+      string initScript = InitializationScript.Value;
+      string result = matLabConnector.Execute("cd " + Path.GetDirectoryName(initScript));
+      if (!string.IsNullOrEmpty(result)) throw new InvalidOperationException(result);
+
+      result = matLabConnector.Execute(Path.GetFileNameWithoutExtension(initScript));
+      if (!string.IsNullOrEmpty(result)) throw new InvalidOperationException(result);
     }
 
     public override void ClearState() {
+      matLabConnector.Execute("clear");
+      changedDirectory = false;
       base.ClearState();
-      matLabConnector.Quit();
     }
 
+    private bool changedDirectory = false;
     private readonly object locker = new object();
     public override IOperation Apply() {
@@ -97,7 +111,14 @@
       lock (locker) {
         string result;
+        string script = evaluationScript.Value;
+
+        if (!changedDirectory) {
+          result = matLabConnector.Execute("cd " + Path.GetDirectoryName(script));
+          if (!string.IsNullOrEmpty(result)) throw new InvalidOperationException(result);
+          changedDirectory = true;
+        }
+
         var parameterVector = ParameterVectorParameter.ActualValue;
         var parameterNames = ParameterNamesParameter.ActualValue;
-        if (parameterNames.Any(string.IsNullOrEmpty)) throw new ArgumentException("Not all parameter names are provided.");
 
         for (int i = 0; i < ProblemSizeParameter.ActualValue.Value; i++) {
@@ -105,11 +126,9 @@
         }
 
-        string script = MatlabEvaluationScriptParameter.ActualValue.Value;
-        result = matLabConnector.Execute(string.Format("run({0});", script));
-        //if (result != 0) ThrowSciLabException(script, result);
+        result = matLabConnector.Execute(Path.GetFileNameWithoutExtension(script));
+        if (!string.IsNullOrEmpty(result)) throw new InvalidOperationException(result);
 
         string qualityVariableName = QualityVariableParameter.ActualValue.Value;
         var quality = matLabConnector.GetVariable(qualityVariableName, "base");
-        //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));
 
         if (double.IsNaN(quality)) quality = double.MaxValue;
@@ -120,15 +139,5 @@
       }
     }
-
-    //private void ThrowSciLabException(string fileName, int errorCode) {
-    //  const string code = "errorMsg = lasterror();";
-    //  int result = DotNetScilab.Scilab.Instance.SendScilabJob(code);
-    //  if (result != 0) throw new InvalidOperationException(string.Format("An error occured during the execution of the Scilab script {0}.", fileName));
-
-    //  string errorMessage = DotNetScilab.Scilab.Instance.readNamedMatrixOfString("errorMsg")[0];
-
-    //  string message = string.Format("The error {1} occured during the execution of the Scilab script {0}. \r\n\r\n {2}", fileName, errorCode, errorMessage);
-    //  throw new InvalidOperationException(message);
-    //}
   }
 }
+
Index: /branches/HeuristicLab.ExternalEvaluation Scientific/HeuristicLab.Problems.ExternalEvaluation.Scilab/3.3/ScilabParameterOptimizationProblem.cs
===================================================================
--- /branches/HeuristicLab.ExternalEvaluation Scientific/HeuristicLab.Problems.ExternalEvaluation.Scilab/3.3/ScilabParameterOptimizationProblem.cs	(revision 9714)
+++ /branches/HeuristicLab.ExternalEvaluation Scientific/HeuristicLab.Problems.ExternalEvaluation.Scilab/3.3/ScilabParameterOptimizationProblem.cs	(revision 9715)
@@ -39,6 +39,6 @@
       get { return (IFixedValueParameter<StringValue>)Parameters[QualityVariableParameterName]; }
     }
-    public IFixedValueParameter<TextFile> ScilabEvaluationScriptParameter {
-      get { return (IFixedValueParameter<TextFile>)Parameters[ScilabEvaluationScriptParameterName]; }
+    public IFixedValueParameter<TextFileValue> ScilabEvaluationScriptParameter {
+      get { return (IFixedValueParameter<TextFileValue>)Parameters[ScilabEvaluationScriptParameterName]; }
     }
     #endregion
@@ -49,5 +49,5 @@
       set { QualityVariableParameter.Value.Value = value; }
     }
-    public TextFile ScilabEvaluationScript {
+    public TextFileValue ScilabEvaluationScript {
       get { return ScilabEvaluationScriptParameter.Value; }
     }
@@ -66,5 +66,5 @@
       : base(new ScilabParameterVectorEvaluator()) {
       Parameters.Add(new FixedValueParameter<StringValue>(QualityVariableParameterName, "The name of the quality variable of the Scilab script.", new StringValue("quality")));
-      Parameters.Add(new FixedValueParameter<TextFile>(ScilabEvaluationScriptParameterName, "The path to the Scilab evaluation script.", new TextFile()));
+      Parameters.Add(new FixedValueParameter<TextFileValue>(ScilabEvaluationScriptParameterName, "The path to the Scilab evaluation script.", new TextFileValue()));
 
       ScilabEvaluationScript.FileDialogFilter = @"Scilab Scripts|*.sce|All files|*.*";
Index: /branches/HeuristicLab.ExternalEvaluation Scientific/HeuristicLab.Problems.ExternalEvaluation.Scilab/3.3/ScilabParameterVectorEvaluator.cs
===================================================================
--- /branches/HeuristicLab.ExternalEvaluation Scientific/HeuristicLab.Problems.ExternalEvaluation.Scilab/3.3/ScilabParameterVectorEvaluator.cs	(revision 9714)
+++ /branches/HeuristicLab.ExternalEvaluation Scientific/HeuristicLab.Problems.ExternalEvaluation.Scilab/3.3/ScilabParameterVectorEvaluator.cs	(revision 9715)
@@ -42,13 +42,13 @@
       get { return (ILookupParameter<StringValue>)Parameters[QualityVariableParameterName]; }
     }
-    public ILookupParameter<TextFile> ScilabEvaluationScriptParameter {
-      get { return (ILookupParameter<TextFile>)Parameters[ScilabEvaluationScriptParameterName]; }
+    public ILookupParameter<TextFileValue> ScilabEvaluationScriptParameter {
+      get { return (ILookupParameter<TextFileValue>)Parameters[ScilabEvaluationScriptParameterName]; }
     }
-    public IFixedValueParameter<TextFile> InitializationScriptParameter {
-      get { return (IFixedValueParameter<TextFile>)Parameters[InitializationScriptParameterName]; }
+    public IFixedValueParameter<TextFileValue> InitializationScriptParameter {
+      get { return (IFixedValueParameter<TextFileValue>)Parameters[InitializationScriptParameterName]; }
     }
     #endregion
 
-    public TextFile InitializationScript {
+    public TextFileValue InitializationScript {
       get { return InitializationScriptParameter.Value; }
     }
@@ -66,6 +66,11 @@
       : base() {
       Parameters.Add(new LookupParameter<StringValue>(QualityVariableParameterName, "The name of the quality variable of the Scilab script."));
-      Parameters.Add(new LookupParameter<TextFile>(ScilabEvaluationScriptParameterName, "The path to the Scilab evaluation script."));
-      Parameters.Add(new FixedValueParameter<TextFile>(InitializationScriptParameterName, "The path to a Scilab script the should be execute before the evaluation starts.", new TextFile()));
+      Parameters.Add(new LookupParameter<TextFileValue>(ScilabEvaluationScriptParameterName, "The path to the Scilab evaluation script."));
+      Parameters.Add(new FixedValueParameter<TextFileValue>(InitializationScriptParameterName, "The path to a Scilab script the should be execute before the evaluation starts.", new TextFileValue()));
+    }
+
+    [StorableHook(HookType.AfterDeserialization)]
+    private void AfterDeserialization() {
+      InitializeState();
     }
 
