Free cookie consent management tool by TermsFeed Policy Generator

Changeset 11076


Ignore:
Timestamp:
07/02/14 17:36:38 (10 years ago)
Author:
gkronber
Message:

#2171: made some changes while reviewing the code.

Location:
trunk/sources/HeuristicLab.Problems.ExternalEvaluation.Scilab/3.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.ExternalEvaluation.Scilab/3.3/ScilabParameterOptimizationProblem.cs

    r10595 r11076  
    7575      Parameters.Add(new FixedValueParameter<StringValue>(QualityVariableParameterName, "The name of the quality variable of the Scilab script.", new StringValue("quality")));
    7676      Parameters.Add(new FixedValueParameter<TextFileValue>(ScilabEvaluationScriptParameterName, "The path to the Scilab evaluation script.", new TextFileValue()));
    77       Parameters.Add(new FixedValueParameter<TextFileValue>(ScilabInitializationScriptParameterName, "The path to a Scilab script the should be execute before the evaluation starts.", new TextFileValue()));
     77      Parameters.Add(new FixedValueParameter<TextFileValue>(ScilabInitializationScriptParameterName, "The path to a Scilab script that should be executed once when the algorithm starts.", new TextFileValue()));
    7878
    7979      ScilabEvaluationScript.FileDialogFilter = @"Scilab Scripts|*.sce|All files|*.*";
  • trunk/sources/HeuristicLab.Problems.ExternalEvaluation.Scilab/3.3/ScilabParameterVectorEvaluator.cs

    r10605 r11076  
    3535  [StorableClass]
    3636  public sealed class ScilabParameterVectorEvaluator : ParameterVectorEvaluator {
     37    private const string MaximizationParameterName = "Maximization";
    3738    private const string QualityVariableParameterName = "QualityVariableName";
    3839    private const string ScilabEvaluationScriptParameterName = "ScilabEvaluationScript";
     
    4041
    4142    #region parameters
     43    public ILookupParameter<BoolValue> MaximizationParameter {
     44      get { return (ILookupParameter<BoolValue>)Parameters[MaximizationParameterName]; }
     45    }
    4246    public ILookupParameter<StringValue> QualityVariableParameter {
    4347      get { return (ILookupParameter<StringValue>)Parameters[QualityVariableParameterName]; }
     
    6266    public ScilabParameterVectorEvaluator()
    6367      : base() {
     68      Parameters.Add(new LookupParameter<BoolValue>(MaximizationParameterName, "The flag which determines if this is a maximization problem."));
    6469      Parameters.Add(new LookupParameter<StringValue>(QualityVariableParameterName, "The name of the quality variable of the Scilab script."));
    6570      Parameters.Add(new LookupParameter<TextFileValue>(ScilabEvaluationScriptParameterName, "The path to the Scilab evaluation script."));
    66       Parameters.Add(new LookupParameter<TextFileValue>(ScilabInitializationScriptParameterName, "The path to a Scilab script the should be execute before the evaluation starts."));
     71      Parameters.Add(new LookupParameter<TextFileValue>(ScilabInitializationScriptParameterName, "The path to a Scilab script that should be executed once when the algorithm starts."));
    6772    }
    6873
    69     private readonly object locker = new object();
     74    private static readonly object locker = new object();
    7075    private static ScilabConnector scilab = null;
    7176    private bool startedScilab = false;
     
    8085
    8186      int result;
    82       //Scilab is used via a c++ wrapper that calls static methods. Hence it is not possible to parallelize the evaluation.
     87      // Scilab is used via a c++ wrapper that calls static methods. Hence it is not possible to parallelize the evaluation.
     88      // It is also not possible to run multiple algorithms solving separate Scilab optimization problems at the same time.
    8389      lock (locker) {
    8490        //initialize scilab and execute initialization script
     
    8692          startedScilab = true;
    8793          scilab = new ScilabConnector(false);
    88           if (!string.IsNullOrEmpty(initializationScript.Value)) {
    89             result = scilab.execScilabScript(initializationScript.Value);
    90             if (result != 0) ThrowSciLabException(initializationScript.Value, result);
    91           }
     94          result = scilab.execScilabScript(initializationScript.Value);
     95          if (result != 0) ThrowSciLabException(initializationScript.Value, result);
    9296        } else if (!startedScilab) {
    9397          throw new InvalidOperationException("Could not run multiple optimization algorithms in parallel.");
     
    96100        var parameterVector = ParameterVectorParameter.ActualValue;
    97101        var parameterNames = ParameterNamesParameter.ActualValue;
    98         if (parameterNames.Any(string.IsNullOrEmpty)) throw new ArgumentException("Not all parameter names are provided.");
     102        if (parameterNames.Any(string.IsNullOrEmpty)) throw new ArgumentException("Not all parameter names are provided. Change the 'ParameterNames' parameter in the 'Problem' tab.");
     103        if (ProblemSizeParameter.ActualValue.Value != parameterVector.Length || ProblemSizeParameter.ActualValue.Value != parameterNames.Length)
     104          throw new ArgumentException("The size of the parameter vector or the parameter names vector does not match the problem size.");
    99105
    100106        for (int i = 0; i < ProblemSizeParameter.ActualValue.Value; i++) {
     
    112118        double quality = values[0];
    113119
    114         if (double.IsNaN(quality)) quality = double.MaxValue;
    115         if (double.IsInfinity(quality)) quality = double.MaxValue;
     120        var worstQualityValue = MaximizationParameter.ActualValue.Value ? double.MinValue : double.MaxValue;
     121        if (double.IsNaN(quality)) quality = worstQualityValue;
     122        if (double.IsInfinity(quality)) quality = worstQualityValue;
    116123
    117124        QualityParameter.ActualValue = new DoubleValue(quality);
Note: See TracChangeset for help on using the changeset viewer.