Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/11/10 21:16:12 (15 years ago)
Author:
abeham
Message:

#893

  • Removed best known quality tracking from BestAverageWorstQualityAnalyzer
  • Added best known quality / solution tracking to problem specific analyzers
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.Knapsack/3.3/Analyzers/BestKnapsackSolutionAnalyzer.cs

    r3667 r3787  
    3939  [StorableClass]
    4040  class BestKnapsackSolutionAnalyzer : SingleSuccessorOperator, IAnalyzer {
    41 
     41    public LookupParameter<BoolValue> MaximizationParameter {
     42      get { return (LookupParameter<BoolValue>)Parameters["Maximization"]; }
     43    }
    4244    public ScopeTreeLookupParameter<BinaryVector> BinaryVectorParameter {
    4345      get { return (ScopeTreeLookupParameter<BinaryVector>)Parameters["BinaryVector"]; }
     
    6163      get { return (ValueLookupParameter<ResultCollection>)Parameters["Results"]; }
    6264    }
     65    public LookupParameter<DoubleValue> BestKnownQualityParameter {
     66      get { return (LookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
     67    }
     68    public LookupParameter<BinaryVector> BestKnownSolutionParameter {
     69      get { return (LookupParameter<BinaryVector>)Parameters["BestKnownSolution"]; }
     70    }
    6371
    6472    public BestKnapsackSolutionAnalyzer()
    6573      : base() {
     74      Parameters.Add(new LookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem."));
    6675      Parameters.Add(new ScopeTreeLookupParameter<BinaryVector>("BinaryVector", "The knapsack solutions from which the best solution should be visualized."));
    6776      Parameters.Add(new LookupParameter<IntValue>("KnapsackCapacity", "Capacity of the Knapsack."));
     
    7281      Parameters.Add(new LookupParameter<KnapsackSolution>("BestSolution", "The best knapsack solution."));
    7382      Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the knapsack solution should be stored."));
     83      Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution."));
     84      Parameters.Add(new LookupParameter<BinaryVector>("BestKnownSolution", "The best known solution."));
    7485    }
    7586
     
    7889      ItemArray<DoubleValue> qualities = QualityParameter.ActualValue;
    7990      ResultCollection results = ResultsParameter.ActualValue;
     91      bool max = MaximizationParameter.ActualValue.Value;
     92      DoubleValue bestKnownQuality = BestKnownQualityParameter.ActualValue;
    8093
    81       int i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
     94      int i = -1;
     95      if (!max)
     96        i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
     97      else i = qualities.Select((x, index) => new { index, x.Value }).OrderByDescending(x => x.Value).First().index;
     98
     99      if (bestKnownQuality == null ||
     100          max && qualities[i].Value > bestKnownQuality.Value ||
     101          !max && qualities[i].Value < bestKnownQuality.Value) {
     102        BestKnownQualityParameter.ActualValue = new DoubleValue(qualities[i].Value);
     103        BestKnownSolutionParameter.ActualValue = (BinaryVector)binaryVectors[i].Clone();
     104      }
    82105
    83106      KnapsackSolution solution = BestSolutionParameter.ActualValue;
    84107      if (solution == null) {
    85         solution = new KnapsackSolution(binaryVectors[i], qualities[i],
     108        solution = new KnapsackSolution((BinaryVector)binaryVectors[i].Clone(), new DoubleValue(qualities[i].Value),
    86109          KnapsackCapacityParameter.ActualValue, WeightsParameter.ActualValue, ValuesParameter.ActualValue);
    87110        BestSolutionParameter.ActualValue = solution;
    88111        results.Add(new Result("Best Knapsack Solution", solution));
    89112      }  else {
    90         solution.BinaryVector = binaryVectors[i];
    91         solution.Quality = qualities[i];
    92         solution.Capacity = KnapsackCapacityParameter.ActualValue;
    93         solution.Weights = WeightsParameter.ActualValue;
    94         solution.Values = ValuesParameter.ActualValue;
    95 
    96         results["Best Knapsack Solution"].Value = solution;
     113        if (max && qualities[i].Value > solution.Quality.Value ||
     114          !max && qualities[i].Value < solution.Quality.Value) {
     115          solution.BinaryVector = (BinaryVector)binaryVectors[i].Clone();
     116          solution.Quality = new DoubleValue(qualities[i].Value);
     117          solution.Capacity = KnapsackCapacityParameter.ActualValue;
     118          solution.Weights = WeightsParameter.ActualValue;
     119          solution.Values = ValuesParameter.ActualValue;
     120        }
    97121      }
    98122
Note: See TracChangeset for help on using the changeset viewer.