Changeset 3787 for trunk/sources/HeuristicLab.Problems.OneMax/3.3/Analyzers
- Timestamp:
- 05/11/10 21:16:12 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.OneMax/3.3/Analyzers/BestOneMaxSolutionAnalyzer.cs
r3667 r3787 39 39 [StorableClass] 40 40 class BestOneMaxSolutionAnalyzer : SingleSuccessorOperator, IAnalyzer { 41 41 public LookupParameter<BoolValue> MaximizationParameter { 42 get { return (LookupParameter<BoolValue>)Parameters["Maximization"]; } 43 } 42 44 public ScopeTreeLookupParameter<BinaryVector> BinaryVectorParameter { 43 45 get { return (ScopeTreeLookupParameter<BinaryVector>)Parameters["BinaryVector"]; } … … 52 54 get { return (ValueLookupParameter<ResultCollection>)Parameters["Results"]; } 53 55 } 56 public LookupParameter<DoubleValue> BestKnownQualityParameter { 57 get { return (LookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; } 58 } 54 59 55 60 public BestOneMaxSolutionAnalyzer() 56 61 : base() { 62 Parameters.Add(new LookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem.")); 57 63 Parameters.Add(new ScopeTreeLookupParameter<BinaryVector>("BinaryVector", "The Onemax solutions from which the best solution should be visualized.")); 58 59 64 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The qualities of the Onemax solutions which should be visualized.")); 60 65 Parameters.Add(new LookupParameter<OneMaxSolution>("BestSolution", "The best Onemax solution.")); 61 66 Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the Onemax solution should be stored.")); 67 Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution.")); 62 68 } 63 69 … … 66 72 ItemArray<DoubleValue> qualities = QualityParameter.ActualValue; 67 73 ResultCollection results = ResultsParameter.ActualValue; 74 bool max = MaximizationParameter.ActualValue.Value; 75 DoubleValue bestKnownQuality = BestKnownQualityParameter.ActualValue; 68 76 69 int i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index; 77 int i = -1; 78 if (!max) 79 i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index; 80 else i = qualities.Select((x, index) => new { index, x.Value }).OrderByDescending(x => x.Value).First().index; 81 82 if (bestKnownQuality == null || 83 max && qualities[i].Value > bestKnownQuality.Value || 84 !max && qualities[i].Value < bestKnownQuality.Value) { 85 BestKnownQualityParameter.ActualValue = new DoubleValue(qualities[i].Value); 86 } 70 87 71 88 OneMaxSolution solution = BestSolutionParameter.ActualValue; 72 89 if (solution == null) { 73 solution = new OneMaxSolution( binaryVectors[i], QualityParameter.ActualValue[i]);90 solution = new OneMaxSolution((BinaryVector)binaryVectors[i].Clone(), new DoubleValue(qualities[i].Value)); 74 91 BestSolutionParameter.ActualValue = solution; 75 92 results.Add(new Result("Best OneMax Solution", solution)); 76 93 } else { 77 solution.BinaryVector = binaryVectors[i]; 78 solution.Quality = QualityParameter.ActualValue[i]; 79 80 results["Best OneMax Solution"].Value = solution; 94 if (max && qualities[i].Value > solution.Quality.Value || 95 !max && qualities[i].Value < solution.Quality.Value) { 96 solution.BinaryVector = (BinaryVector)binaryVectors[i].Clone(); 97 solution.Quality = new DoubleValue(qualities[i].Value); 98 } 81 99 } 82 100
Note: See TracChangeset
for help on using the changeset viewer.