abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
msatOrderJ.c File Reference
#include "msatInt.h"

Go to the source code of this file.

Data Structures

struct  Msat_OrderVar_t_
 
struct  Msat_OrderRing_t_
 
struct  Msat_Order_t_
 DECLARATIONS ///. More...
 

Macros

#define Msat_OrderVarIsInBoundary(p, i)   ((p)->pVars[i].pNext)
 
#define Msat_OrderVarIsAssigned(p, i)   ((p)->pSat->pAssigns[i] != MSAT_VAR_UNASSIGNED)
 
#define Msat_OrderVarIsUsedInCone(p, i)   ((p)->pSat->vVarsUsed->pArray[i])
 
#define Msat_OrderRingForEachEntry(pRing, pVar, pNext)
 

Typedefs

typedef
typedefABC_NAMESPACE_IMPL_START
struct Msat_OrderVar_t_ 
Msat_OrderVar_t
 DECLARATIONS ///. More...
 
typedef struct Msat_OrderRing_t_ Msat_OrderRing_t
 

Functions

static void Msat_OrderRingAddLast (Msat_OrderRing_t *pRing, Msat_OrderVar_t *pVar)
 
static void Msat_OrderRingRemove (Msat_OrderRing_t *pRing, Msat_OrderVar_t *pVar)
 
Msat_Order_tMsat_OrderAlloc (Msat_Solver_t *pSat)
 FUNCTION DEFINITIONS ///. More...
 
void Msat_OrderSetBounds (Msat_Order_t *p, int nVarsMax)
 
void Msat_OrderClean (Msat_Order_t *p, Msat_IntVec_t *vCone)
 
int Msat_OrderCheck (Msat_Order_t *p)
 
void Msat_OrderFree (Msat_Order_t *p)
 
int Msat_OrderVarSelect (Msat_Order_t *p)
 
void Msat_OrderVarAssigned (Msat_Order_t *p, int Var)
 
void Msat_OrderVarUnassigned (Msat_Order_t *p, int Var)
 
void Msat_OrderUpdate (Msat_Order_t *p, int Var)
 

Variables

clock_t timeSelect
 DECLARATIONS ///. More...
 
clock_t timeAssign
 

Macro Definition Documentation

#define Msat_OrderRingForEachEntry (   pRing,
  pVar,
  pNext 
)
Value:
for ( pVar = pRing, \
pNext = pVar? pVar->pNext : NULL; \
pVar; \
pVar = (pNext != pRing)? pNext : NULL, \
pNext = pVar? pVar->pNext : NULL )

Definition at line 74 of file msatOrderJ.c.

#define Msat_OrderVarIsAssigned (   p,
 
)    ((p)->pSat->pAssigns[i] != MSAT_VAR_UNASSIGNED)

Definition at line 70 of file msatOrderJ.c.

#define Msat_OrderVarIsInBoundary (   p,
 
)    ((p)->pVars[i].pNext)

Definition at line 69 of file msatOrderJ.c.

#define Msat_OrderVarIsUsedInCone (   p,
 
)    ((p)->pSat->vVarsUsed->pArray[i])

Definition at line 71 of file msatOrderJ.c.

Typedef Documentation

Definition at line 37 of file msatOrderJ.c.

typedef typedefABC_NAMESPACE_IMPL_START struct Msat_OrderVar_t_ Msat_OrderVar_t

DECLARATIONS ///.

CFile****************************************************************

FileName [msatOrder.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 [The manager of variable assignment.]

Author [Alan Mishchenko alanm.nosp@m.i@ee.nosp@m.cs.be.nosp@m.rkel.nosp@m.ey.ed.nosp@m.u]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - January 1, 2004.]

Revision [

Id:
msatOrder.c,v 1.0 2005/05/30 1:00:00 alanmi Exp

]

Definition at line 36 of file msatOrderJ.c.

Function Documentation

