Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/06/10 12:49:05 (14 years ago)
Author:
svonolfe
Message:
  • Updated OneMax analyzer
  • Updated Knapsack analyzer
  • Fixed bug in OneMax and TF analyzer views

(#999)

Location:
trunk/sources/HeuristicLab.Problems.Knapsack/3.3/Analyzers
Files:
2 deleted
1 edited

Legend:

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

    r3658 r3667  
    3838  [Item("BestKnapsackSolutionAnalyzer", "An operator for analyzing the best solution for a knapsack problem.")]
    3939  [StorableClass]
    40   class BestKnapsackSolutionAnalyzer : SingleSuccessorOperator, IBestKnapsackSolutionAnalyzer, IAnalyzer {
     40  class BestKnapsackSolutionAnalyzer : SingleSuccessorOperator, IAnalyzer {
    4141
    42     public ILookupParameter<BinaryVector> BinaryVectorParameter {
    43       get { return (ILookupParameter<BinaryVector>)Parameters["BinaryVector"]; }
     42    public ScopeTreeLookupParameter<BinaryVector> BinaryVectorParameter {
     43      get { return (ScopeTreeLookupParameter<BinaryVector>)Parameters["BinaryVector"]; }
    4444    }
    45     ILookupParameter IBestKnapsackSolutionAnalyzer.BinaryVectorParameter {
    46       get { return BinaryVectorParameter; }
     45    public LookupParameter<IntValue> KnapsackCapacityParameter {
     46      get { return (LookupParameter<IntValue>)Parameters["KnapsackCapacity"]; }
    4747    }
    48     public ILookupParameter<IntValue> KnapsackCapacityParameter {
    49       get { return (ILookupParameter<IntValue>)Parameters["KnapsackCapacity"]; }
     48    public LookupParameter<IntArray> WeightsParameter {
     49      get { return (LookupParameter<IntArray>)Parameters["Weights"]; }
    5050    }
    51     public ILookupParameter<IntArray> WeightsParameter {
    52       get { return (ILookupParameter<IntArray>)Parameters["Weights"]; }
     51    public LookupParameter<IntArray> ValuesParameter {
     52      get { return (LookupParameter<IntArray>)Parameters["Values"]; }
    5353    }
    54     public ILookupParameter<IntArray> ValuesParameter {
    55       get { return (ILookupParameter<IntArray>)Parameters["Values"]; }
     54    public ScopeTreeLookupParameter<DoubleValue> QualityParameter {
     55      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
    5656    }
    57     public ILookupParameter<DoubleValue> QualityParameter {
    58       get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; }
     57    public LookupParameter<KnapsackSolution> BestSolutionParameter {
     58      get { return (LookupParameter<KnapsackSolution>)Parameters["BestSolution"]; }
    5959    }
    60     ILookupParameter IBestKnapsackSolutionAnalyzer.QualityParameter {
    61       get { return QualityParameter; }
    62     }
    63     public ILookupParameter<KnapsackSolution> BestSolutionParameter {
    64       get { return (ILookupParameter<KnapsackSolution>)Parameters["BestSolution"]; }
    65     }
    66     public IValueLookupParameter<ResultCollection> ResultsParameter {
    67       get { return (IValueLookupParameter<ResultCollection>)Parameters["Results"]; }
     60    public ValueLookupParameter<ResultCollection> ResultsParameter {
     61      get { return (ValueLookupParameter<ResultCollection>)Parameters["Results"]; }
    6862    }
    6963
    7064    public BestKnapsackSolutionAnalyzer()
    7165      : base() {
    72       Parameters.Add(new LookupParameter<BinaryVector>("BinaryVector", "The knapsack solutions from which the best solution should be visualized."));
     66      Parameters.Add(new ScopeTreeLookupParameter<BinaryVector>("BinaryVector", "The knapsack solutions from which the best solution should be visualized."));
    7367      Parameters.Add(new LookupParameter<IntValue>("KnapsackCapacity", "Capacity of the Knapsack."));
    7468      Parameters.Add(new LookupParameter<IntArray>("Weights", "The weights of the items."));
    7569      Parameters.Add(new LookupParameter<IntArray>("Values", "The values of the items."));
    7670
    77       Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The qualities of the knapsack solutions which should be visualized."));
     71      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The qualities of the knapsack solutions which should be visualized."));
    7872      Parameters.Add(new LookupParameter<KnapsackSolution>("BestSolution", "The best knapsack solution."));
    7973      Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the knapsack solution should be stored."));
     
    8175
    8276    public override IOperation Apply() {
    83       BinaryVector binaryVector = BinaryVectorParameter.ActualValue;
    84       DoubleValue quality = QualityParameter.ActualValue;
     77      ItemArray<BinaryVector> binaryVectors = BinaryVectorParameter.ActualValue;
     78      ItemArray<DoubleValue> qualities = QualityParameter.ActualValue;
    8579      ResultCollection results = ResultsParameter.ActualValue;
     80
     81      int i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
    8682
    8783      KnapsackSolution solution = BestSolutionParameter.ActualValue;
    8884      if (solution == null) {
    89         solution = new KnapsackSolution(binaryVector, QualityParameter.ActualValue,
     85        solution = new KnapsackSolution(binaryVectors[i], qualities[i],
    9086          KnapsackCapacityParameter.ActualValue, WeightsParameter.ActualValue, ValuesParameter.ActualValue);
    9187        BestSolutionParameter.ActualValue = solution;
    9288        results.Add(new Result("Best Knapsack Solution", solution));
    9389      }  else {
    94         solution.BinaryVector = binaryVector;
    95         solution.Quality = QualityParameter.ActualValue;
     90        solution.BinaryVector = binaryVectors[i];
     91        solution.Quality = qualities[i];
    9692        solution.Capacity = KnapsackCapacityParameter.ActualValue;
    9793        solution.Weights = WeightsParameter.ActualValue;
Note: See TracChangeset for help on using the changeset viewer.