| 1 |
root |
1.1 |
/********************************************************************* |
| 2 |
|
|
* * |
| 3 |
|
|
* Copyright (c) 1997,1998, 1999 * |
| 4 |
|
|
* Multimedia DB Group and DEIS - CSITE-CNR, * |
| 5 |
|
|
* University of Bologna, Bologna, ITALY. * |
| 6 |
|
|
* * |
| 7 |
|
|
* All Rights Reserved. * |
| 8 |
|
|
* * |
| 9 |
|
|
* Permission to use, copy, and distribute this software and its * |
| 10 |
|
|
* documentation for NON-COMMERCIAL purposes and without fee is * |
| 11 |
|
|
* hereby granted provided that this copyright notice appears in * |
| 12 |
|
|
* all copies. * |
| 13 |
|
|
* * |
| 14 |
|
|
* THE AUTHORS MAKE NO REPRESENTATIONS OR WARRANTIES ABOUT THE * |
| 15 |
|
|
* SUITABILITY OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING * |
| 16 |
|
|
* BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, * |
| 17 |
|
|
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. THE AUTHOR * |
| 18 |
|
|
* SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A * |
| 19 |
|
|
* RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS * |
| 20 |
|
|
* DERIVATIVES. * |
| 21 |
|
|
* * |
| 22 |
|
|
*********************************************************************/ |
| 23 |
|
|
|
| 24 |
|
|
#include "MT.h" |
| 25 |
|
|
#include "MTpredicate.h" |
| 26 |
|
|
#include "MTentry.h" |
| 27 |
|
|
|
| 28 |
|
|
extern dist2sim hfunction; |
| 29 |
|
|
extern double distr[1001]; |
| 30 |
|
|
|
| 31 |
|
|
double Dist2Sim(double dist) { |
| 32 |
|
|
switch(hfunction) { |
| 33 |
|
|
case LINEAR: return 1-dist/maxDist(); |
| 34 |
|
|
case EXPONENTIAL: return exp(-dist); |
| 35 |
|
|
// case DISTR: return distr[(int)(dist*1001/maxDist())]; |
| 36 |
|
|
default: return 0; |
| 37 |
|
|
} |
| 38 |
|
|
} |
| 39 |
|
|
|
| 40 |
|
|
double Sim2Dist(double sim) { |
| 41 |
|
|
switch(hfunction) { |
| 42 |
|
|
case LINEAR: return maxDist()*(1-sim); |
| 43 |
|
|
case EXPONENTIAL: return -log(sim); |
| 44 |
|
|
/* case DISTR: { |
| 45 |
|
|
for(int i=0; distr[i]>=sim; i++); |
| 46 |
|
|
return i*maxDist()/1001; |
| 47 |
|
|
} */ |
| 48 |
|
|
default: return maxDist(); |
| 49 |
|
|
} |
| 50 |
|
|
} |
| 51 |
|
|
|
| 52 |
|
|
int |
| 53 |
|
|
SimpleQuery::Consistent(const GiSTentry& entry) |
| 54 |
|
|
{ |
| 55 |
|
|
assert(entry.IsA()==MTENTRY_CLASS); |
| 56 |
|
|
// cout << "Evaluating " << entry; |
| 57 |
|
|
if((grade==0)||(fabs(grade-((MTentry &)entry).Key()->distance)<=radius+((MTentry &)entry).maxradius())) { // prune for reference point |
| 58 |
|
|
grade=pred->distance(((MTentry &)entry).object()); |
| 59 |
|
|
return(grade<=radius+((MTentry &)entry).maxradius()); |
| 60 |
|
|
} |
| 61 |
|
|
else return FALSE; |
| 62 |
|
|
} |
| 63 |
|
|
|
| 64 |
|
|
int |
| 65 |
|
|
SimpleQuery::NonConsistent(const GiSTentry& entry) |
| 66 |
|
|
{ |
| 67 |
|
|
assert(entry.IsA()==MTENTRY_CLASS); |
| 68 |
|
|
// cout << "Evaluating " << entry; |
| 69 |
|
|
if((grade==0)||(fabs(grade-((MTentry &)entry).Key()->distance)>radius-((MTentry &)entry).maxradius())) { // prune for reference point |
| 70 |
|
|
grade=pred->distance(((MTentry &)entry).object()); |
| 71 |
|
|
return(grade>radius-((MTentry &)entry).maxradius()); |
| 72 |
|
|
} |
| 73 |
|
|
else return FALSE; |
| 74 |
|
|
} |