Msat_Order_t* Msat_OrderAlloc ( Msat_Solver_t pSat)

FUNCTION DEFINITIONS ///.

Function*************************************************************

Synopsis [Allocates the ordering structure.]

Description []

SideEffects []

SeeAlso []

Definition at line 102 of file msatOrderJ.c.

103 {
104  Msat_Order_t * p;
105  p = ALLOC( Msat_Order_t, 1 );
106  memset( p, 0, sizeof(Msat_Order_t) );
107  p->pSat = pSat;
108  Msat_OrderSetBounds( p, pSat->nVarsAlloc );
109  return p;
110 }
char * memset()
static Llb_Mgr_t * p
Definition: llb3Image.c:950
DECLARATIONS ///.
Definition: msatOrderH.c:31
void Msat_OrderSetBounds(Msat_Order_t *p, int nVarsMax)
Definition: msatOrderJ.c:123
#define ALLOC(type, num)
Definition: avl.h:27
Msat_Solver_t * pSat
Definition: msatOrderH.c:33
int Msat_OrderCheck ( Msat_Order_t p)

Function*************************************************************

Synopsis [Checks that the J-boundary is okay.]

Description []

SideEffects []

SeeAlso []

Definition at line 171 of file msatOrderJ.c.

172 {
173  Msat_OrderVar_t * pVar, * pNext;
174  Msat_IntVec_t * vRound;
175  int * pRound, nRound;
176  int * pVars, nVars, i, k;
177  int Counter = 0;
178 
179  // go through all the variables in the boundary
180  Msat_OrderRingForEachEntry( p->rVars.pRoot, pVar, pNext )
181  {
182  assert( !Msat_OrderVarIsAssigned(p, pVar->Num) );
183  // go though all the variables in the neighborhood
184  // and check that it is true that there is least one assigned
185  vRound = (Msat_IntVec_t *)Msat_ClauseVecReadEntry( p->pSat->vAdjacents, pVar->Num );
186  nRound = Msat_IntVecReadSize( vRound );
187  pRound = Msat_IntVecReadArray( vRound );
188  for ( i = 0; i < nRound; i++ )
189  {
190  if ( !Msat_OrderVarIsUsedInCone(p, pRound[i]) )
191  continue;
192  if ( Msat_OrderVarIsAssigned(p, pRound[i]) )
193  break;
194  }
195 // assert( i != nRound );
196 // if ( i == nRound )
197 // return 0;
198  if ( i == nRound )
199  Counter++;
200  }
201  if ( Counter > 0 )
202  printf( "%d(%d) ", Counter, p->rVars.nItems );
203 
204  // we may also check other unassigned variables in the cone
205  // to make sure that if they are not in J-boundary,
206  // then they do not have an assigned neighbor
207  nVars = Msat_IntVecReadSize( p->pSat->vConeVars );
208  pVars = Msat_IntVecReadArray( p->pSat->vConeVars );
209  for ( i = 0; i < nVars; i++ )
210  {
211  assert( Msat_OrderVarIsUsedInCone(p, pVars[i]) );
212  // skip assigned vars, vars in the boundary, and vars not used in the cone
213  if ( Msat_OrderVarIsAssigned(p, pVars[i]) ||
214  Msat_OrderVarIsInBoundary(p, pVars[i]) )
215  continue;
216  // make sure, it does not have assigned neighbors
217  vRound = (Msat_IntVec_t *)Msat_ClauseVecReadEntry( p->pSat->vAdjacents, pVars[i] );
218  nRound = Msat_IntVecReadSize( vRound );
219  pRound = Msat_IntVecReadArray( vRound );
220  for ( k = 0; k < nRound; k++ )
221  {
222  if ( !Msat_OrderVarIsUsedInCone(p, pRound[k]) )
223  continue;
224  if ( Msat_OrderVarIsAssigned(p, pRound[k]) )
225  break;
226  }
227 // assert( k == nRound );
228 // if ( k != nRound )
229 // return 0;
230  }
231  return 1;
232 }
Msat_Clause_t * Msat_ClauseVecReadEntry(Msat_ClauseVec_t *p, int i)
Msat_OrderRing_t rVars
Definition: msatOrderJ.c:60
int Msat_IntVecReadSize(Msat_IntVec_t *p)
Definition: msatVec.c:233
typedefABC_NAMESPACE_IMPL_START struct Msat_OrderVar_t_ Msat_OrderVar_t
DECLARATIONS ///.
Definition: msatOrderJ.c:36
static int Counter
#define Msat_OrderVarIsInBoundary(p, i)
Definition: msatOrderJ.c:69
#define Msat_OrderVarIsAssigned(p, i)
Definition: msatOrderJ.c:70
int * Msat_IntVecReadArray(Msat_IntVec_t *p)
Definition: msatVec.c:217
#define Msat_OrderRingForEachEntry(pRing, pVar, pNext)
Definition: msatOrderJ.c:74
#define assert(ex)
Definition: util_old.h:213
Msat_OrderVar_t * pRoot
Definition: msatOrderJ.c:50
#define Msat_OrderVarIsUsedInCone(p, i)
Definition: msatOrderJ.c:71
Msat_Solver_t * pSat
Definition: msatOrderH.c:33
void Msat_OrderClean ( Msat_Order_t p,
Msat_IntVec_t vCone 
)

