Skip to content

Commit

Permalink
Silence DIMACS warnings by default.
Browse files Browse the repository at this point in the history
  Added a -strict flag that checks correctness of "p cnf" line.
  • Loading branch information
niklasso committed Oct 31, 2012
1 parent 080d3db commit 386e4f3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
12 changes: 5 additions & 7 deletions minisat/core/Dimacs.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static void readClause(B& in, Solver& S, vec<Lit>& lits) {
}

template<class B, class Solver>
static void parse_DIMACS_main(B& in, Solver& S) {
static void parse_DIMACS_main(B& in, Solver& S, bool strictp = false) {
vec<Lit> lits;
int vars = 0;
int clauses = 0;
Expand All @@ -70,18 +70,16 @@ static void parse_DIMACS_main(B& in, Solver& S) {
readClause(in, S, lits);
S.addClause_(lits); }
}
if (vars != S.nVars())
fprintf(stderr, "WARNING! DIMACS header mismatch: wrong number of variables.\n");
if (cnt != clauses)
fprintf(stderr, "WARNING! DIMACS header mismatch: wrong number of clauses.\n");
if (strictp && cnt != clauses)
printf("PARSE ERROR! DIMACS header mismatch: wrong number of clauses\n");
}

// Inserts problem into solver.
//
template<class Solver>
static void parse_DIMACS(gzFile input_stream, Solver& S) {
static void parse_DIMACS(gzFile input_stream, Solver& S, bool strictp = false) {
StreamBuffer in(input_stream);
parse_DIMACS_main(in, S); }
parse_DIMACS_main(in, S, strictp); }

//=================================================================================================
}
Expand Down
3 changes: 2 additions & 1 deletion minisat/core/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ int main(int argc, char** argv)
IntOption verb ("MAIN", "verb", "Verbosity level (0=silent, 1=some, 2=more).", 1, IntRange(0, 2));
IntOption cpu_lim("MAIN", "cpu-lim","Limit on CPU time allowed in seconds.\n", 0, IntRange(0, INT32_MAX));
IntOption mem_lim("MAIN", "mem-lim","Limit on memory usage in megabytes.\n", 0, IntRange(0, INT32_MAX));
BoolOption strictp("MAIN", "strict", "Validate DIMACS header during parsing.", false);

parseOptions(argc, argv, true);

Expand Down Expand Up @@ -91,7 +92,7 @@ int main(int argc, char** argv)
printf("============================[ Problem Statistics ]=============================\n");
printf("| |\n"); }

parse_DIMACS(in, S);
parse_DIMACS(in, S, (bool)strictp);
gzclose(in);
FILE* res = (argc >= 3) ? fopen(argv[2], "wb") : NULL;

Expand Down
3 changes: 2 additions & 1 deletion minisat/simp/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ int main(int argc, char** argv)
StringOption dimacs ("MAIN", "dimacs", "If given, stop after preprocessing and write the result to this file.");
IntOption cpu_lim("MAIN", "cpu-lim","Limit on CPU time allowed in seconds.\n", 0, IntRange(0, INT32_MAX));
IntOption mem_lim("MAIN", "mem-lim","Limit on memory usage in megabytes.\n", 0, IntRange(0, INT32_MAX));
BoolOption strictp("MAIN", "strict", "Validate DIMACS header during parsing.", false);

parseOptions(argc, argv, true);

Expand Down Expand Up @@ -95,7 +96,7 @@ int main(int argc, char** argv)
printf("============================[ Problem Statistics ]=============================\n");
printf("| |\n"); }

parse_DIMACS(in, S);
parse_DIMACS(in, S, (bool)strictp);
gzclose(in);
FILE* res = (argc >= 3) ? fopen(argv[2], "wb") : NULL;

Expand Down

0 comments on commit 386e4f3

Please sign in to comment.