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

Go to the source code of this file.

Data Structures

struct  Msat_Order_t_
 DECLARATIONS ///. More...
 

Macros

#define HLEFT(i)   ((i)<<1)
 
#define HRIGHT(i)   (((i)<<1)+1)
 
#define HPARENT(i)   ((i)>>1)
 
#define HCOMPARE(p, i, j)   ((p)->pSat->pdActivity[i] > (p)->pSat->pdActivity[j])
 
#define HHEAP(p, i)   ((p)->vHeap->pArray[i])
 
#define HSIZE(p)   ((p)->vHeap->nSize)
 
#define HOKAY(p, i)   ((i) >= 0 && (i) < (p)->vIndex->nSize)
 
#define HINHEAP(p, i)   (HOKAY(p, i) && (p)->vIndex->pArray[i] != 0)
 
#define HEMPTY(p)   (HSIZE(p) == 1)
 

Functions

static int Msat_HeapCheck_rec (Msat_Order_t *p, int i)
 
static int Msat_HeapGetTop (Msat_Order_t *p)
 
static void Msat_HeapInsert (Msat_Order_t *p, int n)
 
static void Msat_HeapIncrease (Msat_Order_t *p, int n)
 
static void Msat_HeapPercolateUp (Msat_Order_t *p, int i)
 
static void Msat_HeapPercolateDown (Msat_Order_t *p, int i)
 
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

abctime timeSelect
 DECLARATIONS ///. More...
 

Macro Definition Documentation

#define HCOMPARE (   p,
  i,
 
)    ((p)->pSat->pdActivity[i] > (p)->pSat->pdActivity[j])

Definition at line 47 of file msatOrderH.c.

#define HEMPTY (   p)    (HSIZE(p) == 1)

Definition at line 52 of file msatOrderH.c.

#define HHEAP (   p,
 
)    ((p)->vHeap->pArray[i])

Definition at line 48 of file msatOrderH.c.

#define HINHEAP (   p,
 
)    (HOKAY(p, i) && (p)->vIndex->pArray[i] != 0)

Definition at line 51 of file msatOrderH.c.

#define HLEFT (   i)    ((i)<<1)

Definition at line 44 of file msatOrderH.c.

#define HOKAY (   p,
 
)    ((i) >= 0 && (i) < (p)->vIndex->nSize)

Definition at line 50 of file msatOrderH.c.

#define HPARENT (   i)    ((i)>>1)

Definition at line 46 of file msatOrderH.c.

#define HRIGHT (   i)    (((i)<<1)+1)

Definition at line 45 of file msatOrderH.c.

#define HSIZE (   p)    ((p)->vHeap->nSize)

Definition at line 49 of file msatOrderH.c.

Function Documentation

int Msat_HeapCheck_rec ( Msat_Order_t p,
int  i 
)
static

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

Synopsis [Checks the heap property recursively.]

Description []

SideEffects []

SeeAlso []

Definition at line 282 of file msatOrderH.c.

283 {
284  return i >= HSIZE(p) ||
285  (
286  ( HPARENT(i) == 0 || !HCOMPARE(p, HHEAP(p, i), HHEAP(p, HPARENT(i))) ) &&
287 
288  Msat_HeapCheck_rec( p, HLEFT(i) ) &&
289 
290  Msat_HeapCheck_rec( p, HRIGHT(i) )
291  );
292 }
#define HPARENT(i)
Definition: msatOrderH.c:46
#define HCOMPARE(p, i, j)
Definition: msatOrderH.c:47
static int Msat_HeapCheck_rec(Msat_Order_t *p, int i)
Definition: msatOrderH.c:282
#define HRIGHT(i)
Definition: msatOrderH.c:45
#define HLEFT(i)
Definition: msatOrderH.c:44
#define HSIZE(p)
Definition: msatOrderH.c:49
#define HHEAP(p, i)
Definition: msatOrderH.c:48
int Msat_HeapGetTop ( Msat_Order_t p)
static

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

Synopsis [Retrieves the minimum element.]

Description []

SideEffects []

SeeAlso []

Definition at line 305 of file msatOrderH.c.

