Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/26/15 09:30:43 (8 years ago)
Author:
abeham
Message:

#2521:

  • Adapted Knapsack problem to new problem infrastructure
  • Introduced additional interfaces in binary vector encoding
  • Improved KnapsackImprovementOperator which requires less evaluated solutions in case of an infeasible start solution

Loosely related change:

  • All LookupParameters are now shown by default
  • Wiring code should make sure that wired parameters are hidden
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ProblemRefactoring/HeuristicLab.Problems.Knapsack/3.3/MoveEvaluators/KnapsackOneBitflipMoveEvaluator.cs

    r12012 r13404  
    5151
    5252    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;
    5558
    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      }
    5866
    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;
    6668
    6769      if (MoveQualityParameter.ActualValue == null) MoveQualityParameter.ActualValue = new DoubleValue(moveQuality);
Note: See TracChangeset for help on using the changeset viewer.