SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
SortedAndCutPointSet.java
1/*
2 * Class: SortedAndCutPointSet
3 * Description:
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 Adam L'Archevêque Gaudet and Pierre L'Ecuyer
9 * @since
10
11 * SSJ is free software: you can redistribute it and/or modify it under
12 * the terms of the GNU General Public License (GPL) as published by the
13 * Free Software Foundation, either version 3 of the License, or
14 * any later version.
15
16 * SSJ is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20
21 * A copy of the GNU General Public License is available at
22 <a href="http://www.gnu.org/licenses">GPL licence site</a>.
23 */
24package umontreal.ssj.hups;
25
26import umontreal.ssj.rng.RandomStream;
27import umontreal.ssj.util.PrintfFormat;
28// import java.util.Comparator;
29// import java.util.Arrays;
30import umontreal.ssj.util.multidimsort.MultiDimSort;
31
70public class SortedAndCutPointSet extends CachedPointSet {
71 protected int[] index; // Index that represents the permutation of the sort.
72 protected MultiDimSort sort; // Seems to be needed only by the constructor.
73 protected int numSortCoord; // Number of coordinates used for the sort.
74
92 super(p, 0, p.getNumPoints(), 0, sort.dimension() + 1);
94 numSortCoord = sort.dimension();
95 this.sort = sort;
96 this.P = p;
97 makeIndex();
98 dim = p.getDimension() - numSortCoord;
99 x = new double[numPoints][dim];
100 fillCacheByIndex(numSortCoord, dim);
101 }
102
110 protected int[] makeIndex() {
111 for (int i = 0; i < numPoints; ++i)
112 x[i][numSortCoord] = i; // Adds extra coordinate that saves the point number.
113 sort.sort(x, 0, numPoints);
114 index = new int[numPoints];
115 for (int i = 0; i < numPoints; ++i)
116 index[(int) x[i][numSortCoord]] = i;
117 return index;
118 }
119
125 protected void fillCacheByIndex(int fromDim, int dim) {
126 PointSetIterator itr = P.iterator();
127 for (int i = 0; i < numPoints; ++i) {
128 itr.nextPoint(x[index[i]], fromDim, dim);
129 }
130 }
131
136 public int getDimension() {
137 return dim;
138 }
139
144 return sort;
145 }
146
152 return new SortedAndCutPointSetIterator();
153 }
154
158 public void addRandomShift(int d1, int d2, RandomStream stream) {
159 P.addRandomShift(d1 + numSortCoord, d2 + numSortCoord, stream);
160 fillCacheByIndex(d1 + numSortCoord, d2 + numSortCoord);
161 }
162
169 P.randomize(rand);
170 // Actually we could randomize only from coordinate numSortCoord. ****
171 fillCacheByIndex(numSortCoord, dim);
172 }
173
179 public String toString() {
180 StringBuffer sb = new StringBuffer("SortAndCutPointSet " + PrintfFormat.NEWLINE);
181 sb.append(PrintfFormat.NEWLINE + "Cached point set information {" + PrintfFormat.NEWLINE);
182 sb.append(P.toString());
183 sb.append(PrintfFormat.NEWLINE + "}");
184 return sb.toString();
185 }
186
187// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
188// This class implements a SortedAndCutPointSet iterator.
189// which takes the value in x rather than calling the function
190// getCoordinate inherited from CachedPointSet.
191
193
194 public double nextCoordinate() {
196 outOfBounds();
197 return x[curPointIndex][curCoordIndex++];
198 }
199 }
200
201// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
202// This class implements a SortedAndCutPointSet iterator that takes the points
203// directly in P instead of using the cache.
204 /*
205 * protected class SortedAndCutPointSetIteratorNoCache extends
206 * DefaultPointSetIterator {
207 *
208 * public double nextCoordinate() { if (getCurPointIndex() >= numPoints ||
209 * getCurCoordIndex() >= dim) outOfBounds(); // Not implemented!! To be done...
210 * } }
211 */
212}
This class implements a default point set iterator.
int curPointIndex
Index of the current point.
int curCoordIndex
Index of the current coordinate.
void outOfBounds()
Error message for index out of bounds.
This abstract class represents a general point set.
Definition PointSet.java:99
int numPoints
Number of points.
int getNumPoints()
Returns the number of points.
int getDimension()
Returns the dimension (number of available coordinates) of the points.
int dim
Dimension of the points.
void fillCacheByIndex(int fromDim, int dim)
Called by the constructors and also by \texttt{randomize}.
int[] makeIndex()
Sorts the cached points in x[][] according to the first cached coordinates (the dimension of the sort...
String toString()
Formats a string that contains the information about this point set.
SortedAndCutPointSet(PointSet p, MultiDimSort sort)
Takes the first dim coordinates of the first n points of p and creates a SortedAndCutPointSet from th...
PointSetIterator iterator()
Constructs and returns a point set iterator which gets the values directly from the array.
MultiDimSort getSort()
Returns the sort used.
void randomize(PointSetRandomization rand)
Randomizes the contained point (all coordinates) set using rand.
void addRandomShift(int d1, int d2, RandomStream stream)
Add the shift to the contained point set.
int getDimension()
Returns the number of coordinates of each point, which is the dimension of the original point set min...
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 is the interface for iterators that permit one to go through the points of a PointSet and the su...
int nextPoint(double[] p, int fromDim, int d)
Returns in p the next d coordinates of the current point, starting at coordinate fromDim (i....
This interface is for a randomization that can be used to randomize a umontreal.ssj....
This interface defines the basic structures to handle multiple streams of uniform (pseudo)random numb...
This interface is meant to be implemented by certain multivariate sorting algorithms that sort object...