306 {
307  int Result, NewTop;
308  Result = HHEAP(p, 1);
309  NewTop = Msat_IntVecPop( p->vHeap );
310  p->vHeap->pArray[1] = NewTop;
311  p->vIndex->pArray[NewTop] = 1;
312  p->vIndex->pArray[Result] = 0;
313  if ( p->vHeap->nSize > 1 )
314  Msat_HeapPercolateDown( p, 1 );
315  return Result;
316 }
static void Msat_HeapPercolateDown(Msat_Order_t *p, int i)
Definition: msatOrderH.c:388
Msat_IntVec_t * vIndex
Definition: msatOrderH.c:34
int Msat_IntVecPop(Msat_IntVec_t *p)
Definition: msatVec.c:425
Msat_IntVec_t * vHeap
Definition: msatOrderH.c:35
int * pArray
Definition: msatInt.h:164
#define HHEAP(p, i)
Definition: msatOrderH.c:48
void Msat_HeapIncrease ( Msat_Order_t p,
int  n 
)
static

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

Synopsis [Inserts the new element.]

Description []

SideEffects []

SeeAlso []

Definition at line 348 of file msatOrderH.c.

349 {
350  Msat_HeapPercolateUp( p, p->vIndex->pArray[n] );
351 }
static void Msat_HeapPercolateUp(Msat_Order_t *p, int i)
Definition: msatOrderH.c:364
Msat_IntVec_t * vIndex
Definition: msatOrderH.c:34
int * pArray
Definition: msatInt.h:164
void Msat_HeapInsert ( Msat_Order_t p,
int  n 
)
static

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

Synopsis [Inserts the new element.]

Description []

SideEffects []

SeeAlso []

Definition at line 329 of file msatOrderH.c.

330 {
331  assert( HOKAY(p, n) );
332  p->vIndex->pArray[n] = HSIZE(p);
333  Msat_IntVecPush( p->vHeap, n );
334  Msat_HeapPercolateUp( p, p->vIndex->pArray[n] );
335 }
static void Msat_HeapPercolateUp(Msat_Order_t *p, int i)
Definition: msatOrderH.c:364
Msat_IntVec_t * vIndex
Definition: msatOrderH.c:34
void Msat_IntVecPush(Msat_IntVec_t *p, int Entry)
Definition: msatVec.c:351
#define HOKAY(p, i)
Definition: msatOrderH.c:50
Msat_IntVec_t * vHeap
Definition: msatOrderH.c:35
#define HSIZE(p)
Definition: msatOrderH.c:49
#define assert(ex)
Definition: util_old.h:213
int * pArray
Definition: msatInt.h:164
void Msat_HeapPercolateDown ( Msat_Order_t p,
int  i 
)
static

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

Synopsis [Moves the entry down.]

Description []

SideEffects []

SeeAlso []

Definition at line 388 of file msatOrderH.c.

389 {
390  int x = HHEAP(p, i);
391  int Child;
392  while ( HLEFT(i) < HSIZE(p) )
393  {
394  if ( HRIGHT(i) < HSIZE(p) && HCOMPARE(p, HHEAP(p, HRIGHT(i)), HHEAP(p, HLEFT(i))) )
395  Child = HRIGHT(i);
396  else
397  Child = HLEFT(i);
398  if ( !HCOMPARE(p, HHEAP(p, Child), x) )
399  break;
400  p->vHeap->pArray[i] = HHEAP(p, Child);
401  p->vIndex->pArray[HHEAP(p, i)] = i;
402  i = Child;
403  }
404  p->vHeap->pArray[i] = x;
405  p->vIndex->pArray[x] = i;
406 }
#define HCOMPARE(p, i, j)
Definition: msatOrderH.c:47
Msat_IntVec_t * vIndex
Definition: msatOrderH.c:34
#define HRIGHT(i)
Definition: msatOrderH.c:45
#define HLEFT(i)
Definition: msatOrderH.c:44
Msat_IntVec_t * vHeap
Definition: msatOrderH.c:35
#define HSIZE(p)
Definition: msatOrderH.c:49
int * pArray
Definition: msatInt.h:164
#define HHEAP(p, i)
Definition: msatOrderH.c:48
void Msat_HeapPercolateUp ( Msat_Order_t p,
int  i 
)
static

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

