main.cc
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 #include <cerrno>
00051 #include <string>
00052 #include "fastlib/fastlib.h"
00053 #include "allkfn.h"
00054
00055
00056 int main(int argc, char *argv[]) {
00057 fx_module *module = fx_init(argc, argv, NULL);
00058 std::string result_file = fx_param_str(module, "result_file", "result.txt");
00059 std::string reference_file = fx_param_str_req(module, "reference_file");
00060 Matrix reference_data;
00061 ArrayList<index_t> neighbors;
00062 ArrayList<double> distances;
00063 if (data::Load(reference_file.c_str(), &reference_data)==SUCCESS_FAIL) {
00064 FATAL("Reference file %s not found", reference_file.c_str());
00065 }
00066 NOTIFY("Loaded reference data from file %s", reference_file.c_str());
00067
00068 AllkFN allkfn;
00069 if (fx_param_exists(module, "query_file")) {
00070 std::string query_file=fx_param_str_req(module, "query_file");
00071 Matrix query_data;
00072 if (data::Load(query_file.c_str(), &query_data)==SUCCESS_FAIL) {
00073 FATAL("Query file %s not found", query_file.c_str());
00074 }
00075 NOTIFY("Query data loaded from %s", query_file.c_str());
00076 NOTIFY("Building query and reference tree");
00077 allkfn.Init(query_data, reference_data, module);
00078 } else {
00079 NOTIFY("Building reference tree");
00080 allkfn.Init(reference_data, module);
00081 }
00082 NOTIFY("Tree(s) built");
00083 index_t kfns=fx_param_int_req(module, "kfns");
00084 NOTIFY("Computing %"LI"d furthest neighbors", kfns);
00085 allkfn.ComputeNeighbors(&neighbors, &distances);
00086 NOTIFY("Neighbors computed");
00087 NOTIFY("Exporting results");
00088 FILE *fp=fopen(result_file.c_str(), "w");
00089 if (fp==NULL) {
00090 FATAL("Error while opening %s...%s", result_file.c_str(),
00091 strerror(errno));
00092 }
00093 for(index_t i=0 ; i < neighbors.size()/kfns ; i++) {
00094 for(index_t j=0; j<kfns; j++) {
00095 fprintf(fp, "%"LI"d %"LI"d %lg\n", i, neighbors[i*kfns+j], distances[i*kfns+j]);
00096 }
00097 }
00098 fclose(fp);
00099 fx_done(module);
00100 }