Function*************************************************************

Synopsis [Cleans the ordering structure.]

Description []

SideEffects []

SeeAlso []

Definition at line 150 of file msatOrderJ.c.

151 {
152  Msat_OrderVar_t * pVar, * pNext;
153  // quickly undo the ring
154  Msat_OrderRingForEachEntry( p->rVars.pRoot, pVar, pNext )
155  pVar->pNext = pVar->pPrev = NULL;
156  p->rVars.pRoot = NULL;
157  p->rVars.nItems = 0;
158 }
Msat_OrderRing_t rVars
Definition: msatOrderJ.c:60
typedefABC_NAMESPACE_IMPL_START struct Msat_OrderVar_t_ Msat_OrderVar_t
DECLARATIONS ///.
Definition: msatOrderJ.c:36
#define Msat_OrderRingForEachEntry(pRing, pVar, pNext)
Definition: msatOrderJ.c:74
Msat_OrderVar_t * pRoot
Definition: msatOrderJ.c:50
void Msat_OrderFree ( Msat_Order_t p)

Function*************************************************************

Synopsis [Frees the ordering structure.]

Description []

SideEffects []

SeeAlso []

Definition at line 245 of file msatOrderJ.c.

246 {
247  free( p->pVars );
248  free( p );
249 }
VOID_HACK free()
Msat_OrderVar_t * pVars
Definition: msatOrderJ.c:58
void Msat_OrderRingAddLast ( Msat_OrderRing_t pRing,
Msat_OrderVar_t pVar 
)
static

Function*************************************************************

Synopsis [Adds node to the end of the ring.]

Description []

SideEffects []

SeeAlso []

Definition at line 406 of file msatOrderJ.c.

407 {
408 //printf( "adding %d\n", pVar->Num );
409  // check that the node is not in a ring
410  assert( pVar->pPrev == NULL );
411  assert( pVar->pNext == NULL );
412  // if the ring is empty, make the node point to itself
413  pRing->nItems++;
414  if ( pRing->pRoot == NULL )
415  {
416  pRing->pRoot = pVar;
417  pVar->pPrev = pVar;
418  pVar->pNext = pVar;
419  return;
420  }
421  // if the ring is not empty, add it as the last entry
422  pVar->pPrev = pRing->pRoot->pPrev;
423  pVar->pNext = pRing->pRoot;
424  pVar->pPrev->pNext = pVar;
425  pVar->pNext->pPrev = pVar;
426 
427  // move the root so that it points to the new entry
428 // pRing->pRoot = pRing->pRoot->pPrev;
429 }
#define assert(ex)
Definition: util_old.h:213
Msat_OrderVar_t * pRoot
Definition: msatOrderJ.c:50
void Msat_OrderRingRemove ( Msat_OrderRing_t pRing,
Msat_OrderVar_t pVar 
)
static