Synopsis [Moves the entry up.]

Description []

SideEffects []

SeeAlso []

Definition at line 364 of file msatOrderH.c.

365 {
366  int x = HHEAP(p, i);
367  while ( HPARENT(i) != 0 && HCOMPARE(p, x, HHEAP(p, HPARENT(i))) )
368  {
369  p->vHeap->pArray[i] = HHEAP(p, HPARENT(i));
370  p->vIndex->pArray[HHEAP(p, i)] = i;
371  i = HPARENT(i);
372  }
373  p->vHeap->pArray[i] = x;
374  p->vIndex->pArray[x] = i;
375 }
#define HPARENT(i)
Definition: msatOrderH.c:46
#define HCOMPARE(p, i, j)
Definition: msatOrderH.c:47
Msat_IntVec_t * vIndex
Definition: msatOrderH.c:34
Msat_IntVec_t * vHeap
Definition: msatOrderH.c:35
int * pArray
Definition: msatInt.h:164
#define HHEAP(p, i)
Definition: msatOrderH.c:48
Msat_Order_t* Msat_OrderAlloc ( Msat_Solver_t pSat)

FUNCTION DEFINITIONS ///.

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

Synopsis [Allocates the ordering structure.]

Description []

SideEffects []

SeeAlso []

Definition at line 78 of file msatOrderH.c.

79 {
80  Msat_Order_t * p;
81  p = ABC_ALLOC( Msat_Order_t, 1 );
82  memset( p, 0, sizeof(Msat_Order_t) );
83  p->pSat = pSat;
84  p->vIndex = Msat_IntVecAlloc( 0 );
85  p->vHeap = Msat_IntVecAlloc( 0 );
86  Msat_OrderSetBounds( p, pSat->nVarsAlloc );
87  return p;
88 }
char * memset()
static Llb_Mgr_t * p
Definition: llb3Image.c:950
DECLARATIONS ///.
Definition: msatOrderH.c:31
Msat_IntVec_t * vIndex
Definition: msatOrderH.c:34
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
void Msat_OrderSetBounds(Msat_Order_t *p, int nVarsMax)
Definition: msatOrderH.c:101
Msat_IntVec_t * vHeap
Definition: msatOrderH.c:35
Msat_IntVec_t * Msat_IntVecAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: msatVec.c:48
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 147 of file msatOrderH.c.

148 {
149  return Msat_HeapCheck_rec( p, 1 );
150 }
static int Msat_HeapCheck_rec(Msat_Order_t *p, int i)
Definition: msatOrderH.c:282
void Msat_OrderClean ( Msat_Order_t p,
Msat_IntVec_t vCone 
)

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

Synopsis [Cleans the ordering structure.]

Description []

SideEffects []

SeeAlso []

Definition at line 120 of file msatOrderH.c.

121 {
122  int i;
123  for ( i = 0; i < p->vIndex->nSize; i++ )
124  p->vIndex->pArray[i] = 0;
125  for ( i = 0; i < vCone->nSize; i++ )
126  {
127  assert( i+1 < p->vHeap->nCap );
128  p->vHeap->pArray[i+1] = vCone->pArray[i];
129 
130  assert( vCone->pArray[i] < p->vIndex->nSize );
131  p->vIndex->pArray[vCone->pArray[i]] = i+1;
132  }
133  p->vHeap->nSize = vCone->nSize + 1;
134 }
Msat_IntVec_t * vIndex
Definition: msatOrderH.c:34
for(p=first;p->value< newval;p=p->next)
Msat_IntVec_t * vHeap
Definition: msatOrderH.c:35
#define assert(ex)
Definition: util_old.h:213
int * pArray
Definition: msatInt.h:164
void Msat_OrderFree ( Msat_Order_t p)

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

Synopsis [Frees the ordering structure.]

Description []

SideEffects []

SeeAlso []

Definition at line 163 of file msatOrderH.c.

