diff --git a/lang/zh/gklearn/ged/util/cpp_code.cpp b/lang/zh/gklearn/ged/util/cpp_code.cpp new file mode 100644 index 0000000..acbe22a --- /dev/null +++ b/lang/zh/gklearn/ged/util/cpp_code.cpp @@ -0,0 +1,122 @@ + else if (option.first == "random-inits") { + try { + num_random_inits_ = std::stoul(option.second); + desired_num_random_inits_ = num_random_inits_; + } + catch (...) { + throw Error(std::string("Invalid argument \"") + option.second + "\" for option random-inits. Usage: options = \"[--random-inits ]\""); + } + if (num_random_inits_ <= 0) { + throw Error(std::string("Invalid argument \"") + option.second + "\" for option random-inits. Usage: options = \"[--random-inits ]\""); + } + } + else if (option.first == "randomness") { + if (option.second == "PSEUDO") { + use_real_randomness_ = false; + } + else if (option.second == "REAL") { + use_real_randomness_ = true; + } + else { + throw Error(std::string("Invalid argument \"") + option.second + "\" for option randomness. Usage: options = \"[--randomness REAL|PSEUDO] [...]\""); + } + } + else if (option.first == "stdout") { + if (option.second == "0") { + print_to_stdout_ = 0; + } + else if (option.second == "1") { + print_to_stdout_ = 1; + } + else if (option.second == "2") { + print_to_stdout_ = 2; + } + else { + throw Error(std::string("Invalid argument \"") + option.second + "\" for option stdout. Usage: options = \"[--stdout 0|1|2] [...]\""); + } + } + else if (option.first == "refine") { + if (option.second == "TRUE") { + refine_ = true; + } + else if (option.second == "FALSE") { + refine_ = false; + } + else { + throw Error(std::string("Invalid argument \"") + option.second + "\" for option refine. Usage: options = \"[--refine TRUE|FALSE] [...]\""); + } + } + else if (option.first == "time-limit") { + try { + time_limit_in_sec_ = std::stod(option.second); + } + catch (...) { + throw Error(std::string("Invalid argument \"") + option.second + "\" for option time-limit. Usage: options = \"[--time-limit ] [...]"); + } + } + else if (option.first == "max-itrs") { + try { + max_itrs_ = std::stoi(option.second); + } + catch (...) { + throw Error(std::string("Invalid argument \"") + option.second + "\" for option max-itrs. Usage: options = \"[--max-itrs ] [...]"); + } + } + else if (option.first == "max-itrs-without-update") { + try { + max_itrs_without_update_ = std::stoi(option.second); + } + catch (...) { + throw Error(std::string("Invalid argument \"") + option.second + "\" for option max-itrs-without-update. Usage: options = \"[--max-itrs-without-update ] [...]"); + } + } + else if (option.first == "seed") { + try { + seed_ = std::stoul(option.second); + } + catch (...) { + throw Error(std::string("Invalid argument \"") + option.second + "\" for option seed. Usage: options = \"[--seed ] [...]"); + } + } + else if (option.first == "epsilon") { + try { + epsilon_ = std::stod(option.second); + } + catch (...) { + throw Error(std::string("Invalid argument \"") + option.second + "\" for option epsilon. Usage: options = \"[--epsilon ] [...]"); + } + if (epsilon_ <= 0) { + throw Error(std::string("Invalid argument \"") + option.second + "\" for option epsilon. Usage: options = \"[--epsilon ] [...]"); + } + } + else if (option.first == "inits-increase-order") { + try { + num_inits_increase_order_ = std::stoul(option.second); + } + catch (...) { + throw Error(std::string("Invalid argument \"") + option.second + "\" for option inits-increase-order. Usage: options = \"[--inits-increase-order ]\""); + } + if (num_inits_increase_order_ <= 0) { + throw Error(std::string("Invalid argument \"") + option.second + "\" for option inits-increase-order. Usage: options = \"[--inits-increase-order ]\""); + } + } + else if (option.first == "init-type-increase-order") { + init_type_increase_order_ = option.second; + if (option.second != "CLUSTERS" and option.second != "K-MEANS++") { + throw ged::Error(std::string("Invalid argument ") + option.second + " for option init-type-increase-order. Usage: options = \"[--init-type-increase-order CLUSTERS|K-MEANS++] [...]\""); + } + } + else if (option.first == "max-itrs-increase-order") { + try { + max_itrs_increase_order_ = std::stoi(option.second); + } + catch (...) { + throw Error(std::string("Invalid argument \"") + option.second + "\" for option max-itrs-increase-order. Usage: options = \"[--max-itrs-increase-order ] [...]"); + } + } + else { + std::string valid_options("[--init-type ] [--random-inits ] [--randomness ] [--seed ] [--stdout ] "); + valid_options += "[--time-limit ] [--max-itrs ] [--epsilon ] "; + valid_options += "[--inits-increase-order ] [--init-type-increase-order ] [--max-itrs-increase-order ]"; + throw Error(std::string("Invalid option \"") + option.first + "\". Usage: options = \"" + valid_options + "\""); + }