From 01382ef582f7f8d97df7f5acf48d100e8fc83aa8 Mon Sep 17 00:00:00 2001 From: Dongryeol Lee Date: Wed, 23 Jan 2008 04:29:56 +0000 Subject: [PATCH] Renamed the main driver file --- fastlib/u/dongryel/range_search/build.py | 14 +++++------ .../range_search/ortho_range_search.h | 24 ++++++++++-------- .../{main.cc => ortho_range_search_main.cc} | 25 +++++++++++++++++-- .../u/dongryel/range_search/range_reader.h | 10 ++++---- 4 files changed, 48 insertions(+), 25 deletions(-) rename fastlib/u/dongryel/range_search/{main.cc => ortho_range_search_main.cc} (61%) diff --git a/fastlib/u/dongryel/range_search/build.py b/fastlib/u/dongryel/range_search/build.py index 65c0157cfe..ea28edd127 100644 --- a/fastlib/u/dongryel/range_search/build.py +++ b/fastlib/u/dongryel/range_search/build.py @@ -1,17 +1,17 @@ librule( - name = "range_search", # this line can be safely omitted - sources = [], # files that must be compiled + name = "range_search", + sources = [], headers = ["interval_tree.h", "ortho_range_search.h", - "range_reader.h"], # include files part of the 'lib' - deplibs = ["fastlib:fastlib_int"] # dependency + "range_reader.h"], + deplibs = ["fastlib:fastlib_int"] ) binrule( - name = "range_search_bin", # the executable name - sources = ["main.cc"], # compile multibody.cc - headers = [], # no extra headers + name = "range_search_bin", + sources = ["ortho_range_search_main.cc"], + headers = [], deplibs = [":range_search", "fastlib:fastlib_int"] ) diff --git a/fastlib/u/dongryel/range_search/ortho_range_search.h b/fastlib/u/dongryel/range_search/ortho_range_search.h index 03f02459c8..78d7f2416a 100644 --- a/fastlib/u/dongryel/range_search/ortho_range_search.h +++ b/fastlib/u/dongryel/range_search/ortho_range_search.h @@ -1,12 +1,18 @@ +/** @file ortho_range_search.h + * + * This file contains an implementation of a tree-based and a naive + * algorithm for orthogonal range search. + * + * @author Dongryeol Lee (dongryel) + */ #ifndef ORTHO_RANGE_SEARCH_H #define ORTHO_RANGE_SEARCH_H -#include -#include #include "range_reader.h" -#include "fastlib/fastlib_int.h" +#include "fastlib/fastlib.h" -/** Naive orthogonal range search class */ +/** @brief Naive orthogonal range search class + */ class NaiveOrthoRangeSearch { FORBID_ACCIDENTAL_COPIES(NaiveOrthoRangeSearch); @@ -37,14 +43,10 @@ class NaiveOrthoRangeSearch { } /** initialize the computation object */ - void Init() { - - const char *fname = fx_param_str(NULL, "data", "data.ds"); + void Init(Matrix &data) { - // read in the dataset - Dataset dataset_; - dataset_.InitFromFile(fname); - data_.Own(&(dataset_.matrix())); + // copy the incoming data + data_.Copy(data); // read the orthogonal query range text file range_.Init(data_.n_rows()); diff --git a/fastlib/u/dongryel/range_search/main.cc b/fastlib/u/dongryel/range_search/ortho_range_search_main.cc similarity index 61% rename from fastlib/u/dongryel/range_search/main.cc rename to fastlib/u/dongryel/range_search/ortho_range_search_main.cc index 7ef3fd4ee7..a3a8a83304 100644 --- a/fastlib/u/dongryel/range_search/main.cc +++ b/fastlib/u/dongryel/range_search/ortho_range_search_main.cc @@ -1,12 +1,33 @@ +/** @file ortho_range_search_main.cc + * + * A test driver for the orthogonal range search code. + * + * @author Dongryeol Lee (dongryel) + */ #include "ortho_range_search.h" int main(int argc, char *argv[]) { + // Always initialize FASTexec with main's inputs at the beggining of + // your program. This reads the command line, among other things. fx_init(argc, argv); + + ////////// READING PARAMETERS AND LOADING DATA ///////////////////// + + // The reference data file is a required parameter. + const char* dataset_file_name = fx_param_str_req(NULL, "data"); + + // column-oriented dataset matrix. + Matrix dataset; + + // data::Load inits a matrix with the contents of a .csv or .arff. + data::Load(dataset_file_name, &dataset); + + // flag for determining whether we need to do naive algorithm. bool do_naive = fx_param_exists(NULL, "do_naive"); + // declare fast tree-based orthogonal range search algorithm object. OrthoRangeSearch fast_search; - fast_search.Init(); fast_search.Compute(); @@ -19,7 +40,7 @@ int main(int argc, char *argv[]) { // if naive option is specified, do naive algorithm if(do_naive) { NaiveOrthoRangeSearch search; - search.Init(); + search.Init(dataset); search.Compute(); ArrayList naive_search_results = search.get_results(); bool flag = true; diff --git a/fastlib/u/dongryel/range_search/range_reader.h b/fastlib/u/dongryel/range_search/range_reader.h index 9d5bac2a80..bd28c4cacc 100644 --- a/fastlib/u/dongryel/range_search/range_reader.h +++ b/fastlib/u/dongryel/range_search/range_reader.h @@ -1,7 +1,7 @@ #ifndef RANGE_READER_H #define RANGE_READER_H -#include "fastlib/fastlib_int.h" +#include "fastlib/fastlib.h" // text parser class for handling -INFINITY and INFINITY tokens class RangeReader { @@ -24,11 +24,11 @@ class RangeReader { !isdigit((tokenizer.Current().c_str())[1])) { tokenizer.Gobble(); if(strncmp(tokenizer.Current().c_str(), "INFINITY", 8) == 0) { - range[i].lo = -MAXDOUBLE; + range[i].lo = -DBL_MAX; } } else if(strncmp(tokenizer.Current().c_str(), "INFINITY", 8) == 0) { - range[i].lo = MAXDOUBLE; + range[i].lo = DBL_MAX; } else { range[i].lo = atof(tokenizer.Current().c_str()); @@ -40,11 +40,11 @@ class RangeReader { !isdigit((tokenizer.Current().c_str())[1])) { tokenizer.Gobble(); if(strncmp(tokenizer.Current().c_str(), "INFINITY", 8) == 0) { - range[i].hi = -MAXDOUBLE; + range[i].hi = -DBL_MAX; } } else if(strncmp(tokenizer.Current().c_str(), "INFINITY", 8) == 0) { - range[i].hi = MAXDOUBLE; + range[i].hi = DBL_MAX; } else { range[i].hi = atof(tokenizer.Current().c_str());