Changeset 17522 for branches/2521_ProblemRefactoring/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/BinaryVectorProblem.cs
- Timestamp:
- 04/27/20 18:12:39 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note: See TracChangeset
for help on using the changeset viewer.