Ignore:
Timestamp:
11/29/16 15:46:48 (4 years ago)
Author:
abeham
Message:

#2701, #2708: Made a new branch from ProblemRefactoring and removed ScopedBasicAlgorithm branch (which becomes MemPR branch)

File:
1 edited

Legend:

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

    r13469 r14429  
    9191
    9292      InitializeRandomKnapsackInstance();
     93      Encoding.Length = Weights.Length;
    9394
    9495      InitializeOperators();
     
    9798
    9899    public override double Evaluate(BinaryVector solution, IRandom random) {
     100      var weights = Weights;
     101      var values = Values;
    99102      var totalWeight = 0.0;
    100103      var totalValue = 0.0;
    101104      for (var i = 0; i < solution.Length; i++) {
    102105        if (!solution[i]) continue;
    103         totalWeight += Weights[i];
    104         totalValue += Values[i];
     106        totalWeight += weights[i];
     107        totalValue += values[i];
    105108      }
    106109      return totalWeight > KnapsackCapacity ? KnapsackCapacity - totalWeight : totalValue;
     
    253256      var sysrand = new System.Random();
    254257
    255       var itemCount = sysrand.Next(10, 100);
     258      var power = sysrand.Next(5, 11);
     259      var itemCount = (int)Math.Pow(2, power);
    256260      Weights = new IntArray(itemCount);
    257261      Values = new IntArray(itemCount);
     
    260264
    261265      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);
    264268
    265269        Values[i] = value;
     
    268272      }
    269273
    270       KnapsackCapacity = (int)Math.Round(0.7 * totalWeight);
     274      KnapsackCapacity = (int)Math.Round(0.5 * totalWeight);
    271275    }
    272276  }
Note: See TracChangeset for help on using the changeset viewer.