- Timestamp:
- 01/14/19 22:33:44 (6 years ago)
- Location:
- branches/2521_ProblemRefactoring/HeuristicLab.Problems.Knapsack/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring/HeuristicLab.Problems.Knapsack/3.3/Analyzers/BestKnapsackSolutionAnalyzer.cs
r14429 r16532 60 60 } 61 61 public ILookupParameter<KnapsackSolution> BestSolutionParameter { 62 get { return (ILookupParameter<KnapsackSolution>)Parameters["Best KnapsackSolution"]; }62 get { return (ILookupParameter<KnapsackSolution>)Parameters["BestSolution"]; } 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 KnapsackSolution", "The best Knapsack solution."));86 Parameters.Add(new LookupParameter<KnapsackSolution>("BestSolution", "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/2521_ProblemRefactoring/HeuristicLab.Problems.Knapsack/3.3/KnapsackProblem.cs
r14429 r16532 91 91 92 92 InitializeRandomKnapsackInstance(); 93 Encoding.Length = Weights.Length;94 93 95 94 InitializeOperators(); … … 98 97 99 98 public override double Evaluate(BinaryVector solution, IRandom random) { 100 var weights = Weights;101 var values = Values;102 99 var totalWeight = 0.0; 103 100 var totalValue = 0.0; 104 101 for (var i = 0; i < solution.Length; i++) { 105 102 if (!solution[i]) continue; 106 totalWeight += weights[i];107 totalValue += values[i];103 totalWeight += Weights[i]; 104 totalValue += Values[i]; 108 105 } 109 106 return totalWeight > KnapsackCapacity ? KnapsackCapacity - totalWeight : totalValue; … … 256 253 var sysrand = new System.Random(); 257 254 258 var power = sysrand.Next(5, 11); 259 var itemCount = (int)Math.Pow(2, power); 255 var itemCount = sysrand.Next(10, 100); 260 256 Weights = new IntArray(itemCount); 261 257 Values = new IntArray(itemCount); … … 264 260 265 261 for (int i = 0; i < itemCount; i++) { 266 var value = sysrand.Next(1, 30);267 var weight = sysrand.Next(1, 30);262 var value = sysrand.Next(1, 10); 263 var weight = sysrand.Next(1, 10); 268 264 269 265 Values[i] = value; … … 272 268 } 273 269 274 KnapsackCapacity = (int)Math.Round(0. 5* totalWeight);270 KnapsackCapacity = (int)Math.Round(0.7 * totalWeight); 275 271 } 276 272 }
Note: See TracChangeset
for help on using the changeset viewer.