Free cookie consent management tool by TermsFeed Policy Generator

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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.