Index: trunk/sources/HeuristicLab.Problems.Knapsack/3.3/Analyzers/BestKnapsackSolutionAnalyzer.cs
===================================================================
--- trunk/sources/HeuristicLab.Problems.Knapsack/3.3/Analyzers/BestKnapsackSolutionAnalyzer.cs	(revision 3757)
+++ trunk/sources/HeuristicLab.Problems.Knapsack/3.3/Analyzers/BestKnapsackSolutionAnalyzer.cs	(revision 3787)
@@ -39,5 +39,7 @@
   [StorableClass]
   class BestKnapsackSolutionAnalyzer : SingleSuccessorOperator, IAnalyzer {
-
+    public LookupParameter<BoolValue> MaximizationParameter {
+      get { return (LookupParameter<BoolValue>)Parameters["Maximization"]; }
+    }
     public ScopeTreeLookupParameter<BinaryVector> BinaryVectorParameter {
       get { return (ScopeTreeLookupParameter<BinaryVector>)Parameters["BinaryVector"]; }
@@ -61,7 +63,14 @@
       get { return (ValueLookupParameter<ResultCollection>)Parameters["Results"]; }
     }
+    public LookupParameter<DoubleValue> BestKnownQualityParameter {
+      get { return (LookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
+    }
+    public LookupParameter<BinaryVector> BestKnownSolutionParameter {
+      get { return (LookupParameter<BinaryVector>)Parameters["BestKnownSolution"]; }
+    }
 
     public BestKnapsackSolutionAnalyzer()
       : base() {
+      Parameters.Add(new LookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem."));
       Parameters.Add(new ScopeTreeLookupParameter<BinaryVector>("BinaryVector", "The knapsack solutions from which the best solution should be visualized."));
       Parameters.Add(new LookupParameter<IntValue>("KnapsackCapacity", "Capacity of the Knapsack."));
@@ -72,4 +81,6 @@
       Parameters.Add(new LookupParameter<KnapsackSolution>("BestSolution", "The best knapsack solution."));
       Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the knapsack solution should be stored."));
+      Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution."));
+      Parameters.Add(new LookupParameter<BinaryVector>("BestKnownSolution", "The best known solution."));
     }
 
@@ -78,21 +89,34 @@
       ItemArray<DoubleValue> qualities = QualityParameter.ActualValue;
       ResultCollection results = ResultsParameter.ActualValue;
+      bool max = MaximizationParameter.ActualValue.Value;
+      DoubleValue bestKnownQuality = BestKnownQualityParameter.ActualValue;
 
-      int i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
+      int i = -1;
+      if (!max) 
+        i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
+      else i = qualities.Select((x, index) => new { index, x.Value }).OrderByDescending(x => x.Value).First().index;
+
+      if (bestKnownQuality == null ||
+          max && qualities[i].Value > bestKnownQuality.Value ||
+          !max && qualities[i].Value < bestKnownQuality.Value) {
+        BestKnownQualityParameter.ActualValue = new DoubleValue(qualities[i].Value);
+        BestKnownSolutionParameter.ActualValue = (BinaryVector)binaryVectors[i].Clone();
+      }
 
       KnapsackSolution solution = BestSolutionParameter.ActualValue;
       if (solution == null) {
-        solution = new KnapsackSolution(binaryVectors[i], qualities[i],
+        solution = new KnapsackSolution((BinaryVector)binaryVectors[i].Clone(), new DoubleValue(qualities[i].Value),
           KnapsackCapacityParameter.ActualValue, WeightsParameter.ActualValue, ValuesParameter.ActualValue);
         BestSolutionParameter.ActualValue = solution;
         results.Add(new Result("Best Knapsack Solution", solution));
       }  else {
-        solution.BinaryVector = binaryVectors[i];
-        solution.Quality = qualities[i];
-        solution.Capacity = KnapsackCapacityParameter.ActualValue;
-        solution.Weights = WeightsParameter.ActualValue;
-        solution.Values = ValuesParameter.ActualValue;
-
-        results["Best Knapsack Solution"].Value = solution;
+        if (max && qualities[i].Value > solution.Quality.Value ||
+          !max && qualities[i].Value < solution.Quality.Value) {
+          solution.BinaryVector = (BinaryVector)binaryVectors[i].Clone();
+          solution.Quality = new DoubleValue(qualities[i].Value);
+          solution.Capacity = KnapsackCapacityParameter.ActualValue;
+          solution.Weights = WeightsParameter.ActualValue;
+          solution.Values = ValuesParameter.ActualValue;
+        }
       }
 
