1 #include "mm/fmm/ubodt_gen_app_config.hpp"
2 #include "util/util.hpp"
3 #include "util/debug.hpp"
10 UBODTGenAppConfig::UBODTGenAppConfig(
int argc,
char **argv) {
11 spdlog::set_pattern(
"[%^%l%$][%s:%-3#] %v");
13 std::string configfile(argv[1]);
22 spdlog::set_level((spdlog::level::level_enum) log_level);
27 void UBODTGenAppConfig::load_xml(
const std::string &file) {
28 SPDLOG_INFO(
"Read configuration from xml file: {}",file);
30 boost::property_tree::ptree tree;
31 boost::property_tree::read_xml(file, tree);
32 network_config = NetworkConfig::load_from_xml(tree);
33 delta = tree.get(
"config.parameters.delta", 3000.0);
34 result_file = tree.get<std::string>(
"config.output.file");
36 log_level = tree.get(
"config.other.log_level", 2);
37 use_omp = !(!tree.get_child_optional(
"config.other.use_omp"));
38 SPDLOG_INFO(
"Read configuration from xml file done");
41 void UBODTGenAppConfig::load_arg(
int argc,
char **argv) {
42 SPDLOG_INFO(
"Start reading ubodt configuration from arguments");
43 cxxopts::Options options(
"config",
44 "Configuration parser of ubodt_gen");
46 (
"network",
"Network file name",
47 cxxopts::value<std::string>()->default_value(
""))
48 (
"network_id",
"Network id name",
49 cxxopts::value<std::string>()->default_value(
"id"))
50 (
"source",
"Network source name",
51 cxxopts::value<std::string>()->default_value(
"source"))
52 (
"target",
"Network target name",
53 cxxopts::value<std::string>()->default_value(
"target"))
54 (
"delta",
"Upperbound distance",
55 cxxopts::value<double>()->default_value(
"3000.0"))
56 (
"o,output",
"Output file name",
57 cxxopts::value<std::string>()->default_value(
""))
58 (
"l,log_level",
"Log level", cxxopts::value<int>()->default_value(
"2"))
59 (
"h,help",
"Help information")
60 (
"use_omp",
"Use parallel computing if specified")
61 (
"projected",
"Data is projected or not");
63 help_specified =
true;
66 auto result = options.parse(argc, argv);
68 result_file = result[
"output"].as<std::string>();
69 network_config = NetworkConfig::load_from_arg(result);
70 log_level = result[
"log_level"].as<
int>();
71 delta = result[
"delta"].as<
double>();
72 use_omp = result.count(
"use_omp")>0;
73 if (result.count(
"help")>0) {
74 help_specified =
true;
76 SPDLOG_INFO(
"Finish with reading ubodt arg configuration");
79 void UBODTGenAppConfig::print()
const {
80 SPDLOG_INFO(
"---- Print configuration ----");
81 network_config.print();
82 SPDLOG_INFO(
"Delta {}",delta);
83 SPDLOG_INFO(
"Output file {}",result_file);
85 SPDLOG_INFO(
"Use omp {}",(use_omp ?
"true" :
"false"));
86 SPDLOG_INFO(
"---- Print configuration done ----");
89 void UBODTGenAppConfig::print_help() {
90 std::cout <<
"ubodt_gen argument lists:\n";
91 std::cout <<
"--network (required) <string>: Network file name\n";
92 std::cout <<
"--output (required) <string>: Output file name\n";
93 std::cout <<
"--id (optional) <string>: Network id name (id)\n";
94 std::cout <<
"--source (optional) <string>: Network source name (source)\n";
95 std::cout <<
"--target (optional) <string>: Network target name (target)\n";
96 std::cout <<
"--delta (optional) <double>: upperbound (3000.0)\n";
97 std::cout <<
"--log_level (optional) <int>: log level (2)\n";
98 std::cout <<
"--use_omp: use OpenMP or not\n";
99 std::cout <<
"-h/--help: help information\n";
100 std::cout <<
"For xml configuration, check example folder\n";
103 bool UBODTGenAppConfig::validate()
const {
104 SPDLOG_INFO(
"Validating configuration for UBODT construction");
105 if (!network_config.validate()) {
109 SPDLOG_WARN(
"Overwrite result file {}", result_file);
113 SPDLOG_CRITICAL(
"Output folder {} not exists", output_folder);
117 SPDLOG_CRITICAL(
"Invalid log_level {}, which should be 0 - 6", log_level);
118 SPDLOG_INFO(
"0-trace,1-debug,2-info,3-warn,4-err,5-critical,6-off");
122 SPDLOG_CRITICAL(
"Delta {} should be positive");
125 SPDLOG_INFO(
"Validating done.");
129 bool UBODTGenAppConfig::is_binary_output()
const {