Free cookie consent management tool by TermsFeed Policy Generator

Changeset 9715 for branches


Ignore:
Timestamp:
07/17/13 13:38:25 (11 years ago)
Author:
mkommend
Message:

#2082: Updated external evaluation scientific branch to use the new HL data types.

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  
    3939      get { return (IFixedValueParameter<StringValue>)Parameters[QualityVariableParameterName]; }
    4040    }
    41     public IFixedValueParameter<TextFile> MatlabEvaluationScriptParameter {
    42       get { return (IFixedValueParameter<TextFile>)Parameters[MatlabEvaluationScriptParameterName]; }
     41    public IFixedValueParameter<TextFileValue> MatlabEvaluationScriptParameter {
     42      get { return (IFixedValueParameter<TextFileValue>)Parameters[MatlabEvaluationScriptParameterName]; }
    4343    }
    4444    #endregion
     
    4949      set { QualityVariableParameter.Value.Value = value; }
    5050    }
    51     public TextFile MatlabEvaluationScript {
     51    public TextFileValue MatlabEvaluationScript {
    5252      get { return MatlabEvaluationScriptParameter.Value; }
    5353    }
     
    6666      : base(new MatlabParameterVectorEvaluator()) {
    6767      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()));
    6969
    7070      MatlabEvaluationScript.FileDialogFilter = @"Matlab Scripts|*.m|All files|*.*";
  • branches/HeuristicLab.ExternalEvaluation Scientific/HeuristicLab.Problems.ExternalEvaluation.Matlab/3.3/MatlabParameterVectorEvaluator.cs

    r9698 r9715  
    2222using System;
    2323using System.IO;
    24 using System.Linq;
    2524using HeuristicLab.Common;
    2625using HeuristicLab.Core;
     
    4241      get { return (ILookupParameter<StringValue>)Parameters[QualityVariableParameterName]; }
    4342    }
    44     public ILookupParameter<TextFile> MatlabEvaluationScriptParameter {
    45       get { return (ILookupParameter<TextFile>)Parameters[MatlabEvaluationScriptParameterName]; }
     43    public ILookupParameter<TextFileValue> MatlabEvaluationScriptParameter {
     44      get { return (ILookupParameter<TextFileValue>)Parameters[MatlabEvaluationScriptParameterName]; }
    4645    }
    47     public IFixedValueParameter<TextFile> InitializationScriptParameter {
    48       get { return (IFixedValueParameter<TextFile>)Parameters[InitializationScriptParameterName]; }
     46    public IFixedValueParameter<TextFileValue> InitializationScriptParameter {
     47      get { return (IFixedValueParameter<TextFileValue>)Parameters[InitializationScriptParameterName]; }
    4948    }
    5049    #endregion
    5150
    52     public TextFile InitializationScript {
     51    public TextFileValue InitializationScript {
    5352      get { return InitializationScriptParameter.Value; }
    5453    }
     
    6665      : base() {
    6766      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()));
    7069    }
    7170
     71    [StorableHook(HookType.AfterDeserialization)]
     72    private void AfterDeserialization() {
     73      InitializeState();
     74    }
    7275
    73     private MLApp.IMLApp matLabConnector;
     76    private MLApp.MLApp matLabConnector;
    7477    public override void InitializeState() {
    7578      base.InitializeState();
     79      changedDirectory = false;
    7680
    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      }
    7986
    8087      if (string.IsNullOrEmpty(InitializationScript.Value)) return;
    8188      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);
    8496    }
    8597
    8698    public override void ClearState() {
     99      matLabConnector.Execute("clear");
     100      changedDirectory = false;
    87101      base.ClearState();
    88       matLabConnector.Quit();
    89102    }
    90103
     104    private bool changedDirectory = false;
    91105    private readonly object locker = new object();
    92106    public override IOperation Apply() {
     
    97111      lock (locker) {
    98112        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
    99121        var parameterVector = ParameterVectorParameter.ActualValue;
    100122        var parameterNames = ParameterNamesParameter.ActualValue;
    101         if (parameterNames.Any(string.IsNullOrEmpty)) throw new ArgumentException("Not all parameter names are provided.");
    102123
    103124        for (int i = 0; i < ProblemSizeParameter.ActualValue.Value; i++) {
     
    105126        }
    106127
    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);
    110130
    111131        string qualityVariableName = QualityVariableParameter.ActualValue.Value;
    112132        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));
    114133
    115134        if (double.IsNaN(quality)) quality = double.MaxValue;
     
    120139      }
    121140    }
    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     //}
    133141  }
    134142}
     143
  • branches/HeuristicLab.ExternalEvaluation Scientific/HeuristicLab.Problems.ExternalEvaluation.Scilab/3.3/ScilabParameterOptimizationProblem.cs

    r9688 r9715  
    3939      get { return (IFixedValueParameter<StringValue>)Parameters[QualityVariableParameterName]; }
    4040    }
    41     public IFixedValueParameter<TextFile> ScilabEvaluationScriptParameter {
    42       get { return (IFixedValueParameter<TextFile>)Parameters[ScilabEvaluationScriptParameterName]; }
     41    public IFixedValueParameter<TextFileValue> ScilabEvaluationScriptParameter {
     42      get { return (IFixedValueParameter<TextFileValue>)Parameters[ScilabEvaluationScriptParameterName]; }
    4343    }
    4444    #endregion
     
    4949      set { QualityVariableParameter.Value.Value = value; }
    5050    }
    51     public TextFile ScilabEvaluationScript {
     51    public TextFileValue ScilabEvaluationScript {
    5252      get { return ScilabEvaluationScriptParameter.Value; }
    5353    }
     
    6666      : base(new ScilabParameterVectorEvaluator()) {
    6767      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()));
    6969
    7070      ScilabEvaluationScript.FileDialogFilter = @"Scilab Scripts|*.sce|All files|*.*";
  • branches/HeuristicLab.ExternalEvaluation Scientific/HeuristicLab.Problems.ExternalEvaluation.Scilab/3.3/ScilabParameterVectorEvaluator.cs

    r9698 r9715  
    4242      get { return (ILookupParameter<StringValue>)Parameters[QualityVariableParameterName]; }
    4343    }
    44     public ILookupParameter<TextFile> ScilabEvaluationScriptParameter {
    45       get { return (ILookupParameter<TextFile>)Parameters[ScilabEvaluationScriptParameterName]; }
     44    public ILookupParameter<TextFileValue> ScilabEvaluationScriptParameter {
     45      get { return (ILookupParameter<TextFileValue>)Parameters[ScilabEvaluationScriptParameterName]; }
    4646    }
    47     public IFixedValueParameter<TextFile> InitializationScriptParameter {
    48       get { return (IFixedValueParameter<TextFile>)Parameters[InitializationScriptParameterName]; }
     47    public IFixedValueParameter<TextFileValue> InitializationScriptParameter {
     48      get { return (IFixedValueParameter<TextFileValue>)Parameters[InitializationScriptParameterName]; }
    4949    }
    5050    #endregion
    5151
    52     public TextFile InitializationScript {
     52    public TextFileValue InitializationScript {
    5353      get { return InitializationScriptParameter.Value; }
    5454    }
     
    6666      : base() {
    6767      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();
    7075    }
    7176
Note: See TracChangeset for help on using the changeset viewer.