Changeset 3537 for trunk/sources
- Timestamp:
- 04/26/10 18:58:32 (15 years ago)
- Location:
- trunk/sources
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.Knapsack.Views/3.3/KnapsackSolutionView.cs
r3467 r3537 154 154 //draw knapsack 155 155 graphics.DrawRectangle(Pens.Black, 156 borderX - 1, borderY- 1, width + 2, knapsackHeight + 2);156 borderX - 1, pictureBox.Height - borderY - knapsackHeight - 1, width + 2, knapsackHeight + 2); 157 157 158 158 //draw items sorted by value … … 180 180 double weight = Content.Weights[i]; 181 181 double factor = weight / capacity; 182 int elementHeight = (int)Math. Round(height * factor);182 int elementHeight = (int)Math.Floor(knapsackHeight * factor); 183 183 184 184 double value = Content.Values[i]; -
trunk/sources/HeuristicLab.Problems.Knapsack/3.3/Evaluators/KnapsackEvaluator.cs
r3376 r3537 39 39 get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; } 40 40 } 41 42 public ILookupParameter<DoubleValue> SumWeightsParameter { 43 get { return (ILookupParameter<DoubleValue>)Parameters["SumWeights"]; } 44 } 45 46 public ILookupParameter<DoubleValue> SumValuesParameter { 47 get { return (ILookupParameter<DoubleValue>)Parameters["SumValues"]; } 48 } 49 50 public ILookupParameter<DoubleValue> AppliedPenaltyParameter { 51 get { return (ILookupParameter<DoubleValue>)Parameters["AppliedPenalty"]; } 52 } 41 53 42 54 public ILookupParameter<BinaryVector> BinaryVectorParameter { … … 60 72 : base() { 61 73 Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The evaluated quality of the OneMax solution.")); 74 Parameters.Add(new LookupParameter<DoubleValue>("SumWeights", "The evaluated quality of the OneMax solution.")); 75 Parameters.Add(new LookupParameter<DoubleValue>("SumValues", "The evaluated quality of the OneMax solution.")); 76 Parameters.Add(new LookupParameter<DoubleValue>("AppliedPenalty", "The evaluated quality of the OneMax solution.")); 62 77 Parameters.Add(new LookupParameter<BinaryVector>("BinaryVector", "The OneMax solution given in path representation which should be evaluated.")); 63 78 Parameters.Add(new LookupParameter<IntValue>("KnapsackCapacity", "Capacity of the Knapsack.")); … … 67 82 } 68 83 69 public static DoubleValue Apply(BinaryVector v, IntValue capacity, DoubleValue penalty, IntArray weights, IntArray values) { 84 public struct KnapsackEvaluation { 85 public DoubleValue Quality; 86 public DoubleValue SumWeights; 87 public DoubleValue SumValues; 88 public DoubleValue AppliedPenalty; 89 } 90 91 public static KnapsackEvaluation Apply(BinaryVector v, IntValue capacity, DoubleValue penalty, IntArray weights, IntArray values) { 70 92 if (weights.Length != values.Length) 71 throw new InvalidOperationException("The weights and values parameters of the Knapsack problem have different sizes"); 72 93 throw new InvalidOperationException("The weights and values parameters of the Knapsack problem have different sizes"); 94 95 KnapsackEvaluation result = new KnapsackEvaluation(); 96 73 97 double quality = 0; 74 98 75 99 int weight = 0; 76 100 int value = 0; 101 double appliedPenalty = 0; 77 102 78 103 for (int i = 0; i < v.Length; i++) { … … 84 109 85 110 if (weight > capacity.Value) { 86 quality = 87 value - penalty.Value * (weight - capacity.Value); 88 } else { 89 quality = value; 90 } 111 appliedPenalty = penalty.Value * (weight - capacity.Value); 112 } 91 113 92 return new DoubleValue(quality); 114 quality = value - appliedPenalty; 115 116 result.AppliedPenalty = new DoubleValue(appliedPenalty); 117 result.SumWeights = new DoubleValue(weight); 118 result.SumValues = new DoubleValue(value); 119 result.Quality = new DoubleValue(quality); 120 121 return result; 93 122 } 94 123 … … 96 125 BinaryVector v = BinaryVectorParameter.ActualValue; 97 126 98 DoubleValue quality= Apply(BinaryVectorParameter.ActualValue,127 KnapsackEvaluation evaluation = Apply(BinaryVectorParameter.ActualValue, 99 128 KnapsackCapacityParameter.ActualValue, 100 129 PenaltyParameter.ActualValue, … … 102 131 ValuesParameter.ActualValue); 103 132 104 QualityParameter.ActualValue = quality; 133 QualityParameter.ActualValue = evaluation.Quality; 134 SumWeightsParameter.ActualValue = evaluation.SumWeights; 135 SumValuesParameter.ActualValue = evaluation.SumValues; 136 AppliedPenaltyParameter.ActualValue = evaluation.AppliedPenalty; 105 137 106 138 return base.Apply(); -
trunk/sources/HeuristicLab.Problems.Knapsack/3.3/KnapsackProblem.cs
r3528 r3537 143 143 144 144 int itemCount = rand.Next(10, 100); 145 int capacity = itemCount * 5;146 147 KnapsackCapacity = new IntValue(capacity);148 145 Weights = new IntArray(itemCount); 149 146 Values = new IntArray(itemCount); 147 148 double totalWeight = 0; 150 149 151 150 for (int i = 0; i < itemCount; i++ ) { … … 155 154 Values[i] = value; 156 155 Weights[i] = weight; 157 } 156 totalWeight += weight; 157 } 158 159 int capacity = (int)Math.Round(0.7 * totalWeight); 160 KnapsackCapacity = new IntValue(capacity); 158 161 } 159 162 … … 175 178 176 179 creator.BinaryVectorParameter.ActualName = "KnapsackSolution"; 177 evaluator.QualityParameter.ActualName = "NumberOfOnes";178 180 179 181 InitializeRandomKnapsackInstance(); -
trunk/sources/HeuristicLab.Problems.Knapsack/3.3/MoveEvaluators/KnapsackOneBitflipMoveEvaluator.cs
r3376 r3537 56 56 PenaltyParameter.ActualValue, 57 57 WeightsParameter.ActualValue, 58 ValuesParameter.ActualValue) ;58 ValuesParameter.ActualValue).Quality; 59 59 60 60 double moveQuality = quality.Value;
Note: See TracChangeset
for help on using the changeset viewer.