ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
retFlow.c File Reference
#include "retInt.h"
Include dependency graph for retFlow.c:

Go to the source code of this file.

Functions

void Abc_NtkMaxFlowTest (Abc_Ntk_t *pNtk)
 FUNCTION DEFINITIONS ///.
 
Vec_Ptr_tAbc_NtkMaxFlow (Abc_Ntk_t *pNtk, int fForward, int fVerbose)
 
void Abc_NtkMaxFlowMarkCut_rec (Abc_Obj_t *pObj)
 
void Abc_NtkMaxFlowCollectCut_rec (Abc_Obj_t *pObj, Vec_Ptr_t *vNodes)
 
int Abc_NtkMaxFlowVerifyCut_rec (Abc_Obj_t *pObj, int fForward)
 

Function Documentation

◆ Abc_NtkMaxFlow()

Vec_Ptr_t * Abc_NtkMaxFlow ( Abc_Ntk_t * pNtk,
int fForward,
int fVerbose )

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

Synopsis [Implementation of max-flow/min-cut computation.]

Description []

SideEffects []

SeeAlso []

Definition at line 143 of file retFlow.c.

144{
145 Vec_Ptr_t * vMinCut;
146 Abc_Obj_t * pLatch;
147 int Flow, FlowCur, RetValue, i;
148 abctime clk = Abc_Clock();
149 int fUseDirectedFlow = 1;
150
151 // find the max-flow
152 Abc_NtkCleanCopy( pNtk );
153 Flow = 0;
154 Abc_NtkIncrementTravId(pNtk);
155 Abc_NtkForEachLatch( pNtk, pLatch, i )
156 {
157 if ( fForward )
158 {
159// assert( !Abc_ObjFanout0(pLatch)->fMarkA );
160 FlowCur = Abc_NtkMaxFlowFwdPath2_rec( Abc_ObjFanout0(pLatch) );
161// FlowCur = Abc_NtkMaxFlowFwdPath3_rec( Abc_ObjFanout0(pLatch), pLatch, 1 );
162 Flow += FlowCur;
163 }
164 else
165 {
166 assert( !Abc_ObjFanin0(pLatch)->fMarkA );
167 FlowCur = Abc_NtkMaxFlowBwdPath2_rec( Abc_ObjFanin0(pLatch) );
168 Flow += FlowCur;
169 }
170 if ( FlowCur )
171 Abc_NtkIncrementTravId(pNtk);
172 }
173
174 if ( !fUseDirectedFlow )
175 {
176 Abc_NtkIncrementTravId(pNtk);
177 Abc_NtkForEachLatch( pNtk, pLatch, i )
178 {
179 if ( fForward )
180 {
181 // assert( !Abc_ObjFanout0(pLatch)->fMarkA );
182 FlowCur = Abc_NtkMaxFlowFwdPath_rec( Abc_ObjFanout0(pLatch) );
183 Flow += FlowCur;
184 }
185 else
186 {
187 assert( !Abc_ObjFanin0(pLatch)->fMarkA );
188 FlowCur = Abc_NtkMaxFlowBwdPath_rec( Abc_ObjFanin0(pLatch) );
189 Flow += FlowCur;
190 }
191 if ( FlowCur )
192 Abc_NtkIncrementTravId(pNtk);
193 }
194 }
195// Abc_NtkMaxFlowPrintFlow( pNtk, fForward );
196
197 // mark the nodes reachable from the latches
198 Abc_NtkIncrementTravId(pNtk);
199 Abc_NtkForEachLatch( pNtk, pLatch, i )
200 {
201 if ( fForward )
202 {
203// assert( !Abc_ObjFanout0(pLatch)->fMarkA );
204 if ( fUseDirectedFlow )
205 RetValue = Abc_NtkMaxFlowFwdPath2_rec( Abc_ObjFanout0(pLatch) );
206// RetValue = Abc_NtkMaxFlowFwdPath3_rec( Abc_ObjFanout0(pLatch), pLatch, 1 );
207 else
208 RetValue = Abc_NtkMaxFlowFwdPath_rec( Abc_ObjFanout0(pLatch) );
209 }
210 else
211 {
212 assert( !Abc_ObjFanin0(pLatch)->fMarkA );
213 if ( fUseDirectedFlow )
214 RetValue = Abc_NtkMaxFlowBwdPath2_rec( Abc_ObjFanin0(pLatch) );
215 else
216 RetValue = Abc_NtkMaxFlowBwdPath_rec( Abc_ObjFanin0(pLatch) );
217 }
218 assert( RetValue == 0 );
219 }
220
221 // find the min-cut with the smallest volume
222 vMinCut = Abc_NtkMaxFlowMinCut( pNtk, fForward );
223 // verify the cut
224 if ( !Abc_NtkMaxFlowVerifyCut(pNtk, vMinCut, fForward) )
225 printf( "Abc_NtkMaxFlow() error! The computed min-cut is not a cut!\n" );
226 // make the cut retimable
227 Abc_NtkMaxFlowMinCutUpdate( pNtk, vMinCut, fForward );
228
229 // report the results
230 if ( fVerbose )
231 {
232 printf( "L = %6d. %s max-flow = %6d. Min-cut = %6d. ",
233 Abc_NtkLatchNum(pNtk), fForward? "Forward " : "Backward", Flow, Vec_PtrSize(vMinCut) );
234ABC_PRT( "Time", Abc_Clock() - clk );
235 }
236
237// Abc_NtkMaxFlowPrintCut( pNtk, vMinCut );
238 return vMinCut;
239}
struct Abc_Obj_t_ Abc_Obj_t
Definition abc.h:116
#define Abc_NtkForEachLatch(pNtk, pObj, i)
Definition abc.h:500
ABC_DLL void Abc_NtkCleanCopy(Abc_Ntk_t *pNtk)
Definition abcUtil.c:540
ABC_INT64_T abctime
Definition abc_global.h:332
#define ABC_PRT(a, t)
Definition abc_global.h:255
#define assert(ex)
Definition util_old.h:213
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition vecPtr.h:42
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_NtkMaxFlowCollectCut_rec()

void Abc_NtkMaxFlowCollectCut_rec ( Abc_Obj_t * pObj,
Vec_Ptr_t * vNodes )

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

Synopsis [Visits the TFI up to marked nodes and collects marked nodes.]

Description []

SideEffects []

SeeAlso []

Definition at line 542 of file retFlow.c.

543{
544 Abc_Obj_t * pNext;
545 int i;
546 if ( Abc_NodeIsTravIdCurrent(pObj) )
547 return;
548 Abc_NodeSetTravIdCurrent(pObj);
549 if ( pObj->fMarkA )
550 {
551 Vec_PtrPush( vNodes, pObj );
552 return;
553 }
554 Abc_ObjForEachFanin( pObj, pNext, i )
555 Abc_NtkMaxFlowCollectCut_rec( pNext, vNodes );
556}
#define Abc_ObjForEachFanin(pObj, pFanin, i)
Definition abc.h:527
void Abc_NtkMaxFlowCollectCut_rec(Abc_Obj_t *pObj, Vec_Ptr_t *vNodes)
Definition retFlow.c:542
unsigned fMarkA
Definition abc.h:134
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_NtkMaxFlowMarkCut_rec()

void Abc_NtkMaxFlowMarkCut_rec ( Abc_Obj_t * pObj)

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

Synopsis [Marks the TFI cone with MarkA.]

Description []

SideEffects []

SeeAlso []

Definition at line 520 of file retFlow.c.

521{
522 Abc_Obj_t * pNext;
523 int i;
524 if ( pObj->fMarkA )
525 return;
526 pObj->fMarkA = 1;
527 Abc_ObjForEachFanin( pObj, pNext, i )
529}
void Abc_NtkMaxFlowMarkCut_rec(Abc_Obj_t *pObj)
Definition retFlow.c:520
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_NtkMaxFlowTest()

void Abc_NtkMaxFlowTest ( Abc_Ntk_t * pNtk)

FUNCTION DEFINITIONS ///.

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

Synopsis [Test-bench for the max-flow computation.]

Description []

SideEffects []

SeeAlso []

Definition at line 104 of file retFlow.c.

105{
106 Vec_Ptr_t * vMinCut;
107 Abc_Obj_t * pObj;
108 int i;
109
110 // forward flow
111 Abc_NtkForEachPo( pNtk, pObj, i )
112 pObj->fMarkA = 1;
113 Abc_NtkForEachLatch( pNtk, pObj, i )
114 pObj->fMarkA = Abc_ObjFanin0(pObj)->fMarkA = 1;
115// Abc_ObjFanin0(pObj)->fMarkA = 1;
116 vMinCut = Abc_NtkMaxFlow( pNtk, 1, 1 );
117 Vec_PtrFree( vMinCut );
118 Abc_NtkCleanMarkA( pNtk );
119
120 // backward flow
121 Abc_NtkForEachPi( pNtk, pObj, i )
122 pObj->fMarkA = 1;
123 Abc_NtkForEachLatch( pNtk, pObj, i )
124 pObj->fMarkA = Abc_ObjFanout0(pObj)->fMarkA = 1;
125// Abc_ObjFanout0(pObj)->fMarkA = 1;
126 vMinCut = Abc_NtkMaxFlow( pNtk, 0, 1 );
127 Vec_PtrFree( vMinCut );
128 Abc_NtkCleanMarkA( pNtk );
129
130}
ABC_DLL void Abc_NtkCleanMarkA(Abc_Ntk_t *pNtk)
Definition abcUtil.c:696
#define Abc_NtkForEachPo(pNtk, pPo, i)
Definition abc.h:520
#define Abc_NtkForEachPi(pNtk, pPi, i)
Definition abc.h:516
Vec_Ptr_t * Abc_NtkMaxFlow(Abc_Ntk_t *pNtk, int fForward, int fVerbose)
Definition retFlow.c:143
Here is the call graph for this function:

◆ Abc_NtkMaxFlowVerifyCut_rec()

int Abc_NtkMaxFlowVerifyCut_rec ( Abc_Obj_t * pObj,
int fForward )

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

Synopsis [Verifies the min-cut is indeed a cut.]

Description []

SideEffects []

SeeAlso []

Definition at line 627 of file retFlow.c.

628{
629 Abc_Obj_t * pNext;
630 int i;
631 // skip visited nodes
632 if ( Abc_NodeIsTravIdCurrent(pObj) )
633 return 1;
634 Abc_NodeSetTravIdCurrent(pObj);
635 // visit the node
636 if ( fForward )
637 {
638 if ( Abc_ObjIsCo(pObj) )
639 return 0;
640 // explore the fanouts
641 Abc_ObjForEachFanout( pObj, pNext, i )
642 if ( !Abc_NtkMaxFlowVerifyCut_rec(pNext, fForward) )
643 return 0;
644 }
645 else
646 {
647 if ( Abc_ObjIsCi(pObj) )
648 return 0;
649 // explore the fanins
650 Abc_ObjForEachFanin( pObj, pNext, i )
651 if ( !Abc_NtkMaxFlowVerifyCut_rec(pNext, fForward) )
652 return 0;
653 }
654 return 1;
655}
#define Abc_ObjForEachFanout(pObj, pFanout, i)
Definition abc.h:529
int Abc_NtkMaxFlowVerifyCut_rec(Abc_Obj_t *pObj, int fForward)
Definition retFlow.c:627
Here is the call graph for this function:
Here is the caller graph for this function: