18 #if defined(__GNUC__) // Linux or Mac OS X.
39 DEFINE_bool(all_solutions,
false,
"Search for all solutions.");
41 "Maximum number of solution to search for, 0 means unspecified.");
43 "If false, the solver must follow the defined search."
44 "If true, other search are allowed.");
45 DEFINE_int32(threads, 0,
"Number of threads the solver will use.");
46 DEFINE_bool(presolve,
true,
"Presolve the model to simplify it.");
47 DEFINE_bool(statistics,
false,
"Print solver statistics after search.");
49 "Read the FlatZinc from stdin, not from a file.");
52 "Define problem name when reading from stdin.");
65 char all_param[] =
"--all_solutions";
66 char free_param[] =
"--free_search";
67 char threads_param[] =
"--threads";
68 char solutions_param[] =
"--num_solutions";
69 char logging_param[] =
"--fz_logging";
70 char statistics_param[] =
"--statistics";
71 char seed_param[] =
"--fz_seed";
72 char verbose_param[] =
"--fz_verbose";
73 char debug_param[] =
"--fz_debug";
74 char time_param[] =
"--time_limit";
75 bool use_time_param =
false;
76 for (
int i = 1; i < *argc; ++i) {
77 if (strcmp((*argv)[i],
"-a") == 0) {
78 (*argv)[i] = all_param;
80 if (strcmp((*argv)[i],
"-f") == 0) {
81 (*argv)[i] = free_param;
83 if (strcmp((*argv)[i],
"-p") == 0) {
84 (*argv)[i] = threads_param;
86 if (strcmp((*argv)[i],
"-n") == 0) {
87 (*argv)[i] = solutions_param;
89 if (strcmp((*argv)[i],
"-l") == 0) {
90 (*argv)[i] = logging_param;
92 if (strcmp((*argv)[i],
"-s") == 0) {
93 (*argv)[i] = statistics_param;
95 if (strcmp((*argv)[i],
"-r") == 0) {
96 (*argv)[i] = seed_param;
98 if (strcmp((*argv)[i],
"-v") == 0) {
99 (*argv)[i] = verbose_param;
101 if (strcmp((*argv)[i],
"-d") == 0) {
102 (*argv)[i] = debug_param;
104 if (strcmp((*argv)[i],
"-t") == 0) {
105 (*argv)[i] = time_param;
106 use_time_param =
true;
109 const char kUsage[] =
110 "Usage: see flags.\nThis program parses and solve a flatzinc problem.";
112 gflags::SetUsageMessage(kUsage);
113 gflags::ParseCommandLineFlags(argc, argv,
true);
114 google::InitGoogleLogging((*argv)[0]);
117 if (use_time_param) {
118 FLAGS_time_limit /= 1000.0;
126 std::string problem_name = input_is_filename ?
input : FLAGS_fz_model_name;
127 if (input_is_filename || absl::EndsWith(problem_name,
".fzn")) {
128 CHECK(absl::EndsWith(problem_name,
".fzn"));
129 problem_name.resize(problem_name.size() - 4);
130 const size_t found = problem_name.find_last_of(
"/\\");
131 if (found != std::string::npos) {
132 problem_name = problem_name.substr(found + 1);
136 if (input_is_filename) {
142 FZLOG <<
"File " << (input_is_filename ?
input :
"stdin") <<
" parsed in "
163 int main(
int argc,
char** argv) {
169 if (FLAGS_read_from_stdin) {
170 std::string currentLine;
171 while (std::getline(std::cin, currentLine)) {
172 input.append(currentLine);
176 LOG(ERROR) <<
"Usage: " << argv[0] <<
" <file>";
184 !FLAGS_read_from_stdin);
186 parameters.display_all_solutions = FLAGS_all_solutions;
187 parameters.use_free_search = FLAGS_free_search;
188 parameters.verbose_logging = FLAGS_fz_logging;
190 FLAGS_num_solutions == 0 ?
191 (FLAGS_num_solutions = FLAGS_all_solutions ?
kint32max : 1)
192 : FLAGS_num_solutions;
194 parameters.display_statistics = FLAGS_statistics;
196 parameters.max_time_in_seconds = FLAGS_time_limit;