102 lines
2.8 KiB
C++
102 lines
2.8 KiB
C++
#include <chrono>
|
|
#include "light.hpp"
|
|
#include <unistd.h>
|
|
#include <thread>
|
|
#include <iostream>
|
|
|
|
#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<char*>[OPT(threads)];
|
|
configure_val = new vec<double>[OPT(threads)];
|
|
return;
|
|
}
|
|
assert(false);
|
|
// 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<char*>[ws];
|
|
// configure_val = new vec<double>[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<std::string>(#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<int>(#N, S, C, M, D, cmdline::range((int)L, (int)H)); \
|
|
else parser.add<double>(#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<std::string>(#N);
|
|
STR_PARAS
|
|
#undef STR_PARA
|
|
|
|
#define PARA(N, T, S, M, D, L, H, C) \
|
|
if (!strcmp(#T, "int")) OPT(N) = parser.get<int>(#N); \
|
|
else OPT(N) = parser.get<double>(#N);
|
|
PARAS
|
|
#undef PARA
|
|
|
|
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());
|
|
|
|
} |