- Timestamp:
- 11/26/15 09:30:43 (9 years ago)
- Location:
- branches/ProblemRefactoring/HeuristicLab.Problems.Knapsack/3.3/MoveEvaluators
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ProblemRefactoring/HeuristicLab.Problems.Knapsack/3.3/MoveEvaluators/KnapsackMoveEvaluator.cs
r12012 r13404 25 25 using HeuristicLab.Encodings.BinaryVectorEncoding; 26 26 using HeuristicLab.Operators; 27 using HeuristicLab.Optimization;28 27 using HeuristicLab.Parameters; 29 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 47 46 public ILookupParameter<IntValue> KnapsackCapacityParameter { 48 47 get { return (ILookupParameter<IntValue>)Parameters["KnapsackCapacity"]; } 49 }50 public ILookupParameter<DoubleValue> PenaltyParameter {51 get { return (ILookupParameter<DoubleValue>)Parameters["Penalty"]; }52 48 } 53 49 public ILookupParameter<IntArray> WeightsParameter { -
branches/ProblemRefactoring/HeuristicLab.Problems.Knapsack/3.3/MoveEvaluators/KnapsackOneBitflipMoveEvaluator.cs
r12012 r13404 51 51 52 52 public override IOperation Apply() { 53 BinaryVector binaryVector = BinaryVectorParameter.ActualValue; 54 OneBitflipMove move = OneBitflipMoveParameter.ActualValue; 53 var move = OneBitflipMoveParameter.ActualValue; 54 var solution = BinaryVectorParameter.ActualValue; 55 var weights = WeightsParameter.ActualValue; 56 var values = ValuesParameter.ActualValue; 57 var capacity = KnapsackCapacityParameter.ActualValue.Value; 55 58 56 BinaryVector newSolution = new BinaryVector(binaryVector); 57 newSolution[move.Index] = !newSolution[move.Index]; 59 var totalWeight = !solution[move.Index] ? weights[move.Index] : 0.0; 60 var totalValue = !solution[move.Index] ? values[move.Index] : 0.0; ; 61 for (var i = 0; i < solution.Length; i++) { 62 if (i == move.Index || !solution[i]) continue; 63 totalWeight += weights[i]; 64 totalValue += values[i]; 65 } 58 66 59 DoubleValue quality = KnapsackEvaluator.Apply(newSolution, 60 KnapsackCapacityParameter.ActualValue, 61 PenaltyParameter.ActualValue, 62 WeightsParameter.ActualValue, 63 ValuesParameter.ActualValue).Quality; 64 65 double moveQuality = quality.Value; 67 var moveQuality = totalWeight > capacity ? capacity - totalWeight : totalValue; 66 68 67 69 if (MoveQualityParameter.ActualValue == null) MoveQualityParameter.ActualValue = new DoubleValue(moveQuality);
Note: See TracChangeset
for help on using the changeset viewer.