Changeset 17279
- Timestamp:
- 09/27/19 17:51:35 (5 years ago)
- Location:
- branches/2521_ProblemRefactoring
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/SingleObjectiveProblem.cs
r17270 r17279 38 38 where TEncodedSolution : class, IEncodedSolution { 39 39 40 [Storable] protected IValueParameter<DoubleValue> BestKnownQualityParameter { get; set;}41 [Storable] protected IValueParameter<BoolValue> MaximizationParameter { get; set;}40 [Storable] protected IValueParameter<DoubleValue> BestKnownQualityParameter { get; } 41 [Storable] protected IValueParameter<BoolValue> MaximizationParameter { get; } 42 42 43 43 public double BestKnownQuality { … … 60 60 protected set { 61 61 if (MaximizationParameter.Value.Value == value) return; 62 MaximizationParameter.ReadOnly = false; 62 63 MaximizationParameter.Value = new BoolValue(value).AsReadOnly(); 64 MaximizationParameter.ReadOnly = true; 63 65 } 64 66 } … … 73 75 ParameterizeOperators(); 74 76 } 75 77 76 78 protected SingleObjectiveProblem() : base() { 77 Parameters.Add(MaximizationParameter = new ValueParameter<BoolValue>("Maximization", "Whether the problem should be maximized (True) or minimized (False).", new BoolValue(false).AsReadOnly()) { Hidden = true, ReadOnly = true }); 78 Parameters.Add(BestKnownQualityParameter = new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this problem.")); 79 80 MaximizationParameter = new ValueParameter<BoolValue>("Maximization", "Whether the problem should be maximized (True) or minimized (False).", new BoolValue(false).AsReadOnly()) { Hidden = true, ReadOnly = true }; 81 BestKnownQualityParameter = new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this problem."); 82 83 Parameters.Add(MaximizationParameter); 84 Parameters.Add(BestKnownQualityParameter); 79 85 80 86 Operators.Add(Evaluator); … … 113 119 } 114 120 121 public static bool IsBetter(bool maximization, double quality, double bestQuality) { 122 return (maximization && quality > bestQuality || !maximization && quality < bestQuality); 123 } 124 115 125 public virtual bool IsBetter(double quality, double bestQuality) { 116 return (Maximization && quality > bestQuality || !Maximization && quality <bestQuality);126 return IsBetter(Maximization, quality, bestQuality); 117 127 } 118 128 -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/SingleObjectiveExternalEvaluationProblem.cs
r17270 r17279 93 93 public ExternalEvaluationProblem(TEncoding encoding) 94 94 : base(encoding) { 95 MaximizationParameter.ReadOnly = false; 96 MaximizationParameter.Value = new BoolValue(); // is a read-only boolvalue in base class 95 MaximizationParameter.Value = new BoolValue(); // is a read-only bool value in base class 97 96 Parameters.Add(new OptionalValueParameter<EvaluationCache>("Cache", "Cache of previously evaluated solutions.")); 98 97 Parameters.Add(new ValueParameter<CheckedItemCollection<IEvaluationServiceClient>>("Clients", "The clients that are used to communicate with the external application.", new CheckedItemCollection<IEvaluationServiceClient>() { new EvaluationServiceClient() })); … … 148 147 try { 149 148 return client.Evaluate(message, GetQualityMessageExtensions()); 150 } 151 finally { 149 } finally { 152 150 lock (clientLock) { 153 151 activeClients.Remove(client); … … 166 164 try { 167 165 MessageBuilder.AddToMessage(variable.Value, variable.Name, protobufBuilder); 168 } 169 catch (ArgumentException ex) { 166 } catch (ArgumentException ex) { 170 167 throw new InvalidOperationException(string.Format("ERROR while building solution message: Parameter {0} cannot be added to the message", Name), ex); 171 168 }
Note: See TracChangeset
for help on using the changeset viewer.