Function*************************************************************

Synopsis [Removes the node from the ring.]

Description []

SideEffects []

SeeAlso []

Definition at line 442 of file msatOrderJ.c.

443 {
444 //printf( "removing %d\n", pVar->Num );
445  // check that the var is in a ring
446  assert( pVar->pPrev );
447  assert( pVar->pNext );
448  pRing->nItems--;
449  if ( pRing->nItems == 0 )
450  {
451  assert( pRing->pRoot == pVar );
452  pVar->pPrev = NULL;
453  pVar->pNext = NULL;
454  pRing->pRoot = NULL;
455  return;
456  }
457  // move the root if needed
458  if ( pRing->pRoot == pVar )
459  pRing->pRoot = pVar->pNext;
460  // move the root to the next entry after pVar
461  // this way all the additions to the list will be traversed first
462 // pRing->pRoot = pVar->pPrev;
463  // delete the node
464  pVar->pPrev->pNext = pVar->pNext;
465  pVar->pNext->pPrev = pVar->pPrev;
466  pVar->pPrev = NULL;
467  pVar->pNext = NULL;
468 }
#define assert(ex)
Definition: util_old.h:213
Msat_OrderVar_t * pRoot
Definition: msatOrderJ.c:50
void Msat_OrderSetBounds ( Msat_Order_t p,
int  nVarsMax 
)

Function*************************************************************

Synopsis [Sets the bound of the ordering structure.]

Description [Should be called whenever the SAT solver is resized.]

SideEffects []

SeeAlso []

Definition at line 123 of file msatOrderJ.c.

124 {
125  int i;
126  // add variables if they are missing
127  if ( p->nVarsAlloc < nVarsMax )
128  {
129  p->pVars = REALLOC( Msat_OrderVar_t, p->pVars, nVarsMax );
130  for ( i = p->nVarsAlloc; i < nVarsMax; i++ )
131  {
132  p->pVars[i].pNext = p->pVars[i].pPrev = NULL;
133  p->pVars[i].Num = i;
134  }
135  p->nVarsAlloc = nVarsMax;
136  }
137 }
typedefABC_NAMESPACE_IMPL_START struct Msat_OrderVar_t_ Msat_OrderVar_t
DECLARATIONS ///.
Definition: msatOrderJ.c:36
#define REALLOC(type, obj, num)
Definition: avl.h:29
Msat_OrderVar_t * pVars
Definition: msatOrderJ.c:58
void Msat_OrderUpdate ( Msat_Order_t p,
int  Var 
)

Function*************************************************************

Synopsis [Updates the order after a variable changed weight.]

Description []

SideEffects []

SeeAlso []

Definition at line 390 of file msatOrderJ.c.

391 {
392 }
void Msat_OrderVarAssigned ( Msat_Order_t p,
int  Var 
)

Function*************************************************************

Synopsis [Updates J-boundary when the variable is assigned.]

Description []

SideEffects []

SeeAlso []

Definition at line 305 of file msatOrderJ.c.

