Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 3059 was 3059, checked in by svonolfe, 14 years ago

Updated the IntegerVector project to use the new solution encodings (#909)

File size: 3.0 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 System;
23using System.Collections.Generic;
24using System.Text;
25using HeuristicLab.Core;
26using HeuristicLab.Data;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28
29namespace HeuristicLab.Encodings.IntegerVectorEncoding {
30  /// <summary>
31  /// Generates a new random integer vector with each element uniformly distributed in a specified range.
32  /// </summary>
33  [Item("UniformRandomIntegerVectorCreator", "An operator which creates a new random int vector with each element uniformly distributed in a specified range.")]
34  [StorableClass]
35  [Creatable("Test")]
36  public class UniformRandomIntegerVectorCreator : IntegerVectorCreator {
37    /// <summary>
38    /// Generates a new random integer vector with the given <paramref name="length"/>.
39    /// </summary>
40    /// <param name="random">The random number generator.</param>
41    /// <param name="length">The length of the int vector.</param>
42    /// <param name="min">The minimum value of the sampling range for each vector element (inclusive).</param>
43    /// <param name="max">The maximum value of the sampling range for each vector element (exclusive).</param>
44    /// <returns>The newly created integer vector.</returns>
45    public static IntegerVector Apply(IRandom random, int length, int min, int max) {
46      int[] result = new int[length];
47      for (int i = 0; i < length; i++)
48        result[i] = random.Next(min, max);
49      return new IntegerVector(result);
50    }
51
52    /// <summary>
53    /// Forwards the call to <see cref="Apply(IRandom, int, int, int)"/>.
54    /// </summary>
55    /// <param name="random">The pseudo random number generator to use.</param>
56    /// <param name="length">The length of the int vector.</param>
57    /// <param name="minimum">The minimum value of the sampling range for each vector element (inclusive).</param>
58    /// <param name="maximum">The maximum value of the sampling range for each vector element (exclusive).</param>
59    /// <returns>The newly created int vector.</returns>
60    protected override IntegerVector Create(IRandom random, IntValue length, IntValue minimum, IntValue maximum) {
61      return Apply(random, length.Value, minimum.Value, maximum.Value);
62    }
63  }
64}
Note: See TracBrowser for help on using the repository browser.