164 {
165  Msat_IntVecFree( p->vHeap );
166  Msat_IntVecFree( p->vIndex );
167  ABC_FREE( p );
168 }
Msat_IntVec_t * vIndex
Definition: msatOrderH.c:34
Msat_IntVec_t * vHeap
Definition: msatOrderH.c:35
void Msat_IntVecFree(Msat_IntVec_t *p)
Definition: msatVec.c:160
#define ABC_FREE(obj)
Definition: abc_global.h:232
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 101 of file msatOrderH.c.

102 {
103  Msat_IntVecGrow( p->vIndex, nVarsMax );
104  Msat_IntVecGrow( p->vHeap, nVarsMax + 1 );
105  p->vIndex->nSize = nVarsMax;
106  p->vHeap->nSize = 0;
107 }
Msat_IntVec_t * vIndex
Definition: msatOrderH.c:34
Msat_IntVec_t * vHeap
Definition: msatOrderH.c:35
void Msat_IntVecGrow(Msat_IntVec_t *p, int nCapMin)
Definition: msatVec.c:299
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 257 of file msatOrderH.c.

258 {
259 // if (heap.inHeap(x))
260 // heap.increase(x);
261 
262  abctime clk = Abc_Clock();
263  if ( HINHEAP(p,Var) )
264  Msat_HeapIncrease( p, Var );
265 timeSelect += Abc_Clock() - clk;
266 }
static void Msat_HeapIncrease(Msat_Order_t *p, int n)
Definition: msatOrderH.c:348
#define HINHEAP(p, i)
Definition: msatOrderH.c:51
static abctime Abc_Clock()
Definition: abc_global.h:279
int Var
Definition: SolverTypes.h:42
ABC_INT64_T abctime
Definition: abc_global.h:278
abctime timeSelect
DECLARATIONS ///.
Definition: fraigMan.c:28
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 220 of file msatOrderH.c.

221 {
222 }
int Msat_OrderVarSelect ( Msat_Order_t p)

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

Synopsis [Selects the next variable to assign.]

Description []

SideEffects []

SeeAlso []

Definition at line 183 of file msatOrderH.c.

184 {
185  // Activity based decision:
186 // while (!heap.empty()){
187 // Var next = heap.getmin();
188 // if (toLbool(assigns[next]) == l_Undef)
189 // return next;
190 // }
191 // return var_Undef;
192 
193  int Var;
194  abctime clk = Abc_Clock();
195 
196  while ( !HEMPTY(p) )
197  {
198  Var = Msat_HeapGetTop(p);
199  if ( (p)->pSat->pAssigns[Var] == MSAT_VAR_UNASSIGNED )
200  {
201 //assert( Msat_OrderCheck(p) );
202 timeSelect += Abc_Clock() - clk;
203  return Var;
204  }
205  }
206  return MSAT_ORDER_UNKNOWN;
207 }
#define MSAT_VAR_UNASSIGNED
Definition: msatInt.h:68
#define MSAT_ORDER_UNKNOWN
Definition: msatInt.h:70
static abctime Abc_Clock()
Definition: abc_global.h:279
static int Msat_HeapGetTop(Msat_Order_t *p)
Definition: msatOrderH.c:305
#define HEMPTY(p)
Definition: msatOrderH.c:52
int Var
Definition: SolverTypes.h:42
ABC_INT64_T abctime
Definition: abc_global.h:278
abctime timeSelect
DECLARATIONS ///.
Definition: fraigMan.c:28
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 235 of file msatOrderH.c.

236 {
237 // if (!heap.inHeap(x))
238 // heap.insert(x);
239 
240  abctime clk = Abc_Clock();
241  if ( !HINHEAP(p,Var) )
242  Msat_HeapInsert( p, Var );
243 timeSelect += Abc_Clock() - clk;
244 }
#define HINHEAP(p, i)
Definition: msatOrderH.c:51
static abctime Abc_Clock()
Definition: abc_global.h:279
static void Msat_HeapInsert(Msat_Order_t *p, int n)
Definition: msatOrderH.c:329
int Var
Definition: SolverTypes.h:42
ABC_INT64_T abctime
Definition: abc_global.h:278
abctime timeSelect
DECLARATIONS ///.
Definition: fraigMan.c:28

Variable Documentation

abctime 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.