- Timestamp:
- 11/29/16 15:46:48 (8 years ago)
- Location:
- branches/ProblemRefactoring/HeuristicLab.Problems.Knapsack/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ProblemRefactoring/HeuristicLab.Problems.Knapsack/3.3/Analyzers/BestKnapsackSolutionAnalyzer.cs
r13404 r14429 60 60 } 61 61 public ILookupParameter<KnapsackSolution> BestSolutionParameter { 62 get { return (ILookupParameter<KnapsackSolution>)Parameters["Best Solution"]; }62 get { return (ILookupParameter<KnapsackSolution>)Parameters["BestKnapsackSolution"]; } 63 63 } 64 64 public IValueLookupParameter<ResultCollection> ResultsParameter { … … 84 84 85 85 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The qualities of the Knapsack solutions which should be visualized.")); 86 Parameters.Add(new LookupParameter<KnapsackSolution>("Best Solution", "The best Knapsack solution."));86 Parameters.Add(new LookupParameter<KnapsackSolution>("BestKnapsackSolution", "The best Knapsack solution.")); 87 87 Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the knapsack solution should be stored.")); 88 88 Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution.")); -
branches/ProblemRefactoring/HeuristicLab.Problems.Knapsack/3.3/KnapsackProblem.cs
r13469 r14429 91 91 92 92 InitializeRandomKnapsackInstance(); 93 Encoding.Length = Weights.Length; 93 94 94 95 InitializeOperators(); … … 97 98 98 99 public override double Evaluate(BinaryVector solution, IRandom random) { 100 var weights = Weights; 101 var values = Values; 99 102 var totalWeight = 0.0; 100 103 var totalValue = 0.0; 101 104 for (var i = 0; i < solution.Length; i++) { 102 105 if (!solution[i]) continue; 103 totalWeight += Weights[i];104 totalValue += Values[i];106 totalWeight += weights[i]; 107 totalValue += values[i]; 105 108 } 106 109 return totalWeight > KnapsackCapacity ? KnapsackCapacity - totalWeight : totalValue; … … 253 256 var sysrand = new System.Random(); 254 257 255 var itemCount = sysrand.Next(10, 100); 258 var power = sysrand.Next(5, 11); 259 var itemCount = (int)Math.Pow(2, power); 256 260 Weights = new IntArray(itemCount); 257 261 Values = new IntArray(itemCount); … … 260 264 261 265 for (int i = 0; i < itemCount; i++) { 262 var value = sysrand.Next(1, 10);263 var weight = sysrand.Next(1, 10);266 var value = sysrand.Next(1, 30); 267 var weight = sysrand.Next(1, 30); 264 268 265 269 Values[i] = value; … … 268 272 } 269 273 270 KnapsackCapacity = (int)Math.Round(0. 7* totalWeight);274 KnapsackCapacity = (int)Math.Round(0.5 * totalWeight); 271 275 } 272 276 }
Note: See TracChangeset
for help on using the changeset viewer.