Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVector.cs @ 17398

Last change on this file since 17398 was 17180, checked in by swagner, 5 years ago

#2875: Removed years in copyrights

File size: 3.1 KB
RevLine 
[3054]1#region License Information
2/* HeuristicLab
[17180]3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[3054]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
[8019]22using System;
[3376]23using HeuristicLab.Common;
[3054]24using HeuristicLab.Core;
25using HeuristicLab.Data;
[16565]26using HEAL.Attic;
[3054]27
28namespace HeuristicLab.Encodings.IntegerVectorEncoding {
[16565]29  [StorableType("2DDD33C1-4732-478B-83B1-17226A8F2B61")]
[3054]30  [Item("IntegerVector", "Represents a vector of integer values.")]
31  public class IntegerVector : IntArray {
[4722]32    [StorableConstructor]
[16565]33    protected IntegerVector(StorableConstructorFlag _) : base(_) { }
[4722]34    protected IntegerVector(IntegerVector original, Cloner cloner) : base(original, cloner) { }
[3054]35    public IntegerVector() : base() { }
36    public IntegerVector(int length) : base(length) { }
37    public IntegerVector(int length, IRandom random, int min, int max)
38      : this(length) {
39      Randomize(random, min, max);
40    }
41    public IntegerVector(int[] elements) : base(elements) { }
42    public IntegerVector(IntArray elements)
43      : this(elements.Length) {
44      for (int i = 0; i < array.Length; i++)
45        array[i] = elements[i];
46    }
47
48    public override IDeepCloneable Clone(Cloner cloner) {
[4722]49      return new IntegerVector(this, cloner);
[3054]50    }
51
[8019]52    public virtual void Randomize(IRandom random, int startIndex, int length, int min, int max, int step = 1) {
[3054]53      if (length > 0) {
[8019]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        }
[3054]58        OnReset();
59      }
60    }
[8019]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      }
[3054]71    }
[8019]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);
77    }
[3054]78  }
79}
Note: See TracBrowser for help on using the repository browser.