25package umontreal.ssj.hups;
27import umontreal.ssj.util.PrintfFormat;
28import umontreal.ssj.rng.RandomStream;
56 protected int curPointSets = 0;
57 protected int maxPointSets;
58 protected PointSet pointSet[];
59 protected int startDim[];
60 protected int permutation[][];
71 this.maxPointSets = maxPointSets;
72 pointSet =
new PointSet[maxPointSets];
73 startDim =
new int[maxPointSets];
74 permutation =
new int[maxPointSets][];
84 if (curPointSets == maxPointSets)
85 throw new IllegalArgumentException(
"Cannot pad more, increase maxPointSets parameter");
87 if (dim == Integer.MAX_VALUE)
88 throw new IllegalArgumentException(
"Cannot pad more, dimension already infinite");
91 throw new IllegalArgumentException(
"Padded points must have same number of points");
93 if (curPointSets == 0)
97 dim = Integer.MAX_VALUE;
101 pointSet[curPointSets] = P;
102 startDim[curPointSets] = dim;
115 if (curPointSets == 0)
117 if (numPoints == Integer.MAX_VALUE)
118 throw new IllegalArgumentException(
"Cannot generate infinite permutation");
119 permutation[curPointSets] =
new int[numPoints];
120 for (
int i = 0; i < numPoints; i++)
121 permutation[curPointSets][i] = i;
131 throw new IllegalArgumentException(
"Not enough dimensions");
132 while (j >= startDim[
set])
143 if (permutation[
set] !=
null)
144 i = permutation[
set][i];
146 j = j - startDim[
set - 1];
147 return pointSet[
set].getCoordinate(i, j);
155 for (
int set = 0;
set < curPointSets;
set++) {
156 if (permutation[
set] !=
null) {
157 for (
int i = 0; i < numPoints; i++)
158 permutation[
set][i] = i;
172 for (
int set = 0;
set < curPointSets;
set++)
173 if (permutation[
set] !=
null) {
174 for (
int i = 0; i < numPoints - 1; i++) {
175 int u = stream.
nextInt(0, numPoints - i - 1);
176 int h = permutation[
set][i];
177 permutation[
set][i] = permutation[
set][i + u];
178 permutation[
set][i + u] = h;
187 return new PaddedIterator();
190 public String toString() {
191 StringBuffer sb =
new StringBuffer(
"Padded point set" + PrintfFormat.NEWLINE);
192 sb.append(
"Maximal number of point sets: " + maxPointSets + PrintfFormat.NEWLINE);
193 sb.append(
"Current number of point sets: " + curPointSets + PrintfFormat.NEWLINE);
194 sb.append(
"Number of points: " + numPoints + PrintfFormat.NEWLINE);
195 for (
int i = 0; i < curPointSets; i++) {
197 sb.append(PrintfFormat.NEWLINE);
198 if (permutation[i] ==
null)
199 sb.append(
"Point set ");
201 sb.append(
"Permuted point set ");
202 sb.append(i +
" information: {" + PrintfFormat.NEWLINE + pointSet[i].toString() + PrintfFormat.NEWLINE +
"}");
204 return sb.toString();
209 private class PaddedIterator
extends DefaultPointSetIterator {
211 private PointSetIterator[] pointSetIterators;
212 private int currentSet = 0;
213 private double[] temp;
215 public PaddedIterator() {
216 pointSetIterators =
new PointSetIterator[curPointSets];
218 for (
int i = 0; i < curPointSets; i++) {
219 pointSetIterators[i] = pointSet[i].iterator();
220 if (pointSet[i].getDimension() > maxdim)
221 maxdim = pointSet[i].getDimension();
222 if (permutation[i] !=
null)
223 pointSetIterators[i].setCurPointIndex(permutation[i][0]);
225 if (maxdim == Integer.MAX_VALUE)
226 temp =
new double[16];
228 temp =
new double[maxdim];
231 public void setCurCoordIndex(
int j) {
234 throw new IllegalArgumentException(
"Not enough dimensions");
235 while (j >= startDim[
set])
238 pointSetIterators[currentSet].setCurCoordIndex(
set == 0 ? j : j - startDim[
set - 1]);
239 for (
set = currentSet + 1;
set < pointSetIterators.length;
set++)
240 pointSetIterators[
set].resetCurCoordIndex();
244 public void resetCurCoordIndex() {
246 for (
int i = 0; i < pointSetIterators.length; i++)
247 pointSetIterators[i].resetCurCoordIndex();
251 public double nextCoordinate() {
252 if (curPointIndex >= numPoints || curCoordIndex >= dim)
254 if (curCoordIndex >= startDim[currentSet])
256 double coord = pointSetIterators[currentSet].nextCoordinate();
261 public void nextCoordinates(
double[] p,
int d) {
262 if (curPointIndex >= numPoints || d > dim)
266 int dimen = pointSet[currentSet].getDimension();
267 if (dimen == Integer.MAX_VALUE)
270 dimen -= pointSetIterators[currentSet].getCurCoordIndex();
271 pointSetIterators[currentSet].nextCoordinates(temp, dimen);
272 System.arraycopy(temp, 0, p, i, dimen);
274 curCoordIndex += dimen;
280 public void setCurPointIndex(
int i) {
281 for (
int it = 0; it < pointSetIterators.length; it++)
282 pointSetIterators[it].setCurPointIndex(permutation[it] ==
null ? i : permutation[it][i]);
288 public void resetCurPointIndex() {
289 for (
int i = 0; i < pointSetIterators.length; i++) {
290 if (permutation[i] ==
null)
291 pointSetIterators[i].resetCurPointIndex();
293 pointSetIterators[i].setCurPointIndex(permutation[i][0]);
300 public int resetToNextPoint() {
301 for (
int i = 0; i < pointSetIterators.length; i++) {
302 if (permutation[i] ==
null)
303 pointSetIterators[i].resetToNextPoint();
305 pointSetIterators[i].setCurPointIndex(permutation[i][curPointIndex + 1]);
309 return ++curPointIndex;
312 public String formatState() {
313 return super.formatState() + PrintfFormat.NEWLINE +
"Current padded set: " + currentSet;
This abstract class represents a general point set.
int getNumPoints()
Returns the number of points.
int getDimension()
Returns the dimension (number of available coordinates) of the points.
This is the interface for iterators that permit one to go through the points of a PointSet and the su...
This interface defines the basic structures to handle multiple streams of uniform (pseudo)random numb...
int nextInt(int i, int j)
Returns a (pseudo)random number from the discrete uniform distribution over the integers ,...
PointSetIterator iterator()
Returns a PaddedIterator for this padded point set.
void padPointSetPermute(PointSet P)
Pads the point set P, which is assumed to be finite.
void unrandomize()
Erases all the random permutations of the padded point sets that are randomly permuted.
void padPointSet(PointSet P)
Pads the point set P to the present structure.
PaddedPointSet(int maxPointSets)
This container class realizes padded point sets, constructed by taking some coordinates from a point ...
double getCoordinate(int i, int j)
void randomize(RandomStream stream)
Randomly permutes the points for the padded point sets that have been added via padPointSetPermute.