package umontreal.iro.lecuyer.hups;
/* *
* Title:
* Description:
* Copyright: Copyright (c)
* Company:
* @author
* @version 1.0
*/
import umontreal.iro.lecuyer.util.PrintfFormat;
/**
* This container class caches a point set by precomputing
* and storing its points locally in an array.
* This can be used to speed up computations when using
* a small low-dimensional point set more than once.
*
*/
public class CachedPointSet extends PointSet {
protected PointSet P; // Original PointSet which is cached here.
protected double x[][]; // Cached points.
/**
* Creates a new PointSet object that contains an array storing
* the first dim coordinates of the first n points of P.
* The original point set P itself is not modified.
*
* @param P point set to be cached
*
* @param n number of points
*
* @param dim number of dimensions of the points
*
*
*/
public CachedPointSet (PointSet P, int n, int dim) {
if (P.getNumPoints() < n)
throw new IllegalArgumentException(
"Cannot cache more points than in point set P.");
if (P.getDimension() < dim)
throw new IllegalArgumentException(
"Cannot cache points with more coordinates than the dimension.");
numPoints = n;
this.dim = dim;
this.P = P;
init ();
}
protected void init () {
PointSetIterator itr = P.iterator();
x = new double[numPoints][dim];
for (int i = 0; i < numPoints; i++)
itr.nextPoint (x[i], dim);
}
/**
* Creates a new PointSet object that contains an array storing
* the points of P.
* The number of points and their dimension are the same as in the
* original point set. Both must be finite.
*
* @param P point set to be cached
*
*
*/
public CachedPointSet (PointSet P) {
numPoints = P.getNumPoints();
dim = P.getDimension();
if (numPoints == Integer.MAX_VALUE)
throw new IllegalArgumentException(
"Cannot cache infinite number of points");
if (dim == Integer.MAX_VALUE)
throw new IllegalArgumentException(
"Cannot cache infinite dimensional points");
this.P = P;
init ();
}
/**
* Randomizes the underlying point set using rand and
* recaches the points.
*
*/
public void randomize (PointSetRandomization rand) {
P.randomize(rand);
init();
}
public String toString() {
StringBuffer sb = new StringBuffer ("Cached point set" +
PrintfFormat.NEWLINE);
sb.append (super.toString());
sb.append (PrintfFormat.NEWLINE + "Cached point set information {"
+ PrintfFormat.NEWLINE);
sb.append (P.toString());
sb.append (PrintfFormat.NEWLINE + "}");
return sb.toString();
}
public double getCoordinate (int i, int j) {
return x[i][j];
}
}
Ads help maintain this website.