Changeset 3667 for trunk/sources/HeuristicLab.Problems.Knapsack
- Timestamp:
- 05/06/10 12:49:05 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.Knapsack/3.3
- Files:
-
- 3 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.Knapsack/3.3/Analyzers/BestKnapsackSolutionAnalyzer.cs
r3658 r3667 38 38 [Item("BestKnapsackSolutionAnalyzer", "An operator for analyzing the best solution for a knapsack problem.")] 39 39 [StorableClass] 40 class BestKnapsackSolutionAnalyzer : SingleSuccessorOperator, I BestKnapsackSolutionAnalyzer, IAnalyzer {40 class BestKnapsackSolutionAnalyzer : SingleSuccessorOperator, IAnalyzer { 41 41 42 public ILookupParameter<BinaryVector> BinaryVectorParameter {43 get { return ( ILookupParameter<BinaryVector>)Parameters["BinaryVector"]; }42 public ScopeTreeLookupParameter<BinaryVector> BinaryVectorParameter { 43 get { return (ScopeTreeLookupParameter<BinaryVector>)Parameters["BinaryVector"]; } 44 44 } 45 ILookupParameter IBestKnapsackSolutionAnalyzer.BinaryVectorParameter {46 get { return BinaryVectorParameter; }45 public LookupParameter<IntValue> KnapsackCapacityParameter { 46 get { return (LookupParameter<IntValue>)Parameters["KnapsackCapacity"]; } 47 47 } 48 public ILookupParameter<IntValue> KnapsackCapacityParameter {49 get { return ( ILookupParameter<IntValue>)Parameters["KnapsackCapacity"]; }48 public LookupParameter<IntArray> WeightsParameter { 49 get { return (LookupParameter<IntArray>)Parameters["Weights"]; } 50 50 } 51 public ILookupParameter<IntArray> WeightsParameter {52 get { return ( ILookupParameter<IntArray>)Parameters["Weights"]; }51 public LookupParameter<IntArray> ValuesParameter { 52 get { return (LookupParameter<IntArray>)Parameters["Values"]; } 53 53 } 54 public ILookupParameter<IntArray> ValuesParameter {55 get { return ( ILookupParameter<IntArray>)Parameters["Values"]; }54 public ScopeTreeLookupParameter<DoubleValue> QualityParameter { 55 get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; } 56 56 } 57 public ILookupParameter<DoubleValue> QualityParameter {58 get { return ( ILookupParameter<DoubleValue>)Parameters["Quality"]; }57 public LookupParameter<KnapsackSolution> BestSolutionParameter { 58 get { return (LookupParameter<KnapsackSolution>)Parameters["BestSolution"]; } 59 59 } 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"]; } 68 62 } 69 63 70 64 public BestKnapsackSolutionAnalyzer() 71 65 : 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.")); 73 67 Parameters.Add(new LookupParameter<IntValue>("KnapsackCapacity", "Capacity of the Knapsack.")); 74 68 Parameters.Add(new LookupParameter<IntArray>("Weights", "The weights of the items.")); 75 69 Parameters.Add(new LookupParameter<IntArray>("Values", "The values of the items.")); 76 70 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.")); 78 72 Parameters.Add(new LookupParameter<KnapsackSolution>("BestSolution", "The best knapsack solution.")); 79 73 Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the knapsack solution should be stored.")); … … 81 75 82 76 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; 85 79 ResultCollection results = ResultsParameter.ActualValue; 80 81 int i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index; 86 82 87 83 KnapsackSolution solution = BestSolutionParameter.ActualValue; 88 84 if (solution == null) { 89 solution = new KnapsackSolution(binaryVector , QualityParameter.ActualValue,85 solution = new KnapsackSolution(binaryVectors[i], qualities[i], 90 86 KnapsackCapacityParameter.ActualValue, WeightsParameter.ActualValue, ValuesParameter.ActualValue); 91 87 BestSolutionParameter.ActualValue = solution; 92 88 results.Add(new Result("Best Knapsack Solution", solution)); 93 89 } else { 94 solution.BinaryVector = binaryVector ;95 solution.Quality = QualityParameter.ActualValue;90 solution.BinaryVector = binaryVectors[i]; 91 solution.Quality = qualities[i]; 96 92 solution.Capacity = KnapsackCapacityParameter.ActualValue; 97 93 solution.Weights = WeightsParameter.ActualValue; -
trunk/sources/HeuristicLab.Problems.Knapsack/3.3/HeuristicLab.Problems.Knapsack-3.3.csproj
r3641 r3667 81 81 </ItemGroup> 82 82 <ItemGroup> 83 <Compile Include="Analyzers\MultiPopulationBestKnapsackSolutionAnalyzer.cs" />84 <Compile Include="Analyzers\PopulationBestKnapsackSolutionAnalyzer.cs" />85 83 <Compile Include="Evaluators\KnapsackEvaluator.cs" /> 86 84 <Compile Include="HeuristicLabProblemsKnapsackPlugin.cs" /> 87 <Compile Include="Interfaces\IBestKnapsackSolutionAnalyzer.cs" />88 85 <Compile Include="Interfaces\IKnapsackEvaluator.cs" /> 89 86 <Compile Include="Interfaces\IKnapsackMoveEvaluator.cs" /> -
trunk/sources/HeuristicLab.Problems.Knapsack/3.3/KnapsackProblem.cs
r3641 r3667 124 124 get { return operators.Cast<IOperator>(); } 125 125 } 126 private IEnumerable<IBestKnapsackSolutionAnalyzer> BestKnapsackSolutionAnalyzers{127 get { return operators.OfType< IBestKnapsackSolutionAnalyzer>(); }126 private BestKnapsackSolutionAnalyzer BestKnapsackSolutionAnalyzer { 127 get { return operators.OfType<BestKnapsackSolutionAnalyzer>().FirstOrDefault(); } 128 128 } 129 129 #endregion … … 206 206 ParameterizeSolutionCreator(); 207 207 ParameterizeEvaluator(); 208 ParameterizeAnalyzer s();208 ParameterizeAnalyzer(); 209 209 ParameterizeOperators(); 210 210 OnSolutionCreatorChanged(); … … 212 212 private void SolutionCreator_BinaryVectorParameter_ActualNameChanged(object sender, EventArgs e) { 213 213 ParameterizeEvaluator(); 214 ParameterizeAnalyzer s();214 ParameterizeAnalyzer(); 215 215 ParameterizeOperators(); 216 216 } 217 217 private void EvaluatorParameter_ValueChanged(object sender, EventArgs e) { 218 218 ParameterizeEvaluator(); 219 ParameterizeAnalyzer s();219 ParameterizeAnalyzer(); 220 220 OnEvaluatorChanged(); 221 221 } 222 222 void KnapsackCapacityParameter_ValueChanged(object sender, EventArgs e) { 223 223 ParameterizeEvaluator(); 224 ParameterizeAnalyzer s();224 ParameterizeAnalyzer(); 225 225 } 226 226 void WeightsParameter_ValueChanged(object sender, EventArgs e) { 227 227 ParameterizeEvaluator(); 228 ParameterizeAnalyzer s();228 ParameterizeAnalyzer(); 229 229 ParameterizeSolutionCreator(); 230 230 … … 239 239 void ValuesParameter_ValueChanged(object sender, EventArgs e) { 240 240 ParameterizeEvaluator(); 241 ParameterizeAnalyzer s();241 ParameterizeAnalyzer(); 242 242 ParameterizeSolutionCreator(); 243 243 … … 291 291 } 292 292 } 293 private void ParameterizeAnalyzers() { 294 foreach (IBestKnapsackSolutionAnalyzer analyzer in BestKnapsackSolutionAnalyzers) { 295 analyzer.BinaryVectorParameter.ActualName = SolutionCreator.BinaryVectorParameter.ActualName; 296 analyzer.KnapsackCapacityParameter.ActualName = KnapsackCapacityParameter.Name; 297 analyzer.WeightsParameter.ActualName = WeightsParameter.Name; 298 analyzer.ValuesParameter.ActualName = ValuesParameter.Name; 299 analyzer.ResultsParameter.ActualName = "Results"; 300 } 293 private void ParameterizeAnalyzer() { 294 BestKnapsackSolutionAnalyzer.BinaryVectorParameter.ActualName = SolutionCreator.BinaryVectorParameter.ActualName; 295 BestKnapsackSolutionAnalyzer.KnapsackCapacityParameter.ActualName = KnapsackCapacityParameter.Name; 296 BestKnapsackSolutionAnalyzer.WeightsParameter.ActualName = WeightsParameter.Name; 297 BestKnapsackSolutionAnalyzer.ValuesParameter.ActualName = ValuesParameter.Name; 298 BestKnapsackSolutionAnalyzer.ResultsParameter.ActualName = "Results"; 301 299 } 302 300 private void InitializeOperators() { 303 301 operators = new List<IOperator>(); 304 302 operators.Add(new BestKnapsackSolutionAnalyzer()); 305 operators.Add(new PopulationBestKnapsackSolutionAnalyzer()); 306 operators.Add(new MultiPopulationBestKnapsackSolutionAnalyzer()); 307 ParameterizeAnalyzers(); 303 ParameterizeAnalyzer(); 308 304 foreach (IBinaryVectorOperator op in ApplicationManager.Manager.GetInstances<IBinaryVectorOperator>()) { 309 305 if (!(op is ISingleObjectiveMoveEvaluator) || (op is IKnapsackMoveEvaluator)) {
Note: See TracChangeset
for help on using the changeset viewer.