1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
/**CFile****************************************************************
FileName [msatSolverIo.c]
PackageName [A C version of SAT solver MINISAT, originally developed
in C++ by Niklas Een and Niklas Sorensson, Chalmers University of
Technology, Sweden: http://www.cs.chalmers.se/~een/Satzoo.]
Synopsis [Input/output of CNFs.]
Author [Alan Mishchenko <alanmi@eecs.berkeley.edu>]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - January 1, 2004.]
Revision [$Id: msatSolverIo.c,v 1.0 2004/01/01 1:00:00 alanmi Exp $]
***********************************************************************/
#include "msatInt.h"
ABC_NAMESPACE_IMPL_START
////////////////////////////////////////////////////////////////////////
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
static char * Msat_TimeStamp();
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Msat_SolverPrintAssignment( Msat_Solver_t * p )
{
int i;
printf( "Current assignments are: \n" );
for ( i = 0; i < p->nVars; i++ )
printf( "%d", i % 10 );
printf( "\n" );
for ( i = 0; i < p->nVars; i++ )
if ( p->pAssigns[i] == MSAT_VAR_UNASSIGNED )
printf( "." );
else
{
assert( i == MSAT_LIT2VAR(p->pAssigns[i]) );
if ( MSAT_LITSIGN(p->pAssigns[i]) )
printf( "0" );
else
printf( "1" );
}
printf( "\n" );
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Msat_SolverPrintClauses( Msat_Solver_t * p )
{
Msat_Clause_t ** pClauses;
int nClauses, i;
printf( "Original clauses: \n" );
nClauses = Msat_ClauseVecReadSize( p->vClauses );
pClauses = Msat_ClauseVecReadArray( p->vClauses );
for ( i = 0; i < nClauses; i++ )
{
printf( "%3d: ", i );
Msat_ClausePrint( pClauses[i] );
}
printf( "Learned clauses: \n" );
nClauses = Msat_ClauseVecReadSize( p->vLearned );
pClauses = Msat_ClauseVecReadArray( p->vLearned );
for ( i = 0; i < nClauses; i++ )
{
printf( "%3d: ", i );
Msat_ClausePrint( pClauses[i] );
}
printf( "Variable activity: \n" );
for ( i = 0; i < p->nVars; i++ )
printf( "%3d : %.4f\n", i, p->pdActivity[i] );
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Msat_SolverWriteDimacs( Msat_Solver_t * p, char * pFileName )
{
FILE * pFile;
Msat_Clause_t ** pClauses;
int nClauses, i;
nClauses = Msat_ClauseVecReadSize(p->vClauses) + Msat_ClauseVecReadSize(p->vLearned);
for ( i = 0; i < p->nVars; i++ )
nClauses += ( p->pLevel[i] == 0 );
pFile = fopen( pFileName, "wb" );
fprintf( pFile, "c Produced by Msat_SolverWriteDimacs() on %s\n", Msat_TimeStamp() );
fprintf( pFile, "p cnf %d %d\n", p->nVars, nClauses );
nClauses = Msat_ClauseVecReadSize( p->vClauses );
pClauses = Msat_ClauseVecReadArray( p->vClauses );
for ( i = 0; i < nClauses; i++ )
Msat_ClauseWriteDimacs( pFile, pClauses[i], 1 );
nClauses = Msat_ClauseVecReadSize( p->vLearned );
pClauses = Msat_ClauseVecReadArray( p->vLearned );
for ( i = 0; i < nClauses; i++ )
Msat_ClauseWriteDimacs( pFile, pClauses[i], 1 );
// write zero-level assertions
for ( i = 0; i < p->nVars; i++ )
if ( p->pLevel[i] == 0 )
fprintf( pFile, "%s%d 0\n", ((p->pAssigns[i]&1)? "-": ""), i + 1 );
fprintf( pFile, "\n" );
fclose( pFile );
}
/**Function*************************************************************
Synopsis [Returns the time stamp.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
char * Msat_TimeStamp()
{
static char Buffer[100];
time_t ltime;
char * TimeStamp;
// get the current time
time( <ime );
TimeStamp = asctime( localtime( <ime ) );
TimeStamp[ strlen(TimeStamp) - 1 ] = 0;
strcpy( Buffer, TimeStamp );
return Buffer;
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
ABC_NAMESPACE_IMPL_END
|