306 {
307  Msat_IntVec_t * vRound;
308  int i;//, clk = clock();
309 
310  // make sure the variable is in the boundary
311  assert( Var < p->nVarsAlloc );
312  // if it is not in the boundary (initial decision, random decision), do not remove
313  if ( Msat_OrderVarIsInBoundary( p, Var ) )
314  Msat_OrderRingRemove( &p->rVars, &p->pVars[Var] );
315  // add to the boundary those neighbors that are (1) unassigned, (2) not in boundary
316  // because for them we know that there is a variable (Var) which is assigned
317  vRound = (Msat_IntVec_t *)p->pSat->vAdjacents->pArray[Var];
318  for ( i = 0; i < vRound->nSize; i++ )
319  {
320  if ( !Msat_OrderVarIsUsedInCone(p, vRound->pArray[i]) )
321  continue;
322  if ( Msat_OrderVarIsAssigned(p, vRound->pArray[i]) )
323  continue;
324  if ( Msat_OrderVarIsInBoundary(p, vRound->pArray[i]) )
325  continue;
326  Msat_OrderRingAddLast( &p->rVars, &p->pVars[vRound->pArray[i]] );
327  }
328 //timeSelect += clock() - clk;
329 // Msat_OrderCheck( p );
330 }
static void Msat_OrderRingAddLast(Msat_OrderRing_t *pRing, Msat_OrderVar_t *pVar)
Definition: msatOrderJ.c:406
Msat_OrderRing_t rVars
Definition: msatOrderJ.c:60
for(p=first;p->value< newval;p=p->next)
#define Msat_OrderVarIsInBoundary(p, i)
Definition: msatOrderJ.c:69
static void Msat_OrderRingRemove(Msat_OrderRing_t *pRing, Msat_OrderVar_t *pVar)
Definition: msatOrderJ.c:442
#define Msat_OrderVarIsAssigned(p, i)
Definition: msatOrderJ.c:70
int Var
Definition: SolverTypes.h:42
#define assert(ex)
Definition: util_old.h:213
#define Msat_OrderVarIsUsedInCone(p, i)
Definition: msatOrderJ.c:71
int * pArray
Definition: msatInt.h:164
Msat_OrderVar_t * pVars
Definition: msatOrderJ.c:58
Msat_Solver_t * pSat
Definition: msatOrderH.c:33
int Msat_OrderVarSelect ( Msat_Order_t p)

Function*************************************************************

Synopsis [Selects the next variable to assign.]

Description []

SideEffects []

SeeAlso []

Definition at line 262 of file msatOrderJ.c.

263 {
264  Msat_OrderVar_t * pVar, * pNext, * pVarBest;
265  double * pdActs = p->pSat->pdActivity;
266  double dfActBest;
267 // clock_t clk = clock();
268 
269  pVarBest = NULL;
270  dfActBest = -1.0;
271  Msat_OrderRingForEachEntry( p->rVars.pRoot, pVar, pNext )
272  {
273  if ( dfActBest < pdActs[pVar->Num] )
274  {
275  dfActBest = pdActs[pVar->Num];
276  pVarBest = pVar;
277  }
278  }
279 //timeSelect += clock() - clk;
280 //timeAssign += clock() - clk;
281 
282 //if ( pVarBest && pVarBest->Num % 1000 == 0 )
283 //printf( "%d ", p->rVars.nItems );
284 
285 // Msat_OrderCheck( p );
286  if ( pVarBest )
287  {
288  assert( Msat_OrderVarIsUsedInCone(p, pVarBest->Num) );
289  return pVarBest->Num;
290  }
291  return MSAT_ORDER_UNKNOWN;
292 }
#define MSAT_ORDER_UNKNOWN
Definition: msatInt.h:70
Msat_OrderRing_t rVars
Definition: msatOrderJ.c:60
typedefABC_NAMESPACE_IMPL_START struct Msat_OrderVar_t_ Msat_OrderVar_t
DECLARATIONS ///.
Definition: msatOrderJ.c:36
#define Msat_OrderRingForEachEntry(pRing, pVar, pNext)
Definition: msatOrderJ.c:74
#define assert(ex)
Definition: util_old.h:213
Msat_OrderVar_t * pRoot
Definition: msatOrderJ.c:50
#define Msat_OrderVarIsUsedInCone(p, i)
Definition: msatOrderJ.c:71
Msat_Solver_t * pSat
Definition: msatOrderH.c:33
void Msat_OrderVarUnassigned ( Msat_Order_t p,
int  Var 
)

Function*************************************************************

Synopsis [Updates the order after a variable is unassigned.]

Description []

SideEffects []

SeeAlso []

Definition at line 343 of file msatOrderJ.c.

344 {
345  Msat_IntVec_t * vRound, * vRound2;
346  int i, k;//, clk = clock();
347 
348  // make sure the variable is not in the boundary
349  assert( Var < p->nVarsAlloc );
351  // go through its neigbors - if one of them is assigned add this var
352  // add to the boundary those neighbors that are not there already
353  // this will also get rid of variable outside of the current cone
354  // because they are unassigned in Msat_SolverPrepare()
355  vRound = (Msat_IntVec_t *)p->pSat->vAdjacents->pArray[Var];
356  for ( i = 0; i < vRound->nSize; i++ )
357  if ( Msat_OrderVarIsAssigned(p, vRound->pArray[i]) )
358  break;
359  if ( i != vRound->nSize )
360  Msat_OrderRingAddLast( &p->rVars, &p->pVars[Var] );
361 
362  // unassigning a variable may lead to its adjacents dropping from the boundary
363  for ( i = 0; i < vRound->nSize; i++ )
364  if ( Msat_OrderVarIsInBoundary(p, vRound->pArray[i]) )
365  { // the neighbor is in the J-boundary (and unassigned)
366  assert( !Msat_OrderVarIsAssigned(p, vRound->pArray[i]) );
367  vRound2 = (Msat_IntVec_t *)p->pSat->vAdjacents->pArray[vRound->pArray[i]];
368  // go through its neighbors and determine if there is at least one assigned
369  for ( k = 0; k < vRound2->nSize; k++ )
370  if ( Msat_OrderVarIsAssigned(p, vRound2->pArray[k]) )
371  break;
372  if ( k == vRound2->nSize ) // there is no assigned vars, delete this one
373  Msat_OrderRingRemove( &p->rVars, &p->pVars[vRound->pArray[i]] );
374  }
375 //timeSelect += clock() - clk;
376 // Msat_OrderCheck( p );
377 }
static void Msat_OrderRingAddLast(Msat_OrderRing_t *pRing, Msat_OrderVar_t *pVar)
Definition: msatOrderJ.c:406
Msat_OrderRing_t rVars
Definition: msatOrderJ.c:60
for(p=first;p->value< newval;p=p->next)
#define Msat_OrderVarIsInBoundary(p, i)
Definition: msatOrderJ.c:69
static void Msat_OrderRingRemove(Msat_OrderRing_t *pRing, Msat_OrderVar_t *pVar)
Definition: msatOrderJ.c:442
#define Msat_OrderVarIsAssigned(p, i)
Definition: msatOrderJ.c:70
int Var
Definition: SolverTypes.h:42
#define assert(ex)
Definition: util_old.h:213
int * pArray
Definition: msatInt.h:164
Msat_OrderVar_t * pVars
Definition: msatOrderJ.c:58
Msat_Solver_t * pSat
Definition: msatOrderH.c:33

Variable Documentation

clock_t timeAssign

Definition at line 29 of file fraigMan.c.

clock_t timeSelect

DECLARATIONS ///.

CFile****************************************************************

FileName [fraigMan.c]

PackageName [FRAIG: Functionally reduced AND-INV graphs.]

Synopsis [Implementation of the FRAIG manager.]

Author [Alan Mishchenko alanm.nosp@m.i@ee.nosp@m.cs.be.nosp@m.rkel.nosp@m.ey.ed.nosp@m.u]

Affiliation [UC Berkeley]

Date [Ver. 2.0. Started - October 1, 2004]

Revision [

Id:
fraigMan.c,v 1.11 2005/07/08 01:01:31 alanmi Exp

]

Definition at line 28 of file fraigMan.c.