Changeset 3894
- Timestamp:
- 06/02/10 21:34:31 (15 years ago)
- Location:
- trunk/sources
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.TestFunctions.Views/3.3/SingleObjectiveTestFunctionSolutionView.cs
r3668 r3894 55 55 Content.QualityChanged -= new EventHandler(Content_QualityChanged); 56 56 Content.PopulationChanged -= new EventHandler(Content_PopulationChanged); 57 Content.BoundsChanged -= new EventHandler(Content_BoundsChanged); 57 58 base.DeregisterContentEvents(); 58 59 } … … 63 64 Content.QualityChanged += new EventHandler(Content_QualityChanged); 64 65 Content.PopulationChanged += new EventHandler(Content_PopulationChanged); 66 Content.BoundsChanged += new EventHandler(Content_BoundsChanged); 65 67 } 66 68 … … 99 101 GenerateImage(); 100 102 } 103 } 104 105 private void Content_BoundsChanged(object sender, EventArgs e) { 106 if (InvokeRequired) 107 Invoke(new EventHandler(Content_BoundsChanged), sender, e); 108 else 109 GenerateImage(); 101 110 } 102 111 … … 139 148 } 140 149 pictureBox.Refresh(); 141 DoubleMatrix bounds = Content.Evaluator.Bounds; 150 DoubleMatrix bounds = Content.Bounds; 151 if (bounds == null) bounds = Content.Evaluator.Bounds; 142 152 double xMin = bounds[0, 0], xMax = bounds[0, 1], yMin = bounds[1 % bounds.Rows, 0], yMax = bounds[1 % bounds.Rows, 1]; 143 153 double xStep = backgroundImage.Width / (xMax - xMin), yStep = backgroundImage.Height / (yMax - yMin); … … 164 174 backgroundImage.Dispose(); 165 175 backgroundImage = new Bitmap(pictureBox.Width, pictureBox.Height); 166 DoubleMatrix bounds = Content.Evaluator.Bounds; 176 DoubleMatrix bounds = Content.Bounds; 177 if (bounds == null) bounds = Content.Evaluator.Bounds; 167 178 double xMin = bounds[0, 0], xMax = bounds[0, 1], yMin = bounds[1 % bounds.Rows, 0], yMax = bounds[1 % bounds.Rows, 1]; 168 179 double xStep = (xMax - xMin) / backgroundImage.Width, yStep = (yMax - yMin) / backgroundImage.Height; -
trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/Analyzers/BestSingleObjectiveTestFunctionSolutionAnalyzer.cs
r3797 r3894 69 69 get { return (IValueLookupParameter<ISingleObjectiveTestFunctionProblemEvaluator>)Parameters["Evaluator"]; } 70 70 } 71 public ILookupParameter<DoubleMatrix> BoundsParameter { 72 get { return (ILookupParameter<DoubleMatrix>)Parameters["Bounds"]; } 73 } 71 74 75 protected BestSingleObjectiveTestFunctionSolutionAnalyzer(bool deserializing) : base(deserializing) { } 72 76 public BestSingleObjectiveTestFunctionSolutionAnalyzer() 73 77 : base() { … … 80 84 Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the SingleObjectiveTestFunction solution should be stored.")); 81 85 Parameters.Add(new ValueLookupParameter<ISingleObjectiveTestFunctionProblemEvaluator>("Evaluator", "The evaluator with which the solution is evaluated.")); 86 Parameters.Add(new LookupParameter<DoubleMatrix>("Bounds", "The bounds of the function.")); 87 } 88 89 /// <summary> 90 /// This method can simply be removed when the plugin version is > 3.3 91 /// </summary> 92 [StorableHook(HookType.AfterDeserialization)] 93 private void CompatibilityMethod() { 94 // Bounds are introduced in 3.3.0.3894 95 if (!Parameters.ContainsKey("Bounds")) 96 Parameters.Add(new LookupParameter<DoubleMatrix>("Bounds", "The bounds of the function.")); 82 97 } 83 98 … … 85 100 ItemArray<RealVector> realVectors = RealVectorParameter.ActualValue; 86 101 ItemArray<DoubleValue> qualities = QualityParameter.ActualValue; 87 ResultCollection results = ResultsParameter.ActualValue;88 ISingleObjectiveTestFunctionProblemEvaluator evaluator = EvaluatorParameter.ActualValue;89 102 bool max = MaximizationParameter.ActualValue.Value; 90 103 DoubleValue bestKnownQuality = BestKnownQualityParameter.ActualValue; 104 SingleObjectiveTestFunctionSolution solution = BestSolutionParameter.ActualValue; 91 105 92 106 int i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index; … … 97 111 BestKnownQualityParameter.ActualValue = new DoubleValue(qualities[i].Value); 98 112 BestKnownSolutionParameter.ActualValue = (RealVector)realVectors[i].Clone(); 113 if (solution != null) 114 solution.BestKnownRealVector = BestKnownSolutionParameter.ActualValue; 99 115 } 100 116 101 SingleObjectiveTestFunctionSolution solution = BestSolutionParameter.ActualValue;102 117 if (solution == null) { 103 solution = new SingleObjectiveTestFunctionSolution(realVectors[i], qualities[i], evaluator); 118 ResultCollection results = ResultsParameter.ActualValue; 119 solution = new SingleObjectiveTestFunctionSolution(realVectors[i], qualities[i], EvaluatorParameter.ActualValue); 104 120 solution.Population = realVectors; 105 121 solution.BestKnownRealVector = BestKnownSolutionParameter.ActualValue; 122 solution.Bounds = BoundsParameter.ActualValue; 106 123 BestSolutionParameter.ActualValue = solution; 107 124 results.Add(new Result("Best Solution", solution)); -
trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/Interfaces/IBestSingleObjectiveTestFunctionSolutionAnalyzer.cs
r3647 r3894 26 26 namespace HeuristicLab.Problems.TestFunctions { 27 27 /// <summary> 28 /// An interface which represents operators for analyzing the best solution of single objective TestFunction Problems given in bitvector representation.28 /// An interface which represents operators for analyzing the best solution of single objective TestFunction Problems given in real vector representation. 29 29 /// </summary> 30 30 public interface IBestSingleObjectiveTestFunctionSolutionAnalyzer : IAnalyzer { -
trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/SingleObjectiveTestFunctionProblem.cs
r3865 r3894 307 307 BestSingleObjectiveTestFunctionSolutionAnalyzer.MaximizationParameter.ActualName = MaximizationParameter.Name; 308 308 BestSingleObjectiveTestFunctionSolutionAnalyzer.EvaluatorParameter.ActualName = EvaluatorParameter.Name; 309 BestSingleObjectiveTestFunctionSolutionAnalyzer.BoundsParameter.ActualName = BoundsParameter.Name; 309 310 } 310 311 private void InitializeOperators() { -
trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/SingleObjectiveTestFunctionSolution.cs
r3665 r3894 108 108 } 109 109 110 [Storable] 111 private DoubleMatrix bounds; 112 public DoubleMatrix Bounds { 113 get { return bounds; } 114 set { 115 if (bounds != value) { 116 if (bounds != null) DeregisterBoundsEvents(); 117 bounds = value; 118 if (bounds != null) RegisterBoundsEvents(); 119 OnBoundsChanged(); 120 } 121 } 122 } 123 110 124 public SingleObjectiveTestFunctionSolution() : base() { } 111 125 public SingleObjectiveTestFunctionSolution(RealVector realVector, DoubleValue quality, ISingleObjectiveTestFunctionProblemEvaluator evaluator) … … 125 139 if (bestQuality != null) RegisterQualityEvents(); 126 140 if (population != null) RegisterPopulationEvents(); 141 if (bounds != null) RegisterBoundsEvents(); 127 142 } 128 143 … … 135 150 clone.population = (ItemArray<RealVector>)cloner.Clone(population); 136 151 clone.evaluator = (ISingleObjectiveTestFunctionProblemEvaluator)cloner.Clone(evaluator); 152 clone.bounds = (DoubleMatrix)cloner.Clone(bounds); 137 153 clone.Initialize(); 138 154 return clone; … … 175 191 } 176 192 193 public event EventHandler BoundsChanged; 194 private void OnBoundsChanged() { 195 var changed = BoundsChanged; 196 if (changed != null) 197 changed(this, EventArgs.Empty); 198 } 199 177 200 private void RegisterBestKnownRealVectorEvents() { 178 201 BestKnownRealVector.ItemChanged += new EventHandler<EventArgs<int>>(BestKnownRealVector_ItemChanged); … … 207 230 Population.ItemsReplaced -= new CollectionItemsChangedEventHandler<IndexedItem<RealVector>>(Population_ItemsReplaced); 208 231 } 232 private void RegisterBoundsEvents() { 233 Bounds.ItemChanged += new EventHandler<EventArgs<int, int>>(Bounds_ItemChanged); 234 Bounds.Reset += new EventHandler(Bounds_Reset); 235 } 236 private void DeregisterBoundsEvents() { 237 Bounds.ItemChanged -= new EventHandler<EventArgs<int, int>>(Bounds_ItemChanged); 238 Bounds.Reset -= new EventHandler(Bounds_Reset); 239 } 209 240 210 241 private void BestKnownRealVector_ItemChanged(object sender, EventArgs<int> e) { … … 231 262 private void Population_CollectionReset(object sender, CollectionItemsChangedEventArgs<IndexedItem<RealVector>> e) { 232 263 OnPopulationChanged(); 264 } 265 private void Bounds_ItemChanged(object sender, EventArgs<int, int> e) { 266 OnBoundsChanged(); 267 } 268 private void Bounds_Reset(object sender, EventArgs e) { 269 OnBoundsChanged(); 233 270 } 234 271 #endregion
Note: See TracChangeset
for help on using the changeset viewer.