SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
F2wCycleBasedLFSR.java
1/*
2 * Class: F2wCycleBasedLFSR
3 * Description: point set based upon a linear feedback shift register
4 sequence
5 * Environment: Java
6 * Software: SSJ
7 * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal
8 * Organization: DIRO, Universite de Montreal
9 * @author
10 * @since
11 *
12 *
13 * Licensed under the Apache License, Version 2.0 (the "License");
14 * you may not use this file except in compliance with the License.
15 * You may obtain a copy of the License at
16 *
17 * http://www.apache.org/licenses/LICENSE-2.0
18 *
19 * Unless required by applicable law or agreed to in writing, software
20 * distributed under the License is distributed on an "AS IS" BASIS,
21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 * See the License for the specific language governing permissions and
23 * limitations under the License.
24 *
25 */
26package umontreal.ssj.hups;
27
28import cern.colt.list.*;
29import umontreal.ssj.util.PrintfFormat;
30
58
59 private F2wStructure param;
60
65 public F2wCycleBasedLFSR(int w, int r, int modQ, int step, int nbcoeff, int coeff[], int nocoeff[])
79 {
80 param = new F2wStructure(w, r, modQ, step, nbcoeff, coeff, nocoeff);
81 init();
82 }
83
90 public F2wCycleBasedLFSR(String filename, int no) {
91 param = new F2wStructure(filename, no);
92 init();
93 }
94
95 private void init() {
96 param.initParamLFSR();
97 normFactor = param.normFactor;
98 EpsilonHalf = param.EpsilonHalf;
99 numBits = param.numBits;
100 fillCyclesLFSR();
101 }
102
103 public String toString() {
104 String s = "F2wCycleBasedLFSR:" + PrintfFormat.NEWLINE;
105 return s + param.toString();
106 }
107
108 private void fillCyclesLFSR() {
109 int n = 1 << param.getLog2N();
110 IntArrayList c; // Array used to store the current cycle.
111 int currentState; // The state currently visited.
112 int i;
113 boolean stateVisited[] = new boolean[n];
114
115 // Indicates which states have been visited so far.
116 for (i = 0; i < n; i++)
117 stateVisited[i] = false;
118 int startState = 0; // First state of the cycle currently considered.
119 numPoints = 0;
120 while (startState < n) {
121 stateVisited[startState] = true;
122 c = new IntArrayList();
123 param.state = startState;
124 param.initF2wLFSR();
125 c.add(param.output);
126 param.F2wLFSR();
127 // Warning: watch for overflow !!!
128 while (param.state != startState) {
129 stateVisited[param.state] = true;
130 c.add(param.output);
131 param.F2wLFSR();
132 }
133 addCycle(c);
134 for (i = startState + 1; i < n; i++)
135 if (stateVisited[i] == false)
136 break;
137 startState = i;
138 }
139 }
140}
Similar to CycleBasedPointSet, except that the successive values in the cycles are stored as integers...
void addCycle(AbstractList c)
Adds the cycle c to the list of all cycles.
F2wCycleBasedLFSR(int w, int r, int modQ, int step, int nbcoeff, int coeff[], int nocoeff[])
Constructs a point set with points.
F2wCycleBasedLFSR(String filename, int no)
Constructs a point set after reading its parameters from file filename; the parameters are located at...
String toString()
Formats a string that contains information about the point set.
This class implements methods and fields needed by the classes.
int getLog2N()
This method returns the product .
int numPoints
Number of points.
double EpsilonHalf
To avoid 0 for nextCoordinate when random shifting, we add this to each coordinate.
This class acts like a StringBuffer which defines new types of append methods.
static final String NEWLINE
End-of-line symbol or line separator.