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 11023)
+++ branches/HeuristicLab.ExternalEvaluation Scientific/HeuristicLab.Problems.ExternalEvaluation.Matlab/3.3/MatlabParameterVectorEvaluator.cs	(revision 11028)
@@ -35,5 +35,5 @@
     private const string QualityVariableParameterName = "QualityVariableName";
     private const string MatlabEvaluationScriptParameterName = "MATLABEvaluationScript";
-    private const string InitializationScriptParameterName = "InitializationScript";
+    private const string MatlabInitializationScriptParameterName = "MATLABInitializationScript";
 
     #region parameters
@@ -44,12 +44,8 @@
       get { return (ILookupParameter<TextFileValue>)Parameters[MatlabEvaluationScriptParameterName]; }
     }
-    public IFixedValueParameter<TextFileValue> InitializationScriptParameter {
-      get { return (IFixedValueParameter<TextFileValue>)Parameters[InitializationScriptParameterName]; }
+    public ILookupParameter<TextFileValue> MatlabInitializationScriptParameter {
+      get { return (ILookupParameter<TextFileValue>)Parameters[MatlabInitializationScriptParameterName]; }
     }
     #endregion
-
-    public TextFileValue InitializationScript {
-      get { return InitializationScriptParameter.Value; }
-    }
 
     [StorableConstructor]
@@ -66,51 +62,53 @@
       Parameters.Add(new LookupParameter<StringValue>(QualityVariableParameterName, "The name of the quality variable calculated in the MATLAB script."));
       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()));
+      Parameters.Add(new LookupParameter<TextFileValue>(MatlabInitializationScriptParameterName, "The path to a MATLAB script the should be execute before the evaluation starts."));
     }
 
-    private MLApp.MLApp matLabConnector;
-    public override void InitializeState() {
-      base.InitializeState();
-      changedDirectory = false;
-
-      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 initScript = InitializationScript.Value;
-      var directoryName = Path.GetDirectoryName(initScript);
-      string result = matLabConnector.Execute(string.Format("cd '{0}'", directoryName));
-      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;
+      executedInitializationScript = false;
       base.ClearState();
     }
 
+    private MLApp.MLApp matLabConnector;
     private bool changedDirectory = false;
+    private bool executedInitializationScript = false;
     private readonly object locker = new object();
+
     public override IOperation Apply() {
-      var evaluationScript = MatlabEvaluationScriptParameter.ActualValue;
-      if (string.IsNullOrEmpty(evaluationScript.Value)) throw new FileNotFoundException("The evaluation script in the problem is not set.");
-      if (!evaluationScript.Exists()) throw new FileNotFoundException(string.Format("The evaluation script \"{0}\" cannot be found.", evaluationScript.Value));
+      lock (locker) {
 
-      lock (locker) {
-        if (matLabConnector == null) InitializeState();
+        if (matLabConnector == null) {
+          Type matlabtype = Type.GetTypeFromProgID("matlab.application.single");
+          matLabConnector = (MLApp.MLApp)Activator.CreateInstance(matlabtype);
+          matLabConnector.Visible = 0;
+        }
+        string result;
 
-        string result;
-        string script = evaluationScript.Value;
+        var initializationScript = MatlabInitializationScriptParameter.ActualValue;
+        if (!string.IsNullOrEmpty(initializationScript.Value) && !initializationScript.Exists())
+          throw new FileNotFoundException(string.Format("The initialization script \"{0}\" cannot be found.", initializationScript.Value));
+
+        var evaluationScript = MatlabEvaluationScriptParameter.ActualValue;
+        if (string.IsNullOrEmpty(evaluationScript.Value))
+          throw new FileNotFoundException("The evaluation script in the problem is not set.");
+        if (!evaluationScript.Exists())
+          throw new FileNotFoundException(string.Format("The evaluation script \"{0}\" cannot be found.", evaluationScript.Value));
+
+        if (!string.IsNullOrEmpty(initializationScript.Value) && !executedInitializationScript) {
+          var directoryName = Path.GetDirectoryName(initializationScript.Value);
+          result = matLabConnector.Execute(string.Format("cd '{0}'", directoryName));
+          if (!string.IsNullOrEmpty(result)) throw new InvalidOperationException(result);
+
+          result = matLabConnector.Execute(Path.GetFileNameWithoutExtension(initializationScript.Value));
+          if (!string.IsNullOrEmpty(result)) throw new InvalidOperationException(result);
+
+          executedInitializationScript = true;
+        }
 
         if (!changedDirectory) {
-          var directoryName = Path.GetDirectoryName(script);
+          var directoryName = Path.GetDirectoryName(evaluationScript.Value);
           result = matLabConnector.Execute(string.Format("cd '{0}'", directoryName));
           if (!string.IsNullOrEmpty(result)) throw new InvalidOperationException(result);
@@ -125,5 +123,5 @@
         }
 
-        result = matLabConnector.Execute(Path.GetFileNameWithoutExtension(script));
+        result = matLabConnector.Execute(Path.GetFileNameWithoutExtension(evaluationScript.Value));
         if (!string.IsNullOrEmpty(result)) throw new InvalidOperationException(result);
 
