[3054] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[17181] | 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] | 22 | using System;
|
---|
[3376] | 23 | using HeuristicLab.Common;
|
---|
[3054] | 24 | using HeuristicLab.Core;
|
---|
| 25 | using HeuristicLab.Data;
|
---|
[17097] | 26 | using HEAL.Attic;
|
---|
[3054] | 27 |
|
---|
| 28 | namespace HeuristicLab.Encodings.IntegerVectorEncoding {
|
---|
[17097] | 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]
|
---|
[17097] | 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 | }
|
---|