use of de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException in project elki by elki-project.
the class AbstractRStarTree method initializeCapacities.
@Override
protected void initializeCapacities(E exampleLeaf) {
/* Simulate the creation of a leaf page to get the page capacity */
try {
int cap = 0;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
SpatialPointLeafEntry sl = new SpatialPointLeafEntry(DBIDUtil.importInteger(0), new double[exampleLeaf.getDimensionality()]);
while (baos.size() <= getPageSize()) {
sl.writeExternal(oos);
oos.flush();
cap++;
}
// the last one caused the page to overflow.
leafCapacity = cap - 1;
} catch (IOException e) {
throw new AbortException("Error determining page sizes.", e);
}
/* Simulate the creation of a directory page to get the capacity */
try {
int cap = 0;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
ModifiableHyperBoundingBox hb = new ModifiableHyperBoundingBox(new double[exampleLeaf.getDimensionality()], new double[exampleLeaf.getDimensionality()]);
SpatialDirectoryEntry sl = new SpatialDirectoryEntry(0, hb);
while (baos.size() <= getPageSize()) {
sl.writeExternal(oos);
oos.flush();
cap++;
}
dirCapacity = cap - 1;
} catch (IOException e) {
throw new AbortException("Error determining page sizes.", e);
}
if (dirCapacity <= 2) {
throw new IllegalArgumentException("Node size of " + getPageSize() + " bytes is chosen too small!");
}
final Logging log = getLogger();
if (dirCapacity < 10) {
log.warning("Page size is choosen very small! Maximum number of entries in a directory node = " + dirCapacity);
}
// minimum entries per directory node
dirMinimum = (int) Math.floor(dirCapacity * settings.relativeMinFill);
if (dirMinimum < 1) {
dirMinimum = 1;
}
if (leafCapacity <= 2) {
throw new IllegalArgumentException("Node size of " + getPageSize() + " bytes is chosen too small!");
}
if (leafCapacity < 10) {
log.warning("Page size is choosen very small! Maximum number of entries in a leaf node = " + leafCapacity);
}
// minimum entries per leaf node
leafMinimum = (int) Math.floor(leafCapacity * settings.relativeMinFill);
if (leafMinimum < 1) {
leafMinimum = 1;
}
}
use of de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException in project elki by elki-project.
the class TrivialDBIDFactory method generateStaticDBIDRange.
@Override
public DBIDRange generateStaticDBIDRange(int size) {
final int start = next.getAndAdd(size);
if (start > next.get()) {
throw new AbortException("DBID range allocation error - too many objects allocated!");
}
DBIDRange alloc = new IntegerDBIDRange(start, size);
return alloc;
}
use of de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException in project elki by elki-project.
the class GeneratorXMLDatabaseConnection method processElementStatic.
/**
* Process a 'static' cluster Element in the XML stream.
*
* @param gen Generator
* @param cur Current document nod
*/
private void processElementStatic(GeneratorMain gen, Node cur) {
String name = ((Element) cur).getAttribute(ATTR_NAME);
if (name == null) {
throw new AbortException("No cluster name given in specification file.");
}
ArrayList<double[]> points = new ArrayList<>();
// TODO: check for unknown attributes.
XMLNodeIterator iter = new XMLNodeIterator(cur.getFirstChild());
while (iter.hasNext()) {
Node child = iter.next();
if (TAG_POINT.equals(child.getNodeName())) {
processElementPoint(points, child);
} else if (child.getNodeType() == Node.ELEMENT_NODE) {
LOG.warning("Unknown element in XML specification file: " + child.getNodeName());
}
}
// *** add new cluster object
GeneratorStatic cluster = new GeneratorStatic(name, points);
gen.addCluster(cluster);
if (LOG.isVerbose()) {
LOG.verbose("Loaded cluster " + cluster.name + " from specification.");
}
}
use of de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException in project elki by elki-project.
the class GeneratorXMLDatabaseConnection method processElementClipping.
/**
* Process a 'clipping' Element in the XML stream.
*
* @param cluster
* @param cur Current document nod
*/
private void processElementClipping(GeneratorSingleCluster cluster, Node cur) {
double[] cmin = null, cmax = null;
String minstr = ((Element) cur).getAttribute(ATTR_MIN);
if (minstr != null && minstr.length() > 0) {
cmin = parseVector(minstr);
}
String maxstr = ((Element) cur).getAttribute(ATTR_MAX);
if (maxstr != null && maxstr.length() > 0) {
cmax = parseVector(maxstr);
}
if (cmin == null || cmax == null) {
throw new AbortException("No or incomplete clipping vectors given.");
}
// *** set clipping
cluster.setClipping(cmin, cmax);
// TODO: check for unknown attributes.
XMLNodeIterator iter = new XMLNodeIterator(cur.getFirstChild());
while (iter.hasNext()) {
Node child = iter.next();
if (child.getNodeType() == Node.ELEMENT_NODE) {
LOG.warning("Unknown element in XML specification file: " + child.getNodeName());
}
}
}
use of de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException in project elki by elki-project.
the class GeneratorXMLDatabaseConnection method processElementTranslate.
/**
* Process a 'translate' Element in the XML stream.
*
* @param cluster
* @param cur Current document nod
*/
private void processElementTranslate(GeneratorSingleCluster cluster, Node cur) {
double[] offset = null;
String vstr = ((Element) cur).getAttribute(ATTR_VECTOR);
if (vstr != null && vstr.length() > 0) {
offset = parseVector(vstr);
}
if (offset == null) {
throw new AbortException("No translation vector given.");
}
// *** add new translation
cluster.addTranslation(offset);
// TODO: check for unknown attributes.
XMLNodeIterator iter = new XMLNodeIterator(cur.getFirstChild());
while (iter.hasNext()) {
Node child = iter.next();
if (child.getNodeType() == Node.ELEMENT_NODE) {
LOG.warning("Unknown element in XML specification file: " + child.getNodeName());
}
}
}
Aggregations