- Timestamp:
- 11/26/15 09:30:43 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ProblemRefactoring/HeuristicLab.Problems.Knapsack/3.3/Analyzers/BestKnapsackSolutionAnalyzer.cs
r12012 r13404 36 36 [Item("BestKnapsackSolutionAnalyzer", "An operator for analyzing the best solution for a Knapsack problem.")] 37 37 [StorableClass] 38 public class BestKnapsackSolutionAnalyzer : SingleSuccessorOperator, I Analyzer, ISingleObjectiveOperator {38 public class BestKnapsackSolutionAnalyzer : SingleSuccessorOperator, IBinaryVectorSolutionsOperator, IAnalyzer, ISingleObjectiveOperator { 39 39 public virtual bool EnabledByDefault { 40 40 get { return true; } 41 41 } 42 42 43 public LookupParameter<BoolValue> MaximizationParameter {44 get { return ( LookupParameter<BoolValue>)Parameters["Maximization"]; }43 public ILookupParameter<BoolValue> MaximizationParameter { 44 get { return (ILookupParameter<BoolValue>)Parameters["Maximization"]; } 45 45 } 46 public ScopeTreeLookupParameter<BinaryVector> BinaryVectorParameter {47 get { return ( ScopeTreeLookupParameter<BinaryVector>)Parameters["BinaryVector"]; }46 public IScopeTreeLookupParameter<BinaryVector> BinaryVectorsParameter { 47 get { return (IScopeTreeLookupParameter<BinaryVector>)Parameters["BinaryVectors"]; } 48 48 } 49 public LookupParameter<IntValue> KnapsackCapacityParameter {50 get { return ( LookupParameter<IntValue>)Parameters["KnapsackCapacity"]; }49 public ILookupParameter<IntValue> KnapsackCapacityParameter { 50 get { return (ILookupParameter<IntValue>)Parameters["KnapsackCapacity"]; } 51 51 } 52 public LookupParameter<IntArray> WeightsParameter {53 get { return ( LookupParameter<IntArray>)Parameters["Weights"]; }52 public ILookupParameter<IntArray> WeightsParameter { 53 get { return (ILookupParameter<IntArray>)Parameters["Weights"]; } 54 54 } 55 public LookupParameter<IntArray> ValuesParameter {56 get { return ( LookupParameter<IntArray>)Parameters["Values"]; }55 public ILookupParameter<IntArray> ValuesParameter { 56 get { return (ILookupParameter<IntArray>)Parameters["Values"]; } 57 57 } 58 public ScopeTreeLookupParameter<DoubleValue> QualityParameter {59 get { return ( ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }58 public IScopeTreeLookupParameter<DoubleValue> QualityParameter { 59 get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; } 60 60 } 61 public LookupParameter<KnapsackSolution> BestSolutionParameter {62 get { return ( LookupParameter<KnapsackSolution>)Parameters["BestSolution"]; }61 public ILookupParameter<KnapsackSolution> BestSolutionParameter { 62 get { return (ILookupParameter<KnapsackSolution>)Parameters["BestSolution"]; } 63 63 } 64 public ValueLookupParameter<ResultCollection> ResultsParameter {65 get { return ( ValueLookupParameter<ResultCollection>)Parameters["Results"]; }64 public IValueLookupParameter<ResultCollection> ResultsParameter { 65 get { return (IValueLookupParameter<ResultCollection>)Parameters["Results"]; } 66 66 } 67 public LookupParameter<DoubleValue> BestKnownQualityParameter {68 get { return ( LookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; }67 public ILookupParameter<DoubleValue> BestKnownQualityParameter { 68 get { return (ILookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; } 69 69 } 70 public LookupParameter<BinaryVector> BestKnownSolutionParameter {71 get { return ( LookupParameter<BinaryVector>)Parameters["BestKnownSolution"]; }70 public ILookupParameter<BinaryVector> BestKnownSolutionParameter { 71 get { return (ILookupParameter<BinaryVector>)Parameters["BestKnownSolution"]; } 72 72 } 73 73 … … 78 78 : base() { 79 79 Parameters.Add(new LookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem.")); 80 Parameters.Add(new ScopeTreeLookupParameter<BinaryVector>("BinaryVector ", "The Knapsack solutions from which the best solution should be visualized."));80 Parameters.Add(new ScopeTreeLookupParameter<BinaryVector>("BinaryVectors", "The Knapsack solutions from which the best solution should be visualized.")); 81 81 Parameters.Add(new LookupParameter<IntValue>("KnapsackCapacity", "Capacity of the Knapsack.")); 82 82 Parameters.Add(new LookupParameter<IntArray>("Weights", "The weights of the items.")); … … 95 95 96 96 public override IOperation Apply() { 97 ItemArray<BinaryVector> binaryVectors = BinaryVectorParameter.ActualValue;98 ItemArray<DoubleValue>qualities = QualityParameter.ActualValue;99 ResultCollectionresults = ResultsParameter.ActualValue;100 boolmax = MaximizationParameter.ActualValue.Value;101 DoubleValuebestKnownQuality = BestKnownQualityParameter.ActualValue;97 var binaryVectors = BinaryVectorsParameter.ActualValue; 98 var qualities = QualityParameter.ActualValue; 99 var results = ResultsParameter.ActualValue; 100 var max = MaximizationParameter.ActualValue.Value; 101 var bestKnownQuality = BestKnownQualityParameter.ActualValue; 102 102 103 103 int i = -1; 104 if (!max) 105 i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index; 106 else i = qualities.Select((x, index) => new { index, x.Value }).OrderByDescending(x => x.Value).First().index; 104 i = !max ? qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index 105 : qualities.Select((x, index) => new { index, x.Value }).OrderByDescending(x => x.Value).First().index; 107 106 108 107 if (bestKnownQuality == null || … … 113 112 } 114 113 115 KnapsackSolutionsolution = BestSolutionParameter.ActualValue;114 var solution = BestSolutionParameter.ActualValue; 116 115 if (solution == null) { 117 116 solution = new KnapsackSolution((BinaryVector)binaryVectors[i].Clone(), new DoubleValue(qualities[i].Value),
Note: See TracChangeset
for help on using the changeset viewer.