- Timestamp:
- 04/27/20 18:12:39 (5 years ago)
- Location:
- branches/2521_ProblemRefactoring
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/BinaryVectorMultiObjectiveProblem.cs
r17230 r17522 31 31 [StorableType("b64caac0-a23a-401a-bb7e-ffa3e22b80ea")] 32 32 public abstract class BinaryVectorMultiObjectiveProblem : MultiObjectiveProblem<BinaryVectorEncoding, BinaryVector> { 33 [Storable] protected IResultParameter<ParetoFrontScatterPlot<BinaryVector>> BestResultParameter { get; private set; } 34 public IResultDefinition<ParetoFrontScatterPlot<BinaryVector>> BestResult { get { return BestResultParameter; } } 35 33 36 public int Length { 34 37 get { return Encoding.Length; } … … 45 48 protected BinaryVectorMultiObjectiveProblem(BinaryVectorMultiObjectiveProblem original, Cloner cloner) 46 49 : base(original, cloner) { 50 BestResultParameter = cloner.Clone(original.BestResultParameter); 47 51 RegisterEventHandlers(); 48 52 } … … 51 55 protected BinaryVectorMultiObjectiveProblem(BinaryVectorEncoding encoding) : base(encoding) { 52 56 EncodingParameter.ReadOnly = true; 57 Parameters.Add(BestResultParameter = new ResultParameter<ParetoFrontScatterPlot<BinaryVector>>("Best Pareto Front", "The best Pareto front found.")); 53 58 54 59 Operators.Add(new HammingSimilarityCalculator()); … … 64 69 var fronts = DominationCalculator.CalculateAllParetoFrontsIndices(individuals, qualities, Maximization); 65 70 var plot = new ParetoFrontScatterPlot<BinaryVector>(fronts, individuals, qualities, Objectives, BestKnownFront); 66 results.AddOrUpdateResult("Pareto Front Scatter Plot", plot); 71 72 BestResultParameter.ActualValue = plot; 67 73 } 68 74 -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/BinaryVectorProblem.cs
r17517 r17522 33 33 [StorableType("2F6FEB34-BD19-47AF-9484-7F48565C0C43")] 34 34 public abstract class BinaryVectorProblem : SingleObjectiveProblem<BinaryVectorEncoding, BinaryVector> { 35 [Storable] public IResultParameter<BinaryVector> BestSolutionParameter { get; private set; } 35 [Storable] protected IResultParameter<ISingleObjectiveSolutionContext<BinaryVector>> BestResultParameter { get; private set; } 36 public IResultDefinition<ISingleObjectiveSolutionContext<BinaryVector>> BestResult { get { return BestResultParameter; } } 36 37 37 38 public int Length { … … 49 50 protected BinaryVectorProblem(BinaryVectorProblem original, Cloner cloner) 50 51 : base(original, cloner) { 51 Best SolutionParameter = cloner.Clone(original.BestSolutionParameter);52 BestResultParameter = cloner.Clone(original.BestResultParameter); 52 53 RegisterEventHandlers(); 53 54 } … … 56 57 protected BinaryVectorProblem(BinaryVectorEncoding encoding) : base(encoding) { 57 58 EncodingParameter.ReadOnly = true; 58 BestSolutionParameter = new ResultParameter<BinaryVector>("Best Solution", "The best solution."); 59 Parameters.Add(BestSolutionParameter); 59 Parameters.Add(BestResultParameter = new ResultParameter<ISingleObjectiveSolutionContext<BinaryVector>>("Best Solution", "The best solution.")); 60 60 61 61 Operators.Add(new HammingSimilarityCalculator()); … … 67 67 } 68 68 69 public override void Analyze(BinaryVector[] vectors, double[] qualities, ResultCollection results, IRandom random) { 70 base.Analyze(vectors, qualities, results, random); 71 var best = GetBestSolution(vectors, qualities); 72 BestSolutionParameter.ActualValue = (BinaryVector)best.Item1.Clone(); 69 public override void Analyze(ISingleObjectiveSolutionContext<BinaryVector>[] solutionContexts, ResultCollection results, IRandom random) { 70 var best = GetBest(solutionContexts); 71 var currentBest = BestResultParameter.ActualValue; 72 if (currentBest == null || IsBetter(best.EvaluationResult.Quality, currentBest.EvaluationResult.Quality)) 73 BestResultParameter.ActualValue = (ISingleObjectiveSolutionContext<BinaryVector>)best.Clone(); 73 74 } 74 75 -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVectorMultiObjectiveProblem.cs
r17230 r17522 33 33 [StorableType("11916b0f-4c34-4ece-acae-e28d11211b43")] 34 34 public abstract class IntegerVectorMultiObjectiveProblem : MultiObjectiveProblem<IntegerVectorEncoding, IntegerVector> { 35 [Storable] protected IResultParameter<ParetoFrontScatterPlot<IntegerVector>> BestResultParameter { get; private set; } 36 public IResultDefinition<ParetoFrontScatterPlot<IntegerVector>> BestResult { get { return BestResultParameter; } } 37 35 38 public int Length { 36 39 get { return Encoding.Length; } … … 47 50 protected IntegerVectorMultiObjectiveProblem(IntegerVectorMultiObjectiveProblem original, Cloner cloner) 48 51 : base(original, cloner) { 52 BestResultParameter = cloner.Clone(original.BestResultParameter); 49 53 RegisterEventHandlers(); 50 54 } … … 53 57 protected IntegerVectorMultiObjectiveProblem(IntegerVectorEncoding encoding) : base(encoding) { 54 58 EncodingParameter.ReadOnly = true; 59 Parameters.Add(BestResultParameter = new ResultParameter<ParetoFrontScatterPlot<IntegerVector>>("Best Pareto Front", "The best Pareto front found.")); 55 60 56 61 Operators.Add(new HammingSimilarityCalculator()); … … 66 71 var fronts = DominationCalculator.CalculateAllParetoFrontsIndices(individuals, qualities, Maximization); 67 72 var plot = new ParetoFrontScatterPlot<IntegerVector>(fronts, individuals, qualities, Objectives, BestKnownFront); 68 results.AddOrUpdateResult("Pareto Front Scatter Plot", plot); 73 74 BestResultParameter.ActualValue = plot; 69 75 } 70 76 -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVectorProblem.cs
r16950 r17522 34 34 [StorableType("c6081457-a3de-45ce-9f47-e0eb1c851bd2")] 35 35 public abstract class IntegerVectorProblem : SingleObjectiveProblem<IntegerVectorEncoding, IntegerVector> { 36 [Storable] protected IResultParameter<IntegerVector> BestResultParameter { get; private set; } 37 public IResultDefinition<IntegerVector> BestResult { get => BestResultParameter; } 38 36 39 public int Length { 37 40 get { return Encoding.Length; } … … 48 51 protected IntegerVectorProblem(IntegerVectorProblem original, Cloner cloner) 49 52 : base(original, cloner) { 53 BestResultParameter = cloner.Clone(original.BestResultParameter); 50 54 RegisterEventHandlers(); 51 55 } … … 54 58 protected IntegerVectorProblem(IntegerVectorEncoding encoding) : base(encoding) { 55 59 EncodingParameter.ReadOnly = true; 60 Parameters.Add(BestResultParameter = new ResultParameter<IntegerVector>("Best Solution", "The best solution.")); 56 61 57 62 Operators.Add(new HammingSimilarityCalculator()); -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/SingleObjectiveProblem.cs
r17382 r17522 149 149 150 150 //TODO refactor to solution contexts 151 protected ISingleObjectiveSolutionContext<TEncodedSolution> GetBest(ISingleObjectiveSolutionContext<TEncodedSolution>[] solutionContexts) { 152 return Maximization ? solutionContexts.MaxItems(x => x.EvaluationResult.Quality).First() 153 : solutionContexts.MinItems(x => x.EvaluationResult.Quality).First(); 154 } 151 155 protected Tuple<TEncodedSolution, double> GetBestSolution(TEncodedSolution[] solutions, double[] qualities) { 152 156 return GetBestSolution(solutions, qualities, Maximization); -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/Results/IResultParameter.cs
r17517 r17522 21 21 22 22 using System; 23 using HEAL.Attic; 23 24 using HeuristicLab.Core; 24 using HEAL.Attic;25 25 26 26 namespace HeuristicLab.Optimization { 27 [StorableType("986fa3d0-38f8-43aa-820e-e67d09a29025")] 28 public interface IResultDefinition { 29 string Name { get; set; } 30 } 31 32 [StorableType("4c0c854b-676d-4ccd-96c4-b06a3d7f2fa1")] 33 public interface IResultDefinition<T> : IResultDefinition where T : class, IItem { 34 T Get(ResultCollection results); 35 } 36 27 37 [StorableType("af5d3f60-6f3a-4a44-a906-688ac8296fe3")] 28 public interface IResultParameter : ILookupParameter {38 public interface IResultParameter : ILookupParameter, IResultDefinition { 29 39 string ResultCollectionName { get; set; } 30 40 ResultCollection ResultCollection { get; set; } … … 34 44 35 45 [StorableType("803e6ad6-dd9d-497a-ad1c-7cd3dc5b0d3c")] 36 public interface IResultParameter<T> : ILookupParameter<T>, IResultParameter where T : class, IItem {46 public interface IResultParameter<T> : ILookupParameter<T>, IResultParameter, IResultDefinition<T> where T : class, IItem { 37 47 T DefaultValue { get; set; } 38 48 event EventHandler DefaultValueChanged; -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/Results/ResultParameter.cs
r17517 r17522 62 62 [Storable] 63 63 public ResultCollection ResultCollection { get; set; } 64 65 string IResultDefinition.Name { get => ActualName; set => ActualName = value; } 66 T IResultDefinition<T>.Get(ResultCollection results) => results[ActualName].Value as T; 64 67 65 68 [StorableConstructor]
Note: See TracChangeset
for help on using the changeset viewer.