Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17745


Ignore:
Timestamp:
09/15/20 13:53:11 (4 years ago)
Author:
mkommend
Message:

#2971: Added first draft of results implementation and problem adaptation.

Location:
branches/2521_ProblemRefactoring
Files:
38 edited

Legend:

Unmodified
Added
Removed
  • branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessCovarianceOptimizationProblem.cs

    r17655 r17745  
    274274    }
    275275
    276     public override void Analyze(ISymbolicExpressionTree[] trees, double[] qualities, ResultCollection results, IRandom random) {
    277       if (!results.ContainsKey("Best Solution Quality")) {
    278         results.Add(new Result("Best Solution Quality", typeof(DoubleValue)));
    279       }
    280       if (!results.ContainsKey("Best Tree")) {
    281         results.Add(new Result("Best Tree", typeof(ISymbolicExpressionTree)));
    282       }
    283       if (!results.ContainsKey("Best Solution")) {
    284         results.Add(new Result("Best Solution", typeof(GaussianProcessRegressionSolution)));
    285       }
    286 
    287       var bestQuality = qualities.Max();
    288 
    289       if (results["Best Solution Quality"].Value == null || bestQuality > ((DoubleValue)results["Best Solution Quality"].Value).Value) {
    290         var bestIdx = Array.IndexOf(qualities, bestQuality);
    291         var bestClone = (ISymbolicExpressionTree)trees[bestIdx].Clone();
    292         results["Best Tree"].Value = bestClone;
    293         results["Best Solution Quality"].Value = new DoubleValue(bestQuality);
    294         results["Best Solution"].Value = CreateSolution();
    295       }
     276
     277    public override void Analyze(ISingleObjectiveSolutionContext<ISymbolicExpressionTree>[] solutionContexts, IRandom random) {
     278      //TODO: reimplement code below with results parameter
     279
     280      //if (!results.ContainsKey("Best Solution Quality")) {
     281      //  results.Add(new Result("Best Solution Quality", typeof(DoubleValue)));
     282      //}
     283      //if (!results.ContainsKey("Best Tree")) {
     284      //  results.Add(new Result("Best Tree", typeof(ISymbolicExpressionTree)));
     285      //}
     286      //if (!results.ContainsKey("Best Solution")) {
     287      //  results.Add(new Result("Best Solution", typeof(GaussianProcessRegressionSolution)));
     288      //}
     289
     290      //var bestQuality = qualities.Max();
     291
     292      //if (results["Best Solution Quality"].Value == null || bestQuality > ((DoubleValue)results["Best Solution Quality"].Value).Value) {
     293      //  var bestIdx = Array.IndexOf(qualities, bestQuality);
     294      //  var bestClone = (ISymbolicExpressionTree)trees[bestIdx].Clone();
     295      //  results["Best Tree"].Value = bestClone;
     296      //  results["Best Solution Quality"].Value = new DoubleValue(bestQuality);
     297      //  results["Best Solution"].Value = CreateSolution();
     298      //}
    296299    }
    297300
  • branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.GeneticAlgorithm/3.3/GeneticAlgorithm.cs

    r17695 r17745  
    157157      Parameters.Add(new ValueParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new PercentValue(0.05)));
    158158      Parameters.Add(new ConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));
    159       Parameters.Add(new ValueParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1)));
     159      Parameters.Add(new ValueParameter<IntValue>("Elites", "The number of elite solutions which are kept in each generation.", new IntValue(1)));
    160160      Parameters.Add(new FixedValueParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)", new BoolValue(false)) { Hidden = true });
    161161      Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze each generation.", new MultiAnalyzer()));
  • branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/EvaluationTracker.cs

    r17382 r17745  
    132132    }
    133133
    134     public void Analyze(BinaryVector[] individuals, double[] qualities, ResultCollection results, IRandom random) {
    135       problem.Analyze(individuals, qualities, results, random);
    136     }
    137 
    138     public void Analyze(ISingleObjectiveSolutionContext<BinaryVector>[] solutionContexts, ResultCollection results, IRandom random) {
    139       var solutions = solutionContexts.Select(c => c.EncodedSolution).ToArray();
    140       var qualities = solutionContexts.Select(c => c.EvaluationResult.Quality).ToArray();
    141       Analyze(solutions, qualities, results, random);
     134    public void Analyze(ISingleObjectiveSolutionContext<BinaryVector>[] solutionContexts, IRandom random) {
     135      problem.Analyze(solutionContexts, random);
    142136    }
    143137
  • branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/HillClimber.cs

    r17612 r17745  
    125125        }
    126126
     127        var context = new SingleObjectiveSolutionContext<BinaryVector>(solution);
     128        context.EvaluationResult = new SingleObjectiveEvaluationResult(fitness);
     129        Problem.Analyze(new[] { context }, random);
     130
    127131        Iterations++;
    128132      }
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/BinaryVectorProblem.cs

    r17695 r17745  
    7777    }
    7878
    79     public override void Analyze(ISingleObjectiveSolutionContext<BinaryVector>[] solutionContexts, ResultCollection results, IRandom random) {
    80       base.Analyze(solutionContexts, results, random);
     79    public override void Analyze(ISingleObjectiveSolutionContext<BinaryVector>[] solutionContexts, IRandom random) {
     80      base.Analyze(solutionContexts, random);
    8181      var best = GetBest(solutionContexts);
    8282      if (BestSolution == null || IsBetter(best, BestSolution))
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVectorProblem.cs

    r17695 r17745  
    8282    }
    8383
    84     public override void Analyze(IntegerVector[] vectors, double[] qualities, ResultCollection results, IRandom random) {
    85       base.Analyze(vectors, qualities, results, random);
    86       var best = GetBestSolution(vectors, qualities);
     84    public override void Analyze(ISingleObjectiveSolutionContext<IntegerVector>[] solutionContext, IRandom random) {
     85      base.Analyze(solutionContext, random);
    8786
    88       results.AddOrUpdateResult("Best Solution", (IItem)best.Item1.Clone());
     87      var best = GetBest(solutionContext);
     88
     89      //TODO reimplement code below using results directly
     90      //results.AddOrUpdateResult("Best Solution", (IntegerVector)best.EncodedSolution.Clone());
    8991    }
    9092
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/LinearLinkageProblem.cs

    r17695 r17745  
    7171    }
    7272
    73     public override void Analyze(LinearLinkage[] vectors, double[] qualities, ResultCollection results, IRandom random) {
    74       base.Analyze(vectors, qualities, results, random);
    75       var best = GetBestSolution(vectors, qualities);
     73    public override void Analyze(ISingleObjectiveSolutionContext<LinearLinkage>[] solutionContexts, IRandom random) {
     74      base.Analyze(solutionContexts, random);
    7675
    77       results.AddOrUpdateResult("Best Solution", (Item)best.Item1.Clone());
     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());
    7881    }
    7982
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.PermutationEncoding/3.3/PermutationProblem.cs

    r17695 r17745  
    6969      Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the permutation problem.", Encoding.LengthParameter));
    7070      Parameters.Add(PermutationTypeRefParameter = new ReferenceParameter<EnumValue<PermutationTypes>>("Type", "The type of the permutation.", Encoding.PermutationTypeParameter));
    71      
     71
    7272      Operators.Add(new HammingSimilarityCalculator());
    7373      // TODO: These should be added in the SingleObjectiveProblem base class (if they were accessible from there)
     
    7979    }
    8080
    81     public override void Analyze(Permutation[] permutations, double[] qualities, ResultCollection results, IRandom random) {
    82       base.Analyze(permutations, qualities, results, random);
    83       var best = GetBestSolution(permutations, qualities);
    84       results.AddOrUpdateResult("Best Solution", (IItem)best.Item1.Clone());
     81    public override void Analyze(ISingleObjectiveSolutionContext<Permutation>[] solutionContexts, IRandom random) {
     82      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());
    8587    }
    8688
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.RealVectorEncoding/3.3/RealVectorProblem.cs

    r17695 r17745  
    8080    }
    8181
    82     public override void Analyze(RealVector[] vectors, double[] qualities, ResultCollection results, IRandom random) {
    83       base.Analyze(vectors, qualities, results, random);
    84       var best = GetBestSolution(vectors, qualities);
     82    public override void Analyze(ISingleObjectiveSolutionContext<RealVector>[] solutionContexts, IRandom random) {
     83      base.Analyze(solutionContexts, random);
    8584
    86       results.AddOrUpdateResult("Best Solution", (IItem)best.Item1.Clone());
     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());
    8790    }
    8891
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeProblem.cs

    r17695 r17745  
    7272    }
    7373
    74     protected SymbolicExpressionTreeProblem() : this(new SymbolicExpressionTreeEncoding()) { }   
     74    protected SymbolicExpressionTreeProblem() : this(new SymbolicExpressionTreeEncoding()) { }
    7575    protected SymbolicExpressionTreeProblem(SymbolicExpressionTreeEncoding encoding)
    7676      : base(encoding) {
     
    8080      Parameters.Add(TreeDepthRefParameter = new ReferenceParameter<IntValue>("TreeDepth", "The maximum depth of the tree.", Encoding.TreeDepthParameter));
    8181      Parameters.Add(GrammarRefParameter = new ReferenceParameter<ISymbolicExpressionGrammar>("Grammar", "The grammar that describes a valid tree.", Encoding.GrammarParameter));
    82      
     82
    8383      // TODO: These should be added in the SingleObjectiveProblem base class (if they were accessible from there)
    8484      Operators.Add(new QualitySimilarityCalculator());
     
    8989    }
    9090
    91     public override void Analyze(ISymbolicExpressionTree[] trees, double[] qualities, ResultCollection results,
    92       IRandom random) {
    93       if (!results.ContainsKey("Best Solution Quality")) {
    94         results.Add(new Result("Best Solution Quality", typeof(DoubleValue)));
    95       }
    96       if (!results.ContainsKey("Best Solution")) {
    97         results.Add(new Result("Best Solution", typeof(ISymbolicExpressionTree)));
    98       }
     91    public override void Analyze(ISingleObjectiveSolutionContext<ISymbolicExpressionTree>[] solutionContexts, IRandom random) {
     92      //TODO reimplement code below using results directly
    9993
    100       var bestQuality = Maximization ? qualities.Max() : qualities.Min();
     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      //}
    101100
    102       if (results["Best Solution Quality"].Value == null ||
    103           IsBetter(bestQuality, ((DoubleValue)results["Best Solution Quality"].Value).Value)) {
    104         var bestIdx = Array.IndexOf(qualities, bestQuality);
    105         var bestClone = (IItem)trees[bestIdx].Clone();
     101      //var bestQuality = Maximization ? qualities.Max() : qualities.Min();
    106102
    107         results["Best Solution"].Value = bestClone;
    108         results["Best Solution Quality"].Value = new DoubleValue(bestQuality);
    109       }
     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      //}
    110111    }
    111112
    112     protected override sealed void OnEvaluatorChanged() {
     113    protected sealed override void OnEvaluatorChanged() {
    113114      throw new InvalidOperationException("Evaluator may not change!");
    114115    }
    115116
    116     protected override sealed void OnEncodingChanged() {
     117    protected sealed override void OnEncodingChanged() {
    117118      throw new InvalidOperationException("Encoding may not change!");
    118119    }
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Interfaces/ISingleObjectiveProblemDefinition.cs

    r17699 r17745  
    4343    void Evaluate(ISingleObjectiveSolutionContext<TEncodedSolution> solutionContext, IRandom random, CancellationToken cancellationToken);
    4444
    45     //TODO add cancellationtoken?
    46     void Analyze(ISingleObjectiveSolutionContext<TEncodedSolution>[] solutionContexts, ResultCollection results, IRandom random);
     45    //TODO add cancellation token?
     46    void Analyze(ISingleObjectiveSolutionContext<TEncodedSolution>[] solutionContexts, IRandom random);
    4747
    4848    //TODO remove neighbors from ProblemDefinition?
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Interfaces/internal/ISingleObjectiveAnalysisOperator.cs

    r17699 r17745  
    2828  internal interface ISingleObjectiveAnalysisOperator<TEncodedSolution> : IEncodingOperator, ISingleObjectiveOperator
    2929  where TEncodedSolution : class, IEncodedSolution {
    30     Action<ISingleObjectiveSolutionContext<TEncodedSolution>[], ResultCollection, IRandom> Analyze { get; set; }
     30    Action<ISingleObjectiveSolutionContext<TEncodedSolution>[], IRandom> Analyze { get; set; }
    3131  }
    3232}
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Operators/SingleObjectiveAnalyzer.cs

    r17699 r17745  
    5353    }
    5454
    55     public Action<ISingleObjectiveSolutionContext<TEncodedSolution>[], ResultCollection, IRandom> Analyze { get; set; }
     55    public Action<ISingleObjectiveSolutionContext<TEncodedSolution>[], IRandom> Analyze { get; set; }
    5656
    5757    [StorableConstructor]
     
    8282      }).ToArray();
    8383
    84       Analyze(solutionContexts, results, random);
     84      Analyze(solutionContexts, random);
    8585      foreach (var s in solutionContexts.Zip(scopes, Tuple.Create)) {
    8686        ScopeUtil.CopyToScope(s.Item2, s.Item1);
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/SingleObjectiveProblem.cs

    r17699 r17745  
    110110    }
    111111
    112     public virtual void Analyze(TEncodedSolution[] solutions, double[] qualities, ResultCollection results, IRandom random) { }
    113     public virtual void Analyze(ISingleObjectiveSolutionContext<TEncodedSolution>[] solutionContexts, ResultCollection results, IRandom random) {
    114       var solutions = solutionContexts.Select(c => c.EncodedSolution).ToArray();
    115       var qualities = solutionContexts.Select(c => c.EvaluationResult.Quality).ToArray();
    116       Analyze(solutions, qualities, results, random);
    117     }
     112    public virtual void Analyze(ISingleObjectiveSolutionContext<TEncodedSolution>[] solutionContexts, IRandom random) { }
    118113
    119114    public virtual IEnumerable<TEncodedSolution> GetNeighbors(TEncodedSolution solutions, IRandom random) {
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/SolutionContext.cs

    r17577 r17745  
    8585    public SingleObjectiveSolutionContext(TEncodedSolution encodedSolution) : base(encodedSolution) { }
    8686
    87 
    88     public SingleObjectiveSolutionContext(TEncodedSolution encodedSolution, IEvaluationResult evaluationResult) : base(encodedSolution, evaluationResult) { }
     87    public SingleObjectiveSolutionContext(TEncodedSolution encodedSolution, ISingleObjectiveEvaluationResult evaluationResult) : base(encodedSolution, evaluationResult) { }
    8988
    9089    [StorableConstructor]
     
    110109
    111110
    112     public MultiObjectiveSolutionContext(TEncodedSolution encodedSolution, IEvaluationResult evaluationResult) : base(encodedSolution, evaluationResult) { }
     111    public MultiObjectiveSolutionContext(TEncodedSolution encodedSolution, IMultiObjectiveEvaluationResult evaluationResult) : base(encodedSolution, evaluationResult) { }
    113112
    114113    [StorableConstructor]
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4.csproj

    r16723 r17745  
    124124    <Compile Include="MultiObjective\PearsonRSquaredTreeComplexityEvaluator.cs" />
    125125    <Compile Include="MultiObjective\SymbolicRegressionMultiObjectiveValidationBestSolutionAnalyzer.cs" />
     126    <Compile Include="New Implementation\Objectives\LinearScaling.cs" />
    126127    <Compile Include="Plugin.cs" />
    127128    <Compile Include="SingleObjective\ConstantOptimizationAnalyzer.cs" />
     
    129130    <Compile Include="SingleObjective\SymbolicRegressionSolutionsAnalyzer.cs" />
    130131    <Compile Include="SymbolicRegressionPhenotypicDiversityAnalyzer.cs" />
     132    <Compile Include="New Implementation\SymbolicRegressionProblem.cs" />
    131133    <Compile Include="SymbolicRegressionPruningAnalyzer.cs" />
    132134    <Compile Include="SingleObjective\Evaluators\SymbolicRegressionLogResidualEvaluator.cs" />
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/Interfaces/ISingleObjectiveOptimizationSupport.cs

    r17226 r17745  
    2222using System.Collections.Generic;
    2323using HEAL.Attic;
    24 using HeuristicLab.Common;
    2524using HeuristicLab.Core;
    2625using HeuristicLab.Optimization;
     
    2928  [StorableType("09d522e0-c10f-474c-b7c0-7d7f98e63f44")]
    3029  public interface ISingleObjectiveOptimizationSupport<TEncodedSolution>
    31     where TEncodedSolution : IDeepCloneable {
     30    where TEncodedSolution : class, IEncodedSolution {
    3231
    33     void Analyze(TEncodedSolution[] individuals, double[] qualities, ResultCollection results, IRandom random);
     32    void Analyze(ISingleObjectiveSolutionContext<TEncodedSolution>[] solutionContexts, IRandom random);
    3433    IEnumerable<TEncodedSolution> GetNeighbors(TEncodedSolution individual, IRandom random);
    3534  }
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/SingleObjective/SingleObjectiveOptimizationSupportScript.cs

    r16816 r17745  
    3131  [StorableType("3EB74171-6ECB-4479-861E-DA4EB39FE70C")]
    3232  public sealed class SingleObjectiveOptimizationSupportScript<TEncodedSolution> : OptimizationSupportScript<ISingleObjectiveOptimizationSupport<TEncodedSolution>>, ISingleObjectiveOptimizationSupport<TEncodedSolution>
    33     where TEncodedSolution : IDeepCloneable {
    34    
     33    where TEncodedSolution : class, IEncodedSolution {
     34
    3535    [StorableConstructor]
    3636    private SingleObjectiveOptimizationSupportScript(StorableConstructorFlag _) : base(_) { }
     
    4747    }
    4848
    49     void ISingleObjectiveOptimizationSupport<TEncodedSolution>.Analyze(TEncodedSolution[] individuals, double[] qualities, ResultCollection results, IRandom random) {
    50       CompiledInstance.Analyze(individuals, qualities, results, random);
     49    void ISingleObjectiveOptimizationSupport<TEncodedSolution>.Analyze(ISingleObjectiveSolutionContext<TEncodedSolution>[] solutionContexts, IRandom random) {
     50      CompiledInstance.Analyze(solutionContexts, random);
    5151    }
    5252
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/SingleObjectiveExternalEvaluationProblem.cs

    r17699 r17745  
    117117    }
    118118
    119     public override void Analyze(TEncodedSolution[] solutions, double[] qualities, ResultCollection results, IRandom random) {
    120       OptimizationSupport.Analyze(solutions, qualities, results, random);
     119    public override void Analyze(ISingleObjectiveSolutionContext<TEncodedSolution>[] solutions, IRandom random) {
     120      OptimizationSupport.Analyze(solutions, random);
    121121    }
    122122    public override IEnumerable<TEncodedSolution> GetNeighbors(TEncodedSolution solutions, IRandom random) {
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.GeneticProgramming/3.3/ArtificialAnt/Problem.cs

    r17655 r17745  
    2020#endregion
    2121
    22 using System;
    2322using System.Diagnostics.Contracts;
    24 using System.Linq;
    2523using System.Threading;
    2624using HEAL.Attic;
     
    141139    }
    142140
    143     public override void Analyze(ISymbolicExpressionTree[] trees, double[] qualities, ResultCollection results, IRandom random) {
    144       const string bestSolutionResultName = "Best Solution";
    145       var bestQuality = Maximization ? qualities.Max() : qualities.Min();
    146       var bestIdx = Array.IndexOf(qualities, bestQuality);
     141    //TODO: change to new analyze interface
     142    public override void Analyze(ISingleObjectiveSolutionContext<ISymbolicExpressionTree>[] solutionContexts, IRandom random) {
     143      base.Analyze(solutionContexts, random);
    147144
    148       if (!results.ContainsKey(bestSolutionResultName)) {
    149         results.Add(new Result(bestSolutionResultName, new Solution(World, trees[bestIdx], MaxTimeSteps, qualities[bestIdx])));
    150       } else if (((Solution)(results[bestSolutionResultName].Value)).Quality < qualities[bestIdx]) {
    151         results[bestSolutionResultName].Value = new Solution(World, trees[bestIdx], MaxTimeSteps, qualities[bestIdx]);
    152       }
     145      //TODO reimplement code below using results directly
     146      //  const string bestSolutionResultName = "Best Solution";
     147      //  var bestQuality = Maximization ? qualities.Max() : qualities.Min();
     148      //  var bestIdx = Array.IndexOf(qualities, bestQuality);
     149
     150      //  if (!results.ContainsKey(bestSolutionResultName)) {
     151      //    results.Add(new Result(bestSolutionResultName, new Solution(World, trees[bestIdx], MaxTimeSteps, qualities[bestIdx])));
     152      //  } else if (((Solution)(results[bestSolutionResultName].Value)).Quality < qualities[bestIdx]) {
     153      //    results[bestSolutionResultName].Value = new Solution(World, trees[bestIdx], MaxTimeSteps, qualities[bestIdx]);
     154      //  }
    153155    }
    154156
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.GeneticProgramming/3.3/LawnMower/Problem.cs

    r17655 r17745  
    2020#endregion
    2121
    22 using System;
    23 using System.Linq;
    2422using System.Threading;
    2523using HEAL.Attic;
     
    8078    }
    8179
    82     public override void Analyze(ISymbolicExpressionTree[] trees, double[] qualities, ResultCollection results, IRandom random) {
    83       const string bestSolutionResultName = "Best Solution";
    84       var bestQuality = Maximization ? qualities.Max() : qualities.Min();
    85       var bestIdx = Array.IndexOf(qualities, bestQuality);
     80    public override void Analyze(ISingleObjectiveSolutionContext<ISymbolicExpressionTree>[] solutionContexts, IRandom random) {
     81      base.Analyze(solutionContexts, random);
    8682
    87       if (!results.ContainsKey(bestSolutionResultName)) {
    88         results.Add(new Result(bestSolutionResultName, new Solution(trees[bestIdx], LawnLengthParameter.Value.Value, LawnWidthParameter.Value.Value, bestQuality)));
    89       } else if (((Solution)(results[bestSolutionResultName].Value)).Quality < qualities[bestIdx]) {
    90         results[bestSolutionResultName].Value = new Solution(trees[bestIdx], LawnLengthParameter.Value.Value, LawnWidthParameter.Value.Value, bestQuality);
    91       }
     83      //TODO: reimplement code below using results directly
     84
     85      //const string bestSolutionResultName = "Best Solution";
     86      //var bestQuality = Maximization ? qualities.Max() : qualities.Min();
     87      //var bestIdx = Array.IndexOf(qualities, bestQuality);
     88
     89      //if (!results.ContainsKey(bestSolutionResultName)) {
     90      //  results.Add(new Result(bestSolutionResultName, new Solution(trees[bestIdx], LawnLengthParameter.Value.Value, LawnWidthParameter.Value.Value, bestQuality)));
     91      //} else if (((Solution)(results[bestSolutionResultName].Value)).Quality < qualities[bestIdx]) {
     92      //  results[bestSolutionResultName].Value = new Solution(trees[bestIdx], LawnLengthParameter.Value.Value, LawnWidthParameter.Value.Value, bestQuality);
     93      //}
    9294    }
    9395
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.GeneticProgramming/3.3/robocode/Problem.cs

    r17655 r17745  
    105105    }
    106106
    107     public override void Analyze(ISymbolicExpressionTree[] trees, double[] qualities, ResultCollection results, IRandom random) {
    108       // find the tree with the best quality
    109       double maxQuality = double.NegativeInfinity;
    110       ISymbolicExpressionTree bestTree = null;
    111       for (int i = 0; i < qualities.Length; i++) {
    112         if (qualities[i] > maxQuality) {
    113           maxQuality = qualities[i];
    114           bestTree = trees[i];
    115         }
    116       }
     107    //TODO: change to new analyze interface//TODO: change to new analyze interface
     108    //public override void Analyze(ISymbolicExpressionTree[] trees, double[] qualities, ResultCollection results, IRandom random) {
     109    //  // find the tree with the best quality
     110    //  double maxQuality = double.NegativeInfinity;
     111    //  ISymbolicExpressionTree bestTree = null;
     112    //  for (int i = 0; i < qualities.Length; i++) {
     113    //    if (qualities[i] > maxQuality) {
     114    //      maxQuality = qualities[i];
     115    //      bestTree = trees[i];
     116    //    }
     117    //  }
    117118
    118       // create a solution instance
    119       var bestSolution = new Solution(bestTree, RobocodePath, NrOfRounds, Enemies);
     119    //  // create a solution instance
     120    //  var bestSolution = new Solution(bestTree, RobocodePath, NrOfRounds, Enemies);
    120121
    121       // also add the best solution as a result to the result collection
    122       // or alternatively update the existing result
    123       if (!results.ContainsKey("BestSolution")) {
    124         results.Add(new Result("BestSolution", "The best tank program", bestSolution));
    125       } else {
    126         results["BestSolution"].Value = bestSolution;
    127       }
    128     }
     122    //  // also add the best solution as a result to the result collection
     123    //  // or alternatively update the existing result
     124    //  if (!results.ContainsKey("BestSolution")) {
     125    //    results.Add(new Result("BestSolution", "The best tank program", bestSolution));
     126    //  } else {
     127    //    results["BestSolution"].Value = bestSolution;
     128    //  }
     129    //}
    129130
    130131    private void RegisterEventHandlers() {
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.GrammaticalEvolution/3.4/ArtificialAnt/GEArtificialAntProblem.cs

    r17382 r17745  
    2222#endregion
    2323
    24 using System.Linq;
    2524using System.Threading;
    2625using HEAL.Attic;
     
    117116    }
    118117
    119     public override void Analyze(IntegerVector[] solutions, double[] qualities, ResultCollection results, IRandom random) {
    120       var bounds = Encoding.Bounds;
    121       var len = Encoding.Length;
    122       var grammar = wrappedAntProblem.Encoding.Grammar;
    123       var mapper = GenotypeToPhenotypeMapperParameter.Value;
     118    //TODO: Use SolutionContext wrapper to translate between integer and tree encoded solution
     119    public override void Analyze(ISingleObjectiveSolutionContext<IntegerVector>[] solutionContexts, IRandom random) {
     120      //var bounds = Encoding.Bounds;
     121      //var len = Encoding.Length;
     122      //var grammar = wrappedAntProblem.Encoding.Grammar;
     123      //var mapper = GenotypeToPhenotypeMapperParameter.Value;
    124124
    125       var trees = solutions
    126         .Select(ind => mapper.Map(random, bounds, len, grammar, ind))
    127         .ToArray();
     125      //var trees = solutionContexts
     126      //  .Select(context => mapper.Map(random, bounds, len, grammar, context.EncodedSolution))
     127      //  .ToArray();
    128128
    129       wrappedAntProblem.Analyze(trees, qualities, results, random);
     129      //wrappedAntProblem.Analyze(solutionContexts, random);
    130130    }
    131131  }
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.GraphColoring/3.3/GraphColoringProblem.cs

    r17695 r17745  
    170170    }
    171171
    172     public override void Analyze(LinearLinkage[] lles, double[] qualities, ResultCollection results, IRandom random) {
    173       var orderedIndividuals = lles.Zip(qualities, (i, q) => new { LLE = i, Quality = q }).OrderBy(z => z.Quality);
    174       var best = Maximization ? orderedIndividuals.Last().LLE : orderedIndividuals.First().LLE;
    175 
    176       var llee = best.ToEndLinks();
    177       var colors = llee.Distinct().Count();
    178       var conflicts = CalculateConflicts(llee);
    179 
    180       IResult res;
    181       int bestColors = int.MaxValue, bestConflicts = int.MaxValue;
    182       var improvement = false;
    183       if (!results.TryGetValue("Best Solution Conflicts", out res)) {
    184         bestConflicts = conflicts;
    185         res = new Result("Best Solution Conflicts", new IntValue(bestConflicts));
    186         results.Add(res);
    187       } else {
    188         bestConflicts = ((IntValue)res.Value).Value;
    189         improvement = conflicts < bestConflicts;
    190         if (improvement) ((IntValue)res.Value).Value = bestConflicts = conflicts;
    191       }
    192       if (!results.TryGetValue("Best Solution Colors", out res)) {
    193         bestColors = colors;
    194         res = new Result("Best Solution Colors", new IntValue(bestColors));
    195         results.Add(res);
    196       } else {
    197         bestColors = ((IntValue)res.Value).Value;
    198         improvement = improvement || conflicts == bestConflicts && colors < bestColors;
    199         if (improvement)
    200           ((IntValue)res.Value).Value = bestColors = colors;
    201       }
    202       if (!results.ContainsKey("Best Encoded Solution") || improvement)
    203         results.AddOrUpdateResult("Best Encoded Solution", (LinearLinkage)best.Clone());
    204 
    205       if (!results.TryGetValue("Best Solution", out res) || !(res.Value is IntMatrix)) {
    206         var matrix = new IntMatrix(llee.Length, 2) { ColumnNames = new[] { "Node", "Color" } };
    207         UpdateMatrix(llee, matrix);
    208         res = new Result("Best Solution", matrix);
    209         results.AddOrUpdateResult("Best Solution", matrix);
    210       } else {
    211         if (improvement) {
    212           UpdateMatrix(llee, (IntMatrix)res.Value);
    213         }
    214       }
    215 
    216       if (conflicts == 0) {
    217         if (BestKnownColorsParameter.Value == null || BestKnownColorsParameter.Value.Value > colors)
    218           BestKnownColorsParameter.Value = new IntValue(colors);
    219       }
     172    public override void Analyze(ISingleObjectiveSolutionContext<LinearLinkage>[] solutionContexts, IRandom random) {
     173      base.Analyze(solutionContexts, random);
     174
     175      var lles = solutionContexts.Select(context => context.EncodedSolution).ToArray();
     176
     177      //TODO: reimplement code below using results directly
     178
     179      //var orderedIndividuals = lles.Zip(qualities, (i, q) => new { LLE = i, Quality = q }).OrderBy(z => z.Quality);
     180      //var best = Maximization ? orderedIndividuals.Last().LLE : orderedIndividuals.First().LLE;
     181
     182      //var llee = best.ToEndLinks();
     183      //var colors = llee.Distinct().Count();
     184      //var conflicts = CalculateConflicts(llee);
     185
     186      //IResult res;
     187      //int bestColors = int.MaxValue, bestConflicts = int.MaxValue;
     188      //var improvement = false;
     189      //if (!results.TryGetValue("Best Solution Conflicts", out res)) {
     190      //  bestConflicts = conflicts;
     191      //  res = new Result("Best Solution Conflicts", new IntValue(bestConflicts));
     192      //  results.Add(res);
     193      //} else {
     194      //  bestConflicts = ((IntValue)res.Value).Value;
     195      //  improvement = conflicts < bestConflicts;
     196      //  if (improvement) ((IntValue)res.Value).Value = bestConflicts = conflicts;
     197      //}
     198      //if (!results.TryGetValue("Best Solution Colors", out res)) {
     199      //  bestColors = colors;
     200      //  res = new Result("Best Solution Colors", new IntValue(bestColors));
     201      //  results.Add(res);
     202      //} else {
     203      //  bestColors = ((IntValue)res.Value).Value;
     204      //  improvement = improvement || conflicts == bestConflicts && colors < bestColors;
     205      //  if (improvement)
     206      //    ((IntValue)res.Value).Value = bestColors = colors;
     207      //}
     208      //if (!results.ContainsKey("Best Encoded Solution") || improvement)
     209      //  results.AddOrUpdateResult("Best Encoded Solution", (LinearLinkage)best.Clone());
     210
     211      //if (!results.TryGetValue("Best Solution", out res) || !(res.Value is IntMatrix)) {
     212      //  var matrix = new IntMatrix(llee.Length, 2) { ColumnNames = new[] { "Node", "Color" } };
     213      //  UpdateMatrix(llee, matrix);
     214      //  res = new Result("Best Solution", matrix);
     215      //  results.AddOrUpdateResult("Best Solution", matrix);
     216      //} else {
     217      //  if (improvement) {
     218      //    UpdateMatrix(llee, (IntMatrix)res.Value);
     219      //  }
     220      //}
     221
     222      //if (conflicts == 0) {
     223      //  if (BestKnownColorsParameter.Value == null || BestKnownColorsParameter.Value.Value > colors)
     224      //    BestKnownColorsParameter.Value = new IntValue(colors);
     225      //}
    220226    }
    221227
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.Knapsack/3.3/KnapsackProblem.cs

    r17655 r17745  
    103103    }
    104104
    105     public override void Analyze(BinaryVector[] solutions, double[] qualities, ResultCollection results, IRandom random) {
    106       base.Analyze(solutions, qualities, results, random);
    107 
    108       var best = GetBestSolution(solutions, qualities);
    109 
    110       if (double.IsNaN(BestKnownQuality) || IsBetter(best.Item2, BestKnownQuality)) {
    111         BestKnownQuality = best.Item2;
    112         BestKnownSolution = (BinaryVector)best.Item1.Clone();
    113       }
    114 
    115       IResult result;
    116       if (!results.TryGetValue("Best Knapsack Solution", out result)) {
    117         results.Add(result = new Result("Best Knapsack Solution", typeof(KnapsackSolution)));
    118       }
    119       var solution = (KnapsackSolution)result.Value;
    120       if (solution == null) {
    121         solution = new KnapsackSolution((BinaryVector)best.Item1.Clone(), new DoubleValue(best.Item2),
    122           KnapsackCapacityParameter.Value, WeightsParameter.Value, ValuesParameter.Value);
    123         result.Value = solution;
    124       } else {
    125         if (IsBetter(best.Item2, solution.Quality.Value)) {
    126           solution.BinaryVector = (BinaryVector)best.Item1.Clone();
    127           solution.Quality = new DoubleValue(best.Item2);
    128           solution.Capacity = KnapsackCapacityParameter.Value;
    129           solution.Weights = WeightsParameter.Value;
    130           solution.Values = ValuesParameter.Value;
    131         }
    132       }
     105    public override void Analyze(ISingleObjectiveSolutionContext<BinaryVector>[] solutionContexts, IRandom random) {
     106      base.Analyze(solutionContexts, random);
     107
     108      //TODO reimplement code below using results directly
     109
     110      //var best = GetBestSolution(solutions, qualities);
     111
     112      //if (double.IsNaN(BestKnownQuality) || IsBetter(best.Item2, BestKnownQuality)) {
     113      //  BestKnownQuality = best.Item2;
     114      //  BestKnownSolution = (BinaryVector)best.Item1.Clone();
     115      //}
     116
     117      //IResult result;
     118      //if (!results.TryGetValue("Best Knapsack Solution", out result)) {
     119      //  results.Add(result = new Result("Best Knapsack Solution", typeof(KnapsackSolution)));
     120      //}
     121      //var solution = (KnapsackSolution)result.Value;
     122      //if (solution == null) {
     123      //  solution = new KnapsackSolution((BinaryVector)best.Item1.Clone(), new DoubleValue(best.Item2),
     124      //    KnapsackCapacityParameter.Value, WeightsParameter.Value, ValuesParameter.Value);
     125      //  result.Value = solution;
     126      //} else {
     127      //  if (IsBetter(best.Item2, solution.Quality.Value)) {
     128      //    solution.BinaryVector = (BinaryVector)best.Item1.Clone();
     129      //    solution.Quality = new DoubleValue(best.Item2);
     130      //    solution.Capacity = KnapsackCapacityParameter.Value;
     131      //    solution.Weights = WeightsParameter.Value;
     132      //    solution.Values = ValuesParameter.Value;
     133      //  }
     134      //}
    133135    }
    134136
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.LinearAssignment/3.3/HeuristicLab.Problems.LinearAssignment-3.3.csproj

    r17530 r17745  
    192192      <Private>False</Private>
    193193    </ProjectReference>
     194    <ProjectReference Include="..\..\HeuristicLab.Random\3.3\HeuristicLab.Random-3.3.csproj">
     195      <Project>{F4539FB6-4708-40C9-BE64-0A1390AEA197}</Project>
     196      <Name>HeuristicLab.Random-3.3</Name>
     197    </ProjectReference>
    194198  </ItemGroup>
    195199  <ItemGroup>
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.LinearAssignment/3.3/HungarianAlgorithm.cs

    r17530 r17745  
    2727using HeuristicLab.Encodings.PermutationEncoding;
    2828using HeuristicLab.Optimization;
     29using HeuristicLab.Random;
    2930
    3031namespace HeuristicLab.Problems.LinearAssignment {
     
    6364      var assignment = LinearAssignmentProblemSolver.Solve(Problem.Costs, out double quality);
    6465
    65       Problem.Analyze(new[] { new Permutation(PermutationTypes.Absolute, assignment) },
    66         new[] { quality }, Results, null);
     66      var context = new SingleObjectiveSolutionContext<Permutation>(new Permutation(PermutationTypes.Absolute, assignment));
     67      context.EvaluationResult = new SingleObjectiveEvaluationResult(quality);
     68
     69      var random = new FastRandom(42);
     70      Problem.Analyze(new[] { context }, random);
    6771    }
    6872  }
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.LinearAssignment/3.3/LinearAssignmentProblem.cs

    r17696 r17745  
    136136    }
    137137
    138     public override void Analyze(Permutation[] permutations, double[] qualities, ResultCollection results, IRandom random) {
    139       base.Analyze(permutations, qualities, results, random);
    140 
    141       var costs = Costs;
    142       var rowNames = RowNames;
    143       var columnNames = ColumnNames;
    144       bool max = Maximization;
    145 
    146       var sorted = qualities.Select((x, index) => new { Index = index, Quality = x }).OrderBy(x => x.Quality).ToArray();
    147       if (max) Array.Reverse(sorted);
    148       int i = sorted[0].Index;
    149       var best = Tuple.Create(permutations[i], qualities[i]);
    150 
    151       if (double.IsNaN(BestKnownQuality) || IsBetter(best.Item2, BestKnownQuality)) {
    152         // if there isn't a best-known quality or we improved the best-known quality we'll add the current solution as best-known
    153         BestKnownQuality = best.Item2;
    154         BestKnownSolution = (Permutation)best.Item1.Clone();
    155         BestKnownSolutions = new ItemSet<Permutation>(new PermutationEqualityComparer());
    156         BestKnownSolutions.Add((Permutation)best.Item1.Clone());
    157       } else if (BestKnownQuality == best.Item2) {
    158         // if we matched the best-known quality we'll try to set the best-known solution if it isn't null
    159         // and try to add it to the pool of best solutions if it is different
    160         if (BestKnownSolution == null) BestKnownSolution = (Permutation)best.Item1.Clone();
    161         if (BestKnownSolutions == null) BestKnownSolutions = new ItemSet<Permutation>(new PermutationEqualityComparer());
    162 
    163         foreach (var k in sorted) { // for each solution that we found check if it is in the pool of best-knowns
    164           if (IsBetter(best.Item2, k.Quality)) break; // stop when we reached a solution worse than the best-known quality
    165           var p = permutations[k.Index];
    166           if (!BestKnownSolutions.Contains(p))
    167             BestKnownSolutions.Add((Permutation)permutations[k.Index].Clone());
    168         }
    169       }
    170 
    171       LAPAssignment solution = BestLAPSolutionParameter.ActualValue;
    172       if (solution == null) {
    173         solution = new LAPAssignment(costs, rowNames, columnNames, (Permutation)best.Item1.Clone(), new DoubleValue(best.Item2));
    174         BestLAPSolutionParameter.ActualValue = solution;
    175       } else {
    176         if (IsBetter(best.Item2, solution.Quality.Value)) {
    177           solution.Costs = costs;
    178           solution.Assignment = (Permutation)best.Item1.Clone();
    179           solution.Quality.Value = best.Item2;
    180           if (rowNames != null)
    181             solution.RowNames = rowNames;
    182           else solution.RowNames = null;
    183           if (columnNames != null)
    184             solution.ColumnNames = columnNames;
    185           else solution.ColumnNames = null;
    186         }
    187       }
     138    public override void Analyze(ISingleObjectiveSolutionContext<Permutation>[] solutionContexts, IRandom random) {
     139      base.Analyze(solutionContexts, random);
     140
     141      //TODO reimplement code below using results directly
     142      //var costs = Costs;
     143      //var rowNames = RowNames;
     144      //var columnNames = ColumnNames;
     145      //bool max = Maximization;
     146
     147      //var sorted = qualities.Select((x, index) => new { Index = index, Quality = x }).OrderBy(x => x.Quality).ToArray();
     148      //if (max) Array.Reverse(sorted);
     149      //int i = sorted[0].Index;
     150      //var best = Tuple.Create(permutations[i], qualities[i]);
     151
     152      //if (double.IsNaN(BestKnownQuality) || IsBetter(best.Item2, BestKnownQuality)) {
     153      //  // if there isn't a best-known quality or we improved the best-known quality we'll add the current solution as best-known
     154      //  BestKnownQuality = best.Item2;
     155      //  BestKnownSolution = (Permutation)best.Item1.Clone();
     156      //  BestKnownSolutions = new ItemSet<Permutation>(new PermutationEqualityComparer());
     157      //  BestKnownSolutions.Add((Permutation)best.Item1.Clone());
     158      //} else if (BestKnownQuality == best.Item2) {
     159      //  // if we matched the best-known quality we'll try to set the best-known solution if it isn't null
     160      //  // and try to add it to the pool of best solutions if it is different
     161      //  if (BestKnownSolution == null) BestKnownSolution = (Permutation)best.Item1.Clone();
     162      //  if (BestKnownSolutions == null) BestKnownSolutions = new ItemSet<Permutation>(new PermutationEqualityComparer());
     163
     164      //  foreach (var k in sorted) { // for each solution that we found check if it is in the pool of best-knowns
     165      //    if (IsBetter(best.Item2, k.Quality)) break; // stop when we reached a solution worse than the best-known quality
     166      //    var p = permutations[k.Index];
     167      //    if (!BestKnownSolutions.Contains(p))
     168      //      BestKnownSolutions.Add((Permutation)permutations[k.Index].Clone());
     169      //  }
     170      //}
     171
     172      //LAPAssignment solution = BestLAPSolutionParameter.ActualValue;
     173      //if (solution == null) {
     174      //  solution = new LAPAssignment(costs, rowNames, columnNames, (Permutation)best.Item1.Clone(), new DoubleValue(best.Item2));
     175      //  BestLAPSolutionParameter.ActualValue = solution;
     176      //} else {
     177      //  if (IsBetter(best.Item2, solution.Quality.Value)) {
     178      //    solution.Costs = costs;
     179      //    solution.Assignment = (Permutation)best.Item1.Clone();
     180      //    solution.Quality.Value = best.Item2;
     181      //    if (rowNames != null)
     182      //      solution.RowNames = rowNames;
     183      //    else solution.RowNames = null;
     184      //    if (columnNames != null)
     185      //      solution.ColumnNames = columnNames;
     186      //    else solution.ColumnNames = null;
     187      //  }
     188      //}
    188189
    189190    }
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.LinearAssignment/3.3/Plugin.cs.frame

    r17226 r17745  
    3636  [PluginDependency("HeuristicLab.Optimization.Operators", "3.3")]
    3737  [PluginDependency("HeuristicLab.Parameters", "3.3")]
     38  [PluginDependency("HeuristicLab.Random", "3.3")]
    3839  [PluginDependency("HeuristicLab.Attic", "1.0")]
    3940  public class HeuristicLabProblemsLinearAssignmentPlugin : PluginBase {
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.Orienteering/3.3/OrienteeringProblem.cs

    r17695 r17745  
    121121    }
    122122
    123     public override void Analyze(IntegerVector[] vectors, double[] qualities, ResultCollection results, IRandom random) {
    124       base.Analyze(vectors, qualities, results, random);
    125       var data = OrienteeringProblemData;
    126 
    127       var best = GetBestSolution(vectors, qualities).Item1;
    128       var score = CalculateScore(OrienteeringProblemData, best);
    129       var travelCosts = CalculateTravelCosts(OrienteeringProblemData, best);
    130       var quality = CalculateQuality(OrienteeringProblemData, score, travelCosts);
    131 
    132       if (double.IsNaN(BestKnownQuality) || IsBetter(quality, BestKnownQuality)) {
    133         BestKnownQuality = quality;
    134         BestKnownSolutionParameter.ActualValue = data.GetSolution((IntegerVector)best.Clone(), quality, score, travelCosts);
    135       }
    136       var bestSoFar = BestOrienteeringSolutionParameter.ActualValue;
    137 
    138       if (bestSoFar == null || IsBetter(quality, bestSoFar.Quality.Value)) {
    139         bestSoFar = data.GetSolution((IntegerVector)best.Clone(), quality, score, travelCosts);
    140         BestOrienteeringSolutionParameter.ActualValue = bestSoFar;
    141       }
     123    public override void Analyze(ISingleObjectiveSolutionContext<IntegerVector>[] solutionContexts, IRandom random) {
     124      base.Analyze(solutionContexts, random);
     125
     126      //TODO reimplement code below using results directly
     127
     128      //var data = OrienteeringProblemData;
     129
     130      //var best = GetBestSolution(vectors, qualities).Item1;
     131      //var score = CalculateScore(OrienteeringProblemData, best);
     132      //var travelCosts = CalculateTravelCosts(OrienteeringProblemData, best);
     133      //var quality = CalculateQuality(OrienteeringProblemData, score, travelCosts);
     134
     135      //if (double.IsNaN(BestKnownQuality) || IsBetter(quality, BestKnownQuality)) {
     136      //  BestKnownQuality = quality;
     137      //  BestKnownSolutionParameter.ActualValue = data.GetSolution((IntegerVector)best.Clone(), quality, score, travelCosts);
     138      //}
     139      //var bestSoFar = BestOrienteeringSolutionParameter.ActualValue;
     140
     141      //if (bestSoFar == null || IsBetter(quality, bestSoFar.Quality.Value)) {
     142      //  bestSoFar = data.GetSolution((IntegerVector)best.Clone(), quality, score, travelCosts);
     143      //  BestOrienteeringSolutionParameter.ActualValue = bestSoFar;
     144      //}
    142145    }
    143146    public static double CalculateInsertionCosts(IOrienteeringProblemData data, IList<int> path, int insertPosition, int point) {
     
    173176      if (Dimension != OrienteeringProblemData.Cities) {
    174177        Dimension = OrienteeringProblemData.Cities;
    175         Bounds = new Data.IntMatrix(new [,] { { 0, Dimension } }, @readonly: true);
     178        Bounds = new Data.IntMatrix(new[,] { { 0, Dimension } }, @readonly: true);
    176179      }
    177180    }
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP/3.3/ProbabilisticTSP.cs

    r17680 r17745  
    2121
    2222using System;
    23 using System.Linq;
    2423using HEAL.Attic;
    2524using HeuristicLab.Common;
     
    7776    }
    7877
    79     public override void Analyze(Permutation[] solutions, double[] qualities, ResultCollection results, IRandom random) {
    80       base.Analyze(solutions, qualities, results, random);
    81       var max = Maximization;
     78    public override void Analyze(ISingleObjectiveSolutionContext<Permutation>[] solutionContexts, IRandom random) {
     79      base.Analyze(solutionContexts, random);
    8280
    83       var i = !max ? qualities.Select((x, index) => new { index, Quality = x }).OrderBy(x => x.Quality).First().index
    84                    : qualities.Select((x, index) => new { index, Quality = x }).OrderByDescending(x => x.Quality).First().index;
     81      //TODO reimplement code below using results directly
    8582
    86       if (double.IsNaN(BestKnownQuality) ||
    87           max && qualities[i] > BestKnownQuality ||
    88           !max && qualities[i] < BestKnownQuality) {
    89         BestKnownQuality = qualities[i];
    90         BestKnownSolution = ProbabilisticTSPData.GetSolution((Permutation)solutions[i].Clone(), qualities[i]);
    91       }
     83      //var max = Maximization;
    9284
    93       IResult bestSolutionResult;
    94       if (results.TryGetValue("Best pTSP Solution", out bestSolutionResult)) {
    95         var bestSolution = bestSolutionResult.Value as ITSPSolution;
    96         if (bestSolution == null || Maximization && bestSolution.TourLength.Value < qualities[i]
    97           || !Maximization && bestSolution.TourLength.Value > qualities[i]) {
    98           bestSolutionResult.Value = ProbabilisticTSPData.GetSolution(solutions[i], qualities[i]);
    99         }
    100       } else results.Add(new Result("Best pTSP Solution", ProbabilisticTSPData.GetSolution(solutions[i], qualities[i])));
     85      //var i = !max ? qualities.Select((x, index) => new { index, Quality = x }).OrderBy(x => x.Quality).First().index
     86      //             : qualities.Select((x, index) => new { index, Quality = x }).OrderByDescending(x => x.Quality).First().index;
     87
     88      //if (double.IsNaN(BestKnownQuality) ||
     89      //    max && qualities[i] > BestKnownQuality ||
     90      //    !max && qualities[i] < BestKnownQuality) {
     91      //  BestKnownQuality = qualities[i];
     92      //  BestKnownSolution = ProbabilisticTSPData.GetSolution((Permutation)solutions[i].Clone(), qualities[i]);
     93      //}
     94
     95      //IResult bestSolutionResult;
     96      //if (results.TryGetValue("Best pTSP Solution", out bestSolutionResult)) {
     97      //  var bestSolution = bestSolutionResult.Value as ITSPSolution;
     98      //  if (bestSolution == null || Maximization && bestSolution.TourLength.Value < qualities[i]
     99      //    || !Maximization && bestSolution.TourLength.Value > qualities[i]) {
     100      //    bestSolutionResult.Value = ProbabilisticTSPData.GetSolution(solutions[i], qualities[i]);
     101      //  }
     102      //} else results.Add(new Result("Best pTSP Solution", ProbabilisticTSPData.GetSolution(solutions[i], qualities[i])));
    101103    }
    102104
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/CompiledProblemDefinition.cs

    r17699 r17745  
    7474    }
    7575
    76     public virtual void Analyze(TEncodedSolution[] solutions, double[] qualities, ResultCollection results, IRandom random) { }
    77     public virtual void Analyze(ISingleObjectiveSolutionContext<TEncodedSolution>[] solutionContexts, ResultCollection results, IRandom random) {
    78       var solutions = solutionContexts.Select(c => c.EncodedSolution).ToArray();
    79       var qualities = solutionContexts.Select(c => c.EvaluationResult.Quality).ToArray();
    80       Analyze(solutions, qualities, results, random);
    81     }
     76
     77    public virtual void Analyze(ISingleObjectiveSolutionContext<TEncodedSolution>[] solutionContexts, IRandom random) { }
    8278
    8379    public virtual IEnumerable<TEncodedSolution> GetNeighbors(TEncodedSolution solutions, IRandom random) {
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProblemDefinitionScript.cs

    r17699 r17745  
    6666    }
    6767
    68     void ISingleObjectiveProblemDefinition<TEncoding, TEncodedSolution>.Analyze(ISingleObjectiveSolutionContext<TEncodedSolution>[] solutionContexts, ResultCollection results, IRandom random) {
    69       CompiledProblemDefinition.Analyze(solutionContexts, results, random);
     68    void ISingleObjectiveProblemDefinition<TEncoding, TEncodedSolution>.Analyze(ISingleObjectiveSolutionContext<TEncodedSolution>[] solutionContexts, IRandom random) {
     69      CompiledProblemDefinition.Analyze(solutionContexts, random);
    7070    }
    7171
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProgrammableProblem.cs

    r17699 r17745  
    115115    }
    116116
    117     public override void Analyze(ISingleObjectiveSolutionContext<TEncodedSolution>[] solutionContexts, ResultCollection results, IRandom random) {
    118       ProblemDefinition.Analyze(solutionContexts, results, random);
     117    public override void Analyze(ISingleObjectiveSolutionContext<TEncodedSolution>[] solutionContexts, IRandom random) {
     118      ProblemDefinition.Analyze(solutionContexts, random);
    119119    }
    120120
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.Scheduling/3.3/JobShopSchedulingProblem.cs

    r17694 r17745  
    7676      get { return HeuristicLab.Common.Resources.VSImageLibrary.Type; }
    7777    }
    78    
     78
    7979    #region Parameter Properties
    8080    [Storable] public ReferenceParameter<ItemList<Job>> JobDataParameter { get; private set; }
     
    159159    }
    160160
    161     public override void Analyze(IScheduleSolution[] solutions, double[] qualities, ResultCollection results, IRandom random) {
    162       base.Analyze(solutions, qualities, results, random);
    163 
    164       bool max = Maximization;
    165 
    166       int i = -1;
    167       if (!max)
    168         i = qualities.Select((x, index) => new { index, x }).OrderBy(x => x.x).First().index;
    169       else i = qualities.Select((x, index) => new { index, x }).OrderByDescending(x => x.x).First().index;
    170 
    171       if (double.IsNaN(BestKnownQuality) ||
    172           max && qualities[i] > BestKnownQuality ||
    173           !max && qualities[i] < BestKnownQuality) {
    174         BestKnownQuality = qualities[i];
    175         BestKnownSolution = Encoding.Decode(solutions[i], JobData);
    176       }
    177       Schedule bestSolution;
    178       if (results.TryGetValue("Best Scheduling Solution", out var result)) {
    179         bestSolution = result.Value as Schedule;
    180       } else bestSolution = null;
    181 
    182       if (bestSolution == null || IsBetter(bestSolution.Quality, qualities[i]))
    183         results.AddOrUpdateResult("Best Scheduling Solution", Encoding.Decode(solutions[i], JobData));
     161    public override void Analyze(ISingleObjectiveSolutionContext<IScheduleSolution>[] solutionContexts, IRandom random) {
     162      base.Analyze(solutionContexts, random);
     163
     164      //TODO: reimplement code below using results directly
     165
     166      //bool max = Maximization;
     167
     168      //int i = -1;
     169      //if (!max)
     170      //  i = qualities.Select((x, index) => new { index, x }).OrderBy(x => x.x).First().index;
     171      //else i = qualities.Select((x, index) => new { index, x }).OrderByDescending(x => x.x).First().index;
     172
     173      //if (double.IsNaN(BestKnownQuality) ||
     174      //    max && qualities[i] > BestKnownQuality ||
     175      //    !max && qualities[i] < BestKnownQuality) {
     176      //  BestKnownQuality = qualities[i];
     177      //  BestKnownSolution = Encoding.Decode(solutions[i], JobData);
     178      //}
     179      //Schedule bestSolution;
     180      //if (results.TryGetValue("Best Scheduling Solution", out var result)) {
     181      //  bestSolution = result.Value as Schedule;
     182      //} else bestSolution = null;
     183
     184      //if (bestSolution == null || IsBetter(bestSolution.Quality, qualities[i]))
     185      //  results.AddOrUpdateResult("Best Scheduling Solution", Encoding.Decode(solutions[i], JobData));
    184186    }
    185187
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.TestFunctions/3.3/SingleObjectiveTestFunctionProblem.cs

    r17695 r17745  
    103103    }
    104104
    105     public override void Analyze(RealVector[] realVectors, double[] qualities, ResultCollection results, IRandom random) {
    106       var best = GetBestSolution(realVectors, qualities);
     105    //TODO: change to new analyze interface
     106    public override void Analyze(ISingleObjectiveSolutionContext<RealVector>[] solutionContexts, IRandom random) {
     107      base.Analyze(solutionContexts, random);
    107108
    108       DoubleValue bestKnownQuality = BestKnownQualityParameter.Value;
    109       RealVector bestKnownSolution = null;
    110       var bestKnownUpdate = bestKnownQuality == null || IsBetter(best.Item2, bestKnownQuality.Value);
    111       if (bestKnownUpdate) {
    112         if (bestKnownQuality != null) bestKnownQuality.Value = best.Item2;
    113         else BestKnownQualityParameter.Value = bestKnownQuality = new DoubleValue(best.Item2);
    114         BestKnownSolutionParameter.Value = bestKnownSolution = (RealVector)best.Item1.Clone();
    115       }
     109      //TODO: reimplement code below using results directly
    116110
    117       SingleObjectiveTestFunctionSolution solution = null;
    118       if (results.TryGetValue("Best Solution", out var res) && res.Value != null) {
    119         solution = (SingleObjectiveTestFunctionSolution)res.Value;
    120         if (IsBetter(best.Item2, solution.BestQuality.Value)) {
    121           solution.BestRealVector = (RealVector)best.Item1.Clone();
    122           solution.BestQuality = new DoubleValue(best.Item2);
    123         }
    124       } else {
    125         solution = new SingleObjectiveTestFunctionSolution((RealVector)best.Item1.Clone(),
    126                                                            new DoubleValue(best.Item2),
    127                                                            TestFunctionParameter.Value) {
    128           BestKnownRealVector = bestKnownSolution,
    129           Bounds = BoundsRefParameter.Value
    130         };
    131         results.AddOrUpdateResult("Best Solution", solution);
    132       }
    133       if (best.Item1.Length == 2) solution.Population = new ItemArray<RealVector>(realVectors.Select(x => (RealVector)x.Clone()));
    134       if (bestKnownUpdate) solution.BestKnownRealVector = bestKnownSolution;
     111      //var best = GetBestSolution(realVectors, qualities);
     112
     113      //DoubleValue bestKnownQuality = BestKnownQualityParameter.Value;
     114      //RealVector bestKnownSolution = null;
     115      //var bestKnownUpdate = bestKnownQuality == null || IsBetter(best.Item2, bestKnownQuality.Value);
     116      //if (bestKnownUpdate) {
     117      //  if (bestKnownQuality != null) bestKnownQuality.Value = best.Item2;
     118      //  else BestKnownQualityParameter.Value = bestKnownQuality = new DoubleValue(best.Item2);
     119      //  BestKnownSolutionParameter.Value = bestKnownSolution = (RealVector)best.Item1.Clone();
     120      //}
     121
     122      //SingleObjectiveTestFunctionSolution solution = null;
     123      //if (results.TryGetValue("Best Solution", out var res) && res.Value != null) {
     124      //  solution = (SingleObjectiveTestFunctionSolution)res.Value;
     125      //  if (IsBetter(best.Item2, solution.BestQuality.Value)) {
     126      //    solution.BestRealVector = (RealVector)best.Item1.Clone();
     127      //    solution.BestQuality = new DoubleValue(best.Item2);
     128      //  }
     129      //} else {
     130      //  solution = new SingleObjectiveTestFunctionSolution((RealVector)best.Item1.Clone(),
     131      //                                                     new DoubleValue(best.Item2),
     132      //                                                     TestFunctionParameter.Value) {
     133      //    BestKnownRealVector = bestKnownSolution,
     134      //    Bounds = BoundsRefParameter.Value
     135      //  };
     136      //  results.AddOrUpdateResult("Best Solution", solution);
     137      //}
     138      //if (best.Item1.Length == 2) solution.Population = new ItemArray<RealVector>(realVectors.Select(x => (RealVector)x.Clone()));
     139      //if (bestKnownUpdate) solution.BestKnownRealVector = bestKnownSolution;
    135140    }
    136141
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.TravelingSalesman/3.3/TSP.cs

    r17697 r17745  
    9999    }
    100100
    101     public override void Analyze(Permutation[] solutions, double[] qualities, ResultCollection results, IRandom random) {
    102       base.Analyze(solutions, qualities, results, random);
    103       int i = -1;
    104       if (!Maximization)
    105         i = qualities.Select((x, index) => new { index, Fitness = x }).OrderBy(x => x.Fitness).First().index;
    106       else i = qualities.Select((x, index) => new { index, Fitness = x }).OrderByDescending(x => x.Fitness).First().index;
    107 
    108       if (double.IsNaN(BestKnownQuality) ||
    109           Maximization && qualities[i] > BestKnownQuality ||
    110           !Maximization && qualities[i] < BestKnownQuality) {
    111         var bestKnown = TSPData.GetSolution(solutions[i], qualities[i]);
    112         BestKnownQualityParameter.Value = new DoubleValue(qualities[i]);
    113         BestKnownSolutionParameter.Value = bestKnown;
    114       }
    115 
    116       var bestSolution = BestTSPSolutionParameter.ActualValue;
    117       if (bestSolution == null || IsBetter(qualities[i], bestSolution.TourLength.Value)) {
    118         BestTSPSolutionParameter.ActualValue = TSPData.GetSolution(solutions[i], qualities[i]);
    119       }
     101    public override void Analyze(ISingleObjectiveSolutionContext<Permutation>[] solutionContexts, IRandom random) {
     102      base.Analyze(solutionContexts, random);
     103
     104      //TODO reimplement code below using results directly
     105      //int i = -1;
     106      //if (!Maximization)
     107      //  i = qualities.Select((x, index) => new { index, Fitness = x }).OrderBy(x => x.Fitness).First().index;
     108      //else i = qualities.Select((x, index) => new { index, Fitness = x }).OrderByDescending(x => x.Fitness).First().index;
     109
     110      //if (double.IsNaN(BestKnownQuality) ||
     111      //    Maximization && qualities[i] > BestKnownQuality ||
     112      //    !Maximization && qualities[i] < BestKnownQuality) {
     113      //  var bestKnown = TSPData.GetSolution(solutions[i], qualities[i]);
     114      //  BestKnownQualityParameter.Value = new DoubleValue(qualities[i]);
     115      //  BestKnownSolutionParameter.Value = bestKnown;
     116      //}
     117
     118      //var bestSolution = BestTSPSolutionParameter.ActualValue;
     119      //if (bestSolution == null || IsBetter(qualities[i], bestSolution.TourLength.Value)) {
     120      //  BestTSPSolutionParameter.ActualValue = TSPData.GetSolution(solutions[i], qualities[i]);
     121      //}
    120122    }
    121123
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/VehicleRoutingProblem.cs

    r17718 r17745  
    105105    }
    106106
    107     public override void Analyze(ISingleObjectiveSolutionContext<IVRPEncodedSolution>[] solutionContexts, ResultCollection results, IRandom random) {
    108       base.Analyze(solutionContexts, results, random);
    109       var evaluations = solutionContexts.Select(x => (VRPEvaluation)x.EvaluationResult);
    110 
    111       var bestInPop = evaluations.Select((x, index) => new { index, Eval = x }).OrderBy(x => x.Eval.Quality).First();
    112       IResult bestSolutionResult;
    113       if (!results.TryGetValue("Best VRP Solution", out bestSolutionResult) || !(bestSolutionResult.Value is VRPSolution)) {
    114         var best = new VRPSolution(ProblemInstance, solutionContexts[bestInPop.index].EncodedSolution, (VRPEvaluation)bestInPop.Eval.Clone());
    115         if (bestSolutionResult != null)
    116           bestSolutionResult.Value = best;
    117         else results.Add(bestSolutionResult = new Result("Best VRP Solution", best));
    118       }
    119 
    120       var bestSolution = (VRPSolution)bestSolutionResult.Value;
    121       if (bestSolution == null || bestInPop.Eval.Quality < bestSolution.Evaluation.Quality) {
    122         var best = new VRPSolution(ProblemInstance,
    123           (IVRPEncodedSolution)solutionContexts[bestInPop.index].EncodedSolution.Clone(),
    124           (VRPEvaluation)bestInPop.Eval.Clone());
    125         bestSolutionResult.Value = best;
    126       };
    127 
    128       var bestValidInPop = evaluations.Select((x, index) => new { index, Eval = x }).Where(x => x.Eval.IsFeasible).OrderBy(x => x.Eval.Quality).FirstOrDefault();
    129       IResult bestValidSolutionResult;
    130       if (!results.TryGetValue("Best Valid VRP Solution", out bestValidSolutionResult) || !(bestValidSolutionResult.Value is VRPSolution)) {
    131         var bestValid = new VRPSolution(ProblemInstance, solutionContexts[bestValidInPop.index].EncodedSolution, (VRPEvaluation)bestValidInPop.Eval.Clone());
    132         if (bestValidSolutionResult != null)
    133           bestValidSolutionResult.Value = bestValid;
    134         else results.Add(bestValidSolutionResult = new Result("Best Valid VRP Solution", bestValid));
    135       }
    136 
    137       if (bestValidInPop != null) {
    138         var bestValidSolution = (VRPSolution)bestValidSolutionResult.Value;
    139         if (bestValidSolution == null || bestValidInPop.Eval.Quality < bestValidSolution.Evaluation.Quality) {
    140           var best = new VRPSolution(ProblemInstance,
    141             (IVRPEncodedSolution)solutionContexts[bestValidInPop.index].EncodedSolution.Clone(),
    142             (VRPEvaluation)bestValidInPop.Eval.Clone());
    143           bestValidSolutionResult.Value = best;
    144         };
    145       }
     107    public override void Analyze(ISingleObjectiveSolutionContext<IVRPEncodedSolution>[] solutionContexts, IRandom random) {
     108      base.Analyze(solutionContexts, random);
     109
     110      //TODO reimplement using results directly
     111
     112      //var evaluations = solutionContexts.Select(x => (VRPEvaluation)x.EvaluationResult);
     113
     114      //var bestInPop = evaluations.Select((x, index) => new { index, Eval = x }).OrderBy(x => x.Eval.Quality).First();
     115      //IResult bestSolutionResult;
     116      //if (!results.TryGetValue("Best VRP Solution", out bestSolutionResult) || !(bestSolutionResult.Value is VRPSolution)) {
     117      //  var best = new VRPSolution(ProblemInstance, solutionContexts[bestInPop.index].EncodedSolution, (VRPEvaluation)bestInPop.Eval.Clone());
     118      //  if (bestSolutionResult != null)
     119      //    bestSolutionResult.Value = best;
     120      //  else results.Add(bestSolutionResult = new Result("Best VRP Solution", best));
     121      //}
     122
     123      //var bestSolution = (VRPSolution)bestSolutionResult.Value;
     124      //if (bestSolution == null || bestInPop.Eval.Quality < bestSolution.Evaluation.Quality) {
     125      //  var best = new VRPSolution(ProblemInstance,
     126      //    (IVRPEncodedSolution)solutionContexts[bestInPop.index].EncodedSolution.Clone(),
     127      //    (VRPEvaluation)bestInPop.Eval.Clone());
     128      //  bestSolutionResult.Value = best;
     129      //};
     130
     131      //var bestValidInPop = evaluations.Select((x, index) => new { index, Eval = x }).Where(x => x.Eval.IsFeasible).OrderBy(x => x.Eval.Quality).FirstOrDefault();
     132      //IResult bestValidSolutionResult;
     133      //if (!results.TryGetValue("Best Valid VRP Solution", out bestValidSolutionResult) || !(bestValidSolutionResult.Value is VRPSolution)) {
     134      //  var bestValid = new VRPSolution(ProblemInstance, solutionContexts[bestValidInPop.index].EncodedSolution, (VRPEvaluation)bestValidInPop.Eval.Clone());
     135      //  if (bestValidSolutionResult != null)
     136      //    bestValidSolutionResult.Value = bestValid;
     137      //  else results.Add(bestValidSolutionResult = new Result("Best Valid VRP Solution", bestValid));
     138      //}
     139
     140      //if (bestValidInPop != null) {
     141      //  var bestValidSolution = (VRPSolution)bestValidSolutionResult.Value;
     142      //  if (bestValidSolution == null || bestValidInPop.Eval.Quality < bestValidSolution.Evaluation.Quality) {
     143      //    var best = new VRPSolution(ProblemInstance,
     144      //      (IVRPEncodedSolution)solutionContexts[bestValidInPop.index].EncodedSolution.Clone(),
     145      //      (VRPEvaluation)bestValidInPop.Eval.Clone());
     146      //    bestValidSolutionResult.Value = best;
     147      //  };
     148      //}
    146149    }
    147150
     
    164167    }
    165168
    166     void BestKnownSolutionParameter_ValueChanged(object sender, EventArgs e) {
     169    private void BestKnownSolutionParameter_ValueChanged(object sender, EventArgs e) {
    167170      EvalBestKnownSolution();
    168171    }
    169172
    170     void ProblemInstance_EvaluationChanged(object sender, EventArgs e) {
     173    private void ProblemInstance_EvaluationChanged(object sender, EventArgs e) {
    171174      BestKnownQuality = double.NaN;
    172175      if (BestKnownSolution != null) {
     
    191194    }
    192195
    193     void ProblemInstanceParameter_ValueChanged(object sender, EventArgs e) {
     196    private void ProblemInstanceParameter_ValueChanged(object sender, EventArgs e) {
    194197      InitializeOperators();
    195198      AttachProblemInstanceEventHandlers();
     
    219222        .Where(x => operatorTypes.Add(x)).Select(t => (IOperator)Activator.CreateInstance(t)).ToList();
    220223      newOps.AddRange(ProblemInstance.FilterOperators(analyzers));
    221      
     224
    222225      Operators.Replace(newOps);
    223226    }
Note: See TracChangeset for help on using the changeset viewer.