SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
F2wCycleBasedPolyLCG.java
1/*
2 * Class: F2wCycleBasedPolyLCG
3 * Description: point set based upon a linear congruential sequence in a
4 finite field
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 umontreal.ssj.util.PrintfFormat;
29import umontreal.ssj.rng.*;
30import cern.colt.list.*;
31
62
63 private F2wStructure param;
64
69 public F2wCycleBasedPolyLCG(int w, int r, int modQ, int step, int nbcoeff, int coeff[], int nocoeff[])
83 {
84 param = new F2wStructure(w, r, modQ, step, nbcoeff, coeff, nocoeff);
85 numBits = param.numBits;
86 normFactor = param.normFactor;
87 EpsilonHalf = param.EpsilonHalf;
88 fillCyclesPolyLCG();
89 }
90
97 public F2wCycleBasedPolyLCG(String filename, int no) {
98 param = new F2wStructure(filename, no);
99 numBits = param.numBits;
100 normFactor = param.normFactor;
101 fillCyclesPolyLCG();
102 }
103
104 public String toString() {
105 String s = "F2wCycleBasedPolyLCG:" + PrintfFormat.NEWLINE;
106 return s + param.toString();
107 }
108
109 private void fillCyclesPolyLCG() {
110 int n = 1 << param.getLog2N();
111 int i;
112 int mask1 = (1 << (31 - param.r * param.w)) - 1;
113 int mask2 = ~mask1;
114 RandomStream random = new MRG32k3a();
115 IntArrayList c; // Array used to store the current cycle.
116 int currentState; // The state currently visited.
117
118 boolean stateVisited[] = new boolean[n];
119 // Indicates which states have been visited so far.
120 for (i = 0; i < n; i++)
121 stateVisited[i] = false;
122 int startState = 0; // First state of the cycle currently considered.
123 numPoints = 0;
124 while (startState < n) {
125 stateVisited[startState] = true;
126 c = new IntArrayList();
127 param.state = startState << param.S;
128 c.add(param.state);
129 // c.add ((state & mask2) | (mask1 &
130 // (random.nextInt(0,2147483647))));
131 param.output = param.F2wPolyLCG();
132 // Warning: watch for overflow !!!
133 while (param.state != (startState << param.S)) {
134 stateVisited[param.state >> param.S] = true;
135 // c.add ((param.state&mask2) | (mask1 &
136 // (random.nextInt(0,2147483647))));
137 c.add(param.state);
138 param.output = param.F2wPolyLCG();
139 }
140 addCycle(c);
141 for (i = startState + 1; i < n; i++)
142 if (stateVisited[i] == false)
143 break;
144 startState = i;
145 }
146 }
147}
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.
F2wCycleBasedPolyLCG(int w, int r, int modQ, int step, int nbcoeff, int coeff[], int nocoeff[])
Constructs a point set with points.
String toString()
Formats a string that contains information about the point set.
F2wCycleBasedPolyLCG(String filename, int no)
Constructs a point set after reading its parameters from file filename; the parameters are located at...
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.
Extends the abstract class RandomStreamBase by using as a backbone (or main) generator the combined m...
Definition MRG32k3a.java:46
This class acts like a StringBuffer which defines new types of append methods.
static final String NEWLINE
End-of-line symbol or line separator.
This interface defines the basic structures to handle multiple streams of uniform (pseudo)random numb...