ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
Dimacs.h
Go to the documentation of this file.
1/****************************************************************************************[Dimacs.h]
2Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson
3Copyright (c) 2007-2010, Niklas Sorensson
4
5Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
6associated documentation files (the "Software"), to deal in the Software without restriction,
7including without limitation the rights to use, copy, modify, merge, publish, distribute,
8sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
9furnished to do so, subject to the following conditions:
10
11The above copyright notice and this permission notice shall be included in all copies or
12substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
15NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
17DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
18OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19**************************************************************************************************/
20
21#ifndef Minisat_Dimacs_h
22#define Minisat_Dimacs_h
23
24#include <stdio.h>
25
28
30
31namespace Minisat {
32
33//=================================================================================================
34// DIMACS Parser:
35
36template<class B, class Solver>
37static void readClause(B& in, Solver& S, vec<Lit>& lits) {
38 int parsed_lit, var;
39 lits.clear();
40 for (;;){
41 parsed_lit = parseInt(in);
42 if (parsed_lit == 0) break;
43 var = abs(parsed_lit)-1;
44 while (var >= S.nVars()) S.newVar();
45 lits.push( (parsed_lit > 0) ? mkLit(var) : ~mkLit(var) );
46 }
47}
48
49template<class B, class Solver>
50static void parse_DIMACS_main(B& in, Solver& S) {
51 vec<Lit> lits;
52 int vars = 0;
53 int clauses = 0;
54 int cnt = 0;
55 for (;;){
56 skipWhitespace(in);
57 if (*in == EOF) break;
58 else if (*in == 'p'){
59 if (eagerMatch(in, "p cnf")){
60 vars = parseInt(in);
61 clauses = parseInt(in);
62 // SATRACE'06 hack
63 // if (clauses > 4000000)
64 // S.eliminate(true);
65 }else{
66 printf("PARSE ERROR! Unexpected char: %c\n", *in), exit(3);
67 }
68 } else if (*in == 'c' || *in == 'p')
69 skipLine(in);
70 else{
71 cnt++;
72 readClause(in, S, lits);
73 S.addClause_(lits); }
74 }
75 if (vars != S.nVars())
76 fprintf(stderr, "WARNING! DIMACS header mismatch: wrong number of variables.\n");
77 if (cnt != clauses)
78 fprintf(stderr, "WARNING! DIMACS header mismatch: wrong number of clauses.\n");
79}
80
81// Inserts problem into solver.
82//
83template<class Solver>
84static void parse_DIMACS(gzFile input_stream, Solver& S) {
85 StreamBuffer in(input_stream);
86 parse_DIMACS_main(in, S); }
87
88//=================================================================================================
89}
90
92
93#endif
#define ABC_NAMESPACE_CXX_HEADER_START
#define ABC_NAMESPACE_CXX_HEADER_END
Definition Alg.h:28
int var(Lit p)
Definition SolverTypes.h:64
Lit mkLit(Var var, bool sign=false)
Definition SolverTypes.h:60
VOID_HACK exit()
voidp gzFile
Definition zlib.h:1173