Changeset 16950
- Timestamp:
- 05/13/19 22:56:49 (6 years ago)
- Location:
- branches/2521_ProblemRefactoring
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/BinaryVectorProblem.cs
r16948 r16950 63 63 } 64 64 65 public override void Analyze(BinaryVector[] individuals, double[] qualities, ResultCollection results, IRandom random) { 66 base.Analyze(individuals, qualities, results, random); 67 var orderedIndividuals = individuals.Zip(qualities, (i, q) => new { Individual = i, Quality = q }).OrderBy(z => z.Quality); 68 var best = Maximization ? orderedIndividuals.Last().Individual : orderedIndividuals.First().Individual; 65 public override void Analyze(BinaryVector[] vectors, double[] qualities, ResultCollection results, IRandom random) { 66 base.Analyze(vectors, qualities, results, random); 67 var best = GetBestSolution(vectors, qualities); 69 68 70 results.AddOrUpdateResult("Best Solution", (IItem)best. Clone());69 results.AddOrUpdateResult("Best Solution", (IItem)best.Item1.Clone()); 71 70 } 72 71 -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVectorProblem.cs
r16948 r16950 63 63 } 64 64 65 public override void Analyze(IntegerVector[] individuals, double[] qualities, ResultCollection results, IRandom random) { 66 base.Analyze(individuals, qualities, results, random); 67 var orderedIndividuals = individuals.Zip(qualities, (i, q) => new { Individual = i, Quality = q }).OrderBy(z => z.Quality); 68 var best = Maximization ? orderedIndividuals.Last().Individual : orderedIndividuals.First().Individual; 65 public override void Analyze(IntegerVector[] vectors, double[] qualities, ResultCollection results, IRandom random) { 66 base.Analyze(vectors, qualities, results, random); 67 var best = GetBestSolution(vectors, qualities); 69 68 70 results.AddOrUpdateResult("Best Solution", (IItem)best. Clone());69 results.AddOrUpdateResult("Best Solution", (IItem)best.Item1.Clone()); 71 70 } 72 71 -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/LinearLinkageProblem.cs
r16948 r16950 63 63 } 64 64 65 public override void Analyze(LinearLinkage[] individuals, double[] qualities, ResultCollection results, IRandom random) { 66 base.Analyze(individuals, qualities, results, random); 67 var orderedIndividuals = individuals.Zip(qualities, (i, q) => new { Individual = i, Quality = q }).OrderBy(z => z.Quality); 68 var best = Maximization ? orderedIndividuals.Last().Individual : orderedIndividuals.First().Individual; 65 public override void Analyze(LinearLinkage[] vectors, double[] qualities, ResultCollection results, IRandom random) { 66 base.Analyze(vectors, qualities, results, random); 67 var best = GetBestSolution(vectors, qualities); 69 68 70 results.AddOrUpdateResult("Best Solution", (Item)best. Clone());69 results.AddOrUpdateResult("Best Solution", (Item)best.Item1.Clone()); 71 70 } 72 71 -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.PermutationEncoding/3.3/PermutationProblem.cs
r16948 r16950 68 68 } 69 69 70 public override void Analyze(Permutation[] individuals, double[] qualities, ResultCollection results, IRandom random) { 71 base.Analyze(individuals, qualities, results, random); 72 var orderedIndividuals = individuals.Zip(qualities, (i, q) => new { Individual = i, Quality = q }).OrderBy(z => z.Quality); 73 var best = Maximization ? orderedIndividuals.Last().Individual : orderedIndividuals.First().Individual; 74 75 results.AddOrUpdateResult("Best Solution", (IItem)best.Clone()); 70 public override void Analyze(Permutation[] permutations, double[] qualities, ResultCollection results, IRandom random) { 71 base.Analyze(permutations, qualities, results, random); 72 var best = GetBestSolution(permutations, qualities); 73 results.AddOrUpdateResult("Best Solution", (IItem)best.Item1.Clone()); 76 74 } 77 75 -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.RealVectorEncoding/3.3/RealVectorProblem.cs
r16949 r16950 63 63 } 64 64 65 public override void Analyze(RealVector[] individuals, double[] qualities, ResultCollection results, IRandom random) { 66 base.Analyze(individuals, qualities, results, random); 67 var orderedIndividuals = individuals.Zip(qualities, (i, q) => new { Individual = i, Quality = q }).OrderBy(z => z.Quality); 68 var best = Maximization ? orderedIndividuals.Last().Individual : orderedIndividuals.First().Individual; 65 public override void Analyze(RealVector[] vectors, double[] qualities, ResultCollection results, IRandom random) { 66 base.Analyze(vectors, qualities, results, random); 67 var best = GetBestSolution(vectors, qualities); 69 68 70 results.AddOrUpdateResult("Best Solution", (IItem)best. Clone());69 results.AddOrUpdateResult("Best Solution", (IItem)best.Item1.Clone()); 71 70 } 72 71 -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/MultiObjectiveTestFunctionProblem.cs
r16949 r16950 73 73 set { ProblemSizeParameter.Value.Value = value; } 74 74 } 75 public int Objectives {75 public new int Objectives { 76 76 get { return ObjectivesParameter.Value.Value; } 77 77 set { ObjectivesParameter.Value.Value = value; } -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/TestFunctions/MultiObjectiveTestFunction.cs
r16723 r16950 22 22 using System; 23 23 using System.Collections.Generic; 24 using HEAL.Attic; 24 25 using HeuristicLab.Common; 25 26 using HeuristicLab.Core; … … 27 28 using HeuristicLab.Encodings.RealVectorEncoding; 28 29 using HeuristicLab.Parameters; 29 using HEAL.Attic;30 30 31 31 namespace HeuristicLab.Problems.TestFunctions.MultiObjective { … … 71 71 /// </summary> 72 72 public bool[] Maximization(int objectives) { 73 CheckObjectives(objectives);73 ThrowIfObjectivesOutOfRange(objectives); 74 74 return GetMaximization(objectives); 75 75 } … … 79 79 /// </summary> 80 80 public double[,] Bounds(int objectives) { 81 CheckObjectives(objectives);81 ThrowIfObjectivesOutOfRange(objectives); 82 82 return GetBounds(objectives); 83 83 } … … 88 88 /// </summary> 89 89 public IEnumerable<double[]> OptimalParetoFront(int objectives) { 90 CheckObjectives(objectives);90 ThrowIfObjectivesOutOfRange(objectives); 91 91 return GetOptimalParetoFront(objectives); 92 92 } … … 97 97 /// </summary> 98 98 public double[] ReferencePoint(int objectives) { 99 CheckObjectives(objectives);99 ThrowIfObjectivesOutOfRange(objectives); 100 100 return GetReferencePoint(objectives); 101 101 } … … 106 106 /// </summary> 107 107 public virtual double OptimalHypervolume(int objectives) { 108 CheckObjectives(objectives);108 ThrowIfObjectivesOutOfRange(objectives); 109 109 return GetBestKnownHypervolume(objectives); 110 110 } … … 114 114 } 115 115 116 protected void CheckObjectives(int objectives) {116 protected void ThrowIfObjectivesOutOfRange(int objectives) { 117 117 if (objectives < MinimumObjectives) throw new ArgumentException(string.Format("There must be at least {0} objectives", MinimumObjectives)); 118 118 if (objectives > MaximumObjectives) throw new ArgumentException(string.Format("There must be at most {0} objectives", MaximumObjectives)); … … 121 121 [StorableConstructor] 122 122 protected MultiObjectiveTestFunction(StorableConstructorFlag _) : base(_) { } 123 124 123 protected MultiObjectiveTestFunction(MultiObjectiveTestFunction original, Cloner cloner) 125 124 : base(original, cloner) { … … 129 128 MaximumSolutionLength = original.MaximumSolutionLength; 130 129 } 131 132 130 protected MultiObjectiveTestFunction(int minimumObjectives, int maximumObjectives, int minimumSolutionLength, int maximumSolutionLength) 133 131 : base() { -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.TestFunctions/3.3/SingleObjectiveTestFunctionProblem.cs
r16949 r16950 116 116 117 117 public override void Analyze(RealVector[] realVectors, double[] qualities, ResultCollection results, IRandom random) { 118 119 bool max = Maximization; 118 var best = GetBestSolution(realVectors, qualities); 119 120 120 DoubleValue bestKnownQuality = BestKnownQualityParameter.Value; 121 RealVector bestKnownSolution = null; 122 var bestKnownUpdate = bestKnownQuality == null || IsBetter(best.Item2, bestKnownQuality.Value); 123 if (bestKnownUpdate) { 124 if (bestKnownQuality != null) bestKnownQuality.Value = best.Item2; 125 else BestKnownQualityParameter.Value = bestKnownQuality = new DoubleValue(best.Item2); 126 BestKnownSolutionParameter.Value = bestKnownSolution = (RealVector)best.Item1.Clone(); 127 } 128 121 129 SingleObjectiveTestFunctionSolution solution = null; 122 130 if (results.TryGetValue("Best Solution", out var res)) { 123 131 solution = (SingleObjectiveTestFunctionSolution)res.Value; 124 } 125 126 int i = -1; 127 if (!max) i = qualities.Select((x, index) => new { index, quality = x }).OrderBy(x => x.quality).First().index; 128 else i = qualities.Select((x, index) => new { index, quality = x }).OrderByDescending(x => x.quality).First().index; 129 130 if (bestKnownQuality == null || 131 max && qualities[i] > bestKnownQuality.Value 132 || !max && qualities[i] < bestKnownQuality.Value) { 133 BestKnownQualityParameter.Value = new DoubleValue(qualities[i]); 134 BestKnownSolutionParameter.Value = (RealVector)realVectors[i].Clone(); 135 if (solution != null) 136 solution.BestKnownRealVector = BestKnownSolutionParameter.Value; 137 } 138 139 if (solution == null) { 140 solution = new SingleObjectiveTestFunctionSolution((RealVector)realVectors[i].Clone(), 141 new DoubleValue(qualities[i]), 142 TestFunctionParameter.Value); 143 solution.Population = realVectors[i].Length == 2 144 ? new ItemArray<RealVector>(realVectors.Select(x => x.Clone()).Cast<RealVector>()) 145 : null; 146 solution.BestKnownRealVector = BestKnownSolutionParameter.Value; 147 solution.Bounds = BoundsParameter.Value; 132 if (IsBetter(best.Item2, solution.BestQuality.Value)) { 133 solution.BestRealVector = (RealVector)best.Item1.Clone(); 134 solution.BestQuality = new DoubleValue(best.Item2); 135 } 136 } else { 137 solution = new SingleObjectiveTestFunctionSolution((RealVector)best.Item1.Clone(), 138 new DoubleValue(best.Item2), 139 TestFunctionParameter.Value) { 140 BestKnownRealVector = bestKnownSolution, 141 Bounds = BoundsParameter.Value 142 }; 148 143 results.Add(new Result("Best Solution", solution)); 149 } else { 150 if (max && qualities[i] > solution.BestQuality.Value 151 || !max && qualities[i] < solution.BestQuality.Value) { 152 solution.BestRealVector = (RealVector)realVectors[i].Clone(); 153 solution.BestQuality = new DoubleValue(qualities[i]); 154 } 155 solution.Population = realVectors[i].Length == 2 156 ? new ItemArray<RealVector>(realVectors.Select(x => x.Clone()).Cast<RealVector>()) 157 : null; 158 } 144 } 145 if (best.Item1.Length == 2) solution.Population = new ItemArray<RealVector>(realVectors.Select(x => (RealVector)x.Clone())); 146 if (bestKnownUpdate) solution.BestKnownRealVector = bestKnownSolution; 159 147 } 160 148
Note: See TracChangeset
for help on using the changeset viewer.