Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/19/10 16:22:26 (14 years ago)
Author:
svonolfe
Message:

The Knapsack problem is now initialized with a random instance (#917)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.Knapsack/3.3/Knapsack.cs

    r3124 r3125  
    138138    #endregion
    139139
     140    private void InitializeRandomKnapsackInstance() {
     141      System.Random rand = new System.Random();
     142
     143      int itemCount = rand.Next(10, 100);
     144      int capacity = itemCount * 5;
     145
     146      KnapsackCapacity = new IntValue(capacity);
     147      Weights = new IntArray(itemCount);
     148      Values = new IntArray(itemCount);
     149
     150      for (int i = 0; i < itemCount; i++ ) {
     151        int value = rand.Next(1, 10);
     152        int weight = rand.Next(1, 10);
     153
     154        Values[i] = value;
     155        Weights[i] = weight;
     156      }
     157    }
     158
    140159    public Knapsack()
    141160      : base() {
     
    155174      creator.BinaryVectorParameter.ActualName = "KnapsackSolution";
    156175      evaluator.QualityParameter.ActualName = "NumberOfOnes";
     176
     177      InitializeRandomKnapsackInstance();
     178     
    157179      ParameterizeSolutionCreator();
    158180      ParameterizeEvaluator();
Note: See TracChangeset for help on using the changeset viewer.