Sei sulla pagina 1di 13

# SEARCHING EFFICIENCY IN TWO-DIMENSIONAL GEOMETRIC

## SEARCHING EFFICIENCY IN TWO-DIMENSIONAL GEOMETRIC

COLLEGE OF SYSTEMS ENGINEERING

2013 - AREQUIPA

## SEARCHING EFFICIENCY IN TWO-DIMENSIONAL GEOMETRIC

INDEX
SLEEVE NOTES ............................................................................................................ 1 INTRODUCTION ........................................................................................................... 2 INDEXOFCONTENTS .................................................................................................. 3

1. Development ............................................................................................. 4
1.1. Why use data structuresR* tree and B+ tree? ......................................................... 4 1.2. Code ....................................................................................................................... 5 1.2.1. Main .............................................................................................................. 5 1.2.2. Node Arbol R_Asterist.h ............................................................................... 6 1.2.3. R-Asterist.cpp .............................................................................................. 8 1.2.4. R-Asterist.h ................................................................................................. 9 Conclusions .....................................................................Error! Marcador no definido.12 References ...................................................................................................................... 13

## SEARCHING EFFICIENCY IN TWO-DIMENSIONAL GEOMETRIC

INTRODUCTION

In this project " EFFICIENCY IN THE TWO-DIMENSIONAL GEOMETRIC SEARCH " here development a new way of space access; using afusion of two data structures; Tree B+ and Tree R* ; in the case of Tree B+ the global access is faster and the height half of tree is smallest and the case of TreeR*, is a data structure that use space methods ,in other words, to indexing multidimensional information. The project was worked with sub images of a main image, and we'll look for procedures that let us to know if an image point is inside or outside a selected image, to carry out a searching effective in a map or an image according with x and y axes .

## SEARCHING EFFICIENCY IN TWO-DIMENSIONAL GEOMETRIC

2. DEVELOPMENT
Our project has been developed in Visual Studio 2012, and the image handle has been worked with the library: SDL. We have worked with sub images of a main image, and searching procedure that let us to know if an image point is inside or outside a chosen image, and can identify: TOTAL INTERSECTION ANDPARTIAL.

1.1.

## Why use data structures R * Tree and B+ Tree?

We use the B+ tree,because it is a kind of tree data structure, which represents a collection of tidydata, which let us an efficient insertion and deletion of elements. Another benefit that gives us the B+ tree is that global access is faster and the height half of the tree is smaller. Also its leaves can be linked, achieving of this way, a trajectory sequential to cover the keys in the tree. Another reason why we used the tree B + is when we want delete a key is relatively simple, because when we want to delete a key that is relatively simple ; because the keys eliminate is found in the pages sheets and the ability to leave the values without key in the part of indexes as separators simplifies the process . Also to carry out our project is used the tree R*, because it is a structure of data of type tree ,that used structure to methods of spatial access , in other words , for indexing multidimensional data , for example , the axis ( x , y) a geographical location . The R* tree divides the space of way hierarchically in collection, possibly overlapping. Next the development of our project EFFICIENCY IN THE TWO-

## SEARCHING EFFICIENCY IN TWO-DIMENSIONAL GEOMETRIC

1.2.

Code

1.2.1. Main
#include "SDL.h" #include <string> #include <iostream> #include "SDL_image.h" #include <SDL_image.h> #include "Clase_Imagen.h" #include "NodeArbolR_Asterist.h" #include "R_Asterist.h" #define FONDO_IMAG "Mundo2.bmp" #define ORDEN 5 using namespace std; SDL_Surface *pantalla; void esperar(void); SDL_Surface* recortarImag(SDL_Surface *tobecropped, SDL_Rect *r); int main(int args, char* argv[]){ pantalla = new SDL_Surface(); SDL_Init(SDL_INIT_EVERYTHING); Clase_Imagen<int> *obj = new Clase_Imagen<int>(); obj->cargarImagen(FONDO_IMAG); obj->mostrarImag(pantalla,obj->getImagen()); R_Asterist< Clase_Imagen<int>> *raiz = new R_Asterist< Clase_Imagen<int>>(ORDEN); int i = -1; for(; i != 0 ;){ cout<<"DESEA INSERTAR UNA NUEVA IMAGEN?"; cin>>i; swicth(i) case 0: SDL_QUIT(); case 1: Clase_Imagen<int> *obj2 = new Clase_Imagen<int>(); obj2->crearRectangulo(); SDL_Surface* newImag = obj->recortarImag(obj->getImagen(),&obj2->rect); obj2->setImagen(newImag); raiz->insertElement(*obj2); default : break; } while(true){ raiz->mostrar(); } esperar(); return 0; } void esperar (void) { SDL_Event evento; while ( SDL_WaitEvent (& evento)) { if (evento.type == SDL_QUIT || evento.key.keysym.sym == SDLK_ESCAPE) return; } }

## SEARCHING EFFICIENCY IN TWO-DIMENSIONAL GEOMETRIC

1.2.2. NodeArbolR_Asterist.h
#pragma once template<class X> class NodeArbolR_Asterist { private: int orden; int cantElements; bool isFull; bool esHoja; X* elements; NodeArbolR_Asterist<X> *hijos; int ubicarPosicionInsercion(X); public: NodeArbolR_Asterist(void); NodeArbolR_Asterist(int); bool buscarEnNodo(X); bool insertElement(X); void mostrar(void); int getPosicionDeHijo(X); NodeArbolR_Asterist<X>* getHijos(void); X* getElements(void); int getCantElements(void); void setCantElements(int); bool getIsFull(void); bool vaciarNodo(void); ~NodeArbolR_Asterist(void); };

template<class X> NodeArbolR_Asterist<X>::NodeArbolR_Asterist(void){ isFull = false; esHoja = true; orden = 0; cantElements = 0; elements = NULL; hijos = NULL; } template<class X> NodeArbolR_Asterist<X>::NodeArbolR_Asterist(int orden){ isFull = false; esHoja = true; this->orden = orden; cantElements = 0; elements = new X[this->orden -1]; hijos = new NodeArbolR_Asterist<X>[this->orden]; } template<class X> NodeArbolR_Asterist<X>* NodeArbolR_Asterist<X>::getHijos(void){ return hijos; } template<class X> X* NodeArbolR_Asterist<X>::getElements(void){ return elements; } template<class X> void NodeArbolR_Asterist<X>::setCantElements(int cant){ cantElements = cant;

## SEARCHING EFFICIENCY IN TWO-DIMENSIONAL GEOMETRIC

} template<class X> int NodeArbolR_Asterist<X>::getCantElements(void){ return cantElements; } template<class X> bool NodeArbolR_Asterist<X>::getIsFull(void){ return isFull; } template<class X> bool NodeArbolR_Asterist<X>::vaciarNodo(void){ isFull = false; int tempcant = cantElements; NodoBmas<X> *temp = NULL; for(int i = 0; i < cantElements; i++){ elements[i] = NULL; tempcant--; } cantElements = tempcant; //cout<<"\nElementos: " << cantElements<<"\n"; return true; } template<class X> int NodeArbolR_Asterist<X>::ubicarPosicionInsercion(X elem){ //Busqueda Linear "MEJORAR BUSQUEDA DE UBICACION" for(int i = 0; i < cantElements ;i++){ if(this->elements[i] >= elem) return i; } return cantElements; } template<class X> int NodeArbolR_Asterist<X>::getPosicionDeHijo(X elem){ int tempPos = ubicarPosicionInsercion(elem); return tempPos; } template<class X> bool NodeArbolR_Asterist<X>::insertElement(X elem){ X tempElem; X temp2 = elem; NodeArbolR_Asterist<X> *temphijo1 = NULL; NodeArbolR_Asterist<X> *temphijo2 = NULL; int tempCant = cantElements; bool retornar = false; if(!isFull){ if(cantElements == 0){ elements[0] = elem; retornar = true; }else{

## SEARCHING EFFICIENCY IN TWO-DIMENSIONAL GEOMETRIC

if(temp2 < this->getElements()[i]){ tempElem = elements[i]; //temphijo1 = &getHijos()[i]; elements[i] = temp2; //if(temphijo2) // getHijos()[i] = *temphijo2; temp2 = tempElem; //temphijo2 = temphijo1; } } elements[cantElements] = temp2; retornar = true; } if(retornar){ cantElements++; if(cantElements == orden-1) isFull = true; } } return retornar; } template<class X> bool NodeArbolR_Asterist<X>::buscarEnNodo(X elem){ for(int i = 0; i < cantElements ; i++){ if(this->elements[i] == elem) return true; else if(this->elements[i] > elem) return false; } return false; } template<class X> void NodeArbolR_Asterist<X>:: mostrar(void){} template<class X> NodeArbolR_Asterist<X>::~NodeArbolR_Asterist(void){}

1.2.3. R_Asterist.cpp
#include "R_Asterist.h" R_Asterist::R_Asterist(void) {} R_Asterist::~R_Asterist(void) {}

## SEARCHING EFFICIENCY IN TWO-DIMENSIONAL GEOMETRIC

1.2.4. R_Asterist.h
#pragma once #include "NodeArbolR_Asterist.h" #include <queue> template<class X> class R_Asterist { private: int orden; int altura; NodeArbolR_Asterist<X> *raiz; NodeArbolR_Asterist<X>* dividirNodo(NodeArbolR_Asterist<X>*, NodeArbolR_Asterist<X>*); bool insertarEnPadre(NodeArbolR_Asterist<X>*, NodeArbolR_Asterist<X>*); bool dividirNodo(NodeArbolR_Asterist<X>*,X); NodeArbolR_Asterist<X>* OrdenAlfaHojas(NodeArbolR_AsteristX>*, X, int); NodeArbolR_Asterist<X>* OrdenAlfaNodos(NodeArbolR_Asterist<X>*, NodeArbolR_Asterist<X>*, int); NodeArbolR_Asterist<X>* OrdenBeta(NodeArbolR_Asterist<X>*, X, int); NodeArbolR_Asterist<X>* buscarNodoInsert(X); NodeArbolR_Asterist<X>* buscarNodoPadre(NodeArbolR_Asterist<X>*, X); public: bool insertElement(X); bool buscarElement(X); bool eliminarElement(X); void mostrar(void); R_Asterist(void); R_Asterist(int); ~R_Asterist(void); }; template<class X> R_Asterist<X>::R_Asterist(void){ orden = 0; altura = 0; raiz = NULL; } template<class X> R_Asterist<X>::R_Asterist(int n){ orden = n; altura = 0; raiz = new NodoBmas<X>(orden); } template<class X> NodeArbolR_Asterist<X>* R_Asterist<X>::buscarNodoInsert(X elem){ NodeArbolR_Asterist<X> *temp = raiz; int tempPos = temp->getPosicionDeHijo(elem); while(temp->getHijos()[tempPos].getHijos()){ temp = &temp->getHijos()[tempPos]; tempPos = temp->getPosicionDeHijo(elem); }return temp;}

## SEARCHING EFFICIENCY IN TWO-DIMENSIONAL GEOMETRIC

template<class X> bool R_Asterist<X>::insertElement(X elem){ bool retornar = false; NodeArbolR_Asterist<X> *tempNodoInsert = this->buscarNodoInsert(elem); if(!tempNodoInsert->insertElement(elem)){ if(tempNodoInsert->getIsFull()){ dividirNodo(tempNodoInsert,elem); } } return retornar; } template<class X> NodeArbolR_Asterist<X>* R_Asterist<X>::OrdenAlfaHojas(NodeArbolR_Asterist<X>* node, X elem, int pos){ NodeArbolR_Asterist<X> *nodeInz = new NodoBmas<X>(orden); NodeArbolR_Asterist<X> *nodeDerc = new NodoBmas<X>(orden); int limite = orden % 2 +1; int posTemp = 0; if( pos <= limite){ nodeInz->insertElement(elem); }else{ nodeDerc->insertElement(elem); } int u = 0; for(; u <= limite; u++){ if( nodeInz->getCantElements() <= limite){ nodeInz->insertElement(node->getElements()[u]);}} u--; for(; u < node->getCantElements(); u++){ nodeDerc->insertElement(node->getElements()[u]);} node->vaciarNodo(); node->insertElement(nodeInz->getElements()[nodeInz->getCantElements()-1]); node->getHijos()[0] = *nodeInz; node->getHijos()[1] = *nodeDerc; return node; } template<class X> NodeArbolR_Asterist<X>* R_Asterist<X>::OrdenAlfaNodos(NodeArbolR_Asterist<X>* padre, NodeArbolR_Asterist<X>* node, int pos){ NodeArbolR_Asterist<X> *tempNode = new NodeArbolR_Asterist<X>(orden+1); NodeArbolR_Asterist<X> *newNode = new NodeArbolR_Asterist<X>(orden); /*tempNode->getHijos()[pos] = tempHijos[0];*/ tempNode->insertElement(node->getElements()[0]); NodeArbolR_Asterist<X> *tempHijos = node->getHijos(); *node = tempHijos[0]; tempNode->getHijos()[pos + 1] = tempHijos[1]; int posY = 0; for(int i = 0; i <= orden ;i++ ){ tempNode->insertElement(padre->getElements()[posY]); if( i != pos +1 ){ tempNode->getHijos()[i] = padre->getHijos()[posY]; posY++;}}

10

11

## SEARCHING EFFICIENCY IN TWO-DIMENSIONAL GEOMETRIC

CONCLUSIONS

We conclude thatthe use of theR *treeis more efficientto searcha locationby coordinatescompared to othertrees wherewe may losetoo much time.

It also offersoccupy a spaceefficient memorythis occurs whenthere is completeor partialintersection ofimageswhere a newsubdivisionoccurs andthe images

areoriginalbutineachthere isanyintersectionandthis helps us tonot storegarbageand occupyin memory. It also offersmemory savingsbecause it is notnecessary to loadthe entireimage tosearchbut onlychildren orsectorsof images thatare chosenforcritical operations.

12

## SEARCHING EFFICIENCY IN TWO-DIMENSIONAL GEOMETRIC

REFERENCES

Antonin Guttman: R-Trees: A Dynamic Index Structure for Spatial Searching, Proc. ACM SIGMOD International Conference on Management of Data, ISBN 0-89791-128-8

Lars Arge, Mark de Berg, Herman J.Haverkort, Ke Yi: The Priority RTree: A Practically Efficient and Worst-Case Optimal R-Tree, Proc. ACM SIGMOD international conference on Management of data, ISBN 158113-859-8

13