Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/03/19 15:37:38 (5 years ago)
Author:
mkommend
Message:

#2521: Renamed Solution to EncodedSolution.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/SingleObjectiveProblem.cs

    r16723 r16751  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using HEAL.Attic;
    2526using HeuristicLab.Common;
    2627using HeuristicLab.Core;
    2728using HeuristicLab.Data;
    2829using HeuristicLab.Parameters;
    29 using HEAL.Attic;
    3030
    3131namespace HeuristicLab.Optimization {
    3232  [StorableType("2697320D-0259-44BB-BD71-7EE1B10F664C")]
    33   public abstract class SingleObjectiveProblem<TEncoding, TSolution> :
    34     Problem<TEncoding, TSolution, SingleObjectiveEvaluator<TSolution>>,
    35     ISingleObjectiveProblem<TEncoding, TSolution>,
    36     ISingleObjectiveProblemDefinition<TEncoding, TSolution>
    37     where TEncoding : class, IEncoding<TSolution>
    38     where TSolution : class, ISolution {
     33  public abstract class SingleObjectiveProblem<TEncoding, TEncodedSolution> :
     34    Problem<TEncoding, TEncodedSolution, SingleObjectiveEvaluator<TEncodedSolution>>,
     35    ISingleObjectiveProblem<TEncoding, TEncodedSolution>,
     36    ISingleObjectiveProblemDefinition<TEncoding, TEncodedSolution>
     37    where TEncoding : class, IEncoding<TEncodedSolution>
     38    where TEncodedSolution : class, IEncodedSolution {
    3939
    4040    protected IValueParameter<DoubleValue> BestKnownQualityParameter {
     
    6464    protected SingleObjectiveProblem(StorableConstructorFlag _) : base(_) { }
    6565
    66     protected SingleObjectiveProblem(SingleObjectiveProblem<TEncoding, TSolution> original, Cloner cloner)
     66    protected SingleObjectiveProblem(SingleObjectiveProblem<TEncoding, TEncodedSolution> original, Cloner cloner)
    6767      : base(original, cloner) {
    6868      ParameterizeOperators();
     
    7575
    7676      Operators.Add(Evaluator);
    77       Operators.Add(new SingleObjectiveAnalyzer<TSolution>());
    78       Operators.Add(new SingleObjectiveImprover<TSolution>());
    79       Operators.Add(new SingleObjectiveMoveEvaluator<TSolution>());
    80       Operators.Add(new SingleObjectiveMoveGenerator<TSolution>());
    81       Operators.Add(new SingleObjectiveMoveMaker<TSolution>());
     77      Operators.Add(new SingleObjectiveAnalyzer<TEncodedSolution>());
     78      Operators.Add(new SingleObjectiveImprover<TEncodedSolution>());
     79      Operators.Add(new SingleObjectiveMoveEvaluator<TEncodedSolution>());
     80      Operators.Add(new SingleObjectiveMoveGenerator<TEncodedSolution>());
     81      Operators.Add(new SingleObjectiveMoveMaker<TEncodedSolution>());
    8282
    8383      ParameterizeOperators();
     
    9090
    9191      Operators.Add(Evaluator);
    92       Operators.Add(new SingleObjectiveAnalyzer<TSolution>());
    93       Operators.Add(new SingleObjectiveImprover<TSolution>());
    94       Operators.Add(new SingleObjectiveMoveEvaluator<TSolution>());
    95       Operators.Add(new SingleObjectiveMoveGenerator<TSolution>());
    96       Operators.Add(new SingleObjectiveMoveMaker<TSolution>());
     92      Operators.Add(new SingleObjectiveAnalyzer<TEncodedSolution>());
     93      Operators.Add(new SingleObjectiveImprover<TEncodedSolution>());
     94      Operators.Add(new SingleObjectiveMoveEvaluator<TEncodedSolution>());
     95      Operators.Add(new SingleObjectiveMoveGenerator<TEncodedSolution>());
     96      Operators.Add(new SingleObjectiveMoveMaker<TEncodedSolution>());
    9797
    9898      ParameterizeOperators();
     
    105105
    106106    public abstract bool Maximization { get; }
    107     public abstract double Evaluate(TSolution solution, IRandom random);
    108     public virtual void Analyze(TSolution[] solutions, double[] qualities, ResultCollection results, IRandom random) { }
    109     public virtual IEnumerable<TSolution> GetNeighbors(TSolution solution, IRandom random) {
    110       return Enumerable.Empty<TSolution>();
     107    public abstract double Evaluate(TEncodedSolution solution, IRandom random);
     108    public virtual void Analyze(TEncodedSolution[] solutions, double[] qualities, ResultCollection results, IRandom random) { }
     109    public virtual IEnumerable<TEncodedSolution> GetNeighbors(TEncodedSolution solution, IRandom random) {
     110      return Enumerable.Empty<TEncodedSolution>();
    111111    }
    112112
     
    115115    }
    116116
    117     protected Tuple<TSolution, double> GetBestSolution(TSolution[] solutions, double[] qualities) {
     117    protected Tuple<TEncodedSolution, double> GetBestSolution(TEncodedSolution[] solutions, double[] qualities) {
    118118      return GetBestSolution(solutions, qualities, Maximization);
    119119    }
    120     public static Tuple<TSolution, double> GetBestSolution(TSolution[] solutions, double[] qualities, bool maximization) {
     120    public static Tuple<TEncodedSolution, double> GetBestSolution(TEncodedSolution[] solutions, double[] qualities, bool maximization) {
    121121      var zipped = solutions.Zip(qualities, (s, q) => new { Solution = s, Quality = q });
    122122      var best = (maximization ? zipped.OrderByDescending(z => z.Quality) : zipped.OrderBy(z => z.Quality)).First();
     
    154154
    155155    private void ParameterizeOperators() {
    156       foreach (var op in Operators.OfType<ISingleObjectiveEvaluationOperator<TSolution>>())
     156      foreach (var op in Operators.OfType<ISingleObjectiveEvaluationOperator<TEncodedSolution>>())
    157157        op.EvaluateFunc = Evaluate;
    158       foreach (var op in Operators.OfType<ISingleObjectiveAnalysisOperator<TSolution>>())
     158      foreach (var op in Operators.OfType<ISingleObjectiveAnalysisOperator<TEncodedSolution>>())
    159159        op.AnalyzeAction = Analyze;
    160       foreach (var op in Operators.OfType<INeighborBasedOperator<TSolution>>())
     160      foreach (var op in Operators.OfType<INeighborBasedOperator<TEncodedSolution>>())
    161161        op.GetNeighborsFunc = GetNeighbors;
    162162    }
Note: See TracChangeset for help on using the changeset viewer.