Free cookie consent management tool by TermsFeed Policy Generator

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

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

Location:
branches/ProblemRefactoring/HeuristicLab.Problems.Knapsack/3.3
Files:
2 edited

Legend:

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

    r13404 r14429  
    6060    }
    6161    public ILookupParameter<KnapsackSolution> BestSolutionParameter {
    62       get { return (ILookupParameter<KnapsackSolution>)Parameters["BestSolution"]; }
     62      get { return (ILookupParameter<KnapsackSolution>)Parameters["BestKnapsackSolution"]; }
    6363    }
    6464    public IValueLookupParameter<ResultCollection> ResultsParameter {
     
    8484
    8585      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The qualities of the Knapsack solutions which should be visualized."));
    86       Parameters.Add(new LookupParameter<KnapsackSolution>("BestSolution", "The best Knapsack solution."));
     86      Parameters.Add(new LookupParameter<KnapsackSolution>("BestKnapsackSolution", "The best Knapsack solution."));
    8787      Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the knapsack solution should be stored."));
    8888      Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution."));
  • 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.