7 #include "core/Solver.h" 21 void display_meta(
bool display_desc =
false) {
22 std::cout <<
"Timetabler version " __TIMETABLER_VERSION__ << std::endl;
25 <<
"A highly customizable timetabling software for educational\n" 26 "institutions that encodes timetabling constraints as a SAT\n" 27 "formula and solves them using a MaxSAT solver." 34 const struct option long_options[] = {{
"help", no_argument, 0,
'h'},
35 {
"fields", required_argument, 0,
'f'},
36 {
"input", required_argument, 0,
'i'},
37 {
"custom", required_argument, 0,
'c'},
38 {
"output", required_argument, 0,
'o'},
39 {
"verbosity", required_argument, 0,
'b'},
40 {
"version", no_argument, 0,
'v'},
46 const std::string option_desc[] = {
"display this help",
49 "custom constraints file",
51 "specify verbosity level (0-3)" 60 void display_help(std::string exec =
"timetabler") {
62 std::cout <<
"\nUsage:\n";
63 std::cout <<
" " << exec
64 <<
" -i|--input <input_file>" 65 " -f|--fields <fields_file>" 66 " [-c|--custom <custom_constraints_file>]" 67 " -o|--output <output_file>" 69 std::cout <<
"Options:\n";
70 for (
int i = 0; long_options[i].name != 0; i++) {
71 if (long_options[i].val)
72 std::cout <<
'-' << char(long_options[i].val) <<
", ";
73 std::cout << std::left <<
"--" << std::setw(8) << long_options[i].name
74 <<
"\t" << option_desc[i] <<
"\n";
83 void display_error(std::string err) {
84 std::cout << err << std::endl;
85 std::cout <<
"Use --help option to know about supported options." 100 int main(
int argc,
char *
const *argv) {
101 std::string input_file, fields_file, custom_file, output_file;
102 unsigned verbosity = 3;
105 int option_index = 0;
107 getopt_long(argc, argv,
"hi:f:c:o:b:v", long_options, &option_index);
115 display_help(std::string(argv[0]));
121 input_file = std::string(optarg);
124 fields_file = std::string(optarg);
127 custom_file = std::string(optarg);
130 output_file = std::string(optarg);
133 verbosity = std::stoi(optarg);
138 display_error(
"Unrecognised argument: " + std::to_string(c));
145 display_error(
"Unrecognised argument: " + std::string(argv[optind]));
148 if (input_file ==
"" || fields_file ==
"" || output_file ==
"") {
150 "Fields filename, input filename and output filename are required.");
154 Parser parser(timetabler);
158 LOG(INFO) <<
"Input is valid";
160 LOG(ERROR) <<
"Input is invalid";
166 if (custom_file !=
"") {
168 LOG(INFO) <<
"Custom constraints parsed.";
void addConstraints()
Adds all the constraints with their respective weights using the Timetabler object to the solver...
static void setVerbosity(int verb)
Sets the verbosity level for logging. (0 - EMPTY, 1 - ERROR, 2 - WARNING, 3 - INFO). All messages of levels in and below the current verbosity level are displayed in the output.
Class for constraint adder.
Class for constraint encoder.
void parseFields(std::string file)
Parse the fields given in a file.
void parseInput(std::string file)
Parses the input given in a file.
bool verify()
Verifies if the input is valid.
void addVars()
Requests for variables to be added to the solver and stores the data.
void parseCustomConstraints(std::string file, ConstraintEncoder *constraintEncoder, Timetabler *timetabler)
Parses custom constraints given in a file and adds them to the solver.