Changeset 11076
- Timestamp:
- 07/02/14 17:36:38 (10 years ago)
- 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 75 75 Parameters.Add(new FixedValueParameter<StringValue>(QualityVariableParameterName, "The name of the quality variable of the Scilab script.", new StringValue("quality"))); 76 76 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 th e should be execute before the evaluationstarts.", 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())); 78 78 79 79 ScilabEvaluationScript.FileDialogFilter = @"Scilab Scripts|*.sce|All files|*.*"; -
trunk/sources/HeuristicLab.Problems.ExternalEvaluation.Scilab/3.3/ScilabParameterVectorEvaluator.cs
r10605 r11076 35 35 [StorableClass] 36 36 public sealed class ScilabParameterVectorEvaluator : ParameterVectorEvaluator { 37 private const string MaximizationParameterName = "Maximization"; 37 38 private const string QualityVariableParameterName = "QualityVariableName"; 38 39 private const string ScilabEvaluationScriptParameterName = "ScilabEvaluationScript"; … … 40 41 41 42 #region parameters 43 public ILookupParameter<BoolValue> MaximizationParameter { 44 get { return (ILookupParameter<BoolValue>)Parameters[MaximizationParameterName]; } 45 } 42 46 public ILookupParameter<StringValue> QualityVariableParameter { 43 47 get { return (ILookupParameter<StringValue>)Parameters[QualityVariableParameterName]; } … … 62 66 public ScilabParameterVectorEvaluator() 63 67 : base() { 68 Parameters.Add(new LookupParameter<BoolValue>(MaximizationParameterName, "The flag which determines if this is a maximization problem.")); 64 69 Parameters.Add(new LookupParameter<StringValue>(QualityVariableParameterName, "The name of the quality variable of the Scilab script.")); 65 70 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 th e should be execute before the evaluationstarts."));71 Parameters.Add(new LookupParameter<TextFileValue>(ScilabInitializationScriptParameterName, "The path to a Scilab script that should be executed once when the algorithm starts.")); 67 72 } 68 73 69 private readonly object locker = new object();74 private static readonly object locker = new object(); 70 75 private static ScilabConnector scilab = null; 71 76 private bool startedScilab = false; … … 80 85 81 86 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. 83 89 lock (locker) { 84 90 //initialize scilab and execute initialization script … … 86 92 startedScilab = true; 87 93 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); 92 96 } else if (!startedScilab) { 93 97 throw new InvalidOperationException("Could not run multiple optimization algorithms in parallel."); … … 96 100 var parameterVector = ParameterVectorParameter.ActualValue; 97 101 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."); 99 105 100 106 for (int i = 0; i < ProblemSizeParameter.ActualValue.Value; i++) { … … 112 118 double quality = values[0]; 113 119 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; 116 123 117 124 QualityParameter.ActualValue = new DoubleValue(quality);
Note: See TracChangeset
for help on using the changeset viewer.