Changeset 3787
- Timestamp:
- 05/11/10 21:16:12 (15 years ago)
- Location:
- trunk/sources
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Analysis/3.3/BestAverageWorstQualityAnalyzer.cs
r3662 r3787 77 77 get { return (BestQualityMemorizer)OperatorGraph.InitialOperator; } 78 78 } 79 private BestQualityMemorizer BestKnownQualityMemorizer {80 get { return (BestQualityMemorizer)BestQualityMemorizer.Successor; }81 }82 79 private BestAverageWorstQualityCalculator BestAverageWorstQualityCalculator { 83 get { return (BestAverageWorstQualityCalculator)Best KnownQualityMemorizer.Successor; }80 get { return (BestAverageWorstQualityCalculator)BestQualityMemorizer.Successor; } 84 81 } 85 82 #endregion … … 103 100 #region Create operators 104 101 BestQualityMemorizer bestQualityMemorizer = new BestQualityMemorizer(); 105 BestQualityMemorizer bestKnownQualityMemorizer = new BestQualityMemorizer();106 102 BestAverageWorstQualityCalculator bestAverageWorstQualityCalculator = new BestAverageWorstQualityCalculator(); 107 103 DataTableValuesCollector dataTableValuesCollector = new DataTableValuesCollector(); … … 113 109 bestQualityMemorizer.QualityParameter.ActualName = QualityParameter.Name; 114 110 bestQualityMemorizer.QualityParameter.Depth = QualityParameter.Depth; 115 116 bestKnownQualityMemorizer.BestQualityParameter.ActualName = BestKnownQualityParameter.Name;117 bestKnownQualityMemorizer.MaximizationParameter.ActualName = MaximizationParameter.Name;118 bestKnownQualityMemorizer.QualityParameter.ActualName = QualityParameter.Name;119 bestKnownQualityMemorizer.QualityParameter.Depth = QualityParameter.Depth;120 111 121 112 bestAverageWorstQualityCalculator.AverageQualityParameter.ActualName = CurrentAverageQualityParameter.Name; … … 151 142 #region Create operator graph 152 143 OperatorGraph.InitialOperator = bestQualityMemorizer; 153 bestQualityMemorizer.Successor = bestKnownQualityMemorizer; 154 bestKnownQualityMemorizer.Successor = bestAverageWorstQualityCalculator; 144 bestQualityMemorizer.Successor = bestAverageWorstQualityCalculator; 155 145 bestAverageWorstQualityCalculator.Successor = dataTableValuesCollector; 156 146 dataTableValuesCollector.Successor = qualityDifferenceCalculator; … … 177 167 private void QualityParameter_DepthChanged(object sender, System.EventArgs e) { 178 168 BestQualityMemorizer.QualityParameter.Depth = QualityParameter.Depth; 179 BestKnownQualityMemorizer.QualityParameter.Depth = QualityParameter.Depth;180 169 BestAverageWorstQualityCalculator.QualityParameter.Depth = QualityParameter.Depth; 181 170 } -
trunk/sources/HeuristicLab.Problems.Knapsack/3.3/Analyzers/BestKnapsackSolutionAnalyzer.cs
r3667 r3787 39 39 [StorableClass] 40 40 class BestKnapsackSolutionAnalyzer : 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"]; } … … 61 63 get { return (ValueLookupParameter<ResultCollection>)Parameters["Results"]; } 62 64 } 65 public LookupParameter<DoubleValue> BestKnownQualityParameter { 66 get { return (LookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; } 67 } 68 public LookupParameter<BinaryVector> BestKnownSolutionParameter { 69 get { return (LookupParameter<BinaryVector>)Parameters["BestKnownSolution"]; } 70 } 63 71 64 72 public BestKnapsackSolutionAnalyzer() 65 73 : base() { 74 Parameters.Add(new LookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem.")); 66 75 Parameters.Add(new ScopeTreeLookupParameter<BinaryVector>("BinaryVector", "The knapsack solutions from which the best solution should be visualized.")); 67 76 Parameters.Add(new LookupParameter<IntValue>("KnapsackCapacity", "Capacity of the Knapsack.")); … … 72 81 Parameters.Add(new LookupParameter<KnapsackSolution>("BestSolution", "The best knapsack solution.")); 73 82 Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the knapsack solution should be stored.")); 83 Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution.")); 84 Parameters.Add(new LookupParameter<BinaryVector>("BestKnownSolution", "The best known solution.")); 74 85 } 75 86 … … 78 89 ItemArray<DoubleValue> qualities = QualityParameter.ActualValue; 79 90 ResultCollection results = ResultsParameter.ActualValue; 91 bool max = MaximizationParameter.ActualValue.Value; 92 DoubleValue bestKnownQuality = BestKnownQualityParameter.ActualValue; 80 93 81 int i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index; 94 int i = -1; 95 if (!max) 96 i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index; 97 else i = qualities.Select((x, index) => new { index, x.Value }).OrderByDescending(x => x.Value).First().index; 98 99 if (bestKnownQuality == null || 100 max && qualities[i].Value > bestKnownQuality.Value || 101 !max && qualities[i].Value < bestKnownQuality.Value) { 102 BestKnownQualityParameter.ActualValue = new DoubleValue(qualities[i].Value); 103 BestKnownSolutionParameter.ActualValue = (BinaryVector)binaryVectors[i].Clone(); 104 } 82 105 83 106 KnapsackSolution solution = BestSolutionParameter.ActualValue; 84 107 if (solution == null) { 85 solution = new KnapsackSolution( binaryVectors[i], qualities[i],108 solution = new KnapsackSolution((BinaryVector)binaryVectors[i].Clone(), new DoubleValue(qualities[i].Value), 86 109 KnapsackCapacityParameter.ActualValue, WeightsParameter.ActualValue, ValuesParameter.ActualValue); 87 110 BestSolutionParameter.ActualValue = solution; 88 111 results.Add(new Result("Best Knapsack Solution", solution)); 89 112 } else { 90 solution.BinaryVector = binaryVectors[i]; 91 solution.Quality = qualities[i]; 92 solution.Capacity = KnapsackCapacityParameter.ActualValue; 93 solution.Weights = WeightsParameter.ActualValue; 94 solution.Values = ValuesParameter.ActualValue; 95 96 results["Best Knapsack Solution"].Value = solution; 113 if (max && qualities[i].Value > solution.Quality.Value || 114 !max && qualities[i].Value < solution.Quality.Value) { 115 solution.BinaryVector = (BinaryVector)binaryVectors[i].Clone(); 116 solution.Quality = new DoubleValue(qualities[i].Value); 117 solution.Capacity = KnapsackCapacityParameter.ActualValue; 118 solution.Weights = WeightsParameter.ActualValue; 119 solution.Values = ValuesParameter.ActualValue; 120 } 97 121 } 98 122 -
trunk/sources/HeuristicLab.Problems.Knapsack/3.3/KnapsackProblem.cs
r3739 r3787 80 80 get { return BestKnownQualityParameter; } 81 81 } 82 public OptionalValueParameter<BinaryVector> BestKnownSolutionParameter { 83 get { return (OptionalValueParameter<BinaryVector>)Parameters["BestKnownSolution"]; } 84 } 82 85 #endregion 83 86 … … 119 122 get { return BestKnownQualityParameter.Value; } 120 123 set { BestKnownQualityParameter.Value = value; } 124 } 125 public BinaryVector BestKnownSolution { 126 get { return BestKnownSolutionParameter.Value; } 127 set { BestKnownSolutionParameter.Value = value; } 121 128 } 122 129 private List<IOperator> operators; … … 164 171 Parameters.Add(new ValueParameter<IKnapsackEvaluator>("Evaluator", "The operator which should be used to evaluate Knapsack solutions.", evaluator)); 165 172 Parameters.Add(new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this Knapsack instance.")); 173 Parameters.Add(new OptionalValueParameter<BinaryVector>("BestKnownSolution", "The best known solution of this Knapsack instance.")); 166 174 167 175 creator.BinaryVectorParameter.ActualName = "KnapsackSolution"; -
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 -
trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/Analyzers/BestSingleObjectiveTestFunctionSolutionAnalyzer.cs
r3781 r3787 39 39 [StorableClass] 40 40 class BestSingleObjectiveTestFunctionSolutionAnalyzer : SingleSuccessorOperator, IBestSingleObjectiveTestFunctionSolutionAnalyzer, IAnalyzer { 41 41 public LookupParameter<BoolValue> MaximizationParameter { 42 get { return (LookupParameter<BoolValue>)Parameters["Maximization"]; } 43 } 42 44 public ScopeTreeLookupParameter<RealVector> RealVectorParameter { 43 45 get { return (ScopeTreeLookupParameter<RealVector>)Parameters["RealVector"]; } … … 70 72 public BestSingleObjectiveTestFunctionSolutionAnalyzer() 71 73 : base() { 74 Parameters.Add(new LookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem.")); 72 75 Parameters.Add(new ScopeTreeLookupParameter<RealVector>("RealVector", "The SingleObjectiveTestFunction solutions from which the best solution should be visualized.")); 73 76 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The qualities of the SingleObjectiveTestFunction solutions which should be visualized.")); … … 84 87 ResultCollection results = ResultsParameter.ActualValue; 85 88 ISingleObjectiveTestFunctionProblemEvaluator evaluator = EvaluatorParameter.ActualValue; 86 bool max = evaluator.Maximization; 89 bool max = MaximizationParameter.ActualValue.Value; 90 DoubleValue bestKnownQuality = BestKnownQualityParameter.ActualValue; 87 91 88 92 int i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index; 93 94 if (bestKnownQuality == null || 95 max && qualities[i].Value > bestKnownQuality.Value 96 || !max && qualities[i].Value < bestKnownQuality.Value) { 97 BestKnownQualityParameter.ActualValue = new DoubleValue(qualities[i].Value); 98 BestKnownSolutionParameter.ActualValue = (RealVector)realVectors[i].Clone(); 99 } 100 89 101 SingleObjectiveTestFunctionSolution solution = BestSolutionParameter.ActualValue; 90 102 if (solution == null) { 91 103 solution = new SingleObjectiveTestFunctionSolution(realVectors[i], qualities[i], evaluator); 92 104 solution.Population = realVectors; 93 double bestknownQuality = BestKnownQualityParameter.ActualValue.Value;94 if (max && qualities[i].Value >= bestknownQuality95 || !max && qualities[i].Value <= bestknownQuality) {96 BestKnownSolutionParameter.ActualValue = (RealVector)realVectors[i].Clone();97 }98 105 solution.BestKnownRealVector = BestKnownSolutionParameter.ActualValue; 99 106 BestSolutionParameter.ActualValue = solution; 100 results.Add(new Result("Best S ingleObjectiveTestFunction Solution", solution));107 results.Add(new Result("Best Solution", solution)); 101 108 } else { 102 double bestknownQuality = BestKnownQualityParameter.ActualValue.Value;103 if (max && qualities[i].Value >= bestknownQuality104 || !max && qualities[i].Value <= bestknownQuality) {105 BestKnownSolutionParameter.ActualValue = (RealVector)realVectors[i].Clone();106 }107 109 if (max && qualities[i].Value > solution.BestQuality.Value 108 110 || !max && qualities[i].Value < solution.BestQuality.Value) { … … 111 113 } 112 114 solution.Population = realVectors; 113 //results["Best SingleObjectiveTestFunction Solution"].Value = solution;114 115 } 115 116 -
trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/Analyzers/BestTSPSolutionAnalyzer.cs
r3692 r3787 37 37 [StorableClass] 38 38 public sealed class BestTSPSolutionAnalyzer : SingleSuccessorOperator, IAnalyzer { 39 public LookupParameter<BoolValue> MaximizationParameter { 40 get { return (LookupParameter<BoolValue>)Parameters["Maximization"]; } 41 } 39 42 public LookupParameter<DoubleMatrix> CoordinatesParameter { 40 43 get { return (LookupParameter<DoubleMatrix>)Parameters["Coordinates"]; } … … 52 55 get { return (ValueLookupParameter<ResultCollection>)Parameters["Results"]; } 53 56 } 57 public LookupParameter<DoubleValue> BestKnownQualityParameter { 58 get { return (LookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; } 59 } 60 public LookupParameter<Permutation> BestKnownSolutionParameter { 61 get { return (LookupParameter<Permutation>)Parameters["BestKnownSolution"]; } 62 } 54 63 55 64 public BestTSPSolutionAnalyzer() 56 65 : base() { 66 Parameters.Add(new LookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem.")); 57 67 Parameters.Add(new LookupParameter<DoubleMatrix>("Coordinates", "The x- and y-Coordinates of the cities.")); 58 68 Parameters.Add(new ScopeTreeLookupParameter<Permutation>("Permutation", "The TSP solutions given in path representation from which the best solution should be analyzed.")); … … 60 70 Parameters.Add(new LookupParameter<PathTSPTour>("BestSolution", "The best TSP solution.")); 61 71 Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the best TSP solution should be stored.")); 72 Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this TSP instance.")); 73 Parameters.Add(new LookupParameter<Permutation>("BestKnownSolution", "The best known solution of this TSP instance.")); 62 74 } 63 75 … … 67 79 ItemArray<DoubleValue> qualities = QualityParameter.ActualValue; 68 80 ResultCollection results = ResultsParameter.ActualValue; 81 bool max = MaximizationParameter.ActualValue.Value; 82 DoubleValue bestKnownQuality = BestKnownQualityParameter.ActualValue; 69 83 70 int i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index; 84 int i = -1; 85 if (!max) 86 i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index; 87 else i = qualities.Select((x, index) => new { index, x.Value }).OrderByDescending(x => x.Value).First().index; 88 89 if (bestKnownQuality == null || 90 max && qualities[i].Value > bestKnownQuality.Value || 91 !max && qualities[i].Value < bestKnownQuality.Value) { 92 BestKnownQualityParameter.ActualValue = new DoubleValue(qualities[i].Value); 93 BestKnownSolutionParameter.ActualValue = (Permutation)permutations[i].Clone(); 94 } 71 95 72 96 PathTSPTour tour = BestSolutionParameter.ActualValue; … … 76 100 results.Add(new Result("Best TSP Solution", tour)); 77 101 } else { 78 if (tour.Quality.Value > qualities[i].Value) { 102 if (max && tour.Quality.Value < qualities[i].Value || 103 !max && tour.Quality.Value > qualities[i].Value) { 79 104 tour.Coordinates = coordinates; 80 105 tour.Permutation = (Permutation)permutations[i].Clone(); 81 106 tour.Quality.Value = qualities[i].Value; 82 results["Best TSP Solution"].Value = tour;83 107 } 84 108 }
Note: See TracChangeset
for help on using the changeset viewer.