From af3dd36766c27ccea2441ec6a8858d90d03338ff Mon Sep 17 00:00:00 2001 From: Mate Soos Date: Mon, 9 Dec 2024 22:20:01 +0100 Subject: [PATCH] Allow setting indep set via 'c int' over multiple lines --- src/dimacsparser.h | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/dimacsparser.h b/src/dimacsparser.h index cab6f1b43..35b7e2dc8 100644 --- a/src/dimacsparser.h +++ b/src/dimacsparser.h @@ -73,6 +73,8 @@ class DimacsParser std::string stringify(uint32_t x) const; bool check_var(const uint32_t var); bool parseWeight(C& in); + vector ind_vars; + bool ind_vars_set = false; #ifdef DEBUG_DIMACSPARSER_CMS bool parse_solve_simp_comment(C& in, const bool solve); @@ -453,22 +455,33 @@ bool DimacsParser::parseComments(C& in, const std::string& str) cout << "c Parsed Solver::new_vars( " << n << " )" << endl; } } else if (str == "ind") { - vector sampl_vars; - if (!parseIndependentSet(in, sampl_vars)) return false; - solver->set_sampl_vars(sampl_vars); + if (!parseIndependentSet(in, ind_vars)) return false; + ind_vars_set = true } else if (str == "p") { in.skipWhitespace(); std::string str2; in.parseString(str2); if (str2 == "weight") { + if (ind_vars_set) { + cout << "ERROR: 'ind' and weights cannot be used together, you have to set independent support via 'c p show' " << endl; + exit(-1); + } solver->set_weighted(true); if (!parseWeight(in)) return false; } else if (str2 == "show") { + if (ind_vars_set) { + cout << "ERROR: 'c ind' and 'c p show' cannot be used together" << endl; + exit(-1); + } in.skipWhitespace(); vector sampl_vars; if (!parseIndependentSet(in, sampl_vars)) { return false; } solver->set_sampl_vars(sampl_vars); } else if (str2 == "optshow") { + if (ind_vars_set) { + cout << "ERROR: 'c ind' and 'c p optshow' cannot be used together" << endl; + exit(-1); + } in.skipWhitespace(); vector opt_sampl_vars; if (!parseIndependentSet(in, opt_sampl_vars)) { return false; } @@ -591,6 +604,7 @@ bool DimacsParser::parse_DIMACS_main(C& in) in.skipWhitespace(); switch (*in) { case EOF: + if (ind_vars_set) solver->set_sampl_vars(ind_vars); return true; case 'p': if (!parse_header(in)) {