📄 spatialindextest.java
字号:
deletePerformanceLog.info(indexType + "," +
testId + "," +
indexProperties.getProperty("MinNodeEntries") + "," +
indexProperties.getProperty("MaxNodeEntries") + "," +
indexProperties.getProperty("TreeVariant") + "," +
si.size() + "," +
count + "," +
(float) time / (float) count);
}
} else if (operation.equals("DELETEALLRANDOM")) {
long randomSeedBase = Long.parseLong(st.nextToken());
int maxCount = Integer.parseInt(st.nextToken());
int startId = Integer.parseInt(st.nextToken());
float scale = Float.parseFloat(st.nextToken());
if (testType == REFERENCE_COMPARISON_TEST || testType == REFERENCE_GENERATE) {
writeOutput(outputBuffer.toString(), outputFile, referenceFile);
}
for (int count = 1; count <= maxCount; count++) {
long startTime = System.currentTimeMillis();
long randomSeed = randomSeedBase + count;
if (testType == REFERENCE_COMPARISON_TEST || testType == REFERENCE_GENERATE) {
writeOutput("DeleteAll: iteration " + count + ", random seed=" + randomSeed, outputFile, referenceFile);
}
random.setSeed(randomSeed);
for (int id = startId; id < startId + count; id++) {
Rectangle r = getRandomRectangle(random, scale);
si.add(r, id);
if (testType == REFERENCE_COMPARISON_TEST || testType == REFERENCE_GENERATE) {
String outputLine = " " + id + " " + r.toString() + " : OK";
writeOutput(outputLine, outputFile, referenceFile);
}
}
random.setSeed(randomSeed);
int successfulDeleteCount = 0;
for (int id = startId; id < startId + count; id++) {
Rectangle r = getRandomRectangle(random, scale);
boolean deleted = si.delete(r, id);
if (deleted) {
successfulDeleteCount++;
}
if (testType == REFERENCE_COMPARISON_TEST || testType == REFERENCE_GENERATE) {
String outputLine = " " + id + " " + r.toString() + " : " + deleted;
writeOutput(outputLine, outputFile, referenceFile);
}
}
long time = System.currentTimeMillis() - startTime;
if (log.isDebugEnabled()) {
log.debug("Attempted to delete " + count + " entries (" + successfulDeleteCount + " successful) in " + time + "ms (" + time / (float) count + " ms per delete)");
}
}
} else if (operation.equals("NEARESTRANDOM")) {
int queryCount = Integer.parseInt(st.nextToken());
float scale = Float.parseFloat(st.nextToken());
if (testType == REFERENCE_COMPARISON_TEST || testType == REFERENCE_GENERATE) {
writeOutput(outputBuffer.toString(), outputFile, referenceFile);
}
long startTime = System.currentTimeMillis();
int totalEntriesReturned = 0;
for (int id = 0; id < queryCount; id++) {
float x = (float) random.nextGaussian() * scale;
float y = (float) random.nextGaussian() * scale;
List l = ld.nearest(new Point(x, y), Float.POSITIVE_INFINITY);
totalEntriesReturned += l.size();
if (testType == REFERENCE_COMPARISON_TEST || testType == REFERENCE_GENERATE) {
StringBuffer tempBuffer = new StringBuffer(" " + id + " " +
df.format(x) + " " +
df.format(y) + " : OK");
Iterator i = l.iterator();
while (i.hasNext()) {
tempBuffer.append(' ');
tempBuffer.append((Integer)i.next()).toString();
}
writeOutput(tempBuffer.toString(), outputFile, referenceFile);
}
}
long time = System.currentTimeMillis() - startTime;
if (log.isDebugEnabled()) {
log.debug("NearestQueried " + queryCount + " times in " + time + "ms. Per query: " + time / (float) queryCount + " ms, " + (totalEntriesReturned / (float) queryCount) + " entries");
}
if (testType == PERFORMANCE_TEST) {
nearestPerformanceLog.info(indexType + "," +
testId + "," +
indexProperties.getProperty("MinNodeEntries") + "," +
indexProperties.getProperty("MaxNodeEntries") + "," +
indexProperties.getProperty("TreeVariant") + "," +
si.size() + "," +
queryCount + "," +
(float) totalEntriesReturned / (float) queryCount + "," +
(float) time / (float) queryCount);
}
}
else if (operation.equals("INTERSECTRANDOM")) {
int queryCount = Integer.parseInt(st.nextToken());
float scale = Float.parseFloat(st.nextToken());
if (testType == REFERENCE_COMPARISON_TEST || testType == REFERENCE_GENERATE) {
writeOutput(outputBuffer.toString(), outputFile, referenceFile);
}
long startTime = System.currentTimeMillis();
int totalEntriesReturned = 0;
for (int id = 0; id < queryCount; id++) {
Rectangle r = getRandomRectangle(random, scale);
List l = ld.intersects(r);
totalEntriesReturned += l.size();
if (testType == REFERENCE_COMPARISON_TEST || testType == REFERENCE_GENERATE) {
Iterator i = l.iterator();
StringBuffer tempBuffer = new StringBuffer(" " + id + " " + r.toString() + " : OK");
while (i.hasNext()) {
tempBuffer.append(' ');
tempBuffer.append((Integer)i.next()).toString();
}
writeOutput(tempBuffer.toString(), outputFile, referenceFile);
}
}
long time = System.currentTimeMillis() - startTime;
if (log.isDebugEnabled()) {
log.debug("IntersectQueried " + queryCount + " times in " + time + "ms. Per query: " + time / (float) queryCount + " ms, " + (totalEntriesReturned / (float) queryCount) + " entries");
}
if (testType == PERFORMANCE_TEST) {
intersectPerformanceLog.info(indexType + "," +
testId + "," +
indexProperties.getProperty("MinNodeEntries") + "," +
indexProperties.getProperty("MaxNodeEntries") + "," +
indexProperties.getProperty("TreeVariant") + "," +
si.size() + "," +
queryCount + "," +
(float) totalEntriesReturned / (float) queryCount + "," +
(float) time / (float) queryCount);
}
}
else if (operation.equals("CONTAINSRANDOM")) {
int queryCount = Integer.parseInt(st.nextToken());
float scale = Float.parseFloat(st.nextToken());
if (testType == REFERENCE_COMPARISON_TEST || testType == REFERENCE_GENERATE) {
writeOutput(outputBuffer.toString(), outputFile, referenceFile);
}
long startTime = System.currentTimeMillis();
int totalEntriesReturned = 0;
for (int id = 0; id < queryCount; id++) {
Rectangle r = getRandomRectangle(random, scale);
List l = ld.contains(r);
totalEntriesReturned += l.size();
if (testType == REFERENCE_COMPARISON_TEST || testType == REFERENCE_GENERATE) {
Iterator i = l.iterator();
StringBuffer tempBuffer = new StringBuffer(" " + id + " " + r.toString() + " : OK");
while (i.hasNext()) {
tempBuffer.append(' ');
tempBuffer.append((Integer)i.next()).toString();
}
writeOutput(tempBuffer.toString(), outputFile, referenceFile);
}
}
long time = System.currentTimeMillis() - startTime;
if (log.isDebugEnabled()) {
log.debug("ContainsQueried " + queryCount + " times in " + time + "ms. Per query: " + time / (float) queryCount + " ms, " + (totalEntriesReturned / (float) queryCount) + " entries");
}
if (testType == PERFORMANCE_TEST) {
containsPerformanceLog.info(indexType + "," +
testId + "," +
indexProperties.getProperty("MinNodeEntries") + "," +
indexProperties.getProperty("MaxNodeEntries") + "," +
indexProperties.getProperty("TreeVariant") + "," +
si.size() + "," +
queryCount + "," +
(float) totalEntriesReturned / (float) queryCount + "," +
(float) time / (float) queryCount);
}
}
else if (operation.equals("ADD")) {
int id = Integer.parseInt(st.nextToken());
float x1 = Float.parseFloat(st.nextToken());
float y1 = Float.parseFloat(st.nextToken());
float x2 = Float.parseFloat(st.nextToken());
float y2 = Float.parseFloat(st.nextToken());
si.add(new Rectangle(x1, y1, x2, y2), id);
if (testType == REFERENCE_COMPARISON_TEST || testType == REFERENCE_GENERATE) {
outputBuffer.append(" : OK");
writeOutput(outputBuffer.toString(), outputFile, referenceFile);
}
}
else if (operation.equals("DELETE")) {
int id = Integer.parseInt(st.nextToken());
float x1 = Float.parseFloat(st.nextToken());
float y1 = Float.parseFloat(st.nextToken());
float x2 = Float.parseFloat(st.nextToken());
float y2 = Float.parseFloat(st.nextToken());
boolean deleted = si.delete(new Rectangle(x1, y1, x2, y2), id);
if (testType == REFERENCE_COMPARISON_TEST || testType == REFERENCE_GENERATE) {
if (deleted) {
outputBuffer.append(" : OK");
} else {
outputBuffer.append(" : Not found");
}
writeOutput(outputBuffer.toString(), outputFile, referenceFile);
}
}
else if (operation.equals("NEAREST")) {
float x = Float.parseFloat(st.nextToken());
float y = Float.parseFloat(st.nextToken());
List l = ld.nearest(new Point(x, y), Float.POSITIVE_INFINITY);
if (testType == REFERENCE_COMPARISON_TEST || testType == REFERENCE_GENERATE) {
outputBuffer.append(" : OK");
Iterator i = l.iterator();
while (i.hasNext()) {
outputBuffer.append(" ");
outputBuffer.append((Integer)i.next()).toString();
}
writeOutput(outputBuffer.toString(), outputFile, referenceFile);
}
}
else if (operation.equals("INTERSECT")) {
float x1 = Float.parseFloat(st.nextToken());
float y1 = Float.parseFloat(st.nextToken());
float x2 = Float.parseFloat(st.nextToken());
float y2 = Float.parseFloat(st.nextToken());
List l = ld.intersects(new Rectangle(x1, y1, x2, y2));
if (testType == REFERENCE_COMPARISON_TEST || testType == REFERENCE_GENERATE) {
outputBuffer.append(" : OK");
Iterator i = l.iterator();
while (i.hasNext()) {
outputBuffer.append(" ");
outputBuffer.append((Integer)i.next()).toString();
}
writeOutput(outputBuffer.toString(), outputFile, referenceFile);
}
}
} // for each token on the current input line
} // for each input line
} catch (IOException e) {
log.error(e);
return -1;
}
long scriptEndTime = System.currentTimeMillis();
// try and clean up the largest objects to prevent garbage collection
// from slowing down a future run.
ld = null;
si = null;
System.gc();
return scriptEndTime - scriptStartTime;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -