Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Creators/UniformRandomIntegerVectorCreator.cs @ 4068

Last change on this file since 4068 was 4068, checked in by swagner, 14 years ago

Sorted usings and removed unused usings in entire solution (#1094)

File size: 2.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using HeuristicLab.Core;
23using HeuristicLab.Data;
24using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
25
26namespace HeuristicLab.Encodings.IntegerVectorEncoding {
27  /// <summary>
28  /// Generates a new random integer vector with each element uniformly distributed in a specified range.
29  /// </summary>
30  [Item("UniformRandomIntegerVectorCreator", "An operator which creates a new random int vector with each element uniformly distributed in a specified range.")]
31  [StorableClass]
32  public class UniformRandomIntegerVectorCreator : IntegerVectorCreator {
33    /// <summary>
34    /// Generates a new random integer vector with the given <paramref name="length"/>.
35    /// </summary>
36    /// <param name="random">The random number generator.</param>
37    /// <param name="length">The length of the int vector.</param>
38    /// <param name="min">The minimum value of the sampling range for each vector element (inclusive).</param>
39    /// <param name="max">The maximum value of the sampling range for each vector element (exclusive).</param>
40    /// <returns>The newly created integer vector.</returns>
41    public static IntegerVector Apply(IRandom random, int length, int min, int max) {
42      int[] result = new int[length];
43      for (int i = 0; i < length; i++)
44        result[i] = random.Next(min, max);
45      return new IntegerVector(result);
46    }
47
48    /// <summary>
49    /// Forwards the call to <see cref="Apply(IRandom, int, int, int)"/>.
50    /// </summary>
51    /// <param name="random">The pseudo random number generator to use.</param>
52    /// <param name="length">The length of the int vector.</param>
53    /// <param name="minimum">The minimum value of the sampling range for each vector element (inclusive).</param>
54    /// <param name="maximum">The maximum value of the sampling range for each vector element (exclusive).</param>
55    /// <returns>The newly created int vector.</returns>
56    protected override IntegerVector Create(IRandom random, IntValue length, IntValue minimum, IntValue maximum) {
57      return Apply(random, length.Value, minimum.Value, maximum.Value);
58    }
59  }
60}
Note: See TracBrowser for help on using the repository browser.