[2854] | 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 |
|
---|
| 22 | using System;
|
---|
[2836] | 23 | using HeuristicLab.Core;
|
---|
| 24 |
|
---|
[3053] | 25 | namespace HeuristicLab.Encodings.PermutationEncoding_33.Tests {
|
---|
[2836] | 26 | public class TestRandom : IRandom {
|
---|
| 27 | #region Variables and Properties
|
---|
| 28 | private int[] intNumbers;
|
---|
| 29 | public int[] IntNumbers {
|
---|
| 30 | get { return intNumbers; }
|
---|
| 31 | set {
|
---|
| 32 | if (value == null) intNumbers = new int[0];
|
---|
| 33 | else intNumbers = value;
|
---|
| 34 | }
|
---|
| 35 | }
|
---|
| 36 | private int nextIntIndex;
|
---|
| 37 | private double[] doubleNumbers;
|
---|
| 38 | public double[] DoubleNumbers {
|
---|
| 39 | get { return doubleNumbers; }
|
---|
| 40 | set {
|
---|
| 41 | if (value == null) doubleNumbers = new double[0];
|
---|
| 42 | else doubleNumbers = value;
|
---|
| 43 | }
|
---|
| 44 | }
|
---|
| 45 | private int nextDoubleIndex;
|
---|
| 46 | #endregion
|
---|
| 47 |
|
---|
| 48 | public TestRandom() {
|
---|
| 49 | intNumbers = new int[0];
|
---|
| 50 | doubleNumbers = new double[0];
|
---|
| 51 | nextIntIndex = 0;
|
---|
| 52 | nextDoubleIndex = 0;
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | public TestRandom(int[] intNumbers, double[] doubleNumbers) {
|
---|
| 56 | if (intNumbers == null) intNumbers = new int[0];
|
---|
| 57 | else this.intNumbers = intNumbers;
|
---|
| 58 | if (doubleNumbers == null) doubleNumbers = new double[0];
|
---|
| 59 | else this.doubleNumbers = doubleNumbers;
|
---|
| 60 | nextIntIndex = 0;
|
---|
| 61 | nextDoubleIndex = 0;
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | #region IRandom Members
|
---|
| 65 |
|
---|
| 66 | public void Reset() {
|
---|
| 67 | nextIntIndex = 0;
|
---|
| 68 | nextDoubleIndex = 0;
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | public void Reset(int seed) {
|
---|
| 72 | throw new NotImplementedException();
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | public int Next() {
|
---|
| 76 | if (nextIntIndex >= intNumbers.Length) throw new InvalidOperationException("Random: No more integer random numbers available");
|
---|
| 77 | return intNumbers[nextIntIndex++];
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | public int Next(int maxVal) {
|
---|
| 81 | if (nextIntIndex >= intNumbers.Length) throw new InvalidOperationException("Random: No more integer random numbers available");
|
---|
[2840] | 82 | if (IntNumbers[nextIntIndex] >= maxVal) throw new InvalidOperationException("Random: Next integer random number (" + IntNumbers[nextIntIndex] + ") is >= " + maxVal);
|
---|
[2836] | 83 | return intNumbers[nextIntIndex++];
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | public int Next(int minVal, int maxVal) {
|
---|
| 87 | if (nextIntIndex >= intNumbers.Length) throw new InvalidOperationException("Random: No more integer random numbers available");
|
---|
[2840] | 88 | if (IntNumbers[nextIntIndex] < minVal || IntNumbers[nextIntIndex] >= maxVal) throw new InvalidOperationException("Random: Next integer random number (" + IntNumbers[nextIntIndex] + ") is not in the range [" + minVal + ";" + maxVal + ")");
|
---|
[2836] | 89 | return intNumbers[nextIntIndex++];
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | public double NextDouble() {
|
---|
| 93 | if (nextDoubleIndex >= doubleNumbers.Length) throw new InvalidOperationException("Random: No more double random numbers available");
|
---|
[2840] | 94 | if (doubleNumbers[nextDoubleIndex] < 0.0 || doubleNumbers[nextDoubleIndex] >= 1.0) throw new InvalidOperationException("Random: Next double ranomd number (" + DoubleNumbers[nextDoubleIndex] + ") is not in the range [0;1)");
|
---|
[2836] | 95 | return doubleNumbers[nextDoubleIndex++];
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 | #endregion
|
---|
| 99 |
|
---|
| 100 | #region IItem Members
|
---|
| 101 |
|
---|
| 102 | public string ItemName {
|
---|
| 103 | get { throw new NotImplementedException(); }
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | public string ItemDescription {
|
---|
| 107 | get { throw new NotImplementedException(); }
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 | public System.Drawing.Image ItemImage {
|
---|
| 111 | get { throw new NotImplementedException(); }
|
---|
| 112 | }
|
---|
| 113 |
|
---|
[3317] | 114 | public bool ReadOnlyView {
|
---|
| 115 | get { throw new NotImplementedException(); }
|
---|
| 116 | set { throw new NotImplementedException(); }
|
---|
| 117 | }
|
---|
| 118 |
|
---|
[3306] | 119 | public event EventHandler ItemImageChanged;
|
---|
[3317] | 120 | public event EventHandler ReadOnlyViewChanged;
|
---|
[2932] | 121 | public event EventHandler ToStringChanged;
|
---|
[2836] | 122 |
|
---|
| 123 | #endregion
|
---|
| 124 |
|
---|
| 125 | #region IDeepCloneable Members
|
---|
| 126 |
|
---|
| 127 | public IDeepCloneable Clone(Cloner cloner) {
|
---|
| 128 | throw new NotImplementedException();
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | #endregion
|
---|
| 132 |
|
---|
| 133 | #region ICloneable Members
|
---|
| 134 |
|
---|
| 135 | public object Clone() {
|
---|
| 136 | throw new NotImplementedException();
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 | #endregion
|
---|
| 140 | }
|
---|
| 141 | }
|
---|