Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/02/12 00:29:39 (12 years ago)
Author:
abeham
Message:

#1775: added branch of plugin and new operators

Location:
branches/IntegerVectorEncoding/HeuristicLab.Encodings.IntegerVectorEncoding
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/IntegerVectorEncoding/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVector.cs

    r7259 r7681  
    2020#endregion
    2121
     22using System;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Core;
     
    4950    }
    5051
    51     public virtual void Randomize(IRandom random, int startIndex, int length, int min, int max) {
     52    public virtual void Randomize(IRandom random, int startIndex, int length, int min, int max, int step = 1) {
    5253      if (length > 0) {
    53         for (int i = 0; i < length; i++)
    54           array[startIndex + i] = random.Next(min, max);
     54        int numbers = (int)Math.Floor((max - min) / (double)step);
     55        for (int i = startIndex; i < startIndex + length; i++) {
     56          array[i] = random.Next(numbers) * step + min;
     57        }
    5558        OnReset();
    5659      }
    5760    }
    58     public void Randomize(IRandom random, int min, int max) {
    59       Randomize(random, 0, Length, min, max);
     61    public virtual void Randomize(IRandom random, int startIndex, int length, IntMatrix bounds) {
     62      if (length > 0) {
     63        for (int i = startIndex; i < startIndex + length; i++) {
     64          int min = bounds[i % bounds.Rows, 0], max = bounds[i % bounds.Rows, 1], step = 1;
     65          if (bounds.Columns > 2) step = bounds[i % bounds.Rows, 2];
     66          int numbers = (int)Math.Floor((max - min) / (double)step);
     67          array[i] = random.Next(numbers) * step + min;
     68        }
     69        OnReset();
     70      }
     71    }
     72    public void Randomize(IRandom random, int min, int max, int step = 1) {
     73      Randomize(random, 0, Length, min, max, step);
     74    }
     75    public void Randomize(IRandom random, IntMatrix bounds) {
     76      Randomize(random, 0, Length, bounds);
    6077    }
    6178  }
Note: See TracChangeset for help on using the changeset viewer.