#include #include "light.hpp" #include #include #include #include "utils/cmdline.h" light::light(): finalResult (0), winner_period (1e9), winner_id (-1), maxtime (5000) { opt = new paras(); opt->init_paras(); } light::~light() { for (int i = 0; i < workers.size(); i++) delete(workers[i]); workers.clear(true); } void light::configure_from_file(const char* file) { if (!strcmp(file, "")) { configure_name = new vec[OPT(threads)]; configure_val = new vec[OPT(threads)]; return; } printf("c Get configure file: %s\n", file); std::ifstream fin(file); char buf[1000]; fin.getline(buf, 1000); char *p = buf + 6; int ws, ss, id = 0; p = read_int(p, &ws); p = read_int(p, &ss); printf("%d %d\n", ws, ss); opt->set_para("threads", ws); configure_name = new vec[ws]; configure_val = new vec[ws]; while (fin.getline(buf, 1000)) { p = strtok(buf, " "); printf("%s\n", p); solver_type.push(0); while (p) { p = strtok(NULL, " "); printf("%s\n", p); if (!p) break; int l = strlen(p), pos = 0; for (int i = 1; i < l; i++) if (p[i] == '=') pos = i; char *name = new char[pos]; strncpy(name, p, pos); printf("%s\n", name); configure_name[id].push(name); char *val = p + pos + 1; double v = atof(val); printf("%.2lf\n", v); configure_val[id].push(v); } printf("out\n"); id++; } } void light::arg_parse(int argc, char **argv) { cmdline::parser parser; #define STR_PARA(N, S, M, D, C) \ parser.add(#N, S, C, M, D); STR_PARAS #undef STR_PARA #define PARA(N, T, S, M, D, L, H, C) \ if (!strcmp(#T, "int")) parser.add(#N, S, C, M, D, cmdline::range((int)L, (int)H)); \ else parser.add(#N, S, C, M, D, cmdline::range((double)L, (double)H)); PARAS #undef PARA parser.parse_check(argc, argv); #define STR_PARA(N, S, M, D, C) \ OPT(N) = parser.get(#N); STR_PARAS #undef STR_PARA #define PARA(N, T, S, M, D, L, H, C) \ if (!strcmp(#T, "int")) OPT(N) = parser.get(#N); \ else OPT(N) = parser.get(#N); PARAS #undef PARA // print arguments printf("------------ arguments ------------\n"); #define STR_PARA(N, S, M, D, C) \ printf("%-20s: %s\n", #N, OPT(N).c_str()); STR_PARAS #undef STR_PARA #define PARA(N, T, S, M, D, L, H, C) \ if (!strcmp(#T, "int")) printf("%-20s: %-10d\n", #N, OPT(N)); \ else printf("%-20s: %-10.2f\n", #N, OPT(N)); PARAS #undef PARA printf("-----------------------------------\n"); std::string file_string = OPT(instance); filename = new char[file_string.size() + 1]; memcpy(filename, file_string.c_str(), file_string.length()); filename[file_string.length()] = '\0'; configure_from_file(OPT(config).c_str()); }