Skip to content

Commit

Permalink
N-tree is now created and queried with stretched arguments (duration …
Browse files Browse the repository at this point in the history
…1 hour)
  • Loading branch information
fabioValdes9 committed Feb 9, 2024
1 parent 3b4d0b4 commit 375dc5e
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 105 deletions.
187 changes: 102 additions & 85 deletions Algebras/MainMemory2/MainMemory2Algebra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4136,6 +4136,99 @@ Operator matchbelowSOp(
matchbelowSTM<true>
);

/*
Auxiliary functions applied for M-tree2 and N-tree creation and querying.

*/
void StretchOrCompress(const Point& src, Point& res) {
res = src;
}

void StretchOrCompress(const CcString& src, CcString& res) {
res = src;
}

void StretchOrCompress(const CcInt& src, CcInt& res) {
res = src;
}

void StretchOrCompress(const CcReal& src, CcReal& res) {
res = src;
}

void StretchOrCompress(const Rectangle<1>& src, Rectangle<1>& res) {
res = src;
}

void StretchOrCompress(const Rectangle<2>& src, Rectangle<2>& res) {
res = src;
}

void StretchOrCompress(const Rectangle<3>& src, Rectangle<3>& res) {
res = src;
}

void StretchOrCompress(const Rectangle<4>& src, Rectangle<4>& res) {
res = src;
}

void StretchOrCompress(const Rectangle<8>& src, Rectangle<8>& res) {
res = src;
}

void StretchOrCompress(const hist_hsv<64, false>& src,
hist_hsv<64, false>& res) {
res.CopyFrom(&src);
}

void StretchOrCompress(const hist_hsv<128, false>& src,
hist_hsv<128, false>& res) {
res.CopyFrom(&src);
}

void StretchOrCompress(const hist_hsv<256, false>& src,
hist_hsv<256, false>& res) {
res.CopyFrom(&src);
}

void StretchOrCompress(const hist_hsv<256, true>& src,
hist_hsv<256, true>& res) {
res.CopyFrom(&src);
}

void StretchOrCompress(const temporalalgebra::MPoint& src,
temporalalgebra::MPoint& res) {
datetime::DateTime duration(0, 3600000, datetime::durationtype);
StretchOrCompressToDuration<MPoint, UPoint>(src, duration, true, true, res);
}

void StretchOrCompress(const temporalalgebra::CUPoint& src,
temporalalgebra::CUPoint& res) {
datetime::DateTime duration(0, 3600000, datetime::durationtype);
StretchOrCompressUnitToDuration<CUPoint>(src, duration, true, res);
}

void StretchOrCompress(const temporalalgebra::CMPoint& src,
temporalalgebra::CMPoint& res) {
datetime::DateTime duration(0, 3600000, datetime::durationtype);
StretchOrCompressToDuration<CMPoint, CUPoint>(src, duration, true, true, res);
}

void StretchOrCompress(const stj::MLabel& src, stj::MLabel& res) {
res = src;
}

void StretchOrCompress(const stj::MLabels& src, stj::MLabels& res) {
res = src;
}

void StretchOrCompress(const stj::MPlace& src, stj::MPlace& res) {
res = src;
}

void StretchOrCompress(const stj::MPlaces& src, stj::MPlaces& res) {
res = src;
}

/*
6 M-tree support
Expand Down Expand Up @@ -4694,11 +4787,13 @@ int mcreatemtree2StreamVM(Word* args, Word& result, int message, Word& local,
sym = (Sym*)(tuple->GetAttribute(indexSym));
TupleIdentifier* tid = (TupleIdentifier*)(tuple->GetAttribute(indexTID));
if (tid->IsDefined()) {
Spa copySpa = *spa;
Sym copySym = *sym;
flobused = flobused || copySpa.NumOfFLOBs() > 0 ||
copySym.NumOfFLOBs() > 0;
pair<Spa, Sym> spasym(copySpa, copySym);
Spa spaStretched(true);
StretchOrCompress(*spa, spaStretched);
Sym symStretched(true);
StretchOrCompress(*sym, symStretched);
flobused = flobused || spaStretched.NumOfFLOBs() > 0 ||
symStretched.NumOfFLOBs() > 0;
pair<Spa, Sym> spasym(spaStretched, symStretched);
MTreeEntry<pair<Spa, Sym> > entry(spasym, tid->GetTid());
// pair<pair<Spa, Sym>, TupleId> p(spasym, tid->GetTid());
tree->insert(entry);
Expand Down Expand Up @@ -5985,84 +6080,6 @@ ListExpr mclosestCenterNTM(ListExpr args) {
// nl->Second(a2));
}

/*
Auxiliary functions applied for N-tree creation and querying.

*/
void StretchOrCompress(const Point& src, Point& res) {
res = src;
}

void StretchOrCompress(const CcString& src, CcString& res) {
res = src;
}

void StretchOrCompress(const CcInt& src, CcInt& res) {
res = src;
}

void StretchOrCompress(const CcReal& src, CcReal& res) {
res = src;
}

void StretchOrCompress(const Rectangle<1>& src, Rectangle<1>& res) {
res = src;
}

void StretchOrCompress(const Rectangle<2>& src, Rectangle<2>& res) {
res = src;
}

void StretchOrCompress(const Rectangle<3>& src, Rectangle<3>& res) {
res = src;
}

void StretchOrCompress(const Rectangle<4>& src, Rectangle<4>& res) {
res = src;
}

void StretchOrCompress(const Rectangle<8>& src, Rectangle<8>& res) {
res = src;
}

void StretchOrCompress(const hist_hsv<64, false>& src,
hist_hsv<64, false>& res) {
res.CopyFrom(&src);
}

void StretchOrCompress(const hist_hsv<128, false>& src,
hist_hsv<128, false>& res) {
res.CopyFrom(&src);
}

void StretchOrCompress(const hist_hsv<256, false>& src,
hist_hsv<256, false>& res) {
res.CopyFrom(&src);
}

void StretchOrCompress(const hist_hsv<256, true>& src,
hist_hsv<256, true>& res) {
res.CopyFrom(&src);
}

void StretchOrCompress(const temporalalgebra::MPoint& src,
temporalalgebra::MPoint& res) {
datetime::DateTime duration(0, 3600000, datetime::durationtype);
StretchOrCompressToDuration<MPoint, UPoint>(src, duration, true, true, res);
}

void StretchOrCompress(const temporalalgebra::CUPoint& src,
temporalalgebra::CUPoint& res) {
datetime::DateTime duration(0, 3600000, datetime::durationtype);
StretchOrCompressUnitToDuration<CUPoint>(src, duration, true, res);
}

void StretchOrCompress(const temporalalgebra::CMPoint& src,
temporalalgebra::CMPoint& res) {
datetime::DateTime duration(0, 3600000, datetime::durationtype);
StretchOrCompressToDuration<CMPoint, CUPoint>(src, duration, true, true, res);
}

template<class T, class Dist, int variant>
class closestCenterNInfo {
public:
Expand Down Expand Up @@ -6399,7 +6416,7 @@ class distRangeNInfo {
rel = mrel->getmmrel();
T* stretched = new T(true);
StretchOrCompress(*ref, *stretched);
MTreeEntry<T> p(*ref, 0);
MTreeEntry<T> p(*stretched, 0);
stretched->DeleteIfAllowed();
it = ntreeX->getNtreeX()->rangeSearch(p, range);
}
Expand Down Expand Up @@ -6814,7 +6831,7 @@ class mnearestNeighborNInfo {
k = min((int)_k, (int)(rel->size()));
T* stretched = new T(true);
StretchOrCompress(*q, *stretched);
MTreeEntry<T> p(*q, 0);
MTreeEntry<T> p(*stretched, 0);
stretched->DeleteIfAllowed();
it = ntreeX->getNtreeX()->nnSearch(p, k);
sc = SecondoSystem::GetCatalog();
Expand Down
6 changes: 3 additions & 3 deletions Algebras/Temporal/Temporal.examples
Original file line number Diff line number Diff line change
Expand Up @@ -801,19 +801,19 @@ Operator : distanceAvg
Number : 1
Signature : mpoint x mpoint (x duration) (x geoid) -> real
Example : query distanceAvg(train5, train6)
Result : 17030.615965
Result : 12368.294642

Operator : distanceAvgLB
Number : 1
Signature : cXpoint x cXpoint (x duration) (x geoid) -> real (X = m|u)
Example : query distanceAvgLB(cbbox(train5), cbbox(train6))
Result : 13561.344094
Result : 6433.35614

Operator : distanceAvgUB
Number : 1
Signature : cXpoint x cXpoint (x duration) (x geoid) -> real (X = m|u)
Example : query distanceAvgUB(cbbox(train5), cbbox(train6))
Result : 23050.401494
Result : 21866.491402

Operator : cbbox
Number : 1
Expand Down
43 changes: 34 additions & 9 deletions Algebras/Temporal/TemporalAlgebra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3346,6 +3346,8 @@ double CUPoint::DistanceAvg(const CUPoint& cup, const DateTime& duration,
CMPoint cm1(true), cm2(true);
cm1.Add(*this);
cm2.Add(cup);
cout << *this << endl << cup;
cout << endl << endl << cm1 << endl << cm2 << endl;
return DistanceComputation<CMPoint, CUPoint>::DistanceAvg(cm1, cm2, duration,
upperBound, geoid);
}
Expand Down Expand Up @@ -12978,7 +12980,7 @@ ListExpr StretchTypeMap(ListExpr args) {
return nl->TypeError();
}
if (MPoint::checkType(nl->First(args)) ||
CMPoint::checkType(nl->Second(args))) {
CMPoint::checkType(nl->First(args))) {
if (Duration::checkType(nl->Second(args))) {
return nl->First(args);
}
Expand Down Expand Up @@ -14638,8 +14640,16 @@ int DistanceAvgMap(Word* args, Word& result, int message, Word& local,
else if (qp->GetNoSons(s) == 3) {
geoid = (Geoid*)args[2].addr;
}
DistanceComputation<MPoint, UPoint>::DistanceAvg(*((MPoint*)args[0].addr),
*((MPoint*)args[1].addr), *duration, true, *((CcReal*)result.addr), geoid);
MPoint *stretched1 = new MPoint(true);
StretchOrCompressToDuration<MPoint, UPoint>(*((MPoint*)args[0].addr),
*duration, true, true, *stretched1);
MPoint *stretched2 = new MPoint(true);
StretchOrCompressToDuration<MPoint, UPoint>(*((MPoint*)args[1].addr),
*duration, true, true, *stretched2);
DistanceComputation<MPoint, UPoint>::DistanceAvg(*stretched1, *stretched2,
*duration, true, *((CcReal*)result.addr), geoid);
stretched1->DeleteIfAllowed();
stretched2->DeleteIfAllowed();
return 0;
}

Expand All @@ -14660,9 +14670,16 @@ int DistanceAvgCMMap(Word* args, Word& result, int message, Word& local,
else if (qp->GetNoSons(s) == 3) {
geoid = (Geoid*)args[2].addr;
}
DistanceComputation<CMPoint, CUPoint>::DistanceAvg(*((CMPoint*)args[0].addr),
*((CMPoint*)args[1].addr), *duration,
upperBound, *((CcReal*)result.addr), geoid);
CMPoint *stretched1 = new CMPoint(true);
StretchOrCompressToDuration<CMPoint, CUPoint>(*((CMPoint*)args[0].addr),
*duration, true, true, *stretched1);
CMPoint *stretched2 = new CMPoint(true);
StretchOrCompressToDuration<CMPoint, CUPoint>(*((CMPoint*)args[1].addr),
*duration, true, true, *stretched2);
DistanceComputation<CMPoint, CUPoint>::DistanceAvg(*stretched1, *stretched2,
*duration, upperBound, *((CcReal*)result.addr), geoid);
stretched1->DeleteIfAllowed();
stretched2->DeleteIfAllowed();
return 0;
}

Expand All @@ -14682,9 +14699,17 @@ int DistanceAvgCUMap(Word* args, Word& result, int message, Word& local,
}
else if (qp->GetNoSons(s) == 3) {
geoid = (Geoid*)args[2].addr;
}
((CUPoint*)args[0].addr)->DistanceAvg(*((CUPoint*)args[1].addr), *duration,
upperBound, *((CcReal*)result.addr), geoid);
}
CUPoint *stretched1 = new CUPoint(true);
StretchOrCompressUnitToDuration<CUPoint>(*((CUPoint*)args[0].addr), *duration,
true, *stretched1);
CUPoint *stretched2 = new CUPoint(true);
StretchOrCompressUnitToDuration<CUPoint>(*((CUPoint*)args[1].addr), *duration,
true, *stretched2);
stretched1->DistanceAvg(*stretched2, *duration, upperBound,
*((CcReal*)result.addr), geoid);
stretched1->DeleteIfAllowed();
stretched2->DeleteIfAllowed();
return 0;
}

Expand Down
Loading

0 comments on commit 375dc5e

Please sign in to comment.