summaryrefslogtreecommitdiffstats
path: root/src/sat/aig/aigMan.c
blob: 4c64c897c3de1a44fa66b84b4eff8a4a0c7d11e8 (plain)
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
/**CFile****************************************************************

  FileName    [aigMan.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [And-Inverter Graph package.]

  Synopsis    []

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

  Date        [Ver. 1.0. Started - June 20, 2005.]

  Revision    [$Id: aigMan.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]

***********************************************************************/

#include "aig.h"

////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////
///                     FUNCTION DEFINITIONS                         ///
////////////////////////////////////////////////////////////////////////

/**Function*************************************************************

  Synopsis    [Sets the default parameters.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Aig_ManSetDefaultParams( Aig_Param_t * pParam )
{
    memset( pParam, 0, sizeof(Aig_Param_t) );
    pParam->nPatsRand = 4096;  // the number of random patterns
    pParam->nBTLimit  =   99;  // backtrack limit at the intermediate nodes
    pParam->nSeconds  =    1;  // the timeout for the final miter in seconds
}

/**Function*************************************************************

  Synopsis    [Starts the AIG manager.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Aig_Man_t * Aig_ManStart( Aig_Param_t * pParam )
{
    Aig_Man_t * p;
    // set the random seed for simulation
    srand( 0xDEADCAFE );
    // start the manager
    p = ALLOC( Aig_Man_t, 1 );
    memset( p, 0, sizeof(Aig_Man_t) );
    p->pParam     = &p->Param;
    p->nTravIds   =  1;
    p->nPatsMax   = 25;
    // set the defaults
    *p->pParam    = *pParam;
    // start memory managers
    p->mmNodes    = Aig_MemFixedStart( sizeof(Aig_Node_t) );
    // allocate node arrays
    p->vPis       = Vec_PtrAlloc( 1000 );    // the array of primary inputs
    p->vPos       = Vec_PtrAlloc( 1000 );    // the array of primary outputs
    p->vNodes     = Vec_PtrAlloc( 1000 );    // the array of internal nodes
    // start the table
    p->pTable     = Aig_TableCreate( 1000 );
    // create the constant node
    p->pConst1    = Aig_NodeCreateConst( p );
    // initialize other variables
    p->vFanouts   = Vec_PtrAlloc( 10 ); 
    p->vToReplace = Vec_PtrAlloc( 10 ); 
    p->vClassTemp = Vec_IntAlloc( 10 );
    p->vPats      = Vec_PtrAlloc( p->nPatsMax );
    return p;
}

/**Function*************************************************************

  Synopsis    [Returns the number of dangling nodes removed.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Aig_ManCleanup( Aig_Man_t * pMan )
{
    Aig_Node_t * pAnd;
    int i, nNodesOld;
    nNodesOld = Aig_ManAndNum(pMan);
    Aig_ManForEachAnd( pMan, pAnd, i )
        if ( pAnd->nRefs == 0 )
            Aig_NodeDeleteAnd_rec( pMan, pAnd );
    return nNodesOld - Aig_ManAndNum(pMan);
}

/**Function*************************************************************

  Synopsis    [Stops the AIG manager.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Aig_ManStop( Aig_Man_t * p )
{
    // SAT solver
    if ( p->pSat )       solver_delete( p->pSat );
    if ( p->vVar2Sat )   Vec_IntFree( p->vVar2Sat );
    if ( p->vSat2Var )   Vec_IntFree( p->vSat2Var );
    if ( p->vPiSatNums ) Vec_IntFree( p->vPiSatNums );
    // fanouts
    if ( p->vFanPivots ) Vec_PtrFree( p->vFanPivots );
    if ( p->vFanFans0 )  Vec_PtrFree( p->vFanFans0 );
    if ( p->vFanFans1 )  Vec_PtrFree( p->vFanFans1 );
    if ( p->vClasses  )  Vec_VecFree( p->vClasses );
    // patterns
    if ( p->vPats )      Vec_PtrFree( p->vPats );
    if ( p->pPatMask )   Aig_PatternFree( p->pPatMask );
    // nodes
    Aig_MemFixedStop( p->mmNodes, 0 );
    Vec_PtrFree( p->vNodes );
    Vec_PtrFree( p->vPis );
    Vec_PtrFree( p->vPos );
    // temporary
    Vec_PtrFree( p->vFanouts );
    Vec_PtrFree( p->vToReplace );
    Vec_IntFree( p->vClassTemp );
    Aig_TableFree( p->pTable );
    free( p );
}

////////////////////////////////////////////////////////////////////////
///                       END OF FILE                                ///
////////////////////////////////////////////////////////////////////////