SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
LCGPointSet.java
1/*
2 * Class: LCGPointSet
3 * Description: point set defined via a linear congruential recurrence
4 * Environment: Java
5 * Software: SSJ
6 * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal
7 * Organization: DIRO, Universite de Montreal
8 * @author
9 * @since
10 *
11 *
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 * http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 *
24 */
25package umontreal.ssj.hups;
26
27import cern.colt.list.*;
28
37public class LCGPointSet extends CycleBasedPointSet {
38
39 private int a; // Multiplier.
40
50 public LCGPointSet(int n, int a) {
51 this.a = a;
52 double invn = 1.0 / (double) n; // 1/n
53 DoubleArrayList c; // Array used to store the current cycle.
54 long currentState; // The state currently visited.
55 int i;
56 boolean stateVisited[] = new boolean[n];
57 // Indicates which states have been visited so far.
58 for (i = 0; i < n; i++)
59 stateVisited[i] = false;
60 int startState = 0; // First state of the cycle currently considered.
61 numPoints = 0;
62 while (startState < n) {
63 stateVisited[startState] = true;
64 c = new DoubleArrayList();
65 c.add(startState * invn);
66 // We use the fact that a "long" has 64 bits in Java.
67 currentState = (startState * (long) a) % (long) n;
68 while (currentState != startState) {
69 stateVisited[(int) currentState] = true;
70 c.add(currentState * invn);
71 currentState = (currentState * (long) a) % (long) n;
72 }
73 addCycle(c);
74 for (i = startState + 1; i < n; i++)
75 if (stateVisited[i] == false)
76 break;
77 startState = i;
78 }
79 }
80
85 public LCGPointSet(int b, int e, int c, int a) {
86 this(computeModulus(b, e, c), a);
87 }
88
89 private static int computeModulus(int b, int e, int c) {
90 int n;
91 int i;
92 if (b == 2)
93 n = (1 << e);
94 else {
95 for (i = 1, n = b; i < e; i++)
96 n *= b;
97 }
98 n += c;
99 return n;
100 }
101
102 public String toString() {
103 StringBuffer sb = new StringBuffer("LCGPointSet with multiplier a = ");
104 sb.append(a);
105 return sb.toString();
106 }
107
111 public int geta() {
112 return a;
113 }
114}
This abstract class provides the basic structures for storing and manipulating a point set defined by...
void addCycle(AbstractList c)
Adds the cycle c to the list of all cycles.
String toString()
Formats a string that contains information about the point set.
LCGPointSet(int b, int e, int c, int a)
Constructs and stores the set of cycles for an LCG with modulus and multiplier .
int geta()
Returns the value of the multiplier .
LCGPointSet(int n, int a)
Constructs and stores the set of cycles for an LCG with modulus.
int numPoints
Number of points.