1 /****************************************************************************************[Dimacs.h]
2 Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson
3 Copyright (c) 2007-2010, Niklas Sorensson
5 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
6 associated documentation files (the "Software"), to deal in the Software without restriction,
7 including without limitation the rights to use, copy, modify, merge, publish, distribute,
8 sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
11 The above copyright notice and this permission notice shall be included in all copies or
12 substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
15 NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
17 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
18 OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 **************************************************************************************************/
21 #ifndef Minisat_Dimacs_h
22 #define Minisat_Dimacs_h
26 #include "libs/minisat/ParseUtils.h"
27 #include "libs/minisat/SolverTypes.h"
31 //=================================================================================================
34 template<class B
, class Solver
>
35 static void readClause(B
& in
, Solver
& S
, vec
<Lit
>& lits
) {
39 parsed_lit
= parseInt(in
);
40 if (parsed_lit
== 0) break;
41 var
= abs(parsed_lit
)-1;
42 while (var
>= S
.nVars()) S
.newVar();
43 lits
.push( (parsed_lit
> 0) ? mkLit(var
) : ~mkLit(var
) );
47 template<class B
, class Solver
>
48 static void parse_DIMACS_main(B
& in
, Solver
& S
, bool strictp
= false) {
55 if (*in
== EOF
) break;
57 if (eagerMatch(in
, "p cnf")){
59 clauses
= parseInt(in
);
61 // if (clauses > 4000000)
64 printf("PARSE ERROR! Unexpected char: %c\n", *in
), exit(3);
66 } else if (*in
== 'c' || *in
== 'p')
70 readClause(in
, S
, lits
);
73 if (strictp
&& cnt
!= clauses
)
74 printf("PARSE ERROR! DIMACS header mismatch: wrong number of clauses\n");
77 // Inserts problem into solver.
79 template<class Solver
>
80 static void parse_DIMACS(gzFile input_stream
, Solver
& S
, bool strictp
= false) {
81 StreamBuffer
in(input_stream
);
82 parse_DIMACS_main(in
, S
, strictp
); }
84 //=================================================================================================