Changeset 17747 for branches/2521_ProblemRefactoring
- Timestamp:
- 09/15/20 17:09:10 (4 years ago)
- Location:
- branches/2521_ProblemRefactoring
- Files:
-
- 5 deleted
- 29 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.CMAEvolutionStrategy/3.4/CMAAnalyzer.cs
r17226 r17747 22 22 using System; 23 23 using System.Linq; 24 using HEAL.Attic; 24 25 using HeuristicLab.Analysis; 25 26 using HeuristicLab.Common; … … 30 31 using HeuristicLab.Optimization; 31 32 using HeuristicLab.Parameters; 32 using HEAL.Attic;33 33 34 34 namespace HeuristicLab.Algorithms.CMAEvolutionStrategy { … … 98 98 progress.Rows.Add(new DataRow("Avg Quality")); 99 99 progress.VisualProperties.YAxisLogScale = true; 100 results.Add(new Result("Progress", progress));100 results.Add(new Result("Progress", "The quality progress over time on a log scale.", progress)); 101 101 } 102 102 progress.Rows["AxisRatio"].Values.Add(sp.AxisRatio); … … 114 114 for (int i = 0; i < sp.C.GetLength(0); i++) 115 115 scaling.Rows.Add(new DataRow("Axis" + i.ToString())); 116 results.Add(new Result("Scaling", scaling));116 results.Add(new Result("Scaling", "The extent to which the individual dimensions are scaled by the mutation.", scaling)); 117 117 } 118 118 for (int i = 0; i < sp.C.GetLength(0); i++) … … 126 126 for (int i = 0; i < vector.Length; i++) 127 127 realVector.Rows.Add(new DataRow("Axis" + i.ToString())); 128 results.Add(new Result("Object Variables", realVector));128 results.Add(new Result("Object Variables", "The value of the centroid point.", realVector)); 129 129 } 130 130 for (int i = 0; i < vector.Length; i++) … … 141 141 for (int i = 0; i < vector.Length; i++) 142 142 stdDevs.Rows.Add(new DataRow("Axis" + i.ToString())); 143 results.Add(new Result("Standard Deviations", stdDevs));143 results.Add(new Result("Standard Deviations", "The standard deviations of the various axis, as well as the minimum and maximum standard deviation.", stdDevs)); 144 144 } 145 145 for (int i = 0; i < vector.Length; i++) -
branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/HillClimber.cs
r17745 r17747 94 94 Parameters.Add(MaximumIterationsParameter = new FixedValueParameter<IntValue>("Maximum Iterations", "", new IntValue(100))); 95 95 96 Results.Add(BestQualityResult = new Result<DoubleValue>("Best Quality" ));97 Results.Add(IterationsResult = new Result<IntValue>("Iterations" ));96 Results.Add(BestQualityResult = new Result<DoubleValue>("Best Quality", "The best quality found so far.")); 97 Results.Add(IterationsResult = new Result<IntValue>("Iterations", "The current iteration.")); 98 98 } 99 99 -
branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/ParameterlessPopulationPyramid.cs
r17680 r17747 229 229 // Set up the results display 230 230 if (!Results.TryGetValue("Iterations", out var result)) 231 Results.Add(new Result("Iterations", resultsIterations = new IntValue(0)));231 Results.Add(new Result("Iterations", "The current iteration.", resultsIterations = new IntValue(0))); 232 232 else result.Value = resultsIterations = new IntValue(0); 233 233 if (!Results.TryGetValue("Evaluations", out var result2)) 234 Results.Add(new Result("Evaluations", resultsEvaluations = new IntValue(0)));234 Results.Add(new Result("Evaluations", "The number of evaluations that have been performed.", resultsEvaluations = new IntValue(0))); 235 235 else result2.Value = resultsEvaluations = new IntValue(0); 236 236 if (!Results.TryGetValue("Best Quality", out var result4)) 237 Results.Add(new Result("Best Quality", resultsBestQuality = new DoubleValue(tracker.BestQuality)));237 Results.Add(new Result("Best Quality", "The best quality that has been observed so far.", resultsBestQuality = new DoubleValue(tracker.BestQuality))); 238 238 else result4.Value = resultsBestQuality = new DoubleValue(tracker.BestQuality); 239 239 if (!Results.TryGetValue("Evaluation Best Solution Was Found", out var result5)) 240 Results.Add(new Result("Evaluation Best Solution Was Found", resultsBestFoundOnEvaluation = new IntValue(tracker.BestFoundOnEvaluation)));240 Results.Add(new Result("Evaluation Best Solution Was Found", "The number of evaluations at which the best solution was found.", resultsBestFoundOnEvaluation = new IntValue(tracker.BestFoundOnEvaluation))); 241 241 else result5.Value = resultsBestFoundOnEvaluation = new IntValue(tracker.BestFoundOnEvaluation); 242 242 var table = new DataTable("Qualities"); … … 245 245 ResultsQualitiesIteration.VisualProperties.LineStyle = DataRowVisualProperties.DataRowLineStyle.Dot; 246 246 if (!Results.TryGetValue("Qualities", out var result6)) 247 Results.Add(new Result("Qualities", table));247 Results.Add(new Result("Qualities", "An analysis of the quality progress over time.", table)); 248 248 else result6.Value = table; 249 249 … … 251 251 table.Rows.Add(ResultsLevels = new DataRow("Levels")); 252 252 if (!Results.TryGetValue("Pyramid Levels", out var result7)) 253 Results.Add(new Result("Pyramid Levels", table));253 Results.Add(new Result("Pyramid Levels", "The number of levels of the pyramid.", table)); 254 254 else result7.Value = table; 255 255 … … 257 257 table.Rows.Add(ResultsSolutions = new DataRow("Solutions")); 258 258 if (!Results.TryGetValue("Stored Solutions", out var result8)) 259 Results.Add(new Result("Stored Solutions", table));259 Results.Add(new Result("Stored Solutions", "The number of solutions that are found over time.", table)); 260 260 else result8.Value = table; 261 261 -
branches/2521_ProblemRefactoring/HeuristicLab.Analysis/3.3/AlleleFrequencyAnalysis/AlleleFrequencyAnalyzer.cs
r17226 r17747 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using HEAL.Attic; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; … … 29 30 using HeuristicLab.Optimization; 30 31 using HeuristicLab.Parameters; 31 using HEAL.Attic;32 32 33 33 namespace HeuristicLab.Analysis { … … 165 165 if (!ResultsParameter.ActualValue.ContainsKey(Name + " Results")) { 166 166 results = new ResultCollection(); 167 ResultsParameter.ActualValue.Add(new Result(Name + " Results", results));167 ResultsParameter.ActualValue.Add(new Result(Name + " Results", "Collection of allele frequency analysis results", results)); 168 168 } else { 169 169 results = (ResultCollection)ResultsParameter.ActualValue[Name + " Results"].Value; … … 173 173 AlleleFrequencyCollection frequenciesCollection = new AlleleFrequencyCollection(frequencies); 174 174 if (!results.ContainsKey("Allele Frequencies")) 175 results.Add(new Result("Allele Frequencies", frequenciesCollection));175 results.Add(new Result("Allele Frequencies", "Displays for all alleles in the population the frequencies with which these occur.", frequenciesCollection)); 176 176 else 177 177 results["Allele Frequencies"].Value = frequenciesCollection; … … 182 182 AlleleFrequencyCollectionHistory history = new AlleleFrequencyCollectionHistory(); 183 183 history.Add(frequenciesCollection); 184 results.Add(new Result("Allele Frequencies History", history));184 results.Add(new Result("Allele Frequencies History", "Snapshots of the allele frequency of each generation.", history)); 185 185 } else { 186 186 ((AlleleFrequencyCollectionHistory)results["Allele Frequencies History"].Value).Add(frequenciesCollection); … … 215 215 allelesTable.Rows["Lost Alleles of Best Known Solution"].VisualProperties.StartIndexZero = true; 216 216 217 results.Add(new Result("Alleles", allelesTable));217 results.Add(new Result("Alleles", "Tabular summary of the allele frequency analysis", allelesTable)); 218 218 } else { 219 219 allelesTable = (DataTable)results["Alleles"].Value; … … 234 234 // store alleles values 235 235 if (!results.ContainsKey("Unique Alleles")) 236 results.Add(new Result("Unique Alleles", new DoubleValue(frequenciesCollection.Count)));236 results.Add(new Result("Unique Alleles", "The number of unique alleles currently in the population.", new DoubleValue(frequenciesCollection.Count))); 237 237 else 238 238 ((DoubleValue)results["Unique Alleles"].Value).Value = frequenciesCollection.Count; 239 239 240 240 if (!results.ContainsKey("Unique Alleles of Best Known Solution")) 241 results.Add(new Result("Unique Alleles of Best Known Solution", new DoubleValue(uniqueRelevantAllelesCount)));241 results.Add(new Result("Unique Alleles of Best Known Solution", "The number of alleles from the best-known solution that are currently present in the population.", new DoubleValue(uniqueRelevantAllelesCount))); 242 242 else 243 243 ((DoubleValue)results["Unique Alleles of Best Known Solution"].Value).Value = uniqueRelevantAllelesCount; 244 244 245 245 if (!results.ContainsKey("Fixed Alleles")) 246 results.Add(new Result("Fixed Alleles", new DoubleValue(fixedAllelesCount)));246 results.Add(new Result("Fixed Alleles", "The number of alleles, that are present in every individual of the population.", new DoubleValue(fixedAllelesCount))); 247 247 else 248 248 ((DoubleValue)results["Fixed Alleles"].Value).Value = fixedAllelesCount; 249 249 250 250 if (!results.ContainsKey("Fixed Alleles of Best Known Solution")) 251 results.Add(new Result("Fixed Alleles of Best Known Solution", new DoubleValue(fixedRelevantAllelesCount)));251 results.Add(new Result("Fixed Alleles of Best Known Solution", "The number of alles from the best-known solution that are present in every individual of the population.", new DoubleValue(fixedRelevantAllelesCount))); 252 252 else 253 253 ((DoubleValue)results["Fixed Alleles of Best Known Solution"].Value).Value = fixedRelevantAllelesCount; 254 254 255 255 if (!results.ContainsKey("Lost Alleles of Best Known Solution")) 256 results.Add(new Result("Lost Alleles of Best Known Solution", new DoubleValue(lostRelevantAllelesCount)));256 results.Add(new Result("Lost Alleles of Best Known Solution", "The number of alles from the best-known solution that are currently not present in the population.", new DoubleValue(lostRelevantAllelesCount))); 257 257 else 258 258 ((DoubleValue)results["Lost Alleles of Best Known Solution"].Value).Value = lostRelevantAllelesCount; … … 282 282 283 283 if (!results.ContainsKey("Scatter Plot")) 284 results.Add(new Result("Scatter Plot", plot));284 results.Add(new Result("Scatter Plot", "A plot that shows the correlation between number of unique alleles that an individual shares with the best-known solution and its relative quality.", plot)); 285 285 else 286 286 results["Scatter Plot"].Value = plot; 287 287 if (storeHistory) { 288 288 if (!results.ContainsKey("Scatter Plot History")) { 289 results.Add(new Result("Scatter Plot History", new ScatterPlotHistory()));289 results.Add(new Result("Scatter Plot History", "Snapshots of the scatter plot that show correlation between shared alleles with best-known solution and relative solution quality.", new ScatterPlotHistory())); 290 290 } 291 291 ((ScatterPlotHistory)results["Scatter Plot History"].Value).Add(plot); … … 300 300 301 301 if (!results.ContainsKey("Average Contained Alleles of Best Known Solution")) 302 results.Add(new Result("Average Contained Alleles of Best Known Solution", new DoubleValue(avgContainedReleventAlleles)));302 results.Add(new Result("Average Contained Alleles of Best Known Solution", "Average number of alleles that individuals share with the best-known solution.", new DoubleValue(avgContainedReleventAlleles))); 303 303 else 304 304 ((DoubleValue)results["Average Contained Alleles of Best Known Solution"].Value).Value = avgContainedReleventAlleles; -
branches/2521_ProblemRefactoring/HeuristicLab.Analysis/3.3/BestScopeSolutionAnalyzer.cs
r17383 r17747 124 124 var solution = cloner.Clone(currentBestScope); 125 125 126 results.Add(new Result(BestSolutionResultName, solution));126 results.Add(new Result(BestSolutionResultName, "The best solution found so far.", solution)); 127 127 } else { 128 128 var bestSolution = (IScope)results[BestSolutionResultName].Value; -
branches/2521_ProblemRefactoring/HeuristicLab.Analysis/3.3/MultiObjective/RankBasedParetoFrontAnalyzer.cs
r17226 r17747 22 22 using System.Collections.Generic; 23 23 using System.Linq; 24 using HEAL.Attic; 24 25 using HeuristicLab.Common; 25 26 using HeuristicLab.Core; … … 27 28 using HeuristicLab.Optimization; 28 29 using HeuristicLab.Parameters; 29 using HEAL.Attic;30 30 31 31 namespace HeuristicLab.Analysis { … … 72 72 if (results.ContainsKey("Pareto Front")) 73 73 results["Pareto Front"].Value = front; 74 else results.Add(new Result("Pareto Front", front));74 else results.Add(new Result("Pareto Front", "A tabular presentation of the current Pareto front.", front)); 75 75 76 76 if (populationLevel) { 77 77 if (results.ContainsKey("Pareto Archive")) 78 78 results["Pareto Archive"].Value = paretoArchive; 79 else results.Add(new Result("Pareto Archive", paretoArchive));79 else results.Add(new Result("Pareto Archive", "The individual solutions on the Pareto front.", paretoArchive)); 80 80 } 81 81 } -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/BinaryVectorMultiObjectiveProblem.cs
r17695 r17747 33 33 [StorableType("b64caac0-a23a-401a-bb7e-ffa3e22b80ea")] 34 34 public abstract class BinaryVectorMultiObjectiveProblem : MultiObjectiveProblem<BinaryVectorEncoding, BinaryVector> { 35 [Storable] protected IResultParameter<ParetoFrontScatterPlot<BinaryVector>> BestResultParameter { get; private set; }36 35 [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; } 36 [Storable] public IResult<ParetoFrontScatterPlot<BinaryVector>> BestParetoFrontResult { get; private set; } 37 37 38 38 public int Dimension { 39 39 get { return DimensionRefParameter.Value.Value; } 40 40 protected set { DimensionRefParameter.Value.Value = value; } 41 } 42 43 protected ParetoFrontScatterPlot<BinaryVector> BestParetoFront { 44 get => BestParetoFrontResult.Value; 45 set => BestParetoFrontResult.Value = value; 41 46 } 42 47 … … 50 55 protected BinaryVectorMultiObjectiveProblem(BinaryVectorMultiObjectiveProblem original, Cloner cloner) 51 56 : base(original, cloner) { 52 BestResultParameter = cloner.Clone(original.BestResultParameter);53 57 DimensionRefParameter = cloner.Clone(original.DimensionRefParameter); 58 BestParetoFrontResult = cloner.Clone(original.BestParetoFrontResult); 59 54 60 RegisterEventHandlers(); 55 61 } … … 59 65 EncodingParameter.ReadOnly = true; 60 66 EvaluatorParameter.ReadOnly = true; 61 Parameters.Add(BestResultParameter = new ResultParameter<ParetoFrontScatterPlot<BinaryVector>>("Best Pareto Front", "The best Pareto front found."));62 67 Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the binary vector problem.", Encoding.LengthParameter)); 68 Results.Add(BestParetoFrontResult = new Result<ParetoFrontScatterPlot<BinaryVector>>("Best Pareto Front", "The best Pareto front found so far.")); 63 69 64 70 Operators.Add(new HammingSimilarityCalculator()); … … 75 81 var plot = new ParetoFrontScatterPlot<BinaryVector>(fronts, individuals, qualities, Objectives, BestKnownFront); 76 82 77 Best ResultParameter.ActualValue= plot;83 BestParetoFront = plot; 78 84 } 79 85 -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/BinaryVectorProblem.cs
r17745 r17747 37 37 [Storable] public IResult<ISingleObjectiveSolutionContext<BinaryVector>> BestSolutionResult { get; private set; } 38 38 39 private ISingleObjectiveSolutionContext<BinaryVector> BestSolution {40 get => BestSolutionResult.Value;41 set => BestSolutionResult.Value = value;42 }43 44 39 public int Dimension { 45 40 get { return DimensionRefParameter.Value.Value; } 46 41 protected set { DimensionRefParameter.Value.Value = value; } 42 } 43 44 protected ISingleObjectiveSolutionContext<BinaryVector> BestSolution { 45 get => BestSolutionResult.Value; 46 set => BestSolutionResult.Value = value; 47 47 } 48 48 … … 66 66 EvaluatorParameter.ReadOnly = true; 67 67 Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the binary vector problem.", Encoding.LengthParameter)); 68 Results.Add(BestSolutionResult = new Result<ISingleObjectiveSolutionContext<BinaryVector>>("Best Solution" ));68 Results.Add(BestSolutionResult = new Result<ISingleObjectiveSolutionContext<BinaryVector>>("Best Solution", "The best solution found so far.")); 69 69 70 70 Operators.Add(new HammingSimilarityCalculator()); -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVectorMultiObjectiveProblem.cs
r17695 r17747 35 35 [StorableType("11916b0f-4c34-4ece-acae-e28d11211b43")] 36 36 public abstract class IntegerVectorMultiObjectiveProblem : MultiObjectiveProblem<IntegerVectorEncoding, IntegerVector> { 37 [Storable] protected IResultParameter<ParetoFrontScatterPlot<IntegerVector>> BestResultParameter { get; private set; }38 37 [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; } 39 38 [Storable] protected ReferenceParameter<IntMatrix> BoundsRefParameter { get; private set; } 39 [Storable] public IResult<ParetoFrontScatterPlot<IntegerVector>> BestParetoFrontResult { get; private set; } 40 40 41 41 public int Dimension { … … 49 49 } 50 50 51 protected ParetoFrontScatterPlot<IntegerVector> BestParetoFront { 52 get => BestParetoFrontResult.Value; 53 set => BestParetoFrontResult.Value = value; 54 } 55 51 56 [StorableConstructor] 52 57 protected IntegerVectorMultiObjectiveProblem(StorableConstructorFlag _) : base(_) { } … … 58 63 protected IntegerVectorMultiObjectiveProblem(IntegerVectorMultiObjectiveProblem original, Cloner cloner) 59 64 : base(original, cloner) { 60 BestResultParameter = cloner.Clone(original.BestResultParameter);61 65 DimensionRefParameter = cloner.Clone(original.DimensionRefParameter); 62 66 BoundsRefParameter = cloner.Clone(original.BoundsRefParameter); 67 BestParetoFrontResult = cloner.Clone(original.BestParetoFrontResult); 63 68 RegisterEventHandlers(); 64 69 } … … 68 73 EncodingParameter.ReadOnly = true; 69 74 EvaluatorParameter.ReadOnly = true; 70 Parameters.Add(BestResultParameter = new ResultParameter<ParetoFrontScatterPlot<IntegerVector>>("Best Pareto Front", "The best Pareto front found."));71 75 Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the integer vector problem.", Encoding.LengthParameter)); 72 76 Parameters.Add(BoundsRefParameter = new ReferenceParameter<IntMatrix>("Bounds", "The bounds of the integer vector problem.", Encoding.BoundsParameter)); 77 Results.Add(BestParetoFrontResult = new Result<ParetoFrontScatterPlot<IntegerVector>>("Best Pareto Front", "The best Pareto front found so far.")); 73 78 74 79 Operators.Add(new HammingSimilarityCalculator()); … … 85 90 var plot = new ParetoFrontScatterPlot<IntegerVector>(fronts, individuals, qualities, Objectives, BestKnownFront); 86 91 87 Best ResultParameter.ActualValue= plot;92 BestParetoFront = plot; 88 93 } 89 94 -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVectorProblem.cs
r17745 r17747 36 36 [StorableType("c6081457-a3de-45ce-9f47-e0eb1c851bd2")] 37 37 public abstract class IntegerVectorProblem : SingleObjectiveProblem<IntegerVectorEncoding, IntegerVector> { 38 [Storable] protected IResultParameter<IntegerVector> BestResultParameter { get; private set; }39 38 [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; } 40 39 [Storable] protected ReferenceParameter<IntMatrix> BoundsRefParameter { get; private set; } 40 [Storable] public IResult<ISingleObjectiveSolutionContext<IntegerVector>> BestSolutionResult { get; private set; } 41 41 42 42 public int Dimension { … … 50 50 } 51 51 52 protected ISingleObjectiveSolutionContext<IntegerVector> BestSolution { 53 get => BestSolutionResult.Value; 54 set => BestSolutionResult.Value = value; 55 } 56 52 57 [StorableConstructor] 53 58 protected IntegerVectorProblem(StorableConstructorFlag _) : base(_) { } … … 59 64 protected IntegerVectorProblem(IntegerVectorProblem original, Cloner cloner) 60 65 : base(original, cloner) { 61 BestResultParameter = cloner.Clone(original.BestResultParameter);62 66 DimensionRefParameter = cloner.Clone(original.DimensionRefParameter); 63 67 BoundsRefParameter = cloner.Clone(original.BoundsRefParameter); 68 BestSolutionResult = cloner.Clone(original.BestSolutionResult); 64 69 RegisterEventHandlers(); 65 70 } … … 69 74 EncodingParameter.ReadOnly = true; 70 75 EvaluatorParameter.ReadOnly = true; 71 Parameters.Add(BestResultParameter = new ResultParameter<IntegerVector>("Best Solution", "The best solution."));72 76 Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the integer vector problem.", Encoding.LengthParameter)); 73 77 Parameters.Add(BoundsRefParameter = new ReferenceParameter<IntMatrix>("Bounds", "The bounding box and step sizes of the values.", Encoding.BoundsParameter)); 78 Results.Add(BestSolutionResult = new Result<ISingleObjectiveSolutionContext<IntegerVector>>("Best Solution", "The best solution found so far.")); 74 79 75 80 Operators.Add(new HammingSimilarityCalculator()); … … 82 87 } 83 88 84 public override void Analyze(ISingleObjectiveSolutionContext<IntegerVector>[] solutionContext, IRandom random) { 85 base.Analyze(solutionContext, random); 86 87 var best = GetBest(solutionContext); 88 89 //TODO reimplement code below using results directly 90 //results.AddOrUpdateResult("Best Solution", (IntegerVector)best.EncodedSolution.Clone()); 89 public override void Analyze(ISingleObjectiveSolutionContext<IntegerVector>[] solutionContexts, IRandom random) { 90 base.Analyze(solutionContexts, random); 91 var best = GetBest(solutionContexts); 92 if (BestSolution == null || IsBetter(best, BestSolution)) 93 BestSolution = best.Clone() as SingleObjectiveSolutionContext<IntegerVector>; 91 94 } 92 95 -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/LinearLinkageMultiObjectiveProblem.cs
r17695 r17747 36 36 public abstract class LinearLinkageMultiObjectiveProblem : MultiObjectiveProblem<LinearLinkageEncoding, LinearLinkage> { 37 37 [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; } 38 public IValueParameter<IntValue> DimensionParameter => DimensionRefParameter;38 [Storable] public IResult<ParetoFrontScatterPlot<LinearLinkage>> BestParetoFrontResult { get; private set; } 39 39 40 40 public int Dimension { 41 41 get { return DimensionRefParameter.Value.Value; } 42 42 set { DimensionRefParameter.Value.Value = value; } 43 } 44 45 protected ParetoFrontScatterPlot<LinearLinkage> BestParetoFront { 46 get => BestParetoFrontResult.Value; 47 set => BestParetoFrontResult.Value = value; 43 48 } 44 49 … … 53 58 : base(original, cloner) { 54 59 DimensionRefParameter = cloner.Clone(original.DimensionRefParameter); 60 BestParetoFrontResult = cloner.Clone(original.BestParetoFrontResult); 61 55 62 RegisterEventHandlers(); 56 63 } … … 61 68 EvaluatorParameter.ReadOnly = true; 62 69 Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the linear linkage problem.", Encoding.LengthParameter)); 63 70 Results.Add(BestParetoFrontResult = new Result<ParetoFrontScatterPlot<LinearLinkage>>("Best Pareto Front", "The best Pareto front found so far.")); 64 71 65 72 Operators.Add(new HammingSimilarityCalculator()); … … 75 82 var fronts = DominationCalculator.CalculateAllParetoFrontsIndices(individuals, qualities, Maximization); 76 83 var plot = new ParetoFrontScatterPlot<LinearLinkage>(fronts, individuals, qualities, Objectives, BestKnownFront); 77 results.AddOrUpdateResult("Pareto Front Scatter Plot", plot); 84 85 BestParetoFront = plot; 78 86 } 79 87 -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/LinearLinkageProblem.cs
r17745 r17747 37 37 public abstract class LinearLinkageProblem : SingleObjectiveProblem<LinearLinkageEncoding, LinearLinkage> { 38 38 [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; } 39 [Storable] public IResult<ISingleObjectiveSolutionContext<LinearLinkage>> BestSolutionResult { get; private set; } 39 40 40 41 public int Dimension { 41 42 get { return DimensionRefParameter.Value.Value; } 42 43 set { DimensionRefParameter.Value.Value = value; } 44 } 45 46 protected ISingleObjectiveSolutionContext<LinearLinkage> BestSolution { 47 get => BestSolutionResult.Value; 48 set => BestSolutionResult.Value = value; 43 49 } 44 50 … … 53 59 : base(original, cloner) { 54 60 DimensionRefParameter = cloner.Clone(original.DimensionRefParameter); 61 BestSolutionResult = cloner.Clone(original.BestSolutionResult); 55 62 RegisterEventHandlers(); 56 63 } … … 61 68 EvaluatorParameter.ReadOnly = true; 62 69 Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the linear linkage problem.", Encoding.LengthParameter)); 70 Results.Add(BestSolutionResult = new Result<ISingleObjectiveSolutionContext<LinearLinkage>>("Best Solution", "The best solution found so far.")); 63 71 64 72 Operators.Add(new HammingSimilarityCalculator()); … … 73 81 public override void Analyze(ISingleObjectiveSolutionContext<LinearLinkage>[] solutionContexts, IRandom random) { 74 82 base.Analyze(solutionContexts, random); 75 76 //TODO: reimplement code below using results directly 77 78 //var best = GetBestSolution(vectors, qualities); 79 80 //results.AddOrUpdateResult("Best Solution", (Item)best.Item1.Clone()); 83 var best = GetBest(solutionContexts); 84 if (BestSolution == null || IsBetter(best, BestSolution)) 85 BestSolution = best.Clone() as SingleObjectiveSolutionContext<LinearLinkage>; 81 86 } 82 87 -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.PermutationEncoding/3.3/PermutationMultiObjectiveProblem.cs
r17695 r17747 37 37 [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; } 38 38 [Storable] protected ReferenceParameter<EnumValue<PermutationTypes>> PermutationTypeRefParameter { get; private set; } 39 [Storable] public IResult<ParetoFrontScatterPlot<Permutation>> BestParetoFrontResult { get; private set; } 39 40 40 41 public int Dimension { … … 46 47 get { return PermutationTypeRefParameter.Value.Value; } 47 48 set { PermutationTypeRefParameter.Value.Value = value; } 49 } 50 51 protected ParetoFrontScatterPlot<Permutation> BestParetoFront { 52 get => BestParetoFrontResult.Value; 53 set => BestParetoFrontResult.Value = value; 48 54 } 49 55 … … 59 65 DimensionRefParameter = cloner.Clone(original.DimensionRefParameter); 60 66 PermutationTypeRefParameter = cloner.Clone(original.PermutationTypeRefParameter); 67 BestParetoFrontResult = cloner.Clone(original.BestParetoFrontResult); 68 61 69 RegisterEventHandlers(); 62 70 } … … 68 76 Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the permutation problem.", Encoding.LengthParameter)); 69 77 Parameters.Add(PermutationTypeRefParameter = new ReferenceParameter<EnumValue<PermutationTypes>>("Type", "The type of the permutation.", Encoding.PermutationTypeParameter)); 78 Results.Add(BestParetoFrontResult = new Result<ParetoFrontScatterPlot<Permutation>>("Best Pareto Front", "The best Pareto front found so far.")); 70 79 71 80 Operators.Add(new HammingSimilarityCalculator()); … … 81 90 var fronts = DominationCalculator.CalculateAllParetoFrontsIndices(individuals, qualities, Maximization); 82 91 var plot = new ParetoFrontScatterPlot<Permutation>(fronts, individuals, qualities, Objectives, BestKnownFront); 83 results.AddOrUpdateResult("Pareto Front Scatter Plot", plot); 92 93 BestParetoFront = plot; 84 94 } 85 95 -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.PermutationEncoding/3.3/PermutationProblem.cs
r17745 r17747 38 38 [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; } 39 39 [Storable] protected ReferenceParameter<EnumValue<PermutationTypes>> PermutationTypeRefParameter { get; private set; } 40 [Storable] public IResult<ISingleObjectiveSolutionContext<Permutation>> BestSolutionResult { get; private set; } 40 41 41 42 public int Dimension { … … 47 48 get { return PermutationTypeRefParameter.Value.Value; } 48 49 set { PermutationTypeRefParameter.Value.Value = value; } 50 } 51 52 protected ISingleObjectiveSolutionContext<Permutation> BestSolution { 53 get => BestSolutionResult.Value; 54 set => BestSolutionResult.Value = value; 49 55 } 50 56 … … 60 66 DimensionRefParameter = cloner.Clone(original.DimensionRefParameter); 61 67 PermutationTypeRefParameter = cloner.Clone(original.PermutationTypeRefParameter); 68 BestSolutionResult = cloner.Clone(original.BestSolutionResult); 62 69 RegisterEventHandlers(); 63 70 } … … 69 76 Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the permutation problem.", Encoding.LengthParameter)); 70 77 Parameters.Add(PermutationTypeRefParameter = new ReferenceParameter<EnumValue<PermutationTypes>>("Type", "The type of the permutation.", Encoding.PermutationTypeParameter)); 78 Results.Add(BestSolutionResult = new Result<ISingleObjectiveSolutionContext<Permutation>>("Best Solution", "The best solution found so far.")); 71 79 72 80 Operators.Add(new HammingSimilarityCalculator()); … … 81 89 public override void Analyze(ISingleObjectiveSolutionContext<Permutation>[] solutionContexts, IRandom random) { 82 90 base.Analyze(solutionContexts, random); 83 84 //TODO reimplement code below using results directly solutionContexts 85 //var best = GetBestSolution(permutations, qualities); 86 //results.AddOrUpdateResult("Best Solution", (IItem)best.Item1.Clone()); 91 var best = GetBest(solutionContexts); 92 if (BestSolution == null || IsBetter(best, BestSolution)) 93 BestSolution = best.Clone() as SingleObjectiveSolutionContext<Permutation>; 87 94 } 88 95 -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.RealVectorEncoding/3.3/RealVectorMultiObjectiveProblem.cs
r17695 r17747 37 37 [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; } 38 38 [Storable] protected ReferenceParameter<DoubleMatrix> BoundsRefParameter { get; private set; } 39 [Storable] public IResult<ParetoFrontScatterPlot<RealVector>> BestParetoFrontResult { get; private set; } 39 40 40 41 public int Dimension { … … 46 47 get { return BoundsRefParameter.Value; } 47 48 set { BoundsRefParameter.Value = value; } 49 } 50 51 protected ParetoFrontScatterPlot<RealVector> BestParetoFront { 52 get => BestParetoFrontResult.Value; 53 set => BestParetoFrontResult.Value = value; 48 54 } 49 55 … … 59 65 DimensionRefParameter = cloner.Clone(original.DimensionRefParameter); 60 66 BoundsRefParameter = cloner.Clone(original.BoundsRefParameter); 67 BestParetoFrontResult = cloner.Clone(original.BestParetoFrontResult); 61 68 RegisterEventHandlers(); 62 69 } … … 68 75 Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the real vector problem.", Encoding.LengthParameter)); 69 76 Parameters.Add(BoundsRefParameter = new ReferenceParameter<DoubleMatrix>("Bounds", "The bounding box of the values.", Encoding.BoundsParameter)); 70 77 Results.Add(BestParetoFrontResult = new Result<ParetoFrontScatterPlot<RealVector>>("Best Pareto Front", "The best Pareto front found so far.")); 71 78 72 79 Operators.Add(new HammingSimilarityCalculator()); … … 82 89 var fronts = DominationCalculator.CalculateAllParetoFrontsIndices(individuals, qualities, Maximization); 83 90 var plot = new ParetoFrontScatterPlot<RealVector>(fronts, individuals, qualities, Objectives, BestKnownFront); 84 results.AddOrUpdateResult("Pareto Front Scatter Plot", plot); 91 92 BestParetoFront = plot; 85 93 } 86 94 -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.RealVectorEncoding/3.3/RealVectorProblem.cs
r17745 r17747 38 38 [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; } 39 39 [Storable] protected ReferenceParameter<DoubleMatrix> BoundsRefParameter { get; private set; } 40 [Storable] public IResult<ISingleObjectiveSolutionContext<RealVector>> BestSolutionResult { get; private set; } 40 41 41 42 public int Dimension { … … 47 48 get { return BoundsRefParameter.Value; } 48 49 set { BoundsRefParameter.Value = value; } 50 } 51 52 protected ISingleObjectiveSolutionContext<RealVector> BestSolution { 53 get => BestSolutionResult.Value; 54 set => BestSolutionResult.Value = value; 49 55 } 50 56 … … 60 66 DimensionRefParameter = cloner.Clone(original.DimensionRefParameter); 61 67 BoundsRefParameter = cloner.Clone(original.BoundsRefParameter); 68 BestSolutionResult = cloner.Clone(original.BestSolutionResult); 62 69 RegisterEventHandlers(); 63 70 } … … 69 76 Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the real vector problem.", Encoding.LengthParameter)); 70 77 Parameters.Add(BoundsRefParameter = new ReferenceParameter<DoubleMatrix>("Bounds", "The bounding box of the values.", Encoding.BoundsParameter)); 78 Results.Add(BestSolutionResult = new Result<ISingleObjectiveSolutionContext<RealVector>>("Best Solution", "The best solution found so far.")); 71 79 72 80 Operators.Add(new HammingSimilarityCalculator()); … … 82 90 public override void Analyze(ISingleObjectiveSolutionContext<RealVector>[] solutionContexts, IRandom random) { 83 91 base.Analyze(solutionContexts, random); 84 85 //TODO: reimplement code below using results directly 86 87 //var best = GetBestSolution(vectors, qualities); 88 89 //results.AddOrUpdateResult("Best Solution", (IItem)best.Item1.Clone()); 92 var best = GetBest(solutionContexts); 93 if (BestSolution == null || IsBetter(best, BestSolution)) 94 BestSolution = best.Clone() as SingleObjectiveSolutionContext<RealVector>; 90 95 } 91 96 -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeMultiObjectiveProblem.cs
r17695 r17747 38 38 [Storable] private ReferenceParameter<IntValue> TreeDepthRefParameter { get; set; } 39 39 [Storable] private ReferenceParameter<ISymbolicExpressionGrammar> GrammarRefParameter { get; set; } 40 [Storable] public IResult<ParetoFrontScatterPlot<ISymbolicExpressionTree>> BestParetoFrontResult { get; private set; } 40 41 41 42 public int TreeLength { … … 54 55 } 55 56 56 // persistence 57 protected ParetoFrontScatterPlot<ISymbolicExpressionTree> BestParetoFront { 58 get => BestParetoFrontResult.Value; 59 set => BestParetoFrontResult.Value = value; 60 } 61 57 62 [StorableConstructor] 58 63 protected SymbolicExpressionTreeMultiObjectiveProblem(StorableConstructorFlag _) : base(_) { } … … 62 67 } 63 68 64 65 // cloning66 69 protected SymbolicExpressionTreeMultiObjectiveProblem(SymbolicExpressionTreeMultiObjectiveProblem original, Cloner cloner) 67 70 : base(original, cloner) { … … 69 72 TreeDepthRefParameter = cloner.Clone(original.TreeDepthRefParameter); 70 73 GrammarRefParameter = cloner.Clone(original.GrammarRefParameter); 74 BestParetoFrontResult = cloner.Clone(original.BestParetoFrontResult); 71 75 RegisterEventHandlers(); 72 76 } … … 79 83 Parameters.Add(TreeDepthRefParameter = new ReferenceParameter<IntValue>("TreeDepth", "The maximum depth of the tree.", Encoding.TreeDepthParameter)); 80 84 Parameters.Add(GrammarRefParameter = new ReferenceParameter<ISymbolicExpressionGrammar>("Grammar", "The grammar that describes a valid tree.", Encoding.GrammarParameter)); 85 Results.Add(BestParetoFrontResult = new Result<ParetoFrontScatterPlot<ISymbolicExpressionTree>>("Best Pareto Front", "The best Pareto front found so far.")); 81 86 82 87 Parameterize(); … … 90 95 var fronts = DominationCalculator.CalculateAllParetoFrontsIndices(trees, qualities, Maximization); 91 96 var plot = new ParetoFrontScatterPlot<ISymbolicExpressionTree>(fronts, trees, qualities, Objectives, BestKnownFront); 92 results.AddOrUpdateResult("Pareto Front Scatter Plot", plot); 97 98 BestParetoFront = plot; 93 99 } 94 100 -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeProblem.cs
r17745 r17747 39 39 [Storable] protected ReferenceParameter<IntValue> TreeDepthRefParameter { get; private set; } 40 40 [Storable] protected ReferenceParameter<ISymbolicExpressionGrammar> GrammarRefParameter { get; private set; } 41 [Storable] public IResult<ISingleObjectiveSolutionContext<ISymbolicExpressionTree>> BestSolutionResult { get; private set; } 41 42 42 43 public int TreeLength { … … 55 56 } 56 57 58 protected ISingleObjectiveSolutionContext<ISymbolicExpressionTree> BestSolution { 59 get => BestSolutionResult.Value; 60 set => BestSolutionResult.Value = value; 61 } 62 57 63 // persistence 58 64 [StorableConstructor] … … 69 75 TreeDepthRefParameter = cloner.Clone(original.TreeDepthRefParameter); 70 76 GrammarRefParameter = cloner.Clone(original.GrammarRefParameter); 77 BestSolutionResult = cloner.Clone(original.BestSolutionResult); 71 78 RegisterEventHandlers(); 72 79 } … … 80 87 Parameters.Add(TreeDepthRefParameter = new ReferenceParameter<IntValue>("TreeDepth", "The maximum depth of the tree.", Encoding.TreeDepthParameter)); 81 88 Parameters.Add(GrammarRefParameter = new ReferenceParameter<ISymbolicExpressionGrammar>("Grammar", "The grammar that describes a valid tree.", Encoding.GrammarParameter)); 89 Results.Add(BestSolutionResult = new Result<ISingleObjectiveSolutionContext<ISymbolicExpressionTree>>("Best Solution", "The best solution found so far.")); 82 90 83 91 // TODO: These should be added in the SingleObjectiveProblem base class (if they were accessible from there) … … 90 98 91 99 public override void Analyze(ISingleObjectiveSolutionContext<ISymbolicExpressionTree>[] solutionContexts, IRandom random) { 92 //TODO reimplement code below using results directly 93 94 //if (!results.ContainsKey("Best Solution Quality")) { 95 // results.Add(new Result("Best Solution Quality", typeof(DoubleValue))); 96 //} 97 //if (!results.ContainsKey("Best Solution")) { 98 // results.Add(new Result("Best Solution", typeof(ISymbolicExpressionTree))); 99 //} 100 101 //var bestQuality = Maximization ? qualities.Max() : qualities.Min(); 102 103 //if (results["Best Solution Quality"].Value == null || 104 // IsBetter(bestQuality, ((DoubleValue)results["Best Solution Quality"].Value).Value)) { 105 // var bestIdx = Array.IndexOf(qualities, bestQuality); 106 // var bestClone = (IItem)trees[bestIdx].Clone(); 107 108 // results["Best Solution"].Value = bestClone; 109 // results["Best Solution Quality"].Value = new DoubleValue(bestQuality); 110 //} 100 base.Analyze(solutionContexts, random); 101 var best = GetBest(solutionContexts); 102 if (BestSolution == null || IsBetter(best, BestSolution)) 103 BestSolution = best.Clone() as SingleObjectiveSolutionContext<ISymbolicExpressionTree>; 111 104 } 112 105 -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/Results/Result.cs
r17595 r17747 151 151 } 152 152 153 public Result(string name) : this(name, typeof(T)) { } 154 public Result(string name, Type dataType) : this(name, string.Empty, dataType) { } 155 public Result(string name, string description, Type dataType) : base(name, description, dataType) { } 156 157 public Result(string name, T value) : this(name, string.Empty, value.GetType(), value) { } 158 public Result(string name, string description, T value) : this(name, description, value.GetType(), value) { } 159 public Result(string name, string description, Type dataType, IItem value) : base(name, description, dataType, value) { } 153 //public Result(string name) : this(name, string.Empty) { } 154 public Result(string name, string description) : base(name, description, typeof(T)) { } 155 156 //public Result(string name, T value) : this(name, string.Empty, value) { } 157 public Result(string name, string description, T value) : base(name, description, typeof(T), value) { } 160 158 } 161 159 } -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/Results/ResultCollection.cs
r17594 r17747 75 75 } 76 76 77 public void AddOrUpdateResult(string name, IItem value ) {77 public void AddOrUpdateResult(string name, IItem value, string description = null) { 78 78 IResult res; 79 79 if (!TryGetValue(name, out res)) { 80 res = new Result(name, value);80 res = new Result(name, description ?? string.Empty, value); 81 81 Add(res); 82 82 } else res.Value = value; -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/Results/ResultParameter.cs
r17718 r17747 114 114 if (!results.TryGetValue(ActualName, out result)) { 115 115 if (DefaultValue == null) return null; 116 result = ItemDescription == Description ? new Result(ActualName, (T)DefaultValue.Clone()) :new Result(ActualName, Description, (T)DefaultValue.Clone());116 result = new Result(ActualName, Description, (T)DefaultValue.Clone()); 117 117 results.Add(result); 118 118 } … … 143 143 IResult result; 144 144 if (!results.TryGetValue(ActualName, out result)) { 145 result = ItemDescription == Description ? new Result(ActualName, value) :new Result(ActualName, Description, value);145 result = new Result(ActualName, Description, value); 146 146 results.Add(result); 147 147 } else result.Value = value; -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/ExternalEvaluationProblem.cs
r17226 r17747 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 26 26 using System.Threading; 27 27 using Google.ProtocolBuffers; 28 using HEAL.Attic; 28 29 using HeuristicLab.Analysis; 29 30 using HeuristicLab.Common; … … 32 33 using HeuristicLab.Optimization; 33 34 using HeuristicLab.Parameters; 34 using HEAL.Attic;35 35 36 36 namespace HeuristicLab.Problems.ExternalEvaluation { … … 40 40 // BackwardsCompatibility3.3 41 41 // Rename class to SingleObjectiveExternalEvaluationProblem 42 public class ExternalEvaluationProblem : SingleObjectiveProblem<IEncoding<IEncodedSolution>, IEncodedSolution>, IExternalEvaluationProblem { 42 public class ExternalEvaluationProblem<TEncoding, TEncodedSolution> : SingleObjectiveProblem<TEncoding, TEncodedSolution>, IExternalEvaluationProblem 43 where TEncoding : class, IEncoding 44 where TEncodedSolution : class, IEncodedSolution { 43 45 44 46 public static new Image StaticItemImage { … … 56 58 get { return (IValueParameter<SolutionMessageBuilder>)Parameters["MessageBuilder"]; } 57 59 } 58 public IFixedValueParameter<SingleObjectiveOptimizationSupportScript> SupportScriptParameter { 59 get { return (IFixedValueParameter<SingleObjectiveOptimizationSupportScript>)Parameters["SupportScript"]; } 60 } 61 62 private IFixedValueParameter<BoolValue> MaximizationParameter { 63 get { return (IFixedValueParameter<BoolValue>)Parameters["Maximization"]; } 60 public IFixedValueParameter<SingleObjectiveOptimizationSupportScript<TEncodedSolution>> SupportScriptParameter { 61 get { return (IFixedValueParameter<SingleObjectiveOptimizationSupportScript<TEncodedSolution>>)Parameters["SupportScript"]; } 64 62 } 65 63 #endregion 66 64 67 65 #region Properties 68 public new IEncoding<IEncodedSolution>Encoding {66 public new TEncoding Encoding { 69 67 get { return base.Encoding; } 70 68 set { base.Encoding = value; } … … 79 77 get { return MessageBuilderParameter.Value; } 80 78 } 81 public SingleObjectiveOptimizationSupportScript OptimizationSupportScript {79 public SingleObjectiveOptimizationSupportScript<TEncodedSolution> OptimizationSupportScript { 82 80 get { return SupportScriptParameter.Value; } 83 81 } 84 private ISingleObjectiveOptimizationSupport OptimizationSupport {82 private ISingleObjectiveOptimizationSupport<TEncodedSolution> OptimizationSupport { 85 83 get { return SupportScriptParameter.Value; } 86 84 } … … 89 87 [StorableConstructor] 90 88 protected ExternalEvaluationProblem(StorableConstructorFlag _) : base(_) { } 91 protected ExternalEvaluationProblem(ExternalEvaluationProblem original, Cloner cloner) : base(original, cloner) { }89 protected ExternalEvaluationProblem(ExternalEvaluationProblem<TEncoding, TEncodedSolution> original, Cloner cloner) : base(original, cloner) { } 92 90 public override IDeepCloneable Clone(Cloner cloner) { 93 return new ExternalEvaluationProblem (this, cloner);91 return new ExternalEvaluationProblem<TEncoding, TEncodedSolution>(this, cloner); 94 92 } 95 public ExternalEvaluationProblem( )96 : base( ) {97 Parameters.Remove("Maximization"); // readonly in base class98 Parameters.Add(new FixedValueParameter<BoolValue>("Maximization", "Set to false if the problem should be minimized.", new BoolValue()));93 public ExternalEvaluationProblem(TEncoding encoding) 94 : base(encoding) { 95 MaximizationParameter.ReadOnly = false; 96 MaximizationParameter.Value = new BoolValue(); // is a read-only bool value in base class 99 97 Parameters.Add(new OptionalValueParameter<EvaluationCache>("Cache", "Cache of previously evaluated solutions.")); 100 98 Parameters.Add(new ValueParameter<CheckedItemCollection<IEvaluationServiceClient>>("Clients", "The clients that are used to communicate with the external application.", new CheckedItemCollection<IEvaluationServiceClient>() { new EvaluationServiceClient() })); 101 99 Parameters.Add(new ValueParameter<SolutionMessageBuilder>("MessageBuilder", "The message builder that converts from HeuristicLab objects to SolutionMessage representation.", new SolutionMessageBuilder()) { Hidden = true }); 102 Parameters.Add(new FixedValueParameter<SingleObjectiveOptimizationSupportScript >("SupportScript", "A script that can provide neighborhood and analyze the results of the optimization.", new SingleObjectiveOptimizationSupportScript()));100 Parameters.Add(new FixedValueParameter<SingleObjectiveOptimizationSupportScript<TEncodedSolution>>("SupportScript", "A script that can provide neighborhood and analyze the results of the optimization.", new SingleObjectiveOptimizationSupportScript<TEncodedSolution>(Results))); 103 101 104 102 Operators.Add(new BestScopeSolutionAnalyzer()); … … 106 104 107 105 #region Single Objective Problem Overrides 108 public override bool Maximization { 109 get { return Parameters.ContainsKey("Maximization") && ((IValueParameter<BoolValue>)Parameters["Maximization"]).Value.Value; } 106 public override ISingleObjectiveEvaluationResult Evaluate(TEncodedSolution solution, IRandom random, CancellationToken cancellationToken) { 107 var qualityMessage = Evaluate(BuildSolutionMessage(solution), cancellationToken); 108 if (!qualityMessage.HasExtension(SingleObjectiveQualityMessage.QualityMessage_)) 109 throw new InvalidOperationException("The received message is not a SingleObjectiveQualityMessage."); 110 var quality = qualityMessage.GetExtension(SingleObjectiveQualityMessage.QualityMessage_).Quality; 111 return new SingleObjectiveEvaluationResult(quality); 112 113 } 114 public virtual QualityMessage Evaluate(SolutionMessage solutionMessage, CancellationToken cancellationToken) { 115 return Cache == null 116 ? EvaluateOnNextAvailableClient(solutionMessage, cancellationToken) 117 : Cache.GetValue(solutionMessage, EvaluateOnNextAvailableClient, GetQualityMessageExtensions(), cancellationToken); 110 118 } 111 119 112 public virtual void SetMaximization(bool maximization) {113 MaximizationParameter.Value.Value = maximization;120 public override void Analyze(ISingleObjectiveSolutionContext<TEncodedSolution>[] solutions, IRandom random) { 121 OptimizationSupport.Analyze(solutions, random); 114 122 } 115 116 public override double Evaluate(IEncodedSolution individual, IRandom random) { 117 var qualityMessage = Evaluate(BuildSolutionMessage(individual)); 118 if (!qualityMessage.HasExtension(SingleObjectiveQualityMessage.QualityMessage_)) 119 throw new InvalidOperationException("The received message is not a SingleObjectiveQualityMessage."); 120 return qualityMessage.GetExtension(SingleObjectiveQualityMessage.QualityMessage_).Quality; 121 } 122 public virtual QualityMessage Evaluate(SolutionMessage solutionMessage) { 123 return Cache == null 124 ? EvaluateOnNextAvailableClient(solutionMessage) 125 : Cache.GetValue(solutionMessage, EvaluateOnNextAvailableClient, GetQualityMessageExtensions()); 126 } 127 128 public override void Analyze(IEncodedSolution[] individuals, double[] qualities, ResultCollection results, IRandom random) { 129 OptimizationSupport.Analyze(individuals, qualities, results, random); 130 } 131 132 public override IEnumerable<IEncodedSolution> GetNeighbors(IEncodedSolution individual, IRandom random) { 133 return OptimizationSupport.GetNeighbors(individual, random); 123 public override IEnumerable<TEncodedSolution> GetNeighbors(TEncodedSolution solutions, IRandom random) { 124 return OptimizationSupport.GetNeighbors(solutions, random); 134 125 } 135 126 #endregion … … 143 134 #region Evaluation 144 135 private HashSet<IEvaluationServiceClient> activeClients = new HashSet<IEvaluationServiceClient>(); 145 private object clientLock = new object();136 private readonly object clientLock = new object(); 146 137 147 private QualityMessage EvaluateOnNextAvailableClient(SolutionMessage message ) {138 private QualityMessage EvaluateOnNextAvailableClient(SolutionMessage message, CancellationToken cancellationToken) { 148 139 IEvaluationServiceClient client = null; 149 140 lock (clientLock) { … … 158 149 try { 159 150 return client.Evaluate(message, GetQualityMessageExtensions()); 160 } 161 finally { 151 } finally { 162 152 lock (clientLock) { 163 153 activeClients.Remove(client); … … 167 157 } 168 158 169 private SolutionMessage BuildSolutionMessage( IEncodedSolution solution, int solutionId = 0) {159 private SolutionMessage BuildSolutionMessage(TEncodedSolution solution, int solutionId = 0) { 170 160 lock (clientLock) { 171 161 SolutionMessage.Builder protobufBuilder = SolutionMessage.CreateBuilder(); … … 176 166 try { 177 167 MessageBuilder.AddToMessage(variable.Value, variable.Name, protobufBuilder); 178 } 179 catch (ArgumentException ex) { 168 } catch (ArgumentException ex) { 180 169 throw new InvalidOperationException(string.Format("ERROR while building solution message: Parameter {0} cannot be added to the message", Name), ex); 181 170 } -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/HeuristicLab.Problems.ExternalEvaluation-3.4.csproj
r16816 r17747 138 138 <Compile Include="MultiObjectiveExternalEvaluationProblem.cs" /> 139 139 <Compile Include="ExternalEvaluationProblemInstances.cs" /> 140 <Compile Include=" SingleObjectiveExternalEvaluationProblem.cs" />140 <Compile Include="ExternalEvaluationProblem.cs" /> 141 141 <Compile Include="Interfaces\IEvaluationServiceClient.cs" /> 142 142 <Compile Include="Interfaces\IEvaluationChannel.cs" /> -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/Interfaces/ISingleObjectiveOptimizationSupport.cs
r17745 r17747 30 30 where TEncodedSolution : class, IEncodedSolution { 31 31 32 void InitializeResults(); 32 33 void Analyze(ISingleObjectiveSolutionContext<TEncodedSolution>[] solutionContexts, IRandom random); 33 34 IEnumerable<TEncodedSolution> GetNeighbors(TEncodedSolution individual, IRandom random); -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/CompiledOptimizationSupport.cs
r17226 r17747 20 20 #endregion 21 21 22 using HeuristicLab.Optimization; 23 22 24 namespace HeuristicLab.Problems.ExternalEvaluation { 23 25 public abstract class CompiledOptimizationSupport { 24 26 25 27 public dynamic vars { get; set; } 28 public ResultCollection Results { get; set; } 26 29 } 27 30 } -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/MultiObjective/MultiObjectiveOptimizationSupportScript.cs
r16816 r17747 33 33 private MultiObjectiveOptimizationSupportScript(StorableConstructorFlag _) : base(_) { } 34 34 private MultiObjectiveOptimizationSupportScript(MultiObjectiveOptimizationSupportScript<TEncodedSolution> original, Cloner cloner) : base(original, cloner) { } 35 public MultiObjectiveOptimizationSupportScript() {35 public MultiObjectiveOptimizationSupportScript() : base() { 36 36 var codeTemplate = Templates.CompiledMultiObjectiveOptimizationSupport; 37 37 codeTemplate = codeTemplate.Replace("ENCODING_NAMESPACE", typeof(TEncodedSolution).Namespace); -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/OptimizationSupportScript.cs
r17226 r17747 23 23 using System.Linq; 24 24 using System.Reflection; 25 using HEAL.Attic; 25 26 using HeuristicLab.Common; 26 using H EAL.Attic;27 using HeuristicLab.Optimization; 27 28 using HeuristicLab.Scripting; 28 29 … … 38 39 } 39 40 41 [Storable] 42 private ResultCollection results; 43 public ResultCollection Results { 44 get { return results; } 45 } 46 40 47 [StorableConstructor] 41 48 protected OptimizationSupportScript(StorableConstructorFlag _) : base(_) { } … … 43 50 : base(original, cloner) { 44 51 variableStore = cloner.Clone(original.variableStore); 52 results = cloner.Clone(original.results); 45 53 } 46 47 protected OptimizationSupportScript()48 54 55 [Obsolete("Do not use this constructor.")] 56 protected OptimizationSupportScript() : base() { 49 57 variableStore = new VariableStore(); 50 58 } 51 59 52 protected OptimizationSupportScript( string code)53 : base( code) {60 protected OptimizationSupportScript(ResultCollection results) 61 : base() { 54 62 variableStore = new VariableStore(); 63 this.results = results; 55 64 } 56 65 … … 86 95 inst = (CompiledOptimizationSupport)Activator.CreateInstance(types.Single(x => typeof(CompiledOptimizationSupport).IsAssignableFrom(x))); 87 96 inst.vars = new Variables(VariableStore); 97 inst.Results = results; 88 98 } catch (Exception e) { 89 99 compiledInstance = null; … … 93 103 var concreteInst = inst as T; 94 104 if (concreteInst == null) 95 throw new OptimizationSupportException( "The optimization support class does not implement ISingleObjectiveOptimizationSupport." + Environment.NewLine + "Please implement that interface in the subclass of CompiledOptimizationSupport.");105 throw new OptimizationSupportException($"The optimization support class does not implement {typeof(T).FullName}." + Environment.NewLine + "Please implement that interface in the subclass of CompiledOptimizationSupport."); 96 106 97 107 CompiledInstance = concreteInst; -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/SingleObjective/CompiledSingleObjectiveOptimizationSupport.cs
r16816 r17747 8 8 public class CompiledSingleObjectiveOptimizationSupport : CompiledOptimizationSupport, ISingleObjectiveOptimizationSupport<SOLUTION_CLASS> { 9 9 10 public void Analyze(SOLUTION_CLASS[] solutions, double[] qualities, ResultCollection results, IRandom random) { 10 // private Result<StringValue> myResult; 11 12 public void InitializeResults() { 13 // Initialize the results that you intend to produce 14 // Uncomment the field above and the code below to add to the problem's results 15 // if (!Results.TryGetValue("My Result", out myResult)) 16 // Results.Add(myResult = new Result<StringValue>("My Result", "My result description.")); 17 } 18 19 public void Analyze(ISingleObjectiveSolutionContext<SOLUTION_CLASS>[] solutionContexts, IRandom random) { 11 20 // Use vars.yourVariable to access variables in the variable store i.e. yourVariable 12 21 // Write or update results given the range of vectors and resulting qualities 13 // Uncomment the following lines if you want to retrieve the best individual22 // Uncomment the following lines if you want to retrieve the current best individual 14 23 // Maximization: 15 // var best Index = qualities.Select((v, i) => Tuple.Create(i, v)).OrderByDescending(x => x.Item2).First().Item1;24 // var best = solutionContexts.OrderByDescending(x => x.EvaluationResult.Quality).First(); 16 25 // Minimization: 17 // var bestIndex = qualities.Select((v, i) => Tuple.Create(i, v)).OrderBy(x => x.Item2).First().Item1; 18 // var best = solutions[bestIndex]; 26 // var best = solutionContexts.OrderBy(x => x.EvaluationResult.Quality).First(); 27 // 28 // myResult.Value = new StringValue("Custom result"); 19 29 } 20 30 -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/SingleObjective/SingleObjectiveOptimizationSupportScript.cs
r17745 r17747 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using HEAL.Attic; … … 36 37 private SingleObjectiveOptimizationSupportScript(StorableConstructorFlag _) : base(_) { } 37 38 private SingleObjectiveOptimizationSupportScript(SingleObjectiveOptimizationSupportScript<TEncodedSolution> original, Cloner cloner) : base(original, cloner) { } 38 public SingleObjectiveOptimizationSupportScript() : base() { 39 [Obsolete("Do not use this constructor.")] 40 public SingleObjectiveOptimizationSupportScript() : this(null) { } 41 public SingleObjectiveOptimizationSupportScript(ResultCollection results) : base(results) { 39 42 var codeTemplate = Templates.CompiledSingleObjectiveOptimizationSupport; 40 43 codeTemplate = codeTemplate.Replace("ENCODING_NAMESPACE", typeof(TEncodedSolution).Namespace); … … 45 48 public override IDeepCloneable Clone(Cloner cloner) { 46 49 return new SingleObjectiveOptimizationSupportScript<TEncodedSolution>(this, cloner); 50 } 51 52 void ISingleObjectiveOptimizationSupport<TEncodedSolution>.InitializeResults() { 53 CompiledInstance.InitializeResults(); 47 54 } 48 55
Note: See TracChangeset
for help on using the changeset viewer.