Changeset 17363 for branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/SingleObjectiveProblem.cs
- Timestamp:
- 11/21/19 17:58:32 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/SingleObjectiveProblem.cs
r17356 r17363 117 117 } 118 118 public abstract double Evaluate(TEncodedSolution solution, IRandom random, CancellationToken cancellationToken); 119 120 public virtual void Evaluate(ISingleObjectiveSolutionContext<TEncodedSolution> solutionContext, IRandom random) { 121 Evaluate(solutionContext, random, CancellationToken.None); 122 } 123 public virtual void Evaluate(ISingleObjectiveSolutionContext<TEncodedSolution> solutionContext, IRandom random, CancellationToken cancellationToken) { 124 double quality = Evaluate(solutionContext.EncodedSolution, random, cancellationToken); 125 solutionContext.EvaluationResult = new SingleObjectiveEvaluationResult(quality); 126 } 127 119 128 public virtual void Analyze(TEncodedSolution[] solutions, double[] qualities, ResultCollection results, IRandom random) { } 120 public virtual IEnumerable<TEncodedSolution> GetNeighbors(TEncodedSolution solution, IRandom random) { 129 public virtual void Analyze(ISingleObjectiveSolutionContext<TEncodedSolution>[] solutionContexts, ResultCollection results, IRandom random) { 130 var solutions = solutionContexts.Select(c => c.EncodedSolution).ToArray(); 131 var qualities = solutionContexts.Select(c => c.EvaluationResult.Quality).ToArray(); 132 Analyze(solutions, qualities, results, random); 133 } 134 135 public virtual IEnumerable<TEncodedSolution> GetNeighbors(TEncodedSolution solutions, IRandom random) { 121 136 return Enumerable.Empty<TEncodedSolution>(); 122 137 } 138 public virtual IEnumerable<ISingleObjectiveSolutionContext<TEncodedSolution>> GetNeighbors(ISingleObjectiveSolutionContext<TEncodedSolution> solutionContext, IRandom random) { 139 return GetNeighbors(solutionContext.EncodedSolution, random).Select(n => new SingleObjectiveSolutionContext<TEncodedSolution>(n)); 140 } 141 142 123 143 124 144 public static bool IsBetter(bool maximization, double quality, double bestQuality) { … … 130 150 } 131 151 152 //TODO refactor to solution contexts 132 153 protected Tuple<TEncodedSolution, double> GetBestSolution(TEncodedSolution[] solutions, double[] qualities) { 133 154 return GetBestSolution(solutions, qualities, Maximization); … … 170 191 private void ParameterizeOperators() { 171 192 foreach (var op in Operators.OfType<ISingleObjectiveEvaluationOperator<TEncodedSolution>>()) 172 op.Evaluate Func= Evaluate;193 op.Evaluate = Evaluate; 173 194 foreach (var op in Operators.OfType<ISingleObjectiveAnalysisOperator<TEncodedSolution>>()) 174 op.Analyze Action= Analyze;195 op.Analyze = Analyze; 175 196 foreach (var op in Operators.OfType<INeighborBasedOperator<TEncodedSolution>>()) 176 op.GetNeighbors Func= GetNeighbors;197 op.GetNeighbors = GetNeighbors; 177 198 } 178 199
Note: See TracChangeset
for help on using the changeset viewer.