├── src.zip ├── src ├── silc │ ├── knn │ ├── object │ ├── path │ ├── silc │ ├── silc.NA │ ├── silc.SF │ ├── silc.cal │ ├── silc.col │ ├── silc.fla │ ├── Readme.txt │ ├── query_location │ ├── batch.0711.pm.sh │ ├── silc.divide.col.p5.log │ ├── run.sh │ ├── Makefile │ └── query_path.cpp ├── road │ ├── node.o │ ├── access.o │ ├── bound.o │ ├── graph.o │ ├── hiernn.o │ ├── param.o │ ├── point.o │ ├── psdraw.o │ ├── Readme.txt │ ├── bin │ │ ├── hiergnn │ │ ├── hiernn │ │ ├── plainnn │ │ ├── distidxnn │ │ ├── hierrange │ │ ├── plaingnn │ │ ├── spatialnn │ │ ├── distbrwsnn │ │ ├── distidxgnn │ │ ├── distidxrange │ │ ├── hiergrange │ │ ├── plaingrange │ │ ├── plainrange │ │ ├── spatialgnn │ │ ├── spatialrange │ │ ├── distbrwsloader │ │ ├── distidxgrange │ │ ├── distidxloader │ │ ├── graphobjloader │ │ ├── spatialgrange │ │ ├── hiergraphloader │ │ └── graphobjqueryloader │ ├── distbrws.o │ ├── distidx.o │ ├── distidxnn.o │ ├── graphmap.o │ ├── graphplot.o │ ├── hiergnn.o │ ├── hiergraph.o │ ├── hierrange.o │ ├── iomeasure.o │ ├── nodemap.o │ ├── objectgen.o │ ├── plaingnn.o │ ├── plainnn.o │ ├── segfmem.o │ ├── segmmem.o │ ├── spatialnn.o │ ├── spqdtree.o │ ├── bordernode.o │ ├── collection.o │ ├── distbrwsnn.o │ ├── distidxgnn.o │ ├── graphsearch.o │ ├── hiergrange.o │ ├── plaingrange.o │ ├── plainrange.o │ ├── spatialgnn.o │ ├── spatialmap.o │ ├── spqdtreerec.o │ ├── distbrwsloader.o │ ├── distbrwssearch.o │ ├── distidxgrange.o │ ├── distidxloader.o │ ├── distidxrange.o │ ├── distidxsearch.o │ ├── gen_rand_obj.cpp │ ├── graphobjloader.o │ ├── graphpartition.o │ ├── hiernn_gtree.o │ ├── hierobjsearch.o │ ├── objectsearch.o │ ├── spatialgrange.o │ ├── spatialrange.o │ ├── spatialsearch.o │ ├── spqdtreenode.o │ ├── hiergraphloader.o │ ├── shortcuttreenode.o │ ├── graphobjqueryloader.o │ ├── hiernn_gptree_dif_dist_test.cc │ ├── run_my.sh │ ├── spqdtreesearch.cc │ ├── spqdtreesearch.h │ ├── object.h │ ├── param.cc │ ├── graphpartition.h │ ├── param.h │ ├── access.h │ ├── iomeasure.h │ ├── spqdtreerec.cc │ ├── segmem.h │ ├── access.cc │ ├── nodemap.h │ ├── graphmap.h │ ├── edge.h │ ├── hiergraph.h │ ├── graph.h │ ├── shortcuttreenode.h │ ├── objectgen.h │ ├── distidx.h │ ├── shortcuttreenode.cc │ ├── spqdtreerec.h │ ├── bound.h │ ├── distbrws.h │ ├── node.h │ ├── objectgen.cc │ ├── bordernode.h │ ├── distbrwssearch.h │ ├── segmmem.h │ ├── hiergraph.cc │ ├── distsign.h │ ├── point.h │ ├── segfmem.h │ ├── spatialmap.cc │ ├── graphplot.h │ ├── point.cc │ ├── spqdtree.h │ ├── bound.cc │ ├── graphmap.cc │ ├── nodemap.cc │ ├── spqdtreenode.h │ ├── spatialmap.h │ ├── distidxsearch.h │ ├── spatialsearch.h │ ├── psdraw.h │ ├── hierobjsearch.h │ ├── iomeasure.cc │ ├── graph.cc │ ├── node.cc │ ├── distbrws.cc │ ├── distidx.cc │ ├── segmmem.cc │ ├── graphsearch.h │ ├── objectsearch.h │ ├── distidxloader.cc │ ├── graphloader.cc │ ├── hiergraphloader.cc │ ├── distbrwsrange.cc │ ├── distbrwsnn.cc │ ├── spqdtreenode.cc │ ├── distbrwssearch.cc │ ├── hiernn.cc │ ├── hiernn_gtree.cc │ ├── graphobjloader.cc │ └── hiernn_gtree_density_bk.cc ├── gtree │ ├── cal.gtree │ ├── cal.minds │ ├── cal.paths │ ├── gtree_build │ ├── gtree_query │ ├── Makefile │ ├── README.txt │ └── cal.object └── gtree_new_p2p │ └── GPlusTree两点最短路查询说明.pdf └── gtree_road_silc_readme.pdf /src.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src.zip -------------------------------------------------------------------------------- /src/silc/knn: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/silc/knn -------------------------------------------------------------------------------- /src/road/node.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/node.o -------------------------------------------------------------------------------- /src/silc/object: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/silc/object -------------------------------------------------------------------------------- /src/silc/path: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/silc/path -------------------------------------------------------------------------------- /src/silc/silc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/silc/silc -------------------------------------------------------------------------------- /src/road/access.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/access.o -------------------------------------------------------------------------------- /src/road/bound.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/bound.o -------------------------------------------------------------------------------- /src/road/graph.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/graph.o -------------------------------------------------------------------------------- /src/road/hiernn.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/hiernn.o -------------------------------------------------------------------------------- /src/road/param.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/param.o -------------------------------------------------------------------------------- /src/road/point.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/point.o -------------------------------------------------------------------------------- /src/road/psdraw.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/psdraw.o -------------------------------------------------------------------------------- /src/silc/silc.NA: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/silc/silc.NA -------------------------------------------------------------------------------- /src/silc/silc.SF: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/silc/silc.SF -------------------------------------------------------------------------------- /src/silc/silc.cal: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/silc/silc.cal -------------------------------------------------------------------------------- /src/silc/silc.col: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/silc/silc.col -------------------------------------------------------------------------------- /src/silc/silc.fla: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/silc/silc.fla -------------------------------------------------------------------------------- /src/gtree/cal.gtree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/gtree/cal.gtree -------------------------------------------------------------------------------- /src/gtree/cal.minds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/gtree/cal.minds -------------------------------------------------------------------------------- /src/gtree/cal.paths: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/gtree/cal.paths -------------------------------------------------------------------------------- /src/road/Readme.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/Readme.txt -------------------------------------------------------------------------------- /src/road/bin/hiergnn: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/bin/hiergnn -------------------------------------------------------------------------------- /src/road/bin/hiernn: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/bin/hiernn -------------------------------------------------------------------------------- /src/road/bin/plainnn: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/bin/plainnn -------------------------------------------------------------------------------- /src/road/distbrws.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/distbrws.o -------------------------------------------------------------------------------- /src/road/distidx.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/distidx.o -------------------------------------------------------------------------------- /src/road/distidxnn.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/distidxnn.o -------------------------------------------------------------------------------- /src/road/graphmap.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/graphmap.o -------------------------------------------------------------------------------- /src/road/graphplot.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/graphplot.o -------------------------------------------------------------------------------- /src/road/hiergnn.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/hiergnn.o -------------------------------------------------------------------------------- /src/road/hiergraph.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/hiergraph.o -------------------------------------------------------------------------------- /src/road/hierrange.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/hierrange.o -------------------------------------------------------------------------------- /src/road/iomeasure.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/iomeasure.o -------------------------------------------------------------------------------- /src/road/nodemap.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/nodemap.o -------------------------------------------------------------------------------- /src/road/objectgen.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/objectgen.o -------------------------------------------------------------------------------- /src/road/plaingnn.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/plaingnn.o -------------------------------------------------------------------------------- /src/road/plainnn.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/plainnn.o -------------------------------------------------------------------------------- /src/road/segfmem.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/segfmem.o -------------------------------------------------------------------------------- /src/road/segmmem.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/segmmem.o -------------------------------------------------------------------------------- /src/road/spatialnn.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/spatialnn.o -------------------------------------------------------------------------------- /src/road/spqdtree.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/spqdtree.o -------------------------------------------------------------------------------- /src/silc/Readme.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/silc/Readme.txt -------------------------------------------------------------------------------- /src/gtree/gtree_build: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/gtree/gtree_build -------------------------------------------------------------------------------- /src/gtree/gtree_query: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/gtree/gtree_query -------------------------------------------------------------------------------- /src/road/bin/distidxnn: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/bin/distidxnn -------------------------------------------------------------------------------- /src/road/bin/hierrange: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/bin/hierrange -------------------------------------------------------------------------------- /src/road/bin/plaingnn: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/bin/plaingnn -------------------------------------------------------------------------------- /src/road/bin/spatialnn: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/bin/spatialnn -------------------------------------------------------------------------------- /src/road/bordernode.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/bordernode.o -------------------------------------------------------------------------------- /src/road/collection.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/collection.o -------------------------------------------------------------------------------- /src/road/distbrwsnn.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/distbrwsnn.o -------------------------------------------------------------------------------- /src/road/distidxgnn.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/distidxgnn.o -------------------------------------------------------------------------------- /src/road/graphsearch.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/graphsearch.o -------------------------------------------------------------------------------- /src/road/hiergrange.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/hiergrange.o -------------------------------------------------------------------------------- /src/road/plaingrange.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/plaingrange.o -------------------------------------------------------------------------------- /src/road/plainrange.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/plainrange.o -------------------------------------------------------------------------------- /src/road/spatialgnn.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/spatialgnn.o -------------------------------------------------------------------------------- /src/road/spatialmap.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/spatialmap.o -------------------------------------------------------------------------------- /src/road/spqdtreerec.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/spqdtreerec.o -------------------------------------------------------------------------------- /src/road/bin/distbrwsnn: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/bin/distbrwsnn -------------------------------------------------------------------------------- /src/road/bin/distidxgnn: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/bin/distidxgnn -------------------------------------------------------------------------------- /src/road/bin/distidxrange: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/bin/distidxrange -------------------------------------------------------------------------------- /src/road/bin/hiergrange: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/bin/hiergrange -------------------------------------------------------------------------------- /src/road/bin/plaingrange: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/bin/plaingrange -------------------------------------------------------------------------------- /src/road/bin/plainrange: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/bin/plainrange -------------------------------------------------------------------------------- /src/road/bin/spatialgnn: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/bin/spatialgnn -------------------------------------------------------------------------------- /src/road/bin/spatialrange: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/bin/spatialrange -------------------------------------------------------------------------------- /src/road/distbrwsloader.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/distbrwsloader.o -------------------------------------------------------------------------------- /src/road/distbrwssearch.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/distbrwssearch.o -------------------------------------------------------------------------------- /src/road/distidxgrange.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/distidxgrange.o -------------------------------------------------------------------------------- /src/road/distidxloader.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/distidxloader.o -------------------------------------------------------------------------------- /src/road/distidxrange.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/distidxrange.o -------------------------------------------------------------------------------- /src/road/distidxsearch.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/distidxsearch.o -------------------------------------------------------------------------------- /src/road/gen_rand_obj.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/gen_rand_obj.cpp -------------------------------------------------------------------------------- /src/road/graphobjloader.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/graphobjloader.o -------------------------------------------------------------------------------- /src/road/graphpartition.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/graphpartition.o -------------------------------------------------------------------------------- /src/road/hiernn_gtree.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/hiernn_gtree.o -------------------------------------------------------------------------------- /src/road/hierobjsearch.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/hierobjsearch.o -------------------------------------------------------------------------------- /src/road/objectsearch.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/objectsearch.o -------------------------------------------------------------------------------- /src/road/spatialgrange.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/spatialgrange.o -------------------------------------------------------------------------------- /src/road/spatialrange.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/spatialrange.o -------------------------------------------------------------------------------- /src/road/spatialsearch.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/spatialsearch.o -------------------------------------------------------------------------------- /src/road/spqdtreenode.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/spqdtreenode.o -------------------------------------------------------------------------------- /src/silc/query_location: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/silc/query_location -------------------------------------------------------------------------------- /gtree_road_silc_readme.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/gtree_road_silc_readme.pdf -------------------------------------------------------------------------------- /src/road/bin/distbrwsloader: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/bin/distbrwsloader -------------------------------------------------------------------------------- /src/road/bin/distidxgrange: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/bin/distidxgrange -------------------------------------------------------------------------------- /src/road/bin/distidxloader: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/bin/distidxloader -------------------------------------------------------------------------------- /src/road/bin/graphobjloader: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/bin/graphobjloader -------------------------------------------------------------------------------- /src/road/bin/spatialgrange: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/bin/spatialgrange -------------------------------------------------------------------------------- /src/road/hiergraphloader.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/hiergraphloader.o -------------------------------------------------------------------------------- /src/road/shortcuttreenode.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/shortcuttreenode.o -------------------------------------------------------------------------------- /src/road/bin/hiergraphloader: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/bin/hiergraphloader -------------------------------------------------------------------------------- /src/road/graphobjqueryloader.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/graphobjqueryloader.o -------------------------------------------------------------------------------- /src/road/bin/graphobjqueryloader: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/bin/graphobjqueryloader -------------------------------------------------------------------------------- /src/gtree_new_p2p/GPlusTree两点最短路查询说明.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/gtree_new_p2p/GPlusTree两点最短路查询说明.pdf -------------------------------------------------------------------------------- /src/road/hiernn_gptree_dif_dist_test.cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TsinghuaDatabaseGroup/GTree/HEAD/src/road/hiernn_gptree_dif_dist_test.cc -------------------------------------------------------------------------------- /src/silc/batch.0711.pm.sh: -------------------------------------------------------------------------------- 1 | #./silc.SF > ./silc.SF.log 2 | #./silc.NA > ./silc.NA.log 3 | ./silc.col > silc.col.log 4 | ./silc.fla > silc.fla.log 5 | -------------------------------------------------------------------------------- /src/road/run_my.sh: -------------------------------------------------------------------------------- 1 | rm ./bin/hiernn_gtree 2 | make hiernn_gtree 3 | scp ./bin/hiernn_gtree dmteam@166.111.17.125:/home/dmteam/dataSets/exp_data/road_e_n_data/ 4 | 5 | -------------------------------------------------------------------------------- /src/silc/silc.divide.col.p5.log: -------------------------------------------------------------------------------- 1 | LOADING NODE...COMPLETE. NODE_COUNT=435666 2 | LOADING EDGE...COMPLETE. 3 | ADD QUAD=435665 SIZE=1 4 | "BUILD" RESULT: 46487 (0.01MS) 5 | -------------------------------------------------------------------------------- /src/gtree/Makefile: -------------------------------------------------------------------------------- 1 | gtree_build: gtree_build.cpp 2 | g++ -std=c++0x -O2 gtree_build.cpp -L/usr/local/lib/ -lmetis -o gtree_build 3 | gtree_query: gtree_query.cpp 4 | g++ -std=c++0x -O2 gtree_query.cpp -L/usr/local/lib/ -lmetis -o gtree_query 5 | -------------------------------------------------------------------------------- /src/silc/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | MORTON=/home/dmteam/dataSets/silc_raw/data/col.morton 3 | DATA=/home/dmteam/dataSets/silc_raw/data/col.object.dat.4300 4 | ./knn ./data/col.cnode ./data/col.cedge 10000 $MORTON ./data/col.object.dat.4300 5 | -------------------------------------------------------------------------------- /src/silc/Makefile: -------------------------------------------------------------------------------- 1 | object: 2 | g++ object.cpp -o object 3 | silc: 4 | g++ silc.cpp -o silc 5 | query: 6 | g++ query_location.cpp -o query 7 | knn: silc_knn.cpp 8 | g++ -o knn silc_knn.cpp 9 | clean: 10 | rm silc; rm object; rm query; rm knn; 11 | -------------------------------------------------------------------------------- /src/road/spqdtreesearch.cc: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | Author: Ken C. K. Lee 3 | Email: cklee@cse.psu.edu 4 | Web: http://www.cse.psu.edu/~cklee 5 | Date: Nov, 2008 6 | ---------------------------------------------------------------------------- */ 7 | 8 | #include "spqdtreesearch.h" 9 | 10 | SPQuadtreeNode* SPQuadtreeSearch::ptSearch(SPQuadtree& a_tree, Point& a_pt) 11 | { 12 | return 0; 13 | } -------------------------------------------------------------------------------- /src/road/spqdtreesearch.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | Author: Ken C. K. Lee 3 | Email: cklee@cse.psu.edu 4 | Web: http://www.cse.psu.edu/~cklee 5 | Date: Nov, 2008 6 | 7 | Copyright(c) Ken C. K. Lee 2008 8 | 9 | This library is for non-commerical use only. 10 | This header file includes class shortest path quad-tree search declaration 11 | ---------------------------------------------------------------------------- */ 12 | #ifndef spqdtreesearch_defined 13 | #define spqdtreesearch_defined 14 | 15 | class SPQuadtree; 16 | class SPQuadtreeNode; 17 | class Point; 18 | 19 | class SPQuadtreeSearch 20 | { 21 | public: 22 | static SPQuadtreeNode* ptSearch(SPQuadtree& a_tree, Point& a_pt); 23 | }; 24 | 25 | #endif 26 | 27 | -------------------------------------------------------------------------------- /src/road/object.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | Author: Ken C. K. Lee 3 | Email: cklee@cse.psu.edu 4 | Web: http://www.cse.psu.edu/~cklee 5 | Date: Jan, 2008 6 | 7 | Copyright(c) Ken C. K. Lee 2008 8 | 9 | This file contains a class Object declaration. 10 | It consists of object information. 11 | ---------------------------------------------------------------------------- */ 12 | #ifndef object_defined 13 | #define object_defined 14 | 15 | class Object 16 | { 17 | public: 18 | const int m_objID; // object id 19 | const int m_objType; // object type 20 | public: 21 | Object(const int a_objID, const int a_objType): 22 | m_objID(a_objID), m_objType(a_objType) {}; 23 | virtual ~Object() {}; 24 | }; 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /src/road/param.cc: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | Author: Ken C. K. Lee 3 | Email: cklee@cse.psu.edu 4 | Web: http://www.cse.psu.edu/~cklee 5 | Date: Nov, 2007 6 | ---------------------------------------------------------------------------- */ 7 | 8 | #include "param.h" 9 | #include 10 | #include 11 | 12 | const char* Param::read(const int a_argc, const char** a_argv, 13 | const char* a_param, 14 | const char* a_def) 15 | { 16 | for (int i=0; i= m_start.size()) 27 | a_start = a_end = -1; 28 | a_start = (long)m_start.get(i); 29 | a_end = (long)m_end.get(i); 30 | } 31 | 32 | void Access::append(const int a_start, const int a_end) 33 | { 34 | m_start.append((void*)a_start); 35 | m_end.append((void*)a_end); 36 | } 37 | 38 | void Access::clean() 39 | { 40 | m_start.clean(); 41 | m_end.clean(); 42 | }; 43 | -------------------------------------------------------------------------------- /src/road/nodemap.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | Author: Ken C. K. Lee 3 | Email: cklee@cse.psu.edu 4 | Web: http://www.cse.psu.edu/~cklee 5 | Date: Jan, 2008 6 | 7 | Copyright(c) Ken C. K. Lee 2008 8 | 9 | This file contains a class Mapping declaration. 10 | That maps objects to a node and vice versa 11 | ---------------------------------------------------------------------------- */ 12 | #ifndef nodemapping_defined 13 | #define nodemapping_defined 14 | 15 | #include "collection.h" 16 | 17 | class NodeMapping 18 | { 19 | public: 20 | Hash m_node2obj; 21 | Hash m_obj2node; 22 | public: 23 | // constructor/destructor 24 | NodeMapping(); 25 | virtual ~NodeMapping(); 26 | // 27 | // update 28 | void addObject(const int a_nodeid, const int a_objid); 29 | void delObject(const int a_nodeid, const int a_objid); 30 | // 31 | // search 32 | const Array* findObject(const int a_nodeid) const; 33 | }; 34 | 35 | #endif 36 | 37 | -------------------------------------------------------------------------------- /src/road/graphmap.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | Author: Ken C. K. Lee 3 | Email: cklee@cse.psu.edu 4 | Web: http://www.cse.psu.edu/~cklee 5 | Date: Jan, 2008 6 | 7 | Copyright(c) Ken C. K. Lee 2008 8 | 9 | This file contains a class GraphMapping declaration. 10 | That maps objects to a subgraph and vice versa 11 | ---------------------------------------------------------------------------- */ 12 | #ifndef graphmapping_defined 13 | #define graphmapping_defined 14 | 15 | #include "collection.h" 16 | 17 | class GraphMapping 18 | { 19 | public: 20 | Hash m_graph2obj; 21 | Hash m_obj2graph; 22 | public: 23 | GraphMapping(); 24 | virtual ~GraphMapping(); 25 | // 26 | // update 27 | void addObject(const int a_graphid, const int a_objid); 28 | void delObject(const int a_graphid, const int a_objid); 29 | // 30 | // search 31 | const Array* findObject(const int a_graphid) const; 32 | }; 33 | 34 | #endif 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /src/road/edge.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | Author: Ken C. K. Lee 3 | Email: cklee@cse.psu.edu 4 | Web: http://www.cse.psu.edu/~cklee 5 | Date: Jan, 2008 6 | 7 | Copyright(c) Ken C. K. Lee 2008 8 | 9 | This file contains a class Edge declaration. 10 | This presents an edge that 11 | * points a neighboring node and 12 | * carries a cost to that node. 13 | ---------------------------------------------------------------------------- */ 14 | #ifndef edge_defined 15 | #define edge_defined 16 | 17 | class Edge 18 | { 19 | public: 20 | int m_neighbor; // neighbor node id 21 | float m_cost; // cost of the edge towards neighbor 22 | public: 23 | // constructor/destructor 24 | Edge(const int m_id, const float a_cost): 25 | m_neighbor(m_id), m_cost(a_cost) {}; 26 | virtual ~Edge() {}; 27 | // 28 | // storage size 29 | int size() const 30 | { 31 | return sizeof(m_neighbor)+sizeof(m_cost); 32 | }; 33 | }; 34 | 35 | #endif 36 | 37 | -------------------------------------------------------------------------------- /src/road/hiergraph.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | Author: Ken C. K. Lee 3 | Email: cklee@cse.psu.edu 4 | Web: http://www.cse.psu.edu/~cklee 5 | Date: Jan, 2008 6 | 7 | Copyright(c) Ken C. K. Lee 2008 8 | 9 | This file contains a class HierGraph declaration. 10 | This provide accesses to graph border nodes. 11 | ---------------------------------------------------------------------------- */ 12 | #ifndef hiergraph_defined 13 | #define hiergraph_defined 14 | 15 | class BorderNode; 16 | #include "collection.h" 17 | #include "graph.h" 18 | 19 | class HierGraph: public Graph 20 | { 21 | public: 22 | // constructor/destructor 23 | HierGraph(SegMemory& a_nodeMem); 24 | virtual ~HierGraph(); 25 | // 26 | // update 27 | virtual int writeNode(const int a_nid, const BorderNode& a_bnode); 28 | // 29 | // search 30 | virtual Node* getNode(const int a_nid); // overload getNode in Graph 31 | virtual BorderNode* getBorderNode(const int a_nid); 32 | }; 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /src/road/graph.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | Author: Ken C. K. Lee 3 | Email: cklee@cse.psu.edu 4 | Web: http://www.cse.psu.edu/~cklee 5 | Date: Jan, 2008 6 | 7 | Copyright(c) Ken C. K. Lee 2008 8 | 9 | This file contains a class Graph declaration. 10 | This provide accesses to graph nodes. 11 | ---------------------------------------------------------------------------- */ 12 | #ifndef graph_defined 13 | #define graph_defined 14 | 15 | class Node; 16 | class SegMemory; 17 | #include "collection.h" 18 | 19 | class Graph 20 | { 21 | protected: 22 | SegMemory& m_nodeMem; // handle of memory for edges 23 | public: 24 | Hash m_nodes; // hash of node to its content in memory 25 | public: 26 | // constructor/destructor 27 | Graph(SegMemory& a_nodeMem); 28 | virtual ~Graph(); 29 | // 30 | // update 31 | virtual int writeNode(const int a_nid, const Node& a_node); 32 | // 33 | // search 34 | virtual Node* getNode(const int a_nid); 35 | }; 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /src/road/shortcuttreenode.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | Author: Ken C. K. Lee 3 | Email: cklee@cse.psu.edu 4 | Web: http://www.cse.psu.edu/~cklee 5 | Date: Jan, 2008 6 | 7 | Copyright(c) Ken C. K. Lee 2008 8 | 9 | This file contains a class ShortcutTreeNode declaration. 10 | This presents a node that contains 11 | - shortcut/edge with a cost to a neighboring bordernode/node. 12 | ---------------------------------------------------------------------------- */ 13 | #ifndef shortcuttreenode_defined 14 | #define shortcuttreenode_defined 15 | 16 | // DESCRIPTION: 17 | // this organizes shortcuts in different level of a graph as a tree. 18 | 19 | #include "collection.h" 20 | 21 | class ShortcutTreeNode 22 | { 23 | public: 24 | const int m_subnetid; 25 | Array m_edges; // edges to neighboring bordernodes/nodes 26 | Array m_child; // child shortcut 27 | public: 28 | ShortcutTreeNode(const int a_subnetid); 29 | virtual ~ShortcutTreeNode(); 30 | 31 | void condense(Array& remain, Array& del); 32 | }; 33 | 34 | #endif 35 | 36 | 37 | -------------------------------------------------------------------------------- /src/road/objectgen.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | Author: Ken C. K. Lee 3 | Email: cklee@cse.psu.edu 4 | Web: http://www.cse.psu.edu/~cklee 5 | Date: Jan, 2008 6 | 7 | Copyright(c) Ken C. K. Lee 2008 8 | 9 | This file contains a class ObjectGen declaration. 10 | It is used to generate object on a network. 11 | ---------------------------------------------------------------------------- */ 12 | #ifndef objectgen_defined 13 | #define objectgen_defined 14 | 15 | #include "collection.h" 16 | class Node; 17 | 18 | class NodeObject 19 | { 20 | public: 21 | const int m_nodeid; 22 | const int m_objid; 23 | public: 24 | NodeObject(const int a_nodeid, const int a_objid): 25 | m_nodeid(a_nodeid), m_objid(a_objid){}; 26 | virtual ~NodeObject() {}; 27 | }; 28 | 29 | class ObjectGen 30 | { 31 | public: 32 | static void uniform( 33 | const int a_numobj, Array& a_allnodes, 34 | Array& a_map); 35 | static void cluster( 36 | const int a_numcluster, const int a_numobj, 37 | Array& a_allnodes, 38 | Array& a_map); 39 | }; 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /src/road/distidx.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | Author: Ken C. K. Lee 3 | Email: cklee@cse.psu.edu 4 | Web: http://www.cse.psu.edu/~cklee 5 | Date: Jan, 2008 6 | 7 | Copyright(c) Ken C. K. Lee 2008 8 | 9 | This file contains a class DistIndex declaration. 10 | That maps objects to individual nodes and indexes their distance using 11 | a distance signature 12 | ---------------------------------------------------------------------------- */ 13 | #ifndef distidx_defined 14 | #define distidx_defined 15 | 16 | #include "collection.h" 17 | 18 | class SegMemory; 19 | 20 | class DistIndex 21 | { 22 | protected: 23 | SegMemory& m_nodeMem; // handle of memory of distance signature 24 | public: 25 | Hash m_nodes; // hash of distance signatures in memory 26 | public: 27 | // constructor/destructor 28 | DistIndex(SegMemory& a_nodeMem); 29 | virtual ~DistIndex(); 30 | // 31 | // update 32 | int writeNode(const int a_nid, Array& a); // array of distance signatures 33 | // 34 | // search 35 | virtual Array* getNode(const int a_nid); 36 | }; 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /src/road/shortcuttreenode.cc: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | Author: Ken C. K. Lee 3 | Email: cklee@cse.psu.edu 4 | Web: http://www.cse.psu.edu/~cklee 5 | Date: Jan, 2008 6 | ---------------------------------------------------------------------------- */ 7 | 8 | #include "edge.h" 9 | #include "shortcuttreenode.h" 10 | 11 | ShortcutTreeNode::ShortcutTreeNode(const int a_subnetid): 12 | m_subnetid(a_subnetid), 13 | m_child(2,2), 14 | m_edges(5,5) 15 | {} 16 | 17 | ShortcutTreeNode::~ShortcutTreeNode() 18 | { 19 | for (int i=0; icondense(remain,del); 33 | } 34 | del.append(this); 35 | } 36 | else 37 | { 38 | remain.append(this); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/road/spqdtreerec.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | Author: Ken C. K. Lee 3 | Email: cklee@cse.psu.edu 4 | Web: http://www.cse.psu.edu/~cklee 5 | Date: Nov, 2008 6 | 7 | Copyright(c) Ken C. K. Lee 2008 8 | 9 | This library is for non-commerical use only. 10 | This header file includes class shortest path quad-tree record declaration 11 | ---------------------------------------------------------------------------- */ 12 | #ifndef spqdtreerec_defined 13 | #define spqdtreerec_defined 14 | 15 | #include "point.h" 16 | 17 | class SPQuadtreeRec 18 | { 19 | public: 20 | const int m_oid; // record (destination) id 21 | Point m_point; // coordinate 22 | int m_firstnode; // 1st visited node on a path 23 | const float m_pathlen; // path length 24 | public: 25 | // constructor/destructor 26 | SPQuadtreeRec( 27 | const int a_id, 28 | const Point& a_point, 29 | const int a_firstnode, 30 | const float a_pathlen); 31 | virtual ~SPQuadtreeRec(); 32 | // 33 | // info 34 | virtual int size() const; 35 | }; 36 | 37 | #endif 38 | 39 | -------------------------------------------------------------------------------- /src/road/bound.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | Author: Ken C. K. Lee 3 | Email: cklee@cse.psu.edu 4 | 5 | Copyright(c) Ken C. K. Lee 2008 6 | 7 | This header file declares Bound class. 8 | This defines the volume bound. 9 | ---------------------------------------------------------------------------- */ 10 | #ifndef BOUND_DEFINED 11 | #define BOUND_DEFINED 12 | 13 | #include "point.h" 14 | 15 | class Bound 16 | { 17 | public: 18 | const Point m_lower; // lower bound 19 | const Point m_upper; // upper bound 20 | public: 21 | // constructor/destructor 22 | Bound(const Point& a_lower, const Point& a_upper); 23 | virtual ~Bound(); 24 | // 25 | // search 26 | virtual int dimen() const; 27 | virtual Point center() const; 28 | // 29 | // is this bound containing another (in param) 30 | virtual bool contain(const Bound& a_bound) const; 31 | virtual bool contain(const Point& a_point) const; 32 | virtual float mindist(const Point& a_pt) const; 33 | virtual bool equal(const Bound& a_bound) const; 34 | // 35 | // info 36 | static int size(const int a_dimen); // storage size 37 | }; 38 | 39 | #endif 40 | 41 | -------------------------------------------------------------------------------- /src/road/distbrws.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | Author: Ken C. K. Lee 3 | Email: cklee@cse.psu.edu 4 | Web: http://www.cse.psu.edu/~cklee 5 | Date: Jan, 2008 6 | 7 | Copyright(c) Ken C. K. Lee 2008 8 | 9 | This file contains a class DistBrows declaration. 10 | That captures individual nodes and indexes their paths to other nodes 11 | based on shortest path quadtrees 12 | ---------------------------------------------------------------------------- */ 13 | #ifndef distbrws_defined 14 | #define distbrws_defined 15 | 16 | #include "collection.h" 17 | 18 | class SegMemory; 19 | class SPQuadtree; 20 | class Bound; 21 | 22 | class DistBrws 23 | { 24 | protected: 25 | SegMemory& m_nodeMem; // handle of memory of distance signature 26 | public: 27 | Hash m_nodes; // hash of distance signatures in memory 28 | public: 29 | // constructor/destructor 30 | DistBrws(SegMemory& a_nodeMem); 31 | virtual ~DistBrws(); 32 | // 33 | // update 34 | int writeNode(const int a_nid, SPQuadtree* a_spqdtree); 35 | // 36 | // search 37 | virtual SPQuadtree* getNode(const int a_nid, const Bound& a_bound); 38 | }; 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /src/road/node.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | Author: Ken C. K. Lee 3 | Email: cklee@cse.psu.edu 4 | Web: http://www.cse.psu.edu/~cklee 5 | Date: Jan, 2008 6 | 7 | Copyright(c) Ken C. K. Lee 2008 8 | 9 | This file contains a class Node declaration. 10 | It consists of node information and edges to neighbors. 11 | ---------------------------------------------------------------------------- */ 12 | #ifndef node_defined 13 | #define node_defined 14 | 15 | #include "collection.h" 16 | 17 | class Edge; 18 | 19 | class Node 20 | { 21 | public: 22 | int m_id; // node id, that should be unique 23 | float m_x, m_y; // the coordinate of the node 24 | Array m_edges; // a set of edges to neighbors 25 | public: 26 | // constructor/destructor 27 | Node(const int a_id, const float a_x=0, const float a_y=0); 28 | virtual ~Node(); 29 | // 30 | // search 31 | float cost(const int a_node); 32 | // 33 | // edge manipulations 34 | void addEdge(Edge& a_edge); 35 | void delEdge(Edge& a_edge); 36 | // 37 | // memory operations 38 | virtual void toMem(char* a_mem, int& a_len) const; // write to mem 39 | virtual void fromMem(char* a_mem, int& a_len); // load from mem 40 | // 41 | static int compareid(const void* a0, const void* a1); 42 | }; 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /src/road/objectgen.cc: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | Author: Ken C. K. Lee 3 | Email: cklee@cse.psu.edu 4 | Web: http://www.cse.psu.edu/~cklee 5 | Date: Jan, 2008 6 | ---------------------------------------------------------------------------- */ 7 | 8 | #include "objectgen.h" 9 | #include "node.h" 10 | #include 11 | #include 12 | 13 | void ObjectGen::uniform(const int a_numobj, Array& a_allnodes, Array& a_map) 14 | { 15 | int numnode = a_allnodes.size(); 16 | int division = numnode / (a_numobj+3); 17 | for (int i=0; im_id, i)); 22 | } 23 | } 24 | 25 | void ObjectGen::cluster(const int a_numcluster, const int a_numobj, 26 | Array& a_allnodes, Array& a_map) 27 | { 28 | int numnode = a_allnodes.size(); 29 | int* centroid = new int[a_numcluster]; 30 | for (int c=0; cm_id; 35 | } 36 | 37 | for (int i=0; i 17 | class ShortcutTreeNode; 18 | 19 | class BorderNode: public Node 20 | { 21 | public: 22 | Array m_shortcuttree; // shortcuttree root 23 | int m_numlinks; // the number of shortcuts and edges 24 | bool m_isBorder; 25 | public: 26 | // constructor/destructor 27 | BorderNode(const int a_id, const float a_x=0, const float a_y=0); 28 | virtual ~BorderNode(); 29 | // 30 | // shortcut manipulation 31 | ShortcutTreeNode* findShortcut(const Array& a_subnet); 32 | void findSubnets(Array& a_subnet); 33 | void addEdge(const Array& a_subnet, const Edge& a_edge); 34 | void delEdge(const Array& a_subnet, const Edge& a_edge); 35 | // 36 | void findSubnet(const Edge& a_edge, Array& a_subnet); 37 | // 38 | // memory operations 39 | virtual void toMem(char* a_mem, int& a_len) const; 40 | virtual void fromMem(char* a_mem, int& a_len); 41 | virtual int size() const; 42 | // 43 | void display(std::ostream& out); 44 | // 45 | }; 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /src/road/distbrwssearch.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | Author: Ken C. K. Lee 3 | Email: cklee@cse.psu.edu 4 | Web: http://www.cse.psu.edu/~cklee 5 | Date: Nov, 2008 6 | 7 | Copyright(c) Ken C. K. Lee 2008 8 | This file contains object search algorithms based on distance browsing 9 | (shortest path quadtree). 10 | ---------------------------------------------------------------------------- */ 11 | #ifndef distbrwssearch_defined 12 | #define distbrwssearch_defined 13 | 14 | #include "objectsearch.h" 15 | class Graph; 16 | class DistBrws; 17 | class Bound; 18 | 19 | class DistBrwsSearch 20 | { 21 | public: 22 | // ------------------------------------------------------------------------ 23 | // single-point range search 24 | // ------------------------------------------------------------------------ 25 | static void rangeSearch( 26 | Graph& a_graph, 27 | DistBrws& a_distbrws, const Bound& a_bound, 28 | const Array& a_nodes, 29 | const int a_src, const float a_range, 30 | Array &a_result, 31 | int &a_nodeaccess, int &a_edgeaccess); 32 | 33 | // ------------------------------------------------------------------------ 34 | // single-point kNN search 35 | // ------------------------------------------------------------------------ 36 | static void nnSearch( 37 | Graph& a_graph, 38 | DistBrws& a_distbrws, const Bound& a_bound, 39 | const Array& a_nodes, 40 | const int a_src, const int a_k, 41 | Array &a_result, 42 | int &a_nodeaccess, int &a_edgeaccess); 43 | }; 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /src/road/segmmem.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | Author: Ken C. K. Lee 3 | Email: cklee@cse.psu.edu 4 | 5 | Copyright(c) Ken C. K. Lee 2008 6 | 7 | This library contains a class SegmentMainMemory declaration. 8 | It provides facilities to read/allocate/free a record of any size 9 | in main memory. 10 | ---------------------------------------------------------------------------- */ 11 | #ifndef segmmem_defined 12 | #define segmmem_defined 13 | 14 | #include "segmem.h" 15 | 16 | class SegMMemory: public SegMemory 17 | { 18 | private: 19 | char* m_memory; // memory (an array of bytes) 20 | int m_memsize; // bound of memory 21 | int m_exp; // expansion 22 | int m_minallsize; // min. allocation size 23 | int m_freelistheader; 24 | 25 | // segment 26 | typedef struct 27 | { 28 | int m_segsize; // size of the segment of content 29 | union 30 | { 31 | int m_nextptr; // next free block (used if this block is free) 32 | char m_content[1]; // body content 33 | } m_body; 34 | } Segment; 35 | 36 | int find(const int a_size); 37 | void expand(const int a_size); 38 | void split(Segment* a_seg, const int a_size); 39 | 40 | public: 41 | // constructor/destructor 42 | SegMMemory(const int a_initsize, const int a_exp, const int a_minsize); 43 | virtual ~SegMMemory(); 44 | // 45 | // read/allocate/free 46 | virtual void* read(int a_pos); 47 | virtual int allocate(void* a_content, const int a_size); 48 | virtual void free(int a_pos); 49 | }; 50 | 51 | #endif 52 | 53 | -------------------------------------------------------------------------------- /src/road/hiergraph.cc: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | Author: Ken C. K. Lee 3 | Email: cklee@cse.psu.edu 4 | Web: http://www.cse.psu.edu/~cklee 5 | Date: Jan, 2008 6 | ---------------------------------------------------------------------------- */ 7 | 8 | #include "hiergraph.h" 9 | #include "bordernode.h" 10 | #include "segmem.h" 11 | 12 | HierGraph::HierGraph(SegMemory& a_nodeMem): 13 | Graph(a_nodeMem) 14 | {}; 15 | 16 | HierGraph::~HierGraph() 17 | {} 18 | 19 | int HierGraph::writeNode(const int a_nid, const BorderNode& a_bnode) 20 | { 21 | // ------------------------------------------------------------------------ 22 | // write a node into memory 23 | // ------------------------------------------------------------------------ 24 | //char mem[4096]; 25 | int sz = a_bnode.size(); 26 | char* mem = new char[sz*2]; 27 | int len=0; 28 | a_bnode.toMem(mem,len); // content marshalling 29 | int pos = m_nodeMem.allocate(mem,len); 30 | m_nodes.put(a_nid, (void*)pos); 31 | delete[] mem; 32 | return 0; 33 | } 34 | 35 | Node* HierGraph::getNode(const int a_nid) 36 | { 37 | return getBorderNode(a_nid); 38 | } 39 | 40 | BorderNode* HierGraph::getBorderNode(const int a_nid) 41 | { 42 | // ------------------------------------------------------------------------ 43 | // retrieve a node from memory 44 | // ------------------------------------------------------------------------ 45 | int pos = (long)m_nodes.get(a_nid); 46 | char* mem = (char*)m_nodeMem.read(pos); 47 | int len=0; 48 | BorderNode* n = new BorderNode(a_nid); 49 | n->fromMem(mem,len); // content unmarshalling 50 | return n; 51 | } 52 | -------------------------------------------------------------------------------- /src/road/distsign.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | Author: Ken C. K. Lee 3 | Email: cklee@cse.psu.edu 4 | Web: http://www.cse.psu.edu/~cklee 5 | Date: Jan, 2008 6 | 7 | Copyright(c) Ken C. K. Lee 2008 8 | 9 | This file contains a class DistSignature declaration. 10 | That represents a distance signature for an object at a node 11 | ---------------------------------------------------------------------------- */ 12 | #ifndef distsign_defined 13 | #define distsign_defined 14 | 15 | #include "collection.h" 16 | 17 | class DistSignature 18 | { 19 | public: 20 | const int m_oid; // an object 21 | const float m_cost; // distance to the object 22 | const int m_prev; // a connecting node closer to the object 23 | public: 24 | DistSignature( 25 | const int a_oid, const float a_cost, const int a_prev): 26 | m_oid(a_oid), m_cost(a_cost), m_prev(a_prev) {}; 27 | virtual ~DistSignature() {}; 28 | static int compare(const void* a0, const void* a1) 29 | { 30 | DistSignature* o0 = *(DistSignature**)a0; 31 | DistSignature* o1 = *(DistSignature**)a1; 32 | if (o0->m_cost < o1->m_cost) return -1; 33 | if (o0->m_cost > o1->m_cost) return +1; 34 | if (o0->m_oid < o1->m_oid) return -1; 35 | if (o0->m_oid > o1->m_oid) return +1; 36 | return 0; 37 | }; 38 | static int compareID(const void* a0, const void* a1) 39 | { 40 | DistSignature* o0 = *(DistSignature**)a0; 41 | DistSignature* o1 = *(DistSignature**)a1; 42 | if (o0->m_oid < o1->m_oid) return -1; 43 | if (o0->m_oid > o1->m_oid) return +1; 44 | return 0; 45 | }; 46 | }; 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /src/road/point.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | Author: Ken C. K. Lee 3 | Email: cklee@cse.psu.edu 4 | Web: http://www.cse.psu.edu/~cklee 5 | Date: Nov, 2007 6 | 7 | Copyright(c) Ken C. K. Lee 2007 8 | 9 | This library is for non-commerical use only. 10 | 11 | This header file includes class Point declaration, that represents 12 | d-dimensional points 13 | ---------------------------------------------------------------------------- */ 14 | 15 | #ifndef POINT_DEFINED 16 | #define POINT_DEFINED 17 | 18 | #define MAXDIMEN 2 // this is used to allocate for max dimensionality 19 | 20 | class Point 21 | { 22 | // data members 23 | public: 24 | const int m_dimen; // dimensionality 25 | protected: 26 | float m_coor[MAXDIMEN]; // dimensional values 27 | // methods 28 | public: 29 | // constructor/destructor 30 | Point(const int a_dimen, const float* a_coor=0); 31 | Point(const Point& a_pt); 32 | virtual ~Point(); 33 | // 34 | // operation 35 | Point& operator=(const Point& a_pt); // assignment 36 | // 37 | // search 38 | float operator[](const int a_i) const; // return d-dimensional value 39 | static Point midpoint(const Point& a_p0, const Point& a_p1); 40 | // 41 | // update 42 | void set(const int a_i, const float a_c); // update 43 | // 44 | // measures 45 | float distance(const Point& a_pt) const; // distance to point a_pt 46 | // 47 | // comparison 48 | bool operator==(const Point& a_pt) const; // if it equals a point 49 | // 50 | // info 51 | static int size(const int a_dimen); // storage size (bytes) 52 | }; 53 | 54 | #endif // POINT_DEFINED 55 | 56 | -------------------------------------------------------------------------------- /src/road/segfmem.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | Author: Ken C. K. Lee 3 | Email: cklee@cse.psu.edu 4 | 5 | Copyright(c) Ken C. K. Lee 2008 6 | 7 | This library contains a class SegmentFileMemory declaration. 8 | It provides facility to read/allocate/free a record of any size in a file. 9 | ---------------------------------------------------------------------------- */ 10 | #ifndef segfmem_defined 11 | #define segfmem_defined 12 | 13 | #include 14 | #include "segmem.h" 15 | 16 | class SegFMemory: public SegMemory 17 | { 18 | protected: 19 | FILE* m_memfile; // memory (in file) 20 | int m_memsize; // bound of memory 21 | int m_exp; // expansion 22 | int m_minsize; // min. allocation size 23 | int m_freelistheader; // pointer to the head of free block list 24 | char* m_buffer; 25 | int m_buflen; 26 | bool m_newfile; 27 | 28 | int find(const int a_size); 29 | void expand(const int a_size); 30 | void split(const int a_address, const int a_size); 31 | void maintain(const int a_address, const int a_size); 32 | public: 33 | // constructor/destructor 34 | SegFMemory( 35 | const char* a_fname, 36 | const int a_initsize, const int a_exp, const int a_minsize, 37 | bool a_newfile); 38 | virtual ~SegFMemory(); 39 | // 40 | // reset the file 41 | virtual void flush(); 42 | // 43 | // read/allocate/free 44 | virtual void* read(int a_pos); 45 | virtual int allocate(void* a_content, const int a_size); 46 | virtual void free(int a_pos); 47 | int checkfreespace(); 48 | // 49 | virtual int size() const; 50 | }; 51 | 52 | #endif 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /src/road/spatialmap.cc: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | Author: Ken C. K. Lee 3 | Email: cklee@cse.psu.edu 4 | Web: http://www.cse.psu.edu/~cklee 5 | Date: Jan, 2008 6 | ---------------------------------------------------------------------------- */ 7 | 8 | #include "spatialmap.h" 9 | 10 | const float* ObjectCoor::m_refx=0; 11 | const float* ObjectCoor::m_refy=0; 12 | int ObjectCoor::m_cnt=0; 13 | 14 | // constructor/destructor 15 | SpatialMapping::SpatialMapping() 16 | { 17 | m_obj2node.clean(); 18 | } 19 | 20 | SpatialMapping::~SpatialMapping() 21 | { 22 | for (int i=0; im_oid == a_objid) 39 | { 40 | m_obj2node.remove(c); 41 | delete c; 42 | break; 43 | } 44 | } 45 | } 46 | 47 | const Array* SpatialMapping::distOrder(const float a_x, const float a_y) 48 | { 49 | ObjectCoor::m_refx = &a_x; 50 | ObjectCoor::m_refy = &a_y; 51 | ObjectCoor::m_cnt = 1; 52 | m_obj2node.sort(ObjectCoor::compare); 53 | return &m_obj2node; 54 | } 55 | 56 | const Array* SpatialMapping::distOrder(const float* a_x, const float* a_y, const int a_cnt) 57 | { 58 | ObjectCoor::m_refx = a_x; 59 | ObjectCoor::m_refy = a_y; 60 | ObjectCoor::m_cnt = a_cnt; 61 | m_obj2node.sort(ObjectCoor::compare); 62 | return &m_obj2node; 63 | } 64 | -------------------------------------------------------------------------------- /src/road/graphplot.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | Author: Ken C. K. Lee 3 | Email: cklee@cse.psu.edu 4 | Web: http://www.cse.psu.edu/~cklee 5 | Date: Jan, 2008 6 | 7 | Copyright(c) Ken C. K. Lee 2008 8 | This file contains search algorithms for graph. 9 | ---------------------------------------------------------------------------- */ 10 | #ifndef graphplot_defined 11 | #define graphplot_defined 12 | 13 | #include "collection.h" 14 | class Graph; 15 | 16 | class GraphPlot 17 | { 18 | public: 19 | static void plot( // plotting a plain graph 20 | const char* a_filename, 21 | Graph& a_graph); 22 | static void plot( // plotting multiple graphs 23 | const char* a_filename, 24 | Graph** a_graph, 25 | const int a_cnt); 26 | static void plot( // plotting a graph with object locations 27 | const char* a_filename, 28 | Hash& a_nodes, 29 | Array& a_node2objects); 30 | static void plot( // plotting a graph with object and query locations 31 | const char* a_filename, 32 | Hash& a_nodes, 33 | Array& a_node2objects, 34 | Array& a_node2queries); 35 | 36 | static void plot( 37 | const char* a_filename, Graph& a_graph, 38 | Array& src1, Array& dest1, 39 | Array& src2, Array& dest2, 40 | const int src, const int dest); 41 | 42 | // this plot the search paths made from source to destination objects 43 | static void plot( 44 | const char* a_filename, Graph& a_graph, 45 | const int a_querynode, Array& a_objnode, 46 | Array& a_visitednode); 47 | 48 | // this plot the search paths made from source to destination objects 49 | static void plot( 50 | const char* a_filename, Graph& a_graph, 51 | const int* a_querynode, const int a_sz, Array& a_objnode, 52 | Array& a_visitednode); 53 | }; 54 | 55 | #endif 56 | 57 | -------------------------------------------------------------------------------- /src/road/point.cc: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | Author: Ken C. K. Lee 3 | Email: cklee@cse.psu.edu 4 | Web: http://www.cse.psu.edu/~cklee 5 | Date: Nov, 2007 6 | ---------------------------------------------------------------------------- */ 7 | 8 | #include "point.h" 9 | #include 10 | #include 11 | 12 | // constructor/destructor 13 | Point::Point(const int a_dimen, const float* a_coor): 14 | m_dimen(a_dimen) 15 | { 16 | if (a_coor != 0) 17 | memcpy(m_coor,a_coor,sizeof(float)*m_dimen); 18 | else 19 | memset(m_coor,0,sizeof(float)*m_dimen); 20 | } 21 | 22 | Point::Point(const Point& a_pt): 23 | m_dimen(a_pt.m_dimen) 24 | { 25 | memcpy(m_coor,a_pt.m_coor,sizeof(float)*m_dimen); 26 | } 27 | 28 | Point::~Point() 29 | {} 30 | 31 | // operation 32 | Point& Point::operator=(const Point& a_pt) 33 | { 34 | if (this != &a_pt) 35 | memcpy(m_coor, a_pt.m_coor, sizeof(float)*m_dimen); 36 | return *this; 37 | } 38 | 39 | Point Point::midpoint(const Point& a_p0, const Point& a_p1) 40 | { 41 | float m[MAXDIMEN]; 42 | for (int i=0; i 18 | class SPQuadtreeNode; 19 | class SPQuadtreeRec; 20 | class Point; 21 | 22 | using namespace std; 23 | 24 | class SPQuadtree 25 | { 26 | public: 27 | const int m_oid; // a node 28 | const Bound m_bound; // area bound 29 | SPQuadtreeNode* m_root; // the root of the tree 30 | protected: 31 | SPQuadtreeNode* findNode(const Point& a_pt); // find a node containing this point 32 | SPQuadtreeNode* findNode(const Bound& a_bd); // find a node containing this bound 33 | public: 34 | // constructor/destructor 35 | SPQuadtree(const int a_oid, const Bound& a_bound); 36 | virtual ~SPQuadtree(); 37 | // 38 | // search 39 | virtual int next(const Point& a_pt); // determine the next node to go for a point 40 | virtual float mindist(const Point& a_pt); // determine the mindist from the node 41 | // 42 | // update 43 | virtual int addObject(SPQuadtreeRec* a_rec); 44 | virtual int addNode(const SPQuadtreeNode& a_node); 45 | virtual void finalize(); // remove all objects and remain info 46 | // for object search 47 | // display 48 | virtual void dump(ostream& a_out); 49 | // 50 | // memory operations 51 | void toMem(char* a_mem, int& a_len) const; 52 | void fromMem(const char* a_mem, int& a_len); 53 | // 54 | bool operator==(const SPQuadtree& a_tree) const; 55 | // 56 | // info 57 | virtual int size() const; 58 | }; 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /src/gtree/README.txt: -------------------------------------------------------------------------------- 1 | First, I want to applogize for my bad coding style (all in one file +_+) 2 | It is originally for experimental test, thus it is not well-formed in c++ style. 3 | Hope not bring any troubles to you when reading the code. 4 | 5 | ----- 6 | 7 | The original code was written in one file, 8 | To make it clear, i split it into two files(parts): 9 | 1. GTree build: (gtree_build.cpp) 10 | INPUT: graph file(.cnode, .cedge) 11 | OUTPUT: GTree index(.gtree) 12 | GTree branch paths(.gpath) 13 | GTree distance matrix(.mind) 14 | 2. GTree KNN Search: (gtree_query.cpp) 15 | INPUT: graph file(.cnode, .cedge) 16 | GTree index(.gtree) 17 | GTree branch paths(.gpath) 18 | GTree distance matrix(.mind) 19 | TODO: KNN Serach(knn_query()) 20 | Some annotations were written among the code. 21 | 22 | ----- 23 | 24 | METIS is the essential part of the GTree, it is used to partition the graph. 25 | Thus, before compile our code, you must install METIS in your linux system. 26 | 27 | METIS link & download: http://glaros.dtc.umn.edu/gkhome/metis/metis/overview 28 | 29 | [CAUTION]: 30 | Beware the linking issue, in our case, we use "g++ ... -lmetis" 31 | If it is not working, you can try "g++ ... -L/**/**/YOUR_METIS_LIB_PATH" 32 | Make sure "metis.h" is in your default include(.h) directory. 33 | 34 | ----- 35 | 36 | For better understanding of our code, we provide example(CAL dataset) 37 | File use: (Note the file input format) 38 | cal.cnode (graph node file) 39 | cal.cedge (graph edge file) 40 | cal.object(candidate object list) 41 | 42 | [CAUTION]: 43 | In our code, we did not assert the input graph is connected graph 44 | But connected graph must be guaranteed before METIS partition the graph 45 | Hence, it is suggested you have to pre-process the input road network for your own dataset 46 | Luckily, all the dataset used in our experiments are naturally connected: 47 | Dataset link & download: 48 | http://www.cs.fsu.edu/~lifeifei/SpatialDataset.htm 49 | http://www.dis.uniroma1.it/challenge9/index.shtml 50 | 51 | ----- 52 | 53 | Quick Use: 54 | make gtree_query 55 | ./gtree_query 56 | 57 | Just for simple test! 58 | 59 | ---- 60 | -------------------------------------------------------------------------------- /src/road/bound.cc: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | Author: Ken C. K. Lee 3 | Email: cklee@cse.psu.edu 4 | Web: http://www.cse.psu.edu/~cklee 5 | Date: Nov, 2008 6 | ---------------------------------------------------------------------------- */ 7 | 8 | #include "bound.h" 9 | #include 10 | 11 | // constructor/destructor 12 | Bound::Bound(const Point& a_lower, const Point& a_upper): 13 | m_lower(a_lower), m_upper(a_upper) 14 | {} 15 | 16 | Bound::~Bound() 17 | {} 18 | 19 | // search 20 | int Bound::dimen() const 21 | { 22 | return m_lower.m_dimen; 23 | } 24 | 25 | Point Bound::center() const 26 | { 27 | return Point::midpoint(m_lower, m_upper); 28 | } 29 | 30 | // is this bound containing another (in param) 31 | bool Bound::contain(const Bound& a_bound) const 32 | { 33 | for (int i=0; i a_bound.m_lower[i]) return false; 36 | if (m_upper[i] < a_bound.m_upper[i]) return false; 37 | } 38 | return true; 39 | } 40 | 41 | // is this bound containing another (in param) 42 | bool Bound::contain(const Point& a_pt) const 43 | { 44 | for (int i=0; i a_pt[i]) return false; 47 | if (m_upper[i] < a_pt[i]) return false; 48 | } 49 | return true; 50 | } 51 | 52 | bool Bound::equal(const Bound& a_bd) const 53 | { 54 | for (int i=0; i m_upper[i]) 71 | d = a_pt[i] - m_upper[i]; 72 | dist += d*d; 73 | } 74 | return sqrt(dist); 75 | } 76 | 77 | 78 | // info 79 | int Bound::size(const int a_dimen) 80 | { 81 | return Point::size(a_dimen)*2; 82 | } 83 | -------------------------------------------------------------------------------- /src/road/graphmap.cc: -------------------------------------------------------------------------------- 1 | #include "graphmap.h" 2 | 3 | GraphMapping::GraphMapping() 4 | {} 5 | 6 | GraphMapping::~GraphMapping() 7 | { 8 | for (HashReader rdr(m_graph2obj); !rdr.isEnd(); rdr.next()) 9 | delete (Array*)rdr.getVal(); 10 | m_graph2obj.clean(); 11 | m_obj2graph.clean(); 12 | } 13 | 14 | void GraphMapping::addObject(const int a_graphid, const int a_objid) 15 | { 16 | // ------------------------------------------------------------------------ 17 | // associate an object to a subgraph 18 | // ------------------------------------------------------------------------ 19 | Array* a = (Array*)m_graph2obj.get(a_graphid); 20 | if (a == 0) 21 | m_graph2obj.put(a_graphid, a=new Array()); 22 | a->append((void*)a_objid); 23 | a->removeDuplicate(); 24 | 25 | // ------------------------------------------------------------------------ 26 | // associate a graph to an object 27 | // ------------------------------------------------------------------------ 28 | int graphid = (long)m_obj2graph.get(a_objid); 29 | if (graphid == 0) 30 | m_obj2graph.put(a_objid,(void*)a_graphid); 31 | return; 32 | } 33 | 34 | void GraphMapping::delObject(const int a_graphid, const int a_objid) 35 | { 36 | // ------------------------------------------------------------------------ 37 | // delete an object from a node 38 | // ------------------------------------------------------------------------ 39 | Array* a = (Array*)m_graph2obj.get(a_graphid); 40 | if (a != 0) 41 | a->remove((void*)a_objid); 42 | 43 | // ------------------------------------------------------------------------ 44 | // delete a node from an object 45 | // ------------------------------------------------------------------------ 46 | m_obj2graph.remove(a_objid); 47 | } 48 | 49 | const Array* GraphMapping::findObject(const int a_graphid) const 50 | { 51 | // ------------------------------------------------------------------------ 52 | // find objects from a node 53 | // ------------------------------------------------------------------------ 54 | return (const Array*)m_graph2obj.get(a_graphid); 55 | } 56 | -------------------------------------------------------------------------------- /src/road/nodemap.cc: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | Author: Ken C. K. Lee 3 | Email: cklee@cse.psu.edu 4 | Web: http://www.cse.psu.edu/~cklee 5 | Date: Jan, 2008 6 | ---------------------------------------------------------------------------- */ 7 | 8 | #include "nodemap.h" 9 | 10 | // constructor/destructor 11 | NodeMapping::NodeMapping() 12 | {} 13 | 14 | NodeMapping::~NodeMapping() 15 | {} 16 | 17 | void NodeMapping::addObject(const int a_nodeid, const int a_objid) 18 | { 19 | // ------------------------------------------------------------------------ 20 | // associate an object to a node 21 | // ------------------------------------------------------------------------ 22 | Array* a = (Array*)m_node2obj.get(a_nodeid); 23 | if (a == 0) 24 | m_node2obj.put(a_nodeid, a = new Array()); 25 | a->append((void*)a_objid); 26 | a->sort(); 27 | 28 | // ------------------------------------------------------------------------ 29 | // associate a node to an object 30 | // ------------------------------------------------------------------------ 31 | int nodeid = (long)m_obj2node.get(a_objid); 32 | if (nodeid == 0) 33 | m_obj2node.put(a_nodeid,(void*)a_nodeid); 34 | return; 35 | } 36 | 37 | void NodeMapping::delObject(const int a_nodeid, const int a_objid) 38 | { 39 | // ------------------------------------------------------------------------ 40 | // delete an object from a node 41 | // ------------------------------------------------------------------------ 42 | Array* a = (Array*)m_node2obj.get(a_nodeid); 43 | if (a != 0) 44 | a->remove((void*)a_objid); 45 | 46 | // ------------------------------------------------------------------------ 47 | // delete a node from an object 48 | // ------------------------------------------------------------------------ 49 | m_obj2node.remove(a_objid); 50 | } 51 | 52 | const Array* NodeMapping::findObject(const int a_nodeid) const 53 | { 54 | // ------------------------------------------------------------------------ 55 | // find objects from a node 56 | // ------------------------------------------------------------------------ 57 | return (const Array*)m_node2obj.get(a_nodeid); 58 | } 59 | -------------------------------------------------------------------------------- /src/road/spqdtreenode.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | Author: Ken C. K. Lee 3 | Email: cklee@cse.psu.edu 4 | Web: http://www.cse.psu.edu/~cklee 5 | Date: Nov, 2008 6 | 7 | Copyright(c) Ken C. K. Lee 2008 8 | 9 | This library is for non-commerical use only. 10 | This header file includes class shortest path quad-tree node declaration 11 | ---------------------------------------------------------------------------- */ 12 | #ifndef spqdtreenode_defined 13 | #define spqdtreenode_defined 14 | 15 | #include "collection.h" 16 | #include "bound.h" 17 | #include 18 | class SPQuadtreeNode; 19 | class SPQuadtreeRec; 20 | 21 | using namespace std; 22 | 23 | #define INFTY 1e10 24 | 25 | class SPQuadtreeNode 26 | { 27 | friend class SPQuadtree; // allow SPQuadtree to access the attributes 28 | public: 29 | const int m_level; // level in a quadtree 30 | const Bound m_bound; // area covered by this node (cell) 31 | protected: 32 | int m_firstnode; // first visited network node (-1: undefined) 33 | int m_numchild; // number of children 34 | SPQuadtreeNode** m_child; // pointers to children nodes 35 | Array m_recs; // array of records 36 | float m_mindist; // minimum distance to a node 37 | public: 38 | // constructor/destructor 39 | SPQuadtreeNode( 40 | const int a_level, 41 | const Bound& a_bound, 42 | const int a_firstvertex=-1, 43 | const float a_mindist=INFTY); 44 | virtual ~SPQuadtreeNode(); 45 | // 46 | // node info for object search 47 | virtual int next() const; 48 | virtual float mindist() const; 49 | // 50 | // child manipulation 51 | virtual int numChild() const; 52 | virtual SPQuadtreeNode* getChild(const int a_i); 53 | virtual void createChild(); 54 | // 55 | // object manipulation 56 | virtual int numRec() const; 57 | virtual int addRec(SPQuadtreeRec* a_rec); 58 | virtual SPQuadtreeRec* getRec(const int a_i); 59 | virtual void removeAllRec(); 60 | // 61 | virtual void dump(ostream& a_out); 62 | // 63 | virtual bool operator==(const SPQuadtreeNode& a_node) const; 64 | // 65 | // info 66 | virtual int size() const; 67 | }; 68 | 69 | #endif 70 | 71 | -------------------------------------------------------------------------------- /src/gtree/cal.object: -------------------------------------------------------------------------------- 1 | 16525 0 2 | 1190 1 3 | 3593 2 4 | 7550 3 5 | 17576 4 6 | 20238 5 7 | 18448 6 8 | 19822 7 9 | 164 8 10 | 7916 9 11 | 3879 10 12 | 4335 11 13 | 361 12 14 | 6187 13 15 | 8962 14 16 | 11769 15 17 | 1416 16 18 | 8661 17 19 | 19923 18 20 | 16382 19 21 | 7991 20 22 | 7388 21 23 | 420 22 24 | 2318 23 25 | 13080 24 26 | 1982 25 27 | 3140 26 28 | 1687 27 29 | 10005 28 30 | 19716 29 31 | 7007 30 32 | 12445 31 33 | 19132 32 34 | 2255 33 35 | 18104 34 36 | 3671 35 37 | 12385 36 38 | 9954 37 39 | 3053 38 40 | 17838 39 41 | 66 40 42 | 15069 41 43 | 3268 42 44 | 12870 43 45 | 13159 44 46 | 13368 45 47 | 5151 46 48 | 5134 47 49 | 3900 48 50 | 270 49 51 | 1268 50 52 | 1311 51 53 | 13178 52 54 | 10320 53 55 | 8401 54 56 | 8166 55 57 | 10596 56 58 | 6474 57 59 | 7015 58 60 | 12551 59 61 | 12886 60 62 | 8911 61 63 | 8846 62 64 | 14891 63 65 | 20600 64 66 | 5128 65 67 | 717 66 68 | 33 67 69 | 15341 68 70 | 12075 69 71 | 13639 70 72 | 17395 71 73 | 15006 72 74 | 1637 73 75 | 14453 74 76 | 20418 75 77 | 13104 76 78 | 12254 77 79 | 19553 78 80 | 5586 79 81 | 14839 80 82 | 1272 81 83 | 12504 82 84 | 6716 83 85 | 15226 84 86 | 20371 85 87 | 11244 86 88 | 20547 87 89 | 4635 88 90 | 2758 89 91 | 12390 90 92 | 6882 91 93 | 2660 92 94 | 13936 93 95 | 9040 94 96 | 555 95 97 | 7131 96 98 | 2279 97 99 | 17698 98 100 | 16446 99 101 | 15411 100 102 | 5720 101 103 | 20408 102 104 | 18564 103 105 | 10203 104 106 | 17574 105 107 | 11975 106 108 | 4049 107 109 | 638 108 110 | 6351 109 111 | 12913 110 112 | 11371 111 113 | 61 112 114 | 20897 113 115 | 4066 114 116 | 16467 115 117 | 3383 116 118 | 15590 117 119 | 10152 118 120 | 17128 119 121 | 13870 120 122 | 17547 121 123 | 8212 122 124 | 5315 123 125 | 17030 124 126 | 15618 125 127 | 1448 126 128 | 15651 127 129 | 7895 128 130 | 10404 129 131 | 15158 130 132 | 17748 131 133 | 18385 132 134 | 5333 133 135 | 14153 134 136 | 13448 135 137 | 7486 136 138 | 18218 137 139 | 2122 138 140 | 5185 139 141 | 3650 140 142 | 10073 141 143 | 5362 142 144 | 769 143 145 | 15688 144 146 | 13721 145 147 | 9137 146 148 | 1201 147 149 | 18207 148 150 | 16484 149 151 | 3855 150 152 | 2581 151 153 | 2613 152 154 | 4790 153 155 | 12255 154 156 | 19511 155 157 | 4078 156 158 | 16688 157 159 | 4887 158 160 | 19455 159 161 | 11999 160 162 | 135 161 163 | 1873 162 164 | 7749 163 165 | 11116 164 166 | 11373 165 167 | 276 166 168 | 8843 167 169 | 414 168 170 | 4097 169 171 | -------------------------------------------------------------------------------- /src/road/spatialmap.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | Author: Ken C. K. Lee 3 | Email: cklee@cse.psu.edu 4 | Web: http://www.cse.psu.edu/~cklee 5 | Date: Jan, 2008 6 | 7 | Copyright(c) Ken C. K. Lee 2008 8 | 9 | This file contains a class SpatialMapping declaration. 10 | That maps objects to a coordinate and vice versa 11 | ---------------------------------------------------------------------------- */ 12 | #ifndef spatialmapping_defined 13 | #define spatialmapping_defined 14 | 15 | #include "collection.h" 16 | #include 17 | 18 | class ObjectCoor 19 | { 20 | public: 21 | const int m_oid; 22 | const int m_nid; 23 | const float m_x, m_y; 24 | public: 25 | ObjectCoor(const int a_oid, const int a_nid, const float a_x, const float a_y): 26 | m_oid(a_oid), m_nid(a_nid), m_x(a_x), m_y(a_y) {}; 27 | ~ObjectCoor() {}; 28 | float distance(const float a_x, const float a_y) 29 | { 30 | return sqrt((a_x-m_x)*(a_x-m_x) + (a_y-m_y)*(a_y-m_y)); 31 | } 32 | float distance(const float* a_x, const float* a_y, const int a_cnt) 33 | { 34 | float d=0; 35 | for (int i=0; i dd ? d : dd; 39 | } 40 | return d; 41 | } 42 | static const float* m_refx; 43 | static const float* m_refy; 44 | static int m_cnt; 45 | static int compare(const void* a0, const void* a1) 46 | { 47 | ObjectCoor* c0 = *(ObjectCoor**)a0; 48 | ObjectCoor* c1 = *(ObjectCoor**)a1; 49 | float dist0 = c0->distance(m_refx,m_refy,m_cnt); 50 | float dist1 = c1->distance(m_refx,m_refy,m_cnt); 51 | if (dist0 < dist1) return -1; 52 | if (dist0 > dist1) return +1; 53 | if (c0->m_oid < c1->m_oid) return -1; 54 | if (c0->m_oid > c1->m_oid) return +1; 55 | return 0; 56 | }; 57 | }; 58 | 59 | class SpatialMapping 60 | { 61 | public: 62 | Array m_obj2node; 63 | public: 64 | SpatialMapping(); 65 | virtual ~SpatialMapping(); 66 | // 67 | // update 68 | void addObject(const int a_objid, const int a_nodeid, const float m_x, const float m_y); 69 | void delObject(const int a_objid); 70 | // 71 | // search 72 | const Array* distOrder(const float a_x, const float a_y); 73 | const Array* distOrder(const float* a_x, const float* a_y, const int a_cnt); 74 | }; 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /src/road/distidxsearch.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | Author: Ken C. K. Lee 3 | Email: cklee@cse.psu.edu 4 | Web: http://www.cse.psu.edu/~cklee 5 | Date: Jan, 2008 6 | 7 | Copyright(c) Ken C. K. Lee 2008 8 | This file contains object search algorithms based on distance index. 9 | ---------------------------------------------------------------------------- */ 10 | #ifndef distidxsearch_defined 11 | #define distidxsearch_defined 12 | 13 | #include "objectsearch.h" 14 | class Graph; 15 | class DistIndex; 16 | 17 | class DistIndexSearch 18 | { 19 | public: 20 | // ------------------------------------------------------------------------ 21 | // single-point range search 22 | // ------------------------------------------------------------------------ 23 | static void rangeSearch( 24 | Graph& a_graph, DistIndex& a_distidx, 25 | const int a_src, const float a_range, 26 | Array& a_result, int& a_nodeaccess, int& a_edgeaccess); 27 | 28 | // ------------------------------------------------------------------------ 29 | // single-point kNN search 30 | // ------------------------------------------------------------------------ 31 | static void kNNSearch( 32 | Graph& a_graph, DistIndex& a_distidx, 33 | const int a_src, const int a_k, 34 | Array& a_result, int& a_nodeaccess, int& a_edgeaccess); 35 | static void kNNSearch( 36 | Graph& a_graph, DistIndex& a_distidx, 37 | const int a_src, const int a_k, 38 | Array& a_result, int& a_nodeaccess, int& a_edgeaccess, 39 | Array& a_visited); 40 | 41 | // ------------------------------------------------------------------------ 42 | // multi-point range search 43 | // ------------------------------------------------------------------------ 44 | static void groupRangeSearch( 45 | Graph& a_graph, DistIndex& a_distidx, 46 | const int* a_src, const float* a_range, 47 | const int a_cnt, 48 | Array& a_result, int& a_nodeaccess, int& a_edgeaccess); 49 | 50 | // ------------------------------------------------------------------------ 51 | // multi-point kNN search 52 | // ------------------------------------------------------------------------ 53 | static void groupKNNSearch( 54 | Graph& a_graph, DistIndex& a_distidx, 55 | const int* a_src, const int a_cnt, 56 | const int a_k, 57 | Array& a_result, int& a_nodeaccess, int& a_edgeaccess); 58 | static void groupKNNSearch( 59 | Graph& a_graph, DistIndex& a_distidx, 60 | const int* a_src, const int a_cnt, 61 | const int a_k, 62 | Array& a_result, int& a_nodeaccess, int& a_edgeaccess, 63 | Array& a_visited); 64 | }; 65 | 66 | #endif 67 | 68 | -------------------------------------------------------------------------------- /src/road/spatialsearch.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | Author: Ken C. K. Lee 3 | Email: cklee@cse.psu.edu 4 | Web: http://www.cse.psu.edu/~cklee 5 | Date: Jan, 2008 6 | 7 | Copyright(c) Ken C. K. Lee 2008 8 | This file contains object search algorithms based on 9 | object spatial coordinates. 10 | ---------------------------------------------------------------------------- */ 11 | #ifndef spatialobjectsearch_defined 12 | #define spatialobjectsearch_defined 13 | 14 | #include "objectsearch.h" 15 | class Graph; 16 | class SpatialMapping; 17 | 18 | class SpatialObjectSearch 19 | { 20 | public: 21 | // ------------------------------------------------------------------------ 22 | // single-point range search 23 | // ------------------------------------------------------------------------ 24 | static void rangeSearch( 25 | Graph& a_graph, SpatialMapping& a_smap, 26 | const int a_src, const float a_range, 27 | Array& a_result, int& a_nodeaccess, int& a_edgeaccess); 28 | 29 | 30 | // ------------------------------------------------------------------------ 31 | // single-point kNN search 32 | // ------------------------------------------------------------------------ 33 | static void kNNSearch( 34 | Graph& a_graph, SpatialMapping& a_map, 35 | const int a_src, const int a_k, 36 | Array& a_result,int& a_nodeaccess, int& a_edgeaccess); 37 | static void kNNSearch( 38 | Graph& a_graph, SpatialMapping& a_map, 39 | const int a_src, const int a_k, 40 | Array& a_result,int& a_nodeaccess, int& a_edgeaccess, 41 | Array& a_visited); 42 | 43 | 44 | // ------------------------------------------------------------------------ 45 | // multi-point range search 46 | // ------------------------------------------------------------------------ 47 | static void groupRangeSearch( 48 | Graph& a_graph, SpatialMapping& a_smap, 49 | const int* a_src, const float* a_range, 50 | const int a_cnt, 51 | Array& a_result, int& a_nodeaccess, int& a_edgeaccess); 52 | 53 | // ------------------------------------------------------------------------ 54 | // multi-point kNN search 55 | // ------------------------------------------------------------------------ 56 | static void groupKNNSearch( 57 | Graph& a_graph, SpatialMapping& a_smap, 58 | const int* a_src, const int a_cnt, 59 | const int a_k, 60 | Array& a_result, int& a_nodeaccess, int& a_edgeaccess); 61 | static void groupKNNSearch( 62 | Graph& a_graph, SpatialMapping& a_smap, 63 | const int* a_src, const int a_cnt, 64 | const int a_k, 65 | Array& a_result, int& a_nodeaccess, int& a_edgeaccess, 66 | Array& a_visited); 67 | }; 68 | 69 | #endif -------------------------------------------------------------------------------- /src/road/psdraw.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | Author: Ken C. K. Lee 3 | Email: cklee@cse.psu.edu 4 | Web: http://www.cse.psu.edu/~cklee 5 | Date: Nov, 2007 6 | 7 | Copyright(c) Ken C. K. Lee 2007 8 | 9 | This library is for non-commerical use only. 10 | 11 | This header file includes class PSDraw declaration. 12 | This class is used to draw points, lines, polygons in an EPS file 13 | ---------------------------------------------------------------------------- */ 14 | 15 | #ifndef psdraw_defined 16 | #define psdraw_defined 17 | 18 | #include 19 | 20 | using namespace std; 21 | 22 | class PSDraw 23 | { 24 | // data members 25 | protected: 26 | fstream m_f; 27 | const float m_cwminx; // clipping window 28 | const float m_cwmaxx; 29 | const float m_cwminy; 30 | const float m_cwmaxy; 31 | const int m_minx; // bounding box in EPS 32 | const int m_miny; 33 | const int m_maxx; 34 | const int m_maxy; 35 | const float m_xscale; 36 | const float m_yscale; 37 | // methods 38 | public: 39 | // constructor/destructor 40 | PSDraw( // create an EPS file with a specified 41 | const char* a_filename, // clipping window 42 | float a_cwminx, float a_cwminy, 43 | float a_cwmaxx, float a_cwmaxy, 44 | int a_minx=50, int a_miny=50, // bounding box on a page 45 | int a_maxx=550, int a_maxy=550);// default: 50, 50, 550, 550 46 | virtual ~PSDraw(); 47 | 48 | void point( // point 49 | float a_x, float a_y, 50 | float a_lineGrayScale=0); 51 | void line( // line 52 | float a_xstart, float a_ystart, 53 | float a_xend, float a_yend, 54 | float a_lineGrayScale=0, 55 | int width=0); 56 | void line( // rgb line 57 | float a_xstart, float a_ystart, 58 | float a_xend, float a_yend, 59 | float a_red, float a_green, float a_blue, 60 | int width=0); 61 | void box( // rectangular box frame 62 | float a_xmin, float a_ymin, 63 | float a_xmax, float a_ymax, 64 | float a_lineGrayScale=0); 65 | void box( // rectangular box frame 66 | float a_xmin, float a_ymin, 67 | float a_xmax, float a_ymax, 68 | float a_red, float a_green, float a_blue); 69 | void solidbox( // rectangular solid box 70 | float a_xmin, float a_ymin, 71 | float a_xmax, float a_ymax, 72 | float a_lineGrayScale=0); 73 | void polygon( // polygon with n points 74 | float* a_x, float* a_y, const int a_n, 75 | float a_lineGrayScale=0); 76 | 77 | }; 78 | 79 | #endif // PSDRAW_DEFINED 80 | 81 | -------------------------------------------------------------------------------- /src/road/hierobjsearch.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | Author: Ken C. K. Lee 3 | Email: cklee@cse.psu.edu 4 | Web: http://www.cse.psu.edu/~cklee 5 | Date: Jan, 2008 6 | 7 | Copyright(c) Ken C. K. Lee 2008 8 | This file contains object search algorithms for hiergraph. 9 | ---------------------------------------------------------------------------- */ 10 | #ifndef hierobjectsearch_defined 11 | #define hierobjectsearch_defined 12 | 13 | #include "objectsearch.h" 14 | class HierGraph; 15 | class GraphMapping; 16 | 17 | class HierObjectSearch 18 | { 19 | public: 20 | // ------------------------------------------------------------------------ 21 | // single point range search 22 | // ------------------------------------------------------------------------ 23 | static void rangeSearch( 24 | HierGraph& a_graph, NodeMapping& a_nmap, GraphMapping& a_gmap, 25 | const int a_src, const float a_range, 26 | Array& a_result, int& a_nodeaccess, int& a_edgeaccess); 27 | 28 | 29 | // ------------------------------------------------------------------------ 30 | // single point kNN search 31 | // ------------------------------------------------------------------------ 32 | static void kNNSearch( 33 | HierGraph& a_graph, NodeMapping& a_map, GraphMapping& a_gmap, 34 | const int a_src, const int k, 35 | Array& a_result,int& nodeaccess, int& edgeaccess); 36 | static void kNNSearch( 37 | HierGraph& a_graph, NodeMapping& a_map, GraphMapping& a_gmap, 38 | const int a_src, const int k, 39 | Array& a_result,int& nodeaccess, int& edgeaccess, 40 | Array& visited); 41 | 42 | 43 | // ------------------------------------------------------------------------ 44 | // multi-point range search 45 | // ------------------------------------------------------------------------ 46 | static void groupRangeSearch( 47 | HierGraph& a_graph, NodeMapping& a_map, GraphMapping& a_gmap, 48 | const int* a_src, const float* a_range, 49 | const int a_cnt, 50 | Array& a_result,int& nodeaccess, int& edgeaccess); 51 | 52 | // ------------------------------------------------------------------------ 53 | // multi-point kNN search 54 | // ------------------------------------------------------------------------ 55 | static void groupKNNSearch( 56 | HierGraph& a_graph, NodeMapping& a_map, GraphMapping& a_gmap, 57 | const int* a_src, const int a_cnt, 58 | const int a_k, 59 | Array& a_result,int& nodeaccess, int& edgeaccess); 60 | static void groupKNNSearch( 61 | HierGraph& a_graph, NodeMapping& a_map, GraphMapping& a_gmap, 62 | const int* a_src, const int a_cnt, 63 | const int a_k, 64 | Array& a_result,int& nodeaccess, int& edgeaccess, 65 | Array& a_visited); 66 | }; 67 | 68 | #endif 69 | 70 | -------------------------------------------------------------------------------- /src/road/iomeasure.cc: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | Author: Ken C. K. Lee 3 | Email: cklee@cse.psu.edu 4 | Web: http://www.cse.psu.edu/~cklee 5 | Date: Jan, 2008 6 | ---------------------------------------------------------------------------- */ 7 | 8 | #include "iomeasure.h" 9 | #include "access.h" 10 | #include "collection.h" 11 | 12 | int IOMeasure::byte(const Access& a_access) 13 | { 14 | int byte = 0; 15 | for (int i=0; i a_cachesize) 86 | { 87 | if (accessq.isEmpty()) 88 | break; 89 | carrier* c = (carrier*)accessq.dequeue(); 90 | int latest = (long)cache.get(c->m_pageid); 91 | if (c->m_accesstime == latest) 92 | cache.remove(c->m_pageid); 93 | delete c; 94 | } 95 | page++; 96 | } 97 | else 98 | { 99 | cache.replace(e, (void*)timer); 100 | } 101 | } 102 | timer++; 103 | } 104 | 105 | while (!accessq.isEmpty()) 106 | delete (carrier*)accessq.dequeue(); 107 | cache.clean(); 108 | return page; 109 | } 110 | -------------------------------------------------------------------------------- /src/road/graph.cc: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | Author: Ken C. K. Lee 3 | Email: cklee@cse.psu.edu 4 | Web: http://www.cse.psu.edu/~cklee 5 | Date: Jan, 2008 6 | ---------------------------------------------------------------------------- */ 7 | 8 | #include "graph.h" 9 | #include "node.h" 10 | #include "segmem.h" 11 | 12 | // constructor/destructor 13 | Graph::Graph(SegMemory& a_nodeMem): 14 | m_nodeMem(a_nodeMem), 15 | m_nodes(10000) 16 | { 17 | if (m_nodeMem.m_header == -1) return; 18 | 19 | // ------------------------------------------------------------------------ 20 | // load hash table of nodes from memory 21 | // ------------------------------------------------------------------------ 22 | char* nodepos = (char*)m_nodeMem.read(m_nodeMem.m_header); 23 | int len=0; 24 | int sz = *(int*)&nodepos[len]; len+=sizeof(int); 25 | for (int i=0; ifromMem(mem,len); // content unmarshalling 89 | return n; 90 | } 91 | -------------------------------------------------------------------------------- /src/silc/query_path.cpp: -------------------------------------------------------------------------------- 1 | // macro for 64 bits file, larger than 2G 2 | #define _FILE_OFFSET_BITS 64 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | // MACRO for time tick 19 | struct timeval tv; 20 | long ts, te; 21 | #define TIME_TICK_START gettimeofday( &tv, NULL ); ts = tv.tv_sec * 100000 + tv.tv_usec / 10; 22 | #define TIME_TICK_END gettimeofday( &tv, NULL ); te = tv.tv_sec * 100000 + tv.tv_usec / 10; 23 | #define TIME_TICK_PRINT(T) printf("%s RESULT: %ld (0.01MS)\r\n", (#T), te - ts ); 24 | // ---------- 25 | 26 | #define FILE_NODE "../../src/data/col.cnode" 27 | // cal=10000 SF=NA=100 ny=100000 e=100000 col=100000 28 | 29 | #define FILE_PATH "../../common_data/col.path.Q4.dat" 30 | #define FACTOR 0.75 31 | #define PATH_SIZE 1000 32 | 33 | #define MAX_INF 1e100 34 | #define MIN_INF -1e100 35 | 36 | typedef struct{ 37 | double x,y; 38 | vector adjnodes; 39 | vector adjweight; 40 | }Node; 41 | 42 | vector Nodes; 43 | 44 | double min_llx, min_lly, max_urx, max_ury; 45 | 46 | void init_input(){ 47 | FILE *fin; 48 | 49 | // load node 50 | printf("LOADING NODE..."); 51 | fin = fopen(FILE_NODE,"r"); 52 | int nid; 53 | double x,y; 54 | while( fscanf(fin, "%d %lf %lf", &nid, &x, &y ) == 3 ){ 55 | Node node = { x, y }; 56 | Nodes.push_back(node); 57 | } 58 | fclose(fin); 59 | printf("COMPLETE. NODE_COUNT=%d\n", Nodes.size()); 60 | 61 | // load edge 62 | /* printf("LOADING EDGE..."); 63 | fin = fopen(FILE_EDGE, "r"); 64 | int eid; 65 | int snid, enid; 66 | double weight; 67 | int iweight; 68 | while( fscanf(fin,"%d %d %d %lf", &eid, &snid, &enid, &weight ) == 4 ){ 69 | iweight = (int) (weight * WEIGHT_INFLATE_FACTOR + ROUND_FACTOR); 70 | Nodes[snid].adjnodes.push_back( enid ); 71 | Nodes[snid].adjweight.push_back( iweight ); 72 | Nodes[enid].adjnodes.push_back( snid ); 73 | Nodes[enid].adjweight.push_back( iweight ); 74 | } 75 | fclose(fin); 76 | printf("COMPLETE.\n"); 77 | */ 78 | 79 | // init get whole region 80 | min_llx = MAX_INF; min_lly = MAX_INF; 81 | max_urx = MIN_INF; max_ury = MIN_INF; 82 | for ( int i = 0; i < Nodes.size(); i++ ){ 83 | if ( Nodes[i].x < min_llx ) min_llx = Nodes[i].x; 84 | if ( Nodes[i].x > max_urx ) max_urx = Nodes[i].x; 85 | if ( Nodes[i].y < min_lly ) min_lly = Nodes[i].y; 86 | if ( Nodes[i].y > max_ury ) max_ury = Nodes[i].y; 87 | } 88 | 89 | } 90 | 91 | void init(){ 92 | init_input(); 93 | } 94 | 95 | double get_euclidean_dis( int src, int dest ){ 96 | return sqrt((Nodes[src].x - Nodes[dest].x) * (Nodes[src].x - Nodes[dest].x) + (Nodes[src].y - Nodes[dest].y) * (Nodes[src].y - Nodes[dest].y)); 97 | } 98 | 99 | int main(){ 100 | init(); 101 | 102 | FILE *fout = fopen( FILE_PATH, "w" ); 103 | 104 | vector s,t; 105 | s.clear(); 106 | t.clear(); 107 | for ( int i = 0; i < Nodes.size(); i++ ){ 108 | s.push_back(i); 109 | t.push_back(i); 110 | } 111 | 112 | random_shuffle( s.begin(), s.end() ); 113 | random_shuffle( t.begin(), t.end() ); 114 | 115 | double diag = sqrt((max_urx-min_llx)*(max_urx-min_llx)+(max_ury-min_lly)*(max_ury-min_lly)); 116 | double mindis = diag * FACTOR; 117 | 118 | int count = 0; 119 | for (int i = 0; i < Nodes.size(); i++ ){ 120 | if ( s[i] == t[i] ) continue; 121 | if ( get_euclidean_dis( s[i], t[i] ) < mindis ) continue; 122 | 123 | fprintf( fout, "%d %d\n", s[i], t[i] ); 124 | count ++; 125 | if ( count >= PATH_SIZE ) break; 126 | } 127 | 128 | fclose( fout ); 129 | return 0; 130 | } 131 | -------------------------------------------------------------------------------- /src/road/node.cc: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | Author: Ken C. K. Lee 3 | Email: cklee@cse.psu.edu 4 | Web: http://www.cse.psu.edu/~cklee 5 | Date: Jan, 2008 6 | ---------------------------------------------------------------------------- */ 7 | 8 | #include "node.h" 9 | #include "edge.h" 10 | #include 11 | 12 | // constructor/destructor 13 | Node::Node(const int a_id, float a_x, float a_y): 14 | m_id(a_id), m_x(a_x), m_y(a_y) 15 | {} 16 | 17 | Node::~Node() 18 | { 19 | // ------------------------------------------------------------------------ 20 | // clean up edges (free the memory) 21 | // ------------------------------------------------------------------------ 22 | int sz = m_edges.size(); 23 | for (int i=0; im_neighbor == a_node) 35 | return e->m_cost; 36 | } 37 | return 0; 38 | } 39 | 40 | 41 | // edge manipulations 42 | void Node::addEdge(Edge& a_edge) 43 | { 44 | // ------------------------------------------------------------------------ 45 | // add an edge to neighbor 46 | // * if an edge to the same neighbor exists, update its cost. 47 | // ------------------------------------------------------------------------ 48 | int sz = m_edges.size(); 49 | for (int i=0; im_neighbor == a_edge.m_neighbor) 53 | { 54 | e->m_cost = a_edge.m_cost; 55 | return; 56 | } 57 | } 58 | m_edges.append(new Edge(a_edge.m_neighbor,a_edge.m_cost)); 59 | } 60 | 61 | void Node::delEdge(Edge& a_edge) 62 | { 63 | // ------------------------------------------------------------------------ 64 | // remove an edge 65 | // ------------------------------------------------------------------------ 66 | int sz = m_edges.size(); 67 | for (int i=0; im_neighbor == a_edge.m_neighbor) 71 | { 72 | m_edges.remove(e); 73 | return; 74 | } 75 | } 76 | } 77 | 78 | // memory operations 79 | void Node::toMem(char* a_mem, int& a_len) const 80 | { 81 | int numedge = m_edges.size(); 82 | *(int*)&a_mem[a_len] = m_id; a_len += sizeof(m_id); 83 | *(float*)&a_mem[a_len] = m_x; a_len += sizeof(m_x); 84 | *(float*)&a_mem[a_len] = m_y; a_len += sizeof(m_y); 85 | *(int*)&a_mem[a_len] = numedge; a_len += sizeof(int); 86 | for (int i=0; im_neighbor; a_len += sizeof(e->m_neighbor); 90 | *(float*)&a_mem[a_len] = e->m_cost; a_len += sizeof(e->m_cost); 91 | } 92 | } 93 | 94 | void Node::fromMem(char* a_mem, int& a_len) 95 | { 96 | int sz=0; 97 | m_id = *(int*)&a_mem[a_len]; a_len += sizeof(m_id); 98 | m_x = *(float*)&a_mem[a_len]; a_len += sizeof(m_x); 99 | m_y = *(float*)&a_mem[a_len]; a_len += sizeof(m_y); 100 | sz = *(int*)&a_mem[a_len]; a_len += sizeof(sz); 101 | for (int i=0; im_id < n1->m_id) return -1; 116 | if (n0->m_id > n1->m_id) return +1; 117 | return 0; 118 | } 119 | -------------------------------------------------------------------------------- /src/road/distbrws.cc: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | Author: Ken C. K. Lee 3 | Email: cklee@cse.psu.edu 4 | Web: http://www.cse.psu.edu/~cklee 5 | Date: Nov, 2008 6 | ---------------------------------------------------------------------------- */ 7 | 8 | #include "distbrws.h" 9 | #include "node.h" 10 | #include "segmem.h" 11 | #include "spqdtree.h" 12 | 13 | DistBrws::DistBrws(SegMemory& a_nodeMem): 14 | m_nodeMem(a_nodeMem), 15 | m_nodes(1000) 16 | { 17 | if (m_nodeMem.m_header == -1) return; 18 | 19 | // ------------------------------------------------------------------------ 20 | // load hash table of nodes from memory 21 | // ------------------------------------------------------------------------ 22 | char* nodepos = (char*)m_nodeMem.read(m_nodeMem.m_header); 23 | int len=0; 24 | int sz = *(int*)&nodepos[len]; len+=sizeof(int); 25 | for (int i=0; isize(); 69 | //char* mem = new char[sz]; 70 | static char* mem = 0; 71 | static int maxsize = 0; 72 | if (maxsize < sz) 73 | { 74 | if (maxsize != 0) delete[] mem; 75 | mem = new char[maxsize = sz]; 76 | } 77 | int len = 0; 78 | 79 | // ------------------------------------------------------------------------ 80 | // convert a shortest path quadtree into a memory byte string 81 | // ------------------------------------------------------------------------ 82 | a_spqdtree->toMem(mem, len); 83 | 84 | // ------------------------------------------------------------------------ 85 | // store the byte string 86 | // ------------------------------------------------------------------------ 87 | int pos = m_nodeMem.allocate(mem,len); 88 | m_nodes.put(a_nid, (void*)pos); 89 | //delete[] mem; 90 | return 0; 91 | } 92 | 93 | SPQuadtree* DistBrws::getNode(const int a_nid, const Bound& a_bound) 94 | { 95 | // ------------------------------------------------------------------------ 96 | // retrieve the shortest path quad tree for a node from memory 97 | // ------------------------------------------------------------------------ 98 | int pos = (long)m_nodes.get(a_nid); 99 | char* mem = (char*)m_nodeMem.read(pos); 100 | int len=0; 101 | 102 | // ------------------------------------------------------------------------ 103 | // convert a byte string into a shortest path quadtree 104 | // ------------------------------------------------------------------------ 105 | SPQuadtree* tree = new SPQuadtree(a_nid, a_bound); 106 | tree->fromMem(mem, len); 107 | 108 | return tree; 109 | } 110 | -------------------------------------------------------------------------------- /src/road/distidx.cc: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | Author: Ken C. K. Lee 3 | Email: cklee@cse.psu.edu 4 | Web: http://www.cse.psu.edu/~cklee 5 | Date: Jan, 2008 6 | ---------------------------------------------------------------------------- */ 7 | 8 | #include "distidx.h" 9 | #include "node.h" 10 | #include "segmem.h" 11 | #include "distsign.h" 12 | 13 | DistIndex::DistIndex(SegMemory& a_nodeMem): 14 | m_nodeMem(a_nodeMem), 15 | m_nodes(10000) 16 | { 17 | if (m_nodeMem.m_header == -1) return; 18 | 19 | // ------------------------------------------------------------------------ 20 | // load hash table of nodes from memory 21 | // ------------------------------------------------------------------------ 22 | char* nodepos = (char*)m_nodeMem.read(m_nodeMem.m_header); 23 | int len=0; 24 | int sz = *(int*)&nodepos[len]; len+=sizeof(int); 25 | for (int i=0; im_oid; len += sizeof(int); 81 | *(float*)&mem[len] = s->m_cost; len += sizeof(int); 82 | *(int*)&mem[len] = s->m_prev; len += sizeof(int); 83 | } 84 | int pos = m_nodeMem.allocate(mem,len); 85 | m_nodes.put(a_nid, (void*)pos); 86 | delete[] mem; 87 | return 0; 88 | } 89 | 90 | Array* DistIndex::getNode(const int a_nid) 91 | { 92 | // ------------------------------------------------------------------------ 93 | // retrieve the distance signature of a node from memory 94 | // ------------------------------------------------------------------------ 95 | int pos = (long)m_nodes.get(a_nid); 96 | char* mem = (char*)m_nodeMem.read(pos); 97 | int len=0; 98 | 99 | Array* a = new Array; 100 | int sz = *(int*)&mem[len]; len += sizeof(int); 101 | for (int i=0; iappend(new DistSignature(oid, cost, prev)); 107 | } 108 | return a; 109 | } 110 | -------------------------------------------------------------------------------- /src/road/segmmem.cc: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | Author: Ken C. K. Lee 3 | Email: cklee@cse.psu.edu 4 | Web: http://www.cse.psu.edu/~cklee 5 | Date: Jan, 2008 6 | ---------------------------------------------------------------------------- */ 7 | 8 | #include "segmmem.h" 9 | #include 10 | 11 | #define NIL -1 12 | 13 | SegMMemory::SegMMemory(const int a_initsize, 14 | const int a_exp, 15 | const int a_minsize): 16 | m_memory(new char[a_initsize]), 17 | m_memsize(a_initsize), 18 | m_exp(a_exp), 19 | m_minallsize(a_minsize), 20 | m_freelistheader(0) 21 | { 22 | memset(m_memory,0,sizeof(char)*a_initsize); 23 | Segment* start = (Segment*)&m_memory[0]; 24 | start->m_segsize = a_initsize - sizeof(start->m_segsize); 25 | start->m_body.m_nextptr = NIL; 26 | } 27 | 28 | SegMMemory::~SegMMemory() 29 | { 30 | delete[] m_memory; 31 | } 32 | 33 | void* SegMMemory::read(int a_pos) 34 | { 35 | int start = a_pos - sizeof(int); // get start address; 36 | int size = *(int*)&m_memory[start]; 37 | int end = start + size + sizeof(int); // get end address; 38 | //m_history.append(start,end); // added to access history 39 | 40 | return (void*)&m_memory[a_pos]; 41 | } 42 | 43 | int SegMMemory::allocate(void* a_content, const int a_size) 44 | { 45 | const int size = a_size > m_minallsize ? a_size : m_minallsize; 46 | int address = find(size); 47 | if (address == -1) 48 | { 49 | expand(m_exp > size+sizeof(Segment) ? m_exp : size+sizeof(Segment)); 50 | address = find(size); 51 | } 52 | Segment* seg = (Segment*)&m_memory[address]; 53 | split(seg, size); 54 | seg->m_segsize = size; 55 | memcpy(seg->m_body.m_content, a_content, size); 56 | return (long)seg->m_body.m_content - (long)m_memory; 57 | } 58 | 59 | void SegMMemory::free(int a_pos) 60 | { 61 | Segment* seg = (Segment*)&m_memory[a_pos - sizeof(int)]; 62 | seg->m_body.m_nextptr = m_freelistheader; 63 | m_freelistheader = (long)seg-(long)m_memory; 64 | } 65 | 66 | // ---------------------------------------------------------------------------- 67 | int SegMMemory::find(const int a_size) 68 | { 69 | // logic: largest block strategy 70 | // 1. scan the free list for a free block whose block size is the largest 71 | // 2. start from freelistheader 72 | // 3. best is the address to the candidate 73 | // 4. ptrbest is the point to the address to the candidate (used to 74 | // maintain free list) 75 | // 5. return NIL if no good candidate is found 76 | // 6. return the address and update the freelist 77 | // 78 | int largest = a_size; 79 | int* ref = &m_freelistheader; 80 | int best = NIL; 81 | int* ptrbest = 0; 82 | while (*ref != NIL) 83 | { 84 | Segment* seg = (Segment*)&m_memory[*ref]; 85 | if (seg->m_segsize >= largest) 86 | { 87 | largest = seg->m_segsize; 88 | best = *ref; 89 | ptrbest = ref; 90 | } 91 | ref = &seg->m_body.m_nextptr; 92 | } 93 | if (best == NIL) return NIL; 94 | 95 | Segment* seg = (Segment*)&m_memory[best]; 96 | *ptrbest = seg->m_body.m_nextptr; 97 | return best; 98 | } 99 | 100 | void SegMMemory::expand(const int a_size) 101 | { 102 | // logic: 103 | // 1. expand the memory by allocating a replacement memory 104 | // 2. initialize the expanded memory as a segment 105 | // 3. attach the segment to the free list 106 | // 4. update the memory size 107 | // 108 | 109 | char* m_newmem = new char[m_memsize + a_size]; 110 | memcpy(m_newmem, m_memory, m_memsize); 111 | delete m_memory; 112 | m_memory = m_newmem; 113 | // 114 | Segment* seg = (Segment*)&m_memory[m_memsize]; 115 | seg->m_segsize = a_size - sizeof(seg->m_segsize); 116 | seg->m_body.m_nextptr = m_freelistheader; 117 | // 118 | m_freelistheader = m_memsize; 119 | // 120 | m_memsize += a_size; 121 | } 122 | 123 | void SegMMemory::split(Segment* a_seg, const int a_size) 124 | { 125 | int diff = a_seg->m_segsize - a_size; 126 | if (diff > m_minallsize) 127 | { 128 | int address = 129 | (long)a_seg - (long)m_memory + 130 | sizeof(a_seg->m_segsize) + a_size; 131 | Segment* seg = (Segment*)&m_memory[address]; 132 | seg->m_segsize = a_seg->m_segsize - sizeof(a_seg->m_segsize) - a_size; 133 | seg->m_body.m_nextptr = m_freelistheader; 134 | m_freelistheader = address; 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /src/road/graphsearch.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | Author: Ken C. K. Lee 3 | Email: cklee@cse.psu.edu 4 | Web: http://www.cse.psu.edu/~cklee 5 | Date: Jan, 2008 6 | 7 | Copyright(c) Ken C. K. Lee 2008 8 | This file contains search algorithms for graph. 9 | ---------------------------------------------------------------------------- */ 10 | #ifndef graphsearch_defined 11 | #define graphsearch_defined 12 | 13 | #include "collection.h" 14 | class Graph; 15 | 16 | class GraphSearchResult 17 | { 18 | public: 19 | const int m_nid; 20 | const float m_cost; 21 | const float m_acost; // used in A* algorithm 22 | Array m_path; 23 | public: 24 | GraphSearchResult( 25 | const int a_nid, const float a_cost): 26 | m_nid(a_nid), m_path(), m_cost(a_cost), m_acost(0) 27 | { m_path.append((void*)m_nid); }; 28 | GraphSearchResult( 29 | const int a_nid, 30 | const Array& a_path, const float a_cost): 31 | m_nid(a_nid), m_path(a_path), m_cost(a_cost), m_acost(0) 32 | { m_path.append((void*)m_nid); }; 33 | GraphSearchResult( 34 | const int a_nid, 35 | const float a_cost, const float a_acost): 36 | m_nid(a_nid), m_path(), m_cost(a_cost), m_acost(a_acost) 37 | { m_path.append((void*)m_nid); }; 38 | GraphSearchResult( 39 | const int a_nid, const Array& a_path, 40 | const float a_cost, const float a_acost): 41 | m_nid(a_nid), m_path(a_path), m_cost(a_cost), m_acost(a_acost) 42 | { m_path.append((void*)m_nid); }; 43 | ~GraphSearchResult() {}; 44 | static int compare(const void* a0, const void* a1) 45 | { 46 | GraphSearchResult* r0 = *(GraphSearchResult**)a0; 47 | GraphSearchResult* r1 = *(GraphSearchResult**)a1; 48 | if (r0->m_cost < r1->m_cost) return -1; 49 | if (r0->m_cost > r1->m_cost) return +1; 50 | return 0; 51 | }; 52 | static int acompare(const void* a0, const void* a1) 53 | { 54 | GraphSearchResult* r0 = *(GraphSearchResult**)a0; 55 | GraphSearchResult* r1 = *(GraphSearchResult**)a1; 56 | if (r0->m_acost < r1->m_acost) return -1; 57 | if (r0->m_acost > r1->m_acost) return +1; 58 | return 0; 59 | }; 60 | }; 61 | 62 | class GraphSearch 63 | { 64 | public: 65 | // ------------------------------------------------------------------------ 66 | // find the diameter the longest distance in a graph 67 | // ------------------------------------------------------------------------ 68 | static float diameter( 69 | Graph& a_graph,const int a_src, 70 | int& a_nodeaccess, int& a_edgeaccess); 71 | 72 | // ------------------------------------------------------------------------ 73 | // find spanning tree towards a node (for distance index creation) 74 | // ------------------------------------------------------------------------ 75 | static void spanSearch( 76 | Graph& a_graph, const int a_dest, 77 | Array& a_nodes2dest); 78 | 79 | // ------------------------------------------------------------------------ 80 | // find spanning tree from a node (for shortest path quadtree creation) 81 | // ------------------------------------------------------------------------ 82 | static void diffuseSearch( 83 | Graph& a_graph, const int a_src, 84 | Array& a_nodes2src); 85 | 86 | 87 | // ------------------------------------------------------------------------ 88 | // shortest path search for a single destination 89 | // ------------------------------------------------------------------------ 90 | static GraphSearchResult* shortestPathSearch( 91 | Graph& a_graph, const int a_src, const int a_dest, 92 | int& a_nodeaccess, int& a_edgeaccess); 93 | 94 | // ------------------------------------------------------------------------ 95 | // A* shortest path search for a single destination 96 | // ------------------------------------------------------------------------ 97 | static GraphSearchResult* aStar( 98 | Graph& a_graph, const int a_src, const int a_dest, 99 | int& a_nodeaccess, int& a_edgeaccess); 100 | static GraphSearchResult* aStar( 101 | Graph& a_graph, const int a_src, const int a_dest, 102 | int& a_nodeaccess, int& a_edgeaccess, 103 | Array& a_visited); 104 | 105 | // ------------------------------------------------------------------------ 106 | // shortest path search for multple destinations 107 | // ------------------------------------------------------------------------ 108 | static void shortestPathSearch( 109 | Graph& a_graph, const int a_src, Set& a_dest, 110 | Hash& a_result, 111 | int& a_nodeaccess, int& a_edgeaccess); 112 | 113 | // ------------------------------------------------------------------------ 114 | // shortest path search for multple destinations 115 | // ------------------------------------------------------------------------ 116 | static void shortestPathSearch( 117 | Hash& nodes, const int a_src, Set& a_dest, 118 | Hash& a_result, 119 | int& a_nodeaccess, int& a_edgeaccess); 120 | }; 121 | 122 | #endif 123 | 124 | -------------------------------------------------------------------------------- /src/road/objectsearch.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | Author: Ken C. K. Lee 3 | Email: cklee@cse.psu.edu 4 | Web: http://www.cse.psu.edu/~cklee 5 | Date: Jan, 2008 6 | 7 | Copyright(c) Ken C. K. Lee 2008 8 | This file contains object search algorithms for graph. 9 | ---------------------------------------------------------------------------- */ 10 | #ifndef objectsearch_defined 11 | #define objectsearch_defined 12 | 13 | #include "collection.h" 14 | class Graph; 15 | class NodeMapping; 16 | 17 | #define MAXQUERY 10 18 | 19 | class ObjectSearchResult 20 | { 21 | public: 22 | const int m_nid; 23 | const float m_cost; 24 | Array m_path; 25 | Array m_objects; 26 | public: 27 | ObjectSearchResult(const int a_nid, const float a_cost): 28 | m_nid(a_nid), m_cost(a_cost) 29 | { m_path.append((void*)m_nid); }; 30 | ObjectSearchResult(const int a_nid, const Array& a_path, const float a_cost): 31 | m_nid(a_nid), m_path(a_path), m_cost(a_cost) 32 | { m_path.append((void*)m_nid); }; 33 | ~ObjectSearchResult() 34 | { m_path.clean(); }; 35 | void addObjects(const Array& a_objs) 36 | { 37 | for (int i=0; im_cost < r1->m_cost) return -1; 45 | if (r0->m_cost > r1->m_cost) return +1; 46 | return 0; 47 | } 48 | }; 49 | 50 | class GroupObjectSearchResult 51 | { 52 | public: 53 | const int m_oid; 54 | int m_nid; 55 | float m_cost[MAXQUERY]; 56 | Array m_path[MAXQUERY]; 57 | public: 58 | GroupObjectSearchResult(const int a_nid, const int a_oid, const int a_cnt): 59 | m_nid(a_nid), m_oid(a_oid) 60 | { 61 | for (int i=0; i m_cost[i] ? ret : m_cost[i]; 73 | } 74 | return ret; 75 | }; 76 | bool allreached(const int a_cnt) const 77 | { 78 | for (int i=0; isumcost(); 87 | float dist1 = r1->sumcost(); 88 | if (dist0 < dist1) return -1; 89 | if (dist0 > dist1) return +1; 90 | if (r0->m_oid < r1->m_oid) return -1; 91 | if (r0->m_oid > r1->m_oid) return +1; 92 | return 0; 93 | }; 94 | }; 95 | 96 | class ObjectSearch 97 | { 98 | public: 99 | // ------------------------------------------------------------------------ 100 | // single-point range search 101 | // ------------------------------------------------------------------------ 102 | static void rangeSearch( 103 | Graph& a_graph, NodeMapping& a_map, 104 | const int a_src, const float a_range, 105 | Array& a_result, int& a_nodeaccess, int& a_edgeaccess); 106 | 107 | // ------------------------------------------------------------------------ 108 | // single-point kNN search 109 | // ------------------------------------------------------------------------ 110 | static void kNNSearch( 111 | Graph& a_graph, NodeMapping& a_map, 112 | const int a_src, const int k, 113 | Array& a_result,int& nodeaccess, int& edgeaccess); 114 | static void kNNSearch( 115 | Graph& a_graph, NodeMapping& a_map, 116 | const int a_src, const int k, 117 | Array& a_result,int& nodeaccess, int& edgeaccess, 118 | Array& a_access); 119 | 120 | // ------------------------------------------------------------------------ 121 | // multi-point range search 122 | // ------------------------------------------------------------------------ 123 | static void groupRangeSearch( 124 | Graph& a_graph, NodeMapping& a_map, 125 | const int* a_src, const float* a_range, 126 | const int a_cnt, 127 | Array& a_result, int& a_nodeaccess, int& a_edgeaccess); 128 | 129 | // ------------------------------------------------------------------------ 130 | // multi-point kNN search 131 | // ------------------------------------------------------------------------ 132 | static void groupKNNSearch( 133 | Graph& a_graph, NodeMapping& a_map, 134 | const int* a_src, const int a_cnt, 135 | const int a_k, 136 | Array& a_result, int& a_nodeaccess, int& a_edgeaccess); 137 | static void groupKNNSearch( 138 | Graph& a_graph, NodeMapping& a_map, 139 | const int* a_src, const int a_cnt, 140 | const int a_k, 141 | Array& a_result, int& a_nodeaccess, int& a_edgeaccess, 142 | Array& a_visited); 143 | }; 144 | 145 | #endif 146 | 147 | 148 | -------------------------------------------------------------------------------- /src/road/distidxloader.cc: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | Author: Ken C. K. Lee 3 | Email: cklee@cse.psu.edu 4 | Web: http://www.cse.psu.edu/~cklee 5 | Date: Jan, 2008 6 | 7 | Copyright(c) Ken C. K. Lee 2008 8 | This program is for non-commerical use only. 9 | 10 | This program builds a distance index. 11 | 12 | Suggested arguments: 13 | > (prog name) -i graph.idx -o object.dat -d dist.idx -v 14 | explanations: 15 | -i: graph index file (input) 16 | -o: object file 17 | -d: distance index 18 | -v: turn verbose mode on (default: off) 19 | ---------------------------------------------------------------------------- */ 20 | 21 | #include "graph.h" 22 | #include "segfmem.h" 23 | #include "param.h" 24 | #include "collection.h" 25 | #include "distsign.h" 26 | #include "distidx.h" 27 | #include "distidxsearch.h" 28 | #include "graphsearch.h" 29 | #include "access.h" 30 | #include "iomeasure.h" 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | using namespace std; 39 | 40 | #define PAGESIZE 4096 41 | 42 | void helpmsg(const char* pgm) 43 | { 44 | cerr << "Suggested arguments:" << endl; 45 | cerr << "> " << pgm << " "; 46 | cerr << "-h graph.idx -o object.dat -d dist.idx -v" << endl; 47 | cerr << "explanations:" << endl; 48 | cerr << "-i: graph index file" << endl; 49 | cerr << "-o: object file" << endl; 50 | cerr << "-d: distance index" << endl; 51 | cerr << "-v: turn verbose mode on (default: off)" << endl; 52 | } 53 | 54 | int main(const int a_argc, const char** a_argv) 55 | { 56 | if (a_argc == 1) 57 | { 58 | helpmsg(a_argv[0]); 59 | return -1; 60 | } 61 | 62 | cerr << "build distance index" << endl; 63 | //------------------------------------------------------------------------- 64 | // initialization 65 | //------------------------------------------------------------------------- 66 | const char* idxflname = Param::read(a_argc, a_argv, "-i", ""); 67 | const char* objflname = Param::read(a_argc, a_argv, "-o", ""); 68 | const char* didxflname= Param::read(a_argc, a_argv, "-d", ""); 69 | const char* vrbs = Param::read(a_argc, a_argv, "-v", "null"); 70 | bool verbose = strcmp(vrbs,"null") != 0; 71 | 72 | //------------------------------------------------------------------------- 73 | // access graph index file 74 | //------------------------------------------------------------------------- 75 | cerr << "loading a graph index ... "; 76 | SegFMemory segmem(idxflname, PAGESIZE*10, PAGESIZE, 32, false); 77 | Graph graph(segmem); 78 | cerr << "[DONE]" << endl; 79 | 80 | //------------------------------------------------------------------------- 81 | // access object file and create distance index 82 | //------------------------------------------------------------------------- 83 | cerr << "loading objects ... "; 84 | struct timeb starttime, endtime; 85 | float idxtime=0; 86 | int numobj=0; 87 | int numnodes=0; 88 | 89 | Hash nodedistsign; // keep distance signatures as an array for each node 90 | Array nodes; // keep node ids 91 | fstream fobj; 92 | fobj.open(objflname, ios::in); 93 | ftime(&starttime); // time the the object index creation 94 | 95 | while (true) 96 | { 97 | int nodeid, objid; 98 | fobj >> nodeid; 99 | if (fobj.eof()) 100 | break; 101 | fobj >> objid; 102 | 103 | // find object distance to every node 104 | segmem.m_history.clean(); 105 | Array toAllNodes(graph.m_nodes.size()); 106 | GraphSearch::spanSearch(graph, nodeid, toAllNodes); 107 | for (int i=0; im_nid; 111 | int prev= (long)res->m_path.get(0); 112 | float cost = res->m_cost; 113 | 114 | Array* a = (Array*)nodedistsign.get(nid); 115 | if (a == 0) 116 | { 117 | nodedistsign.put(nid, a = new Array); 118 | nodes.append((void*)nid); 119 | } 120 | a->append(new DistSignature(objid, cost, prev)); 121 | delete res; // clean up 122 | } 123 | toAllNodes.clean(); 124 | 125 | numobj++; 126 | } 127 | ftime(&endtime); // time the the object index creation 128 | idxtime = 129 | ((endtime.time*1000 + endtime.millitm) - 130 | (starttime.time*1000 + starttime.millitm)) / 1000.0f; 131 | cerr << "[DONE]" << endl; 132 | 133 | //------------------------------------------------------------------------- 134 | // write distance index to memory 135 | //------------------------------------------------------------------------- 136 | SegFMemory segfmem(didxflname, PAGESIZE*10, PAGESIZE, 32, true); 137 | DistIndex didx(segfmem); 138 | for (int i=0; i (prog name) -n nodefile.txt -e edgefile.txt -i graph.idx -v 14 | explanations: 15 | -n: node file 16 | -e: edge file 17 | -i: graph index file 18 | -v: turn verbose mode on (default: off) 19 | ---------------------------------------------------------------------------- */ 20 | #include "graph.h" 21 | #include "node.h" 22 | #include "edge.h" 23 | #include "param.h" 24 | #include "segfmem.h" 25 | #include "collection.h" 26 | #include 27 | #include 28 | 29 | using namespace std; 30 | 31 | #define MAXNODES 100000 32 | #define PAGESIZE 4096 // 4KB page 33 | 34 | void helpmsg(const char* pgm) 35 | { 36 | cerr << "Suggested arguments:" << endl; 37 | cerr << "> " << pgm << " "; 38 | cerr << "-n nodefile.txt -e edgefile.txt -i graph.idx -v" << endl; 39 | cerr << "explanations:" << endl; 40 | cerr << "-n: node file" << endl; 41 | cerr << " format: nodeID x y " << endl; 42 | cerr << "-e: edge file" << endl; 43 | cerr << " format: src_nodeID dest_nodeID cost" << endl; 44 | cerr << "-i: graph index file (output" << endl; 45 | cerr << "-v: turn verbose mode on (default: off)" << endl; 46 | } 47 | 48 | int main(const int a_argc, const char** a_argv) 49 | { 50 | if (a_argc == 1) 51 | { 52 | helpmsg(a_argv[0]); 53 | return -1; 54 | } 55 | 56 | cerr << "graph loader" << endl; 57 | //------------------------------------------------------------------------- 58 | // initialization 59 | //------------------------------------------------------------------------- 60 | const char* nodeflname = Param::read(a_argc, a_argv, "-n", ""); 61 | const char* edgeflname = Param::read(a_argc, a_argv, "-e", ""); 62 | const char* idxflname = Param::read(a_argc, a_argv, "-i", ""); 63 | const char* vrbs = Param::read(a_argc, a_argv, "-v", "null"); 64 | bool verbose = strcmp(vrbs,"null") != 0; 65 | fstream fnode, fedge; 66 | 67 | Node** node = new Node*[MAXNODES]; 68 | memset(node, 0, sizeof(Node*)*MAXNODES); 69 | int nodecnt=0; 70 | 71 | //------------------------------------------------------------------------- 72 | // loading nodes and edges 73 | //------------------------------------------------------------------------- 74 | cerr << "loading nodes ... "; 75 | fnode.open(nodeflname, ios::in); 76 | while (true) 77 | { 78 | int id; 79 | float x,y; 80 | fnode >> id; 81 | if (fnode.eof()) 82 | break; 83 | 84 | fnode >> x; 85 | fnode >> y; 86 | 87 | node[id] = new Node(id,x,y); 88 | nodecnt = nodecnt > id ? nodecnt : id; 89 | } 90 | cerr << "done" << endl; 91 | 92 | cerr << "loading edges ... "; 93 | fedge.open(edgeflname, ios::in); 94 | while (true) 95 | { 96 | int id; 97 | int src, dest; 98 | float cost; 99 | fedge >> id; 100 | if (fedge.eof()) 101 | break; 102 | fedge >> src; 103 | fedge >> dest; 104 | fedge >> cost; 105 | Edge edge2dest(dest, cost); 106 | Edge edge2src(src, cost); 107 | node[src]->addEdge(edge2dest); 108 | node[dest]->addEdge(edge2src); 109 | } 110 | cerr << "done" << endl; 111 | 112 | fnode.close(); 113 | fedge.close(); 114 | 115 | //------------------------------------------------------------------------- 116 | // insert nodes to graph 117 | //------------------------------------------------------------------------- 118 | cerr << "create a graph ... "; 119 | SegFMemory segmem(idxflname,PAGESIZE*10,PAGESIZE,32,true); // 10 pages, 1 page 120 | Graph graph(segmem); 121 | for (int i=0; i<=nodecnt; i++) 122 | { 123 | if (node[i] != 0 && node[i]->m_edges.size() > 0) 124 | graph.writeNode(node[i]->m_id,*node[i]); 125 | } 126 | cerr << "done" << endl; 127 | 128 | //------------------------------------------------------------------------- 129 | // testing 130 | //------------------------------------------------------------------------- 131 | cerr << "testing ... "; 132 | for (int i=0; i<=nodecnt; i++) 133 | { 134 | if (node[i] == 0) continue; 135 | 136 | Node* m = graph.getNode(node[i]->m_id); 137 | if (m->m_id != node[i]->m_id) 138 | { 139 | cerr << "fail in node " << m->m_id << endl; 140 | return -1; 141 | } 142 | if (m->m_edges.size() != node[i]->m_edges.size()) 143 | { 144 | cerr << "fail in #edges " << endl; 145 | return -1; 146 | } 147 | for (int c1=0; c1m_edges.size(); c1++) 148 | { 149 | int found = 0; 150 | const Edge* e1 = (const Edge*)m->m_edges.get(c1); 151 | for (int c2=0; c2m_edges.size(); c2++) 152 | { 153 | const Edge* e2 = (const Edge*)node[i]->m_edges.get(c2); 154 | if (e1->m_neighbor == e2->m_neighbor && 155 | e1->m_cost == e2->m_cost) 156 | found = 1; 157 | } 158 | if (found != 1) 159 | { 160 | cerr << "fail in edge content" << endl; 161 | return -1; 162 | } 163 | } 164 | delete m; 165 | } 166 | cerr << "done" << endl; 167 | 168 | cerr << "complete!" << endl; 169 | 170 | return 0; 171 | } 172 | 173 | -------------------------------------------------------------------------------- /src/road/hiergraphloader.cc: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | Author: Ken C. K. Lee 3 | Email: cklee@cse.psu.edu 4 | Web: http://www.cse.psu.edu/~cklee 5 | Date: Jan, 2008 6 | 7 | Copyright(c) Ken C. K. Lee 2008 8 | This program is for non-commerical use only. 9 | 10 | This program 11 | * performs graph partitioning and 12 | * outputs a hierarchical graph. 13 | 14 | Suggested arguments: 15 | > (prog name) -n nodefile.txt -e edgefile.txt -t div -l level -h graph.idx -v 16 | explanations: 17 | -n: node file 18 | -e: edge file 19 | -t: division factor 20 | -l: the number of hierarchical levels 21 | -h: hiergraph index file (output) 22 | -v: turn verbose mode on (default: off) 23 | ---------------------------------------------------------------------------- */ 24 | #include "hiergraph.h" 25 | #include "node.h" 26 | #include "edge.h" 27 | #include "segfmem.h" 28 | #include "segmmem.h" 29 | #include "hiergraph.h" 30 | #include "graphpartition.h" 31 | #include "param.h" 32 | #include "collection.h" 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | using namespace std; 41 | 42 | #define MAXNODES 100000 43 | #define PAGESIZE 4096 // 4KB per page 44 | 45 | void helpmsg(const char* pgm) 46 | { 47 | cerr << "Suggested arguments:" << endl; 48 | cerr << "> " << pgm << " "; 49 | cerr << "-n nodefile.txt -e edgefile.txt -t div -l level -h hiergraph.idx -v" << endl; 50 | cerr << "explanations:" << endl; 51 | cerr << "-n: node file" << endl; 52 | cerr << " format: nodeID x y " << endl; 53 | cerr << "-e: edge file" << endl; 54 | cerr << " format: src_nodeID dest_nodeID cost" << endl; 55 | cerr << "-t: division factor" << endl; 56 | cerr << "-l: level (number of hierarchical levels)" << endl; 57 | cerr << "-h: hiergraph index file (output)" << endl; 58 | cerr << "-v: turn verbose mode on (default: off)" << endl; 59 | } 60 | 61 | int main(const int a_argc, const char** a_argv) 62 | { 63 | if (a_argc == 1) 64 | { 65 | helpmsg(a_argv[0]); 66 | return -1; 67 | } 68 | 69 | cerr << "hierarchical graph loader" << endl; 70 | //------------------------------------------------------------------------- 71 | // initialization 72 | //------------------------------------------------------------------------- 73 | const char* nodeflname = Param::read(a_argc, a_argv, "-n", ""); 74 | const char* edgeflname = Param::read(a_argc, a_argv, "-e", ""); 75 | const char* div = Param::read(a_argc, a_argv, "-t", ""); 76 | const char* level = Param::read(a_argc, a_argv, "-l", ""); 77 | const char* idxflname = Param::read(a_argc, a_argv, "-h", ""); 78 | const char* vrbs = Param::read(a_argc, a_argv, "-v", "null"); 79 | bool verbose = strcmp(vrbs,"null") != 0; 80 | fstream fnode, fedge; 81 | 82 | Hash nodes(MAXNODES); 83 | 84 | //------------------------------------------------------------------------- 85 | // loading nodes and edges 86 | //------------------------------------------------------------------------- 87 | cerr << "loading nodes ... "; 88 | fnode.open(nodeflname, ios::in); 89 | while (true) 90 | { 91 | int id; 92 | float x,y; 93 | fnode >> id; 94 | if (fnode.eof()) 95 | break; 96 | 97 | fnode >> x; 98 | fnode >> y; 99 | 100 | nodes.put(id, new Node(id, x,y)); 101 | } 102 | cerr << "[DONE]" << endl; 103 | 104 | cerr << "loading edges ... "; 105 | fedge.open(edgeflname, ios::in); 106 | while (true) 107 | { 108 | int id; 109 | int src, dest; 110 | float cost; 111 | fedge >> id; 112 | if (fedge.eof()) 113 | break; 114 | fedge >> src; 115 | fedge >> dest; 116 | fedge >> cost; 117 | Edge edge2dest(dest, cost); 118 | 119 | Node* srcnode = (Node*)nodes.get(src); 120 | srcnode->addEdge(edge2dest); 121 | 122 | // for directed graph 123 | // Edge edge2src(src, cost); 124 | // Node* destnode = (Node*)nodes.get(dest); 125 | // destnode->addEdge(edge2src); 126 | } 127 | cerr << "[DONE]" << endl; 128 | 129 | fnode.close(); 130 | fedge.close(); 131 | 132 | //------------------------------------------------------------------------- 133 | // access graph index file 134 | //------------------------------------------------------------------------- 135 | SegFMemory hiergraphmem(idxflname, PAGESIZE*10, PAGESIZE, 24, true); 136 | HierGraph hiergraph(hiergraphmem); 137 | 138 | //------------------------------------------------------------------------- 139 | // partition the graph and result in hierarchical graph 140 | //------------------------------------------------------------------------- 141 | cerr << "partition a graph ..." << endl; 142 | struct timeb starttime, endtime; 143 | Array path; 144 | float dist=0; 145 | float totalbuildtime, parttime, shorttime; 146 | ftime(&starttime); // time the algorithm 147 | // graph partitioning 148 | GraphPartition::geoPartition(nodes, atol(div), atol(level), hiergraph, parttime, shorttime); 149 | 150 | ftime(&endtime); 151 | totalbuildtime = 152 | ((endtime.time*1000 + endtime.millitm) - 153 | (starttime.time*1000 + starttime.millitm)) / 1000.0f; 154 | cerr << "[DONE]" << endl; 155 | 156 | // ------------------------------------------------------------------------ 157 | // clean up 158 | // ------------------------------------------------------------------------ 159 | for (HashReader rdr(nodes); !rdr.isEnd(); rdr.next()) 160 | delete (Node*)rdr.getVal(); 161 | 162 | cout << "partitiontime:," << parttime; 163 | cout << ",shortcuttime:," << shorttime; 164 | cout << ",totalbuildtime:" << totalbuildtime << endl; 165 | 166 | return 0; 167 | } 168 | -------------------------------------------------------------------------------- /src/road/distbrwsrange.cc: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | Author: Ken C. K. Lee 3 | Email: cklee@cse.psu.edu 4 | Web: http://www.cse.psu.edu/~cklee 5 | Date: Nov, 2008 6 | 7 | Copyright(c) Ken C. K. Lee 2008 8 | This program is for non-commerical use only. 9 | 10 | This program performs range search based on distance browsing index. 11 | 12 | Suggested arguments: 13 | > (prog name) -i graph.idx -o object.dat -s query.dat -x distbrws.idx -r range -v 14 | explanations: 15 | -i: graph index file (input) 16 | -o: object.dat 17 | -s: query.dat 18 | -x: distbrws.idx 19 | -r: range 20 | -v: turn verbose mode on (default: off) 21 | ---------------------------------------------------------------------------- */ 22 | 23 | #include "graph.h" 24 | #include "node.h" 25 | #include "segfmem.h" 26 | #include "param.h" 27 | #include "collection.h" 28 | #include "spqdtree.h" 29 | #include "spqdtreerec.h" 30 | #include "graphsearch.h" 31 | #include "distbrws.h" 32 | #include "distbrwssearch.h" 33 | #include "access.h" 34 | #include "iomeasure.h" 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | using namespace std; 41 | 42 | #define PAGESIZE 4096 43 | #define INFTY 1e10 44 | 45 | void helpmsg(const char* pgm) 46 | { 47 | cerr << "Suggested arguments:" << endl; 48 | cerr << "> " << pgm << " "; 49 | cerr << "-i graph.idx -o object.dat -s query.dat -x quadtrees.idx -k #NNs -v" << endl; 50 | cerr << "explanations:" << endl; 51 | cerr << "-i: graph index file" << endl; 52 | cerr << "-o: object file" << endl; 53 | cerr << "-s: query file" << endl; 54 | cerr << "-x: quadtrees" << endl; 55 | cerr << "-r: range" << endl; 56 | cerr << "-v: turn verbose mode on (default: off)" << endl; 57 | } 58 | 59 | int main(const int a_argc, const char** a_argv) 60 | { 61 | if (a_argc == 1) 62 | { 63 | helpmsg(a_argv[0]); 64 | return -1; 65 | } 66 | 67 | cerr << "build distance browsing index" << endl; 68 | //------------------------------------------------------------------------- 69 | // initialization 70 | //------------------------------------------------------------------------- 71 | const char* idxflname = Param::read(a_argc, a_argv, "-i", ""); 72 | const char* objflname = Param::read(a_argc, a_argv, "-o", ""); 73 | const char* qryflname = Param::read(a_argc, a_argv, "-q", ""); 74 | const char* dbrwsflname= Param::read(a_argc, a_argv, "-x", ""); 75 | const float r = (float)atof(Param::read(a_argc, a_argv, "-r", "")); 76 | const char* vrbs = Param::read(a_argc, a_argv, "-v", "null"); 77 | bool verbose = strcmp(vrbs,"null") != 0; 78 | 79 | //------------------------------------------------------------------------- 80 | // access graph index file 81 | //------------------------------------------------------------------------- 82 | cerr << "loading a graph index ... "; 83 | SegFMemory segmem(idxflname, PAGESIZE*10, PAGESIZE, 32, false); 84 | Graph graph(segmem); 85 | cerr << "[DONE]" << endl; 86 | 87 | //------------------------------------------------------------------------- 88 | // determine the area covered by the graph 89 | //------------------------------------------------------------------------- 90 | Array nodeidlist; // used to collect a sorted node id list 91 | float min[2], max[2]; 92 | min[0] = min[1] = INFTY; 93 | max[0] = max[1] = -INFTY; 94 | for (HashReader r(graph.m_nodes); !r.isEnd(); r.next()) 95 | { 96 | int nodeid = r.getKey(); 97 | Node* node = (Node*)graph.getNode(nodeid); 98 | min[0] = min[0] < node->m_x ? min[0] : node->m_x; 99 | min[1] = min[1] < node->m_y ? min[1] : node->m_y; 100 | max[0] = max[0] > node->m_x ? max[0] : node->m_x; 101 | max[1] = max[1] > node->m_y ? max[1] : node->m_y; 102 | nodeidlist.append((void*)nodeid); 103 | } 104 | Point ptl(2,min), ptu(2,max); 105 | Bound area(ptl, ptu); 106 | 107 | //------------------------------------------------------------------------- 108 | // load all objects 109 | //------------------------------------------------------------------------- 110 | Array nodeobj; 111 | fstream fobject; 112 | fobject.open(objflname, ios::in); 113 | while (true) 114 | { 115 | int nodeid; 116 | int objid; 117 | fobject >> nodeid; 118 | if (fobject.eof()) 119 | break; 120 | fobject >> objid; 121 | nodeobj.append((void*)nodeid); 122 | } 123 | fobject.close(); 124 | 125 | //------------------------------------------------------------------------- 126 | // load the distance browsing index 127 | //------------------------------------------------------------------------- 128 | SegFMemory segfmem(dbrwsflname, PAGESIZE*10, PAGESIZE, 32, false); 129 | DistBrws distbrws(segfmem); 130 | 131 | //------------------------------------------------------------------------- 132 | // find all query locations as sources 133 | //------------------------------------------------------------------------- 134 | struct timeb starttime, endtime; 135 | float querytime=0; 136 | 137 | cerr << "processing the query ... "; 138 | fstream fquery; 139 | fquery.open(qryflname, ios::in); 140 | while (true) 141 | { 142 | int nodeid; 143 | int qryid; 144 | fquery >> nodeid; 145 | if (fquery.eof()) 146 | break; 147 | fquery >> qryid; 148 | 149 | int nodeaccess=0; 150 | int edgeaccess=0; 151 | Array result; 152 | 153 | ftime(&starttime); // time the the distance browsing query 154 | DistBrwsSearch::rangeSearch( 155 | graph, 156 | distbrws, area, 157 | nodeobj, nodeid, r, 158 | result, 159 | nodeaccess, edgeaccess); 160 | ftime(&endtime); // time the the distance browsing query 161 | querytime += 162 | ((endtime.time*1000 + endtime.millitm) - 163 | (starttime.time*1000 + starttime.millitm)) / 1000.0f; 164 | 165 | for (int i=0; i (prog name) -i graph.idx -o object.dat -q query.dat -x distbrws.idx -k #NNs -v 14 | explanations: 15 | -i: graph index file (input) 16 | -o: object.dat 17 | -q: query.dat 18 | -x: distbrws.idx 19 | -k: #NNs 20 | -v: turn verbose mode on (default: off) 21 | ---------------------------------------------------------------------------- */ 22 | 23 | #include "graph.h" 24 | #include "node.h" 25 | #include "segfmem.h" 26 | #include "param.h" 27 | #include "collection.h" 28 | #include "spqdtree.h" 29 | #include "spqdtreerec.h" 30 | #include "graphsearch.h" 31 | #include "distbrws.h" 32 | #include "distbrwssearch.h" 33 | #include "access.h" 34 | #include "iomeasure.h" 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | using namespace std; 44 | 45 | #define PAGESIZE 4096 46 | #define INFTY 1e10 47 | 48 | void helpmsg(const char* pgm) 49 | { 50 | cerr << "Suggested arguments:" << endl; 51 | cerr << "> " << pgm << " "; 52 | cerr << "-i graph.idx -o object.dat -q query.dat -x quadtrees.idx -k #NNs -v" << endl; 53 | cerr << "explanations:" << endl; 54 | cerr << "-i: graph index file" << endl; 55 | cerr << "-o: object file" << endl; 56 | cerr << "-q: query file" << endl; 57 | cerr << "-x: quadtrees" << endl; 58 | cerr << "-k: #NNs" << endl; 59 | cerr << "-v: turn verbose mode on (default: off)" << endl; 60 | } 61 | 62 | int main(const int a_argc, const char** a_argv) 63 | { 64 | if (a_argc == 1) 65 | { 66 | helpmsg(a_argv[0]); 67 | return -1; 68 | } 69 | 70 | cerr << "build distance browsing index" << endl; 71 | //------------------------------------------------------------------------- 72 | // initialization 73 | //------------------------------------------------------------------------- 74 | const char* idxflname = Param::read(a_argc, a_argv, "-i", ""); 75 | const char* objflname = Param::read(a_argc, a_argv, "-o", ""); 76 | const char* qryflname = Param::read(a_argc, a_argv, "-q", ""); 77 | const char* dbrwsflname= Param::read(a_argc, a_argv, "-x", ""); 78 | const int k = atol(Param::read(a_argc, a_argv, "-k", "")); 79 | const char* vrbs = Param::read(a_argc, a_argv, "-v", "null"); 80 | bool verbose = strcmp(vrbs,"null") != 0; 81 | 82 | //------------------------------------------------------------------------- 83 | // access graph index file 84 | //------------------------------------------------------------------------- 85 | cerr << "loading a graph index ... "; 86 | SegFMemory segmem(idxflname, PAGESIZE*10, PAGESIZE, 32, false); 87 | Graph graph(segmem); 88 | cerr << "[DONE]" << endl; 89 | 90 | //------------------------------------------------------------------------- 91 | // determine the area covered by the graph 92 | //------------------------------------------------------------------------- 93 | Array nodeidlist; // used to collect a sorted node id list 94 | float min[2], max[2]; 95 | min[0] = min[1] = INFTY; 96 | max[0] = max[1] = -INFTY; 97 | for (HashReader r(graph.m_nodes); !r.isEnd(); r.next()) 98 | { 99 | int nodeid = r.getKey(); 100 | Node* node = (Node*)graph.getNode(nodeid); 101 | min[0] = min[0] < node->m_x ? min[0] : node->m_x; 102 | min[1] = min[1] < node->m_y ? min[1] : node->m_y; 103 | max[0] = max[0] > node->m_x ? max[0] : node->m_x; 104 | max[1] = max[1] > node->m_y ? max[1] : node->m_y; 105 | nodeidlist.append((void*)nodeid); 106 | } 107 | Point ptl(2,min), ptu(2,max); 108 | Bound area(ptl, ptu); 109 | 110 | //------------------------------------------------------------------------- 111 | // load all objects 112 | //------------------------------------------------------------------------- 113 | Array nodeobj; 114 | fstream fobject; 115 | fobject.open(objflname, ios::in); 116 | while (true) 117 | { 118 | int nodeid; 119 | int objid; 120 | fobject >> nodeid; 121 | if (fobject.eof()) 122 | break; 123 | fobject >> objid; 124 | nodeobj.append((void*)nodeid); 125 | } 126 | fobject.close(); 127 | 128 | //------------------------------------------------------------------------- 129 | // load the distance browsing index 130 | //------------------------------------------------------------------------- 131 | SegFMemory segfmem(dbrwsflname, PAGESIZE*10, PAGESIZE, 32, false); 132 | DistBrws distbrws(segfmem); 133 | 134 | //------------------------------------------------------------------------- 135 | // find all query locations as sources 136 | //------------------------------------------------------------------------- 137 | struct timeb starttime, endtime; 138 | float querytime=0; 139 | 140 | cerr << "processing the query ... "; 141 | fstream fquery; 142 | fquery.open(qryflname, ios::in); 143 | 144 | while (true) 145 | { 146 | int nodeid; 147 | int qryid; 148 | fquery >> nodeid; 149 | if (fquery.eof()) 150 | break; 151 | fquery >> qryid; 152 | 153 | printf("%d %d\n", nodeid, qryid); 154 | 155 | int nodeaccess=0; 156 | int edgeaccess=0; 157 | Array result; 158 | 159 | ftime(&starttime); // time the the distance browsing query 160 | DistBrwsSearch::nnSearch( 161 | graph, 162 | distbrws, area, 163 | nodeobj, nodeid, k, 164 | result, 165 | nodeaccess, edgeaccess); 166 | ftime(&endtime); // time the the distance browsing query 167 | querytime += 168 | ((endtime.time*1000 + endtime.millitm) - 169 | (starttime.time*1000 + starttime.millitm)) / 1000.0f; 170 | 171 | for (int i=0; i 11 | #include 12 | 13 | using namespace std; 14 | 15 | SPQuadtreeNode::SPQuadtreeNode(const int a_level, 16 | const Bound& a_bound, 17 | const int a_firstnode, 18 | const float a_mindist): 19 | m_level(a_level), m_bound(a_bound), m_firstnode(a_firstnode), m_mindist(a_mindist), 20 | m_numchild(0), m_child(0) 21 | {} 22 | 23 | SPQuadtreeNode::~SPQuadtreeNode() 24 | { 25 | // ------------------------------------------------------------------------ 26 | // delete all objects 27 | // ------------------------------------------------------------------------ 28 | for (int i=0; i 0) 35 | { 36 | for (int i=0; im_bound.contain(rec->m_point)) 114 | { 115 | m_child[j]->addRec(rec); 116 | break; 117 | } 118 | } 119 | } 120 | m_recs.clean(); 121 | m_firstnode = -1; 122 | m_mindist = INFTY; 123 | } 124 | 125 | // object manipulation 126 | int SPQuadtreeNode::numRec() const 127 | { 128 | return m_recs.size(); 129 | } 130 | 131 | int SPQuadtreeNode::addRec(SPQuadtreeRec* a_obj) 132 | { 133 | // ------------------------------------------------------------------------ 134 | // update the node info (first node to reach this area and mindist) 135 | // ------------------------------------------------------------------------ 136 | m_firstnode = a_obj->m_firstnode; 137 | m_mindist = m_mindist < a_obj->m_pathlen ? m_mindist : a_obj->m_pathlen; 138 | 139 | return m_recs.append(a_obj); 140 | } 141 | 142 | SPQuadtreeRec* SPQuadtreeNode::getRec(const int a_i) 143 | { 144 | return (SPQuadtreeRec*)m_recs.get(a_i); 145 | } 146 | 147 | void SPQuadtreeNode::removeAllRec() 148 | { 149 | for (int i=0; i 10) 157 | { 158 | int debug=10; 159 | } 160 | 161 | if (m_firstnode == -1) return; 162 | 163 | for (int i=0; im_bound.m_lower[d]; 176 | cout << ","; 177 | cout << m_child[i]->m_bound.m_upper[d]; 178 | cout << ")-"; 179 | } 180 | cout << endl; 181 | } 182 | */ 183 | 184 | } 185 | 186 | bool SPQuadtreeNode::operator==(const SPQuadtreeNode& a_node) const 187 | { 188 | if (m_level != a_node.m_level) return false; 189 | if (m_firstnode != a_node.m_firstnode) return false; 190 | if (m_mindist != a_node.m_mindist) return false; 191 | if (m_numchild != a_node.m_numchild) return false; 192 | 193 | for (int i=0; i 0) 208 | sz += m_recs.size() * ((SPQuadtreeRec*)m_recs.get(0))->size(); 209 | return sz; 210 | } 211 | -------------------------------------------------------------------------------- /src/road/distbrwssearch.cc: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | Author: Ken C. K. Lee 3 | Email: cklee@cse.psu.edu 4 | Web: http://www.cse.psu.edu/~cklee 5 | Date: Nov, 2008 6 | -----------------------------------------------------------------------------*/ 7 | #include "distbrwssearch.h" 8 | #include "graph.h" 9 | #include "node.h" 10 | #include "distbrws.h" 11 | #include "spqdtree.h" 12 | #include "bound.h" 13 | #include "point.h" 14 | #include 15 | 16 | class nodeobj 17 | { 18 | public: 19 | const int m_objid; // object id 20 | const int m_nodeid; // node id (that contains the object) 21 | const Point m_pt; // coordinate of the node 22 | float m_accdist; // accumulated distance 23 | float m_preddist; // predicted distance (remainder part) 24 | int m_nextnode; // next node to be visited 25 | Array m_path; // path towards the objects 26 | public: 27 | nodeobj( 28 | const int a_objid, const int a_nodeid, 29 | const Point& a_pt, 30 | const float a_accdist, const float a_preddist, 31 | const int a_nextnode): 32 | m_objid(a_objid), 33 | m_nodeid(a_nodeid), 34 | m_pt(a_pt), 35 | m_accdist(a_accdist), 36 | m_preddist(a_preddist), 37 | m_nextnode(a_nextnode) 38 | {}; 39 | ~nodeobj(){}; 40 | static int compare(const void* a0, const void* a1) 41 | { 42 | nodeobj* no0 = *(nodeobj**)a0; 43 | nodeobj* no1 = *(nodeobj**)a1; 44 | const float dist0 = no0->m_accdist + no0->m_preddist; 45 | const float dist1 = no1->m_accdist + no1->m_preddist; 46 | if (dist0 < dist1) return -1; 47 | if (dist0 > dist1) return +1; 48 | if (no0->m_nextnode < no1->m_nextnode) return -1; 49 | if (no0->m_nextnode > no1->m_nextnode) return +1; 50 | if (no0->m_objid < no1->m_objid) return -1; 51 | if (no0->m_objid > no1->m_objid) return +1; 52 | return 0; 53 | }; 54 | }; 55 | 56 | void DistBrwsSearch::rangeSearch(Graph &a_graph, 57 | DistBrws &a_distbrws, const Bound& a_bound, 58 | const Array& a_nodes, 59 | const int a_src, const float a_range, 60 | Array &a_result, 61 | int &a_nodeaccess, int &a_edgeaccess) 62 | { 63 | Queue q; 64 | 65 | SPQuadtree* tree = a_distbrws.getNode(a_src, a_bound); 66 | for (int i=0; im_x; 72 | p[1] = node->m_y; 73 | Point pt(2,p); 74 | const int nextnode = tree->next(pt); 75 | const float preddist = tree->mindist(pt); 76 | q.enqueue(new nodeobj(i, nodeid, pt, 0, preddist, nextnode)); 77 | delete node; 78 | } 79 | delete tree; 80 | 81 | while (!q.isEmpty()) 82 | { 83 | nodeobj* no = (nodeobj*)q.dequeue(); 84 | 85 | //--------------------------------------------------------------------- 86 | // clean up 87 | //--------------------------------------------------------------------- 88 | if (no->m_accdist + no->m_preddist >= a_range) 89 | { 90 | delete no; 91 | continue; 92 | } 93 | 94 | 95 | //--------------------------------------------------------------------- 96 | // exploring the path towards the object 97 | //--------------------------------------------------------------------- 98 | if (no->m_nextnode == no->m_nodeid) 99 | { 100 | // found the result objects 101 | ObjectSearchResult* res = 102 | new ObjectSearchResult(no->m_nodeid, no->m_path, no->m_accdist); 103 | res->m_objects.append((void*)no->m_objid); 104 | a_result.append((void*)res); 105 | delete no; 106 | } 107 | else 108 | { 109 | Node* node = a_graph.getNode(no->m_nextnode); 110 | SPQuadtree* tree = a_distbrws.getNode(no->m_nextnode, a_bound); 111 | no->m_path.append((void*)no->m_nextnode); 112 | no->m_preddist = tree->mindist(no->m_pt); 113 | no->m_nextnode = tree->next(no->m_pt); 114 | no->m_accdist += node->cost(no->m_nextnode); 115 | 116 | q.enqueue(no); 117 | 118 | delete node; 119 | delete tree; 120 | 121 | a_nodeaccess++; 122 | a_edgeaccess++; 123 | } 124 | } 125 | } 126 | 127 | void DistBrwsSearch::nnSearch(Graph &a_graph, 128 | DistBrws &a_distbrws, const Bound& a_bound, 129 | const Array& nodes, 130 | const int a_src, const int a_k, 131 | Array &a_result, 132 | int &a_nodeaccess, int &a_edgeaccess) 133 | { 134 | 135 | BinHeap h(nodeobj::compare); 136 | 137 | 138 | SPQuadtree* tree = a_distbrws.getNode(a_src, a_bound); 139 | for (int i=0; im_x; 145 | p[1] = node->m_y; 146 | Point pt(2,p); 147 | const int nextnode = tree->next(pt); 148 | const float preddist = tree->mindist(pt); 149 | // printf("no=%d next=%d\n", i, nextnode ); 150 | h.insert(new nodeobj(i, nodeid, pt, 0, preddist, nextnode)); 151 | delete node; 152 | } 153 | delete tree; 154 | 155 | 156 | while (!h.isEmpty()) 157 | { 158 | nodeobj* no = (nodeobj*)h.removeTop(); 159 | 160 | 161 | //--------------------------------------------------------------------- 162 | // clean up 163 | //--------------------------------------------------------------------- 164 | if (a_result.size() >= a_k) 165 | { 166 | delete no; 167 | continue; 168 | } 169 | // printf("%d %d %f %f %d\n", no->m_objid, no->m_nodeid, no->m_accdist, no->m_preddist, no->m_nextnode ); 170 | //--------------------------------------------------------------------- 171 | // exploring the path towards the object 172 | //--------------------------------------------------------------------- 173 | if (no->m_nextnode == no->m_nodeid) 174 | { 175 | // found the result objects 176 | ObjectSearchResult* res = 177 | new ObjectSearchResult(no->m_nodeid, no->m_path, no->m_accdist); 178 | res->m_objects.append((void*)no->m_objid); 179 | a_result.append((void*)res); 180 | delete no; 181 | } 182 | else 183 | { 184 | Node* node = a_graph.getNode(no->m_nextnode); 185 | SPQuadtree* tree = a_distbrws.getNode(no->m_nextnode, a_bound); 186 | no->m_path.append((void*)no->m_nextnode); 187 | no->m_preddist = tree->mindist(no->m_pt); 188 | no->m_nextnode = tree->next(no->m_pt); 189 | no->m_accdist += node->cost(no->m_nextnode); 190 | 191 | h.insert(no); 192 | 193 | delete node; 194 | delete tree; 195 | 196 | a_nodeaccess++; 197 | a_edgeaccess++; 198 | } 199 | } 200 | } 201 | -------------------------------------------------------------------------------- /src/road/hiernn.cc: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | Author: Ken C. K. Lee 3 | Email: cklee@cse.psu.edu 4 | Web: http://www.cse.psu.edu/~cklee 5 | Date: Jan, 2008 6 | 7 | Copyright(c) Ken C. K. Lee 2008 8 | This program is for non-commerical use only. 9 | 10 | This program performs kNN search on objects. 11 | 12 | Suggested arguments: 13 | > (prog name) -h hiergraph.idx -o object.dat -q #queries -k k -v 14 | explanations: 15 | -h: hiergraph index file (input) 16 | -o: object file 17 | -q: number of query 18 | -k: k (# of NNs) 19 | -v: turn verbose mode on (default: off) 20 | 21 | MY TEST:(ONLY THESE TWO PARAMS) 22 | -h: hiergraph index file 23 | -x: FILE_OBJECT 24 | ---------------------------------------------------------------------------- */ 25 | 26 | #include "hiergraph.h" 27 | #include "bordernode.h" 28 | #include "shortcuttreenode.h" 29 | #include "segfmem.h" 30 | #include "param.h" 31 | #include "collection.h" 32 | #include "nodemap.h" 33 | #include "graphmap.h" 34 | #include "graphsearch.h" 35 | #include "hierobjsearch.h" 36 | #include "access.h" 37 | #include "iomeasure.h" 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | 48 | using namespace std; 49 | 50 | struct timeval tv; 51 | long ts, te; 52 | #define TIME_TICK_START gettimeofday( &tv, NULL ); ts = tv.tv_sec * 100000 + tv.tv_usec / 10; 53 | #define TIME_TICK_END gettimeofday( &tv, NULL ); te = tv.tv_sec * 100000 + tv.tv_usec / 10; 54 | #define TIME_TICK_DIFF te - ts; 55 | #define TIME_TICK_PRINT(T) printf("%s RESULT: %ld (0.01MS)\r\n", (#T), te - ts ); 56 | 57 | #define PAGESIZE 409600000 58 | //#define FILE_QUERY "wa.query.dat" 59 | 60 | void helpmsg(const char* pgm) 61 | { 62 | cerr << "Suggested arguments:" << endl; 63 | cerr << "> " << pgm << " "; 64 | cerr << "-h graph.idx -o object.dat -r distance -v" << endl; 65 | cerr << "explanations:" << endl; 66 | cerr << "-h: hiergraph index file" << endl; 67 | cerr << "-o: object file" << endl; 68 | cerr << "-q: #queries" << endl; 69 | cerr << "-k: #NNs " << endl; 70 | cerr << "-v: turn verbose mode on (default: off)" << endl; 71 | } 72 | 73 | void test(){ 74 | } 75 | 76 | 77 | int main(const int a_argc, const char** a_argv) 78 | { 79 | if (a_argc == 1) 80 | { 81 | helpmsg(a_argv[0]); 82 | return -1; 83 | } 84 | 85 | cerr << "kNN object search on hierarchical graph" << endl; 86 | //------------------------------------------------------------------------- 87 | // initialization 88 | //------------------------------------------------------------------------- 89 | const char* hidxflname = Param::read(a_argc, a_argv, "-h", ""); 90 | const char* objflname = Param::read(a_argc, a_argv, "-o", ""); 91 | const char* cnumquery = Param::read(a_argc, a_argv, "-q", ""); 92 | const char* ck = Param::read(a_argc, a_argv, "-k", ""); 93 | const char* vrbs = Param::read(a_argc, a_argv, "-v", "null"); 94 | const char* FILE_OBJECT = Param::read(a_argc, a_argv, "-x", ""); 95 | bool verbose = strcmp(vrbs,"null") != 0; 96 | 97 | 98 | //------------------------------------------------------------------------- 99 | // access graph index file 100 | //------------------------------------------------------------------------- 101 | cerr << "loading a graph index ... "; 102 | // SegFMemory segmem(hidxflname, PAGESIZE*10, PAGESIZE, 32, false); 103 | SegFMemory segmem(hidxflname, PAGESIZE, PAGESIZE, 32, false); 104 | HierGraph hiergraph(segmem); 105 | int hiergraphsize = segmem.size(); 106 | cerr << "[DONE]" << endl; 107 | 108 | 109 | // --------------------------- begin test ------------------------------- 110 | 111 | FILE* fin; 112 | fin = fopen(FILE_OBJECT, "r"); 113 | int cases; 114 | fscanf(fin, "%d", &cases); 115 | cout << "Cases: read:" << cases << endl; 116 | 117 | long long all_time, single_time; 118 | int all_cases; 119 | all_time = 0; 120 | all_cases = 0; 121 | for (int i = 0; i < cases; i ++){ 122 | // init time 123 | single_time = 0; 124 | // read obj set 125 | int num_obj; 126 | fscanf(fin, "%d", &num_obj); 127 | cout << "Numobj:" << num_obj << endl; 128 | vector objset; 129 | for (int j = 0; j < num_obj; j ++){ 130 | int obj; 131 | fscanf(fin, "%d", &obj); 132 | cout << "Obj:" << obj << endl; 133 | objset.push_back(obj); 134 | } 135 | 136 | 137 | // ------------------------- init obj ------ 138 | NodeMapping nmap; 139 | GraphMapping gmap; 140 | 141 | for (int j = 0; j < objset.size(); j++){ 142 | int nodeid, objid; 143 | nodeid = objset[j]; 144 | objid = j; 145 | 146 | nmap.addObject(nodeid, objid); 147 | BorderNode* bnode = hiergraph.getBorderNode(nodeid); 148 | 149 | Array* a = &bnode->m_shortcuttree; 150 | while (a->size() > 0) 151 | { 152 | ShortcutTreeNode* s = (ShortcutTreeNode*)a->get(0); 153 | if (s->m_subnetid == 0) break; 154 | gmap.addObject(s->m_subnetid, objid); 155 | a = &s->m_child; 156 | } 157 | 158 | } 159 | 160 | 161 | // read locid and test 162 | int num_ql, locid, K; 163 | 164 | fscanf(fin, "%d", &K); 165 | fscanf(fin, "%d", &num_ql); 166 | cout << "K" << K << "NUM_QL:" << num_ql << endl; 167 | 168 | for (int j = 0; j < num_ql; j ++){ 169 | fscanf(fin, "%d", &locid); 170 | cout << "locid" << locid << endl; 171 | Array result; 172 | int nodeaccess=0; 173 | int edgeaccess=0; 174 | segmem.m_history.clean(); 175 | 176 | // test start! 177 | TIME_TICK_START 178 | HierObjectSearch::kNNSearch(hiergraph,nmap,gmap, locid, K ,result,nodeaccess,edgeaccess); 179 | TIME_TICK_END 180 | 181 | //---------------------------------------------------------------------- 182 | // result clean up 183 | //---------------------------------------------------------------------- 184 | for (int i=0; i (prog name) -h hiergraph.idx -o object.dat -q #queries -k k -v 14 | explanations: 15 | -h: hiergraph index file (input) 16 | -o: object file 17 | -q: number of query 18 | -k: k (# of NNs) 19 | -v: turn verbose mode on (default: off) 20 | 21 | MY TEST:(ONLY THESE TWO PARAMS) 22 | -h: hiergraph index file 23 | -x: FILE_OBJECT 24 | ---------------------------------------------------------------------------- */ 25 | 26 | #include "hiergraph.h" 27 | #include "bordernode.h" 28 | #include "shortcuttreenode.h" 29 | #include "segfmem.h" 30 | #include "param.h" 31 | #include "collection.h" 32 | #include "nodemap.h" 33 | #include "graphmap.h" 34 | #include "graphsearch.h" 35 | #include "hierobjsearch.h" 36 | #include "access.h" 37 | #include "iomeasure.h" 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | 48 | using namespace std; 49 | 50 | struct timeval tv; 51 | long ts, te; 52 | /* 53 | Stopwatch for 0.01ms 54 | #define TIME_TICK_START gettimeofday( &tv, NULL ); ts = tv.tv_sec * 100000 + tv.tv_usec / 10; 55 | #define TIME_TICK_END gettimeofday( &tv, NULL ); te = tv.tv_sec * 100000 + tv.tv_usec / 10; 56 | #define TIME_TICK_DIFF te - ts; 57 | #define TIME_TICK_PRINT(T) printf("%s RESULT: %ld (0.01MS)\r\n", (#T), te - ts ); 58 | */ 59 | //Stop Watch for us 60 | #define TIME_TICK_START gettimeofday( &tv, NULL ); ts = tv.tv_sec * 1000000 + tv.tv_usec ; 61 | #define TIME_TICK_END gettimeofday( &tv, NULL ); te = tv.tv_sec * 1000000 + tv.tv_usec ; 62 | #define TIME_TICK_DIFF te - ts; 63 | #define TIME_TICK_PRINT(T) printf("%s RESULT: %ld (uS)\r\n", (#T), te - ts ); 64 | #define PAGESIZE 409600000 65 | //#define FILE_QUERY "wa.query.dat" 66 | 67 | void helpmsg(const char* pgm) 68 | { 69 | cerr << "Suggested arguments for GPtree test road:" << endl; 70 | cerr << "> " << pgm << " "; 71 | cerr << "-h graph.idx -o object.dat -r distance -v" << endl; 72 | cerr << "explanations:" << endl; 73 | cerr << "-h: hiergraph index file" << endl; 74 | cerr << "-o: object file" << endl; 75 | cerr << "-q: #queries" << endl; 76 | cerr << "-k: #NNs " << endl; 77 | cerr << "-v: turn verbose mode on (default: off)" << endl; 78 | } 79 | 80 | void test(){ 81 | } 82 | 83 | 84 | int main(const int a_argc, const char** a_argv) 85 | { 86 | if (a_argc == 1) 87 | { 88 | helpmsg(a_argv[0]); 89 | return -1; 90 | } 91 | 92 | cerr << "kNN object search on hierarchical graph" << endl; 93 | //------------------------------------------------------------------------- 94 | // initialization 95 | //------------------------------------------------------------------------- 96 | const char* hidxflname = Param::read(a_argc, a_argv, "-h", ""); 97 | const char* objflname = Param::read(a_argc, a_argv, "-o", ""); 98 | const char* cnumquery = Param::read(a_argc, a_argv, "-q", ""); 99 | const char* ck = Param::read(a_argc, a_argv, "-k", "10"); 100 | const char* vrbs = Param::read(a_argc, a_argv, "-v", "null"); 101 | const char* FILE_OBJECT = Param::read(a_argc, a_argv, "-x", ""); 102 | bool verbose = strcmp(vrbs,"null") != 0; 103 | 104 | 105 | //------------------------------------------------------------------------- 106 | // access graph index file 107 | //------------------------------------------------------------------------- 108 | cerr << "loading a graph index ... "; 109 | // SegFMemory segmem(hidxflname, PAGESIZE*10, PAGESIZE, 32, false); 110 | SegFMemory segmem(hidxflname, PAGESIZE, PAGESIZE, 32, false); 111 | HierGraph hiergraph(segmem); 112 | int hiergraphsize = segmem.size(); 113 | cerr << "[DONE]" << endl; 114 | 115 | 116 | // --------------------------- begin test ------------------------------- 117 | 118 | FILE* fin; 119 | fin = fopen(FILE_OBJECT, "r"); 120 | int cases; 121 | //fscanf(fin, "%d", &cases); 122 | cases = 1; 123 | cout << "Cases: read:" << cases << endl; 124 | 125 | long long all_time, single_time, pre_time, ave_time; 126 | int all_cases; 127 | all_time = 0; 128 | all_cases = 0; 129 | single_time = 0; 130 | pre_time = 0; 131 | ave_time = 0; 132 | for (int i = 0; i < cases; i ++){ 133 | // init time 134 | single_time = 0; 135 | // read obj set 136 | int num_obj; 137 | fscanf(fin, "%d", &num_obj); 138 | cout << "Numobj:" << num_obj << endl; 139 | vector objset; 140 | for (int j = 0; j < num_obj; j ++){ 141 | int obj; 142 | fscanf(fin, "%d", &obj); 143 | //cout << "Obj:" << obj << endl; 144 | objset.push_back(obj); 145 | } 146 | 147 | 148 | // ------------------------- init obj ------ 149 | NodeMapping nmap; 150 | GraphMapping gmap; 151 | 152 | TIME_TICK_START 153 | 154 | for (int j = 0; j < objset.size(); j++){ 155 | int nodeid, objid; 156 | nodeid = objset[j]; 157 | objid = j; 158 | 159 | nmap.addObject(nodeid, objid); 160 | BorderNode* bnode = hiergraph.getBorderNode(nodeid); 161 | 162 | Array* a = &bnode->m_shortcuttree; 163 | while (a->size() > 0) 164 | { 165 | ShortcutTreeNode* s = (ShortcutTreeNode*)a->get(0); 166 | if (s->m_subnetid == 0) break; 167 | gmap.addObject(s->m_subnetid, objid); 168 | a = &s->m_child; 169 | } 170 | 171 | } 172 | 173 | TIME_TICK_END 174 | 175 | pre_time = TIME_TICK_DIFF 176 | 177 | // read locid and test 178 | int num_ql, locid, K; 179 | 180 | //fscanf(fin, "%d", &K); 181 | K = atoi(ck); 182 | fscanf(fin, "%d", &num_ql); 183 | cout << "K:" << K << "\tNUM_QL:" << num_ql << endl; 184 | 185 | for (int j = 0; j < num_ql; j ++){ 186 | fscanf(fin, "%d", &locid); 187 | //cout <<"num_ql:"<< num_ql<< "j" << j<< "locid:" << locid << endl; 188 | Array result; 189 | int nodeaccess=0; 190 | int edgeaccess=0; 191 | segmem.m_history.clean(); 192 | 193 | // test start! 194 | TIME_TICK_START 195 | HierObjectSearch::kNNSearch(hiergraph,nmap,gmap, locid, K ,result,nodeaccess,edgeaccess); 196 | TIME_TICK_END 197 | 198 | //---------------------------------------------------------------------- 199 | // result clean up 200 | //---------------------------------------------------------------------- 201 | for (int i=0; i (prog name) 16 | -n nodefile.txt -e edgefile.txt 17 | -m #objects -c #clusters 18 | -i graph.idx -o object.dat -v 19 | explanations: 20 | -n: node file 21 | -e: edge file 22 | -m: #objects 23 | -c: #clusters 24 | -i: graph index file 25 | -o: object file 26 | -p: file that prints the graph in Postscript 27 | -v: turn verbose mode on (default: off) 28 | ---------------------------------------------------------------------------- */ 29 | #include "graph.h" 30 | #include "node.h" 31 | #include "edge.h" 32 | #include "segfmem.h" 33 | #include "objectgen.h" 34 | #include "param.h" 35 | #include "collection.h" 36 | #include "graphplot.h" 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | using namespace std; 43 | 44 | #define MAXNODES 100000 45 | #define PAGESIZE 4096 // 4KB page 46 | 47 | void helpmsg(const char* pgm) 48 | { 49 | cerr << "Suggested arguments:" << endl; 50 | cerr << "> " << pgm << " "; 51 | cerr << "-n nodefile.txt -e edgefile.txt -m #objects -c #clusters "; 52 | cerr << "-i graph.idx -o object.dat -p output.ps -v" << endl; 53 | cerr << "explanations:" << endl; 54 | cerr << "-n: node file" << endl; 55 | cerr << " format: nodeID x y " << endl; 56 | cerr << "-e: edge file" << endl; 57 | cerr << " format: src_nodeID dest_nodeID cost" << endl; 58 | cerr << "-m: number of objects" << endl; 59 | cerr << "-c: number of clusters" << endl; 60 | cerr << "-i: graph index file (output)" << endl; 61 | cerr << "-o: object file (output)" << endl; 62 | cerr << "-p: file that prints the graph in Postscript" << endl; 63 | cerr << "-v: turn verbose mode on (default: off)" << endl; 64 | } 65 | 66 | int main(const int a_argc, const char** a_argv) 67 | { 68 | if (a_argc == 1) 69 | { 70 | helpmsg(a_argv[0]); 71 | return -1; 72 | } 73 | 74 | cerr << "graph & object loader" << endl; 75 | //------------------------------------------------------------------------- 76 | // initialization 77 | //------------------------------------------------------------------------- 78 | const char* nodeflname = Param::read(a_argc, a_argv, "-n", ""); 79 | const char* edgeflname = Param::read(a_argc, a_argv, "-e", ""); 80 | const char* numobject = Param::read(a_argc, a_argv, "-m", ""); 81 | const char* numcluster = Param::read(a_argc, a_argv, "-c", ""); 82 | const char* idxflname = Param::read(a_argc, a_argv, "-i", ""); 83 | const char* objflname = Param::read(a_argc, a_argv, "-o", ""); 84 | const char* psflname = Param::read(a_argc, a_argv, "-p", ""); 85 | const char* vrbs = Param::read(a_argc, a_argv, "-v", "null"); 86 | bool verbose = strcmp(vrbs,"null") != 0; 87 | fstream fnode, fedge; 88 | 89 | Array node2object; // a mapping between nodes and objects 90 | Hash nodes(10000); // this is for fast quick lookup 91 | Array allnodes(10000,100); // this is for node ordering 92 | 93 | //------------------------------------------------------------------------- 94 | // loading nodes and edges 95 | //------------------------------------------------------------------------- 96 | cerr << "loading nodes ... "; 97 | fnode.open(nodeflname, ios::in); 98 | while (true) 99 | { 100 | int id; 101 | float x,y; 102 | fnode >> id; 103 | if (fnode.eof()) 104 | break; 105 | 106 | fnode >> x; 107 | fnode >> y; 108 | 109 | Node* node = new Node(id,x,y); 110 | nodes.put(id,node); 111 | allnodes.append(node); 112 | } 113 | allnodes.sort(Node::compareid); 114 | cerr << "[DONE]" << endl; 115 | 116 | cerr << "loading edges ... "; 117 | fedge.open(edgeflname, ios::in); 118 | while (true) 119 | { 120 | int id; 121 | int src, dest; 122 | float cost; 123 | fedge >> id; 124 | if (fedge.eof()) 125 | break; 126 | fedge >> src; 127 | fedge >> dest; 128 | fedge >> cost; 129 | Edge edge2dest(dest, cost); 130 | Edge edge2src(src, cost); 131 | // source node 132 | Node* srcnode = (Node*)nodes.get(src); 133 | srcnode->addEdge(edge2dest); 134 | // destination node 135 | Node* destnode= (Node*)nodes.get(dest); 136 | destnode->addEdge(edge2src); 137 | } 138 | cerr << "[DONE]" << endl; 139 | 140 | fnode.close(); 141 | fedge.close(); 142 | 143 | //------------------------------------------------------------------------- 144 | // insert nodes to graph 145 | //------------------------------------------------------------------------- 146 | cerr << "create a graph ... "; 147 | SegFMemory segmem(idxflname,PAGESIZE*10,PAGESIZE,32,true); // 10 pages, 1 page 148 | Graph graph(segmem); 149 | for (int i=0; im_edges.size() > 0) 153 | graph.writeNode(node->m_id,*node); 154 | } 155 | cerr << "[DONE]" << endl; 156 | 157 | //------------------------------------------------------------------------- 158 | // create objects 159 | //------------------------------------------------------------------------- 160 | cerr << "create objects ... "; 161 | int numobj = atol(numobject); 162 | int numclu = atol(numcluster); 163 | if (numobj > 0) 164 | { 165 | if (numclu == 0) 166 | ObjectGen::uniform(numobj, allnodes, node2object); 167 | else 168 | ObjectGen::cluster(numclu, numobj, allnodes, node2object); 169 | 170 | fstream fobj; 171 | fobj.open(objflname, ios::out); 172 | for (int i=0; im_nodeid << " " << nobj->m_objid << endl; 176 | } 177 | fobj.close(); 178 | } 179 | cerr << "[DONE]" << endl; 180 | 181 | //------------------------------------------------------------------------- 182 | // testing 183 | //------------------------------------------------------------------------- 184 | cerr << "testing ... "; 185 | for (int i=0; im_id); 190 | if (m->m_id != node->m_id) 191 | { 192 | cerr << "fail in node " << m->m_id << endl; 193 | return -1; 194 | } 195 | if (m->m_edges.size() != node->m_edges.size()) 196 | { 197 | cerr << "fail in #edges " << endl; 198 | return -1; 199 | } 200 | for (int c1=0; c1m_edges.size(); c1++) 201 | { 202 | int found = 0; 203 | const Edge* e1 = (const Edge*)m->m_edges.get(c1); 204 | for (int c2=0; c2m_edges.size(); c2++) 205 | { 206 | const Edge* e2 = (const Edge*)node->m_edges.get(c2); 207 | if (e1->m_neighbor == e2->m_neighbor && 208 | e1->m_cost == e2->m_cost) 209 | found = 1; 210 | } 211 | if (found != 1) 212 | { 213 | cerr << "fail in edge content" << endl; 214 | return -1; 215 | } 216 | } 217 | delete m; 218 | } 219 | cerr << "[DONE]" << endl; 220 | 221 | //------------------------------------------------------------------------- 222 | // plot the graph and objects 223 | //------------------------------------------------------------------------- 224 | if (psflname[0] != 0) 225 | GraphPlot::plot(psflname, nodes, node2object); 226 | 227 | //------------------------------------------------------------------------- 228 | // clean up 229 | //------------------------------------------------------------------------- 230 | for (int i=0; i (prog name) -h hiergraph.idx -o object.dat -q #queries -k k -v 14 | explanations: 15 | -h: hiergraph index file (input) 16 | -o: object file 17 | -q: number of query 18 | -k: k (# of NNs) 19 | -v: turn verbose mode on (default: off) 20 | 21 | MY TEST:(ONLY THESE TWO PARAMS) 22 | -h: hiergraph index file 23 | -x: FILE_OBJECT 24 | ---------------------------------------------------------------------------- */ 25 | 26 | #include "hiergraph.h" 27 | #include "bordernode.h" 28 | #include "shortcuttreenode.h" 29 | #include "segfmem.h" 30 | #include "param.h" 31 | #include "collection.h" 32 | #include "nodemap.h" 33 | #include "graphmap.h" 34 | #include "graphsearch.h" 35 | #include "hierobjsearch.h" 36 | #include "access.h" 37 | #include "iomeasure.h" 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | 48 | using namespace std; 49 | 50 | struct timeval tv; 51 | long ts, te; 52 | /* 53 | Stopwatch for 0.01ms 54 | #define TIME_TICK_START gettimeofday( &tv, NULL ); ts = tv.tv_sec * 100000 + tv.tv_usec / 10; 55 | #define TIME_TICK_END gettimeofday( &tv, NULL ); te = tv.tv_sec * 100000 + tv.tv_usec / 10; 56 | #define TIME_TICK_DIFF te - ts; 57 | #define TIME_TICK_PRINT(T) printf("%s RESULT: %ld (0.01MS)\r\n", (#T), te - ts ); 58 | */ 59 | //Stop Watch for us 60 | #define TIME_TICK_START gettimeofday( &tv, NULL ); ts = tv.tv_sec * 1000000 + tv.tv_usec ; 61 | #define TIME_TICK_END gettimeofday( &tv, NULL ); te = tv.tv_sec * 1000000 + tv.tv_usec ; 62 | #define TIME_TICK_DIFF te - ts; 63 | #define TIME_TICK_PRINT(T) printf("%s RESULT: %ld (uS)\r\n", (#T), te - ts ); 64 | #define PAGESIZE 409600000 65 | //#define FILE_QUERY "wa.query.dat" 66 | 67 | void helpmsg(const char* pgm) 68 | { 69 | cerr << "Suggested arguments for GPtree test road:" << endl; 70 | cerr << "> " << pgm << " "; 71 | cerr << "-h graph.idx -o object.dat -r -b boundNumber -v" << endl; 72 | cerr << "explanations:" << endl; 73 | cerr << "-h: hiergraph index file" << endl; 74 | cerr << "-o: object file" << endl; 75 | cerr << "-q: #queries" << endl; 76 | cerr << "-b: #boundNumber" << endl; 77 | cerr << "-k: #NNs " << endl; 78 | cerr << "-v: turn verbose mode on (default: off)" << endl; 79 | } 80 | 81 | void test(){ 82 | } 83 | 84 | 85 | int main(const int a_argc, const char** a_argv) 86 | { 87 | if (a_argc == 1) 88 | { 89 | helpmsg(a_argv[0]); 90 | return -1; 91 | } 92 | 93 | cerr << "kNN object search on hierarchical graph" << endl; 94 | //------------------------------------------------------------------------- 95 | // initialization 96 | //------------------------------------------------------------------------- 97 | const char* hidxflname = Param::read(a_argc, a_argv, "-h", ""); 98 | const char* objflname = Param::read(a_argc, a_argv, "-o", ""); 99 | const char* cnumquery = Param::read(a_argc, a_argv, "-q", ""); 100 | const char* ck = Param::read(a_argc, a_argv, "-k", "10"); 101 | const char* vrbs = Param::read(a_argc, a_argv, "-v", "null"); 102 | const char* FILE_OBJECT = Param::read(a_argc, a_argv, "-x", ""); 103 | bool verbose = strcmp(vrbs,"null") != 0; 104 | 105 | 106 | //------------------------------------------------------------------------- 107 | // access graph index file 108 | //------------------------------------------------------------------------- 109 | cerr << "loading a graph index ... "; 110 | // SegFMemory segmem(hidxflname, PAGESIZE*10, PAGESIZE, 32, false); 111 | SegFMemory segmem(hidxflname, PAGESIZE, PAGESIZE, 32, false); 112 | HierGraph hiergraph(segmem); 113 | int hiergraphsize = segmem.size(); 114 | cerr << "[DONE]" << endl; 115 | 116 | 117 | // --------------------------- begin test ------------------------------- 118 | 119 | FILE* fin; 120 | fin = fopen(FILE_OBJECT, "r"); 121 | int cases; 122 | //fscanf(fin, "%d", &cases); 123 | cases = 1; 124 | cout << "Cases: read:" << cases << endl; 125 | 126 | long long all_time, single_time, pre_time, ave_time,num_obj_bound; 127 | int all_cases; 128 | all_time = 0; 129 | all_cases = 0; 130 | single_time = 0; 131 | pre_time = 0; 132 | ave_time = 0; 133 | num_obj_bound = 1000;//atoi(density_bound); //用来控制测试密度,直接传递值。 134 | printf ("Bound is :%d \n", num_obj_bound); 135 | getchar(); 136 | for (int i = 0; i < cases; i ++){ 137 | // init time 138 | single_time = 0; 139 | // read obj set 140 | int num_obj; 141 | fscanf(fin, "%d", &num_obj); 142 | cout << "Numobj:" << num_obj << endl; 143 | vector objset; 144 | for (int j = 0; j < num_obj; j ++){ 145 | int obj; 146 | fscanf(fin, "%d", &obj); 147 | //cout << "Obj:" << obj << endl; 148 | if( j < num_obj_bound){ 149 | objset.push_back(obj); 150 | } 151 | } 152 | 153 | 154 | // ------------------------- init obj ------ 155 | NodeMapping nmap; 156 | GraphMapping gmap; 157 | 158 | TIME_TICK_START 159 | 160 | for (int j = 0; j < objset.size(); j++){ 161 | int nodeid, objid; 162 | nodeid = objset[j]; 163 | objid = j; 164 | 165 | nmap.addObject(nodeid, objid); 166 | BorderNode* bnode = hiergraph.getBorderNode(nodeid); 167 | 168 | Array* a = &bnode->m_shortcuttree; 169 | while (a->size() > 0) 170 | { 171 | ShortcutTreeNode* s = (ShortcutTreeNode*)a->get(0); 172 | if (s->m_subnetid == 0) break; 173 | gmap.addObject(s->m_subnetid, objid); 174 | a = &s->m_child; 175 | } 176 | 177 | } 178 | 179 | TIME_TICK_END 180 | 181 | pre_time = TIME_TICK_DIFF 182 | 183 | // read locid and test 184 | int num_ql, locid, K; 185 | 186 | //fscanf(fin, "%d", &K); 187 | K = atoi(ck); 188 | fscanf(fin, "%d", &num_ql); 189 | cout << "K:" << K << "\tNUM_QL:" << num_ql << endl; 190 | 191 | for (int j = 0; j < num_ql; j ++){ 192 | fscanf(fin, "%d", &locid); 193 | //cout <<"num_ql:"<< num_ql<< "j" << j<< "locid:" << locid << endl; 194 | Array result; 195 | int nodeaccess=0; 196 | int edgeaccess=0; 197 | segmem.m_history.clean(); 198 | 199 | // test start! 200 | TIME_TICK_START 201 | HierObjectSearch::kNNSearch(hiergraph,nmap,gmap, locid, K ,result,nodeaccess,edgeaccess); 202 | TIME_TICK_END 203 | 204 | //---------------------------------------------------------------------- 205 | // result clean up 206 | //---------------------------------------------------------------------- 207 | for (int i=0; i