Arnoldo,
it is working now, though only with the RandomPivotSelector. To be
able to check the results I hardcoded five 3-dimensional points:
index.insert(new OBVectorExample (new short[] {10,10,10}));
index.insert(new OBVectorExample (new short[]
{100,100,100}));
index.insert(new OBVectorExample (new short[]
{200,200,200}));
index.insert(new OBVectorExample (new short[]
{300,300,300}));
index.insert(new OBVectorExample (new short[]
{400,400,400}));
And I'm asking for the three points closest to:
OBVectorExample target = new OBVectorExample(new short[] {5,5,5});
within a radius of 1000:
index.searchOB(target, r, result);
The results I get:
<9538 288>
<1 285>
<0 15>
Now, what is the first one? And if I execute this again, I only get
wrong results or errors (OBException:
org.ajmm.obsearch.exception.OutOfRangeException) or
<4183 146>
<4078 117>
<0 15>
It seems to me that I need to clean up some structures? Which ones? I
already tried to clean the index.
for (int p = 0; p < 5; p++) {
index.delete(index.getObject(p));
Thank you,
Helen
public static void main(String[] args) {
try {
short[] mydata = new short[3]; //point object with three
dimensions
RandomPivotSelector ps = new RandomPivotSelector() ;
File dbFolder = new File("/Users/helen/NetBeansProjects/
nntest/dbfile/");
PPTreeShort<OBVectorExample> index = new
PPTreeShort<OBVectorExample>(dbFolder, (short) 30, (byte) 9, ps,
OBVectorExample.class);
Random random = new Random();
/* for(int cx = 0; cx < 10000 ; cx++) {
// **** this is your original code
for (int i = 0; i < 3; i++) {
mydata[i] = (short) random.nextInt();
}
OBVectorExample o = new OBVectorExample(mydata);
// insert the object
index.insert(o);
// **** end of your code
}*/
index.insert(new OBVectorExample (new short[] {10,10,10}));
index.insert(new OBVectorExample (new short[]
{100,100,100}));
index.insert(new OBVectorExample (new short[]
{200,200,200}));
index.insert(new OBVectorExample (new short[]
{300,300,300}));
index.insert(new OBVectorExample (new short[]
{400,400,400}));
index.freeze();
byte k = (byte) 3;
short r = (short) 1000;
OBPriorityQueueShort<OBVectorExample> result =
new OBPriorityQueueShort<OBVectorExample>(k);
if (result == null) {
System.err.println("Result is null");
}
OBVectorExample target = new OBVectorExample(new short[]
{5,5,5});
index.searchOB(target, r, result);
// You can iterate "result".
Iterator < OBResultShort < OBVectorExample> > iter =
result.iterator();
while (iter.hasNext()) {
System.out.println(iter.next());
}
for (int p = 0; p < 5; p++) {
index.delete(index.getObject(p));