ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
giaDeep.c
Go to the documentation of this file.
1
20
21#include "gia.h"
22#include "base/main/main.h"
23#include "base/cmd/cmd.h"
24
26
30
34
46Gia_Man_t * Gia_ManDeepSynOne( int nNoImpr, int TimeOut, int nAnds, int Seed, int fUseTwo, int fVerbose )
47{
48 abctime nTimeToStop = TimeOut ? Abc_Clock() + TimeOut * CLOCKS_PER_SEC : 0;
49 abctime clkStart = Abc_Clock();
50 int s, i, IterMax = 100000, nAndsMin = -1, iIterLast = -1;
52 Gia_Man_t * pNew = Gia_ManDup( pTemp );
53 Abc_Random(1);
54 for ( s = 0; s < 10+Seed; s++ )
55 Abc_Random(0);
56 for ( i = 0; i < IterMax; i++ )
57 {
58 char * pCompress2rs = "balance -l; resub -K 6 -l; rewrite -l; resub -K 6 -N 2 -l; refactor -l; resub -K 8 -l; balance -l; resub -K 8 -N 2 -l; rewrite -l; resub -K 10 -l; rewrite -z -l; resub -K 10 -N 2 -l; balance -l; resub -K 12 -l; refactor -z -l; resub -K 12 -N 2 -l; rewrite -z -l; balance -l";
59 unsigned Rand = Abc_Random(0);
60 int fDch = Rand & 1;
61 //int fCom = (Rand >> 1) & 3;
62 int fCom = (Rand >> 1) & 1;
63 int fFx = (Rand >> 2) & 1;
64 int KLut = fUseTwo ? 2 + (i % 5) : 3 + (i % 4);
65 int fChange = 0;
66 char Command[2000];
67 char pComp[1000];
68 if ( fCom == 3 )
69 sprintf( pComp, "; &put; %s; %s; %s; &get", pCompress2rs, pCompress2rs, pCompress2rs );
70 else if ( fCom == 2 )
71 sprintf( pComp, "; &put; %s; %s; &get", pCompress2rs, pCompress2rs );
72 else if ( fCom == 1 )
73 sprintf( pComp, "; &put; %s; &get", pCompress2rs );
74 else if ( fCom == 0 )
75 sprintf( pComp, "; &dc2" );
76 sprintf( Command, "&dch%s; &if -a -K %d; &mfs -e -W 20 -L 20%s%s",
77 fDch ? " -f" : "", KLut, fFx ? "; &fx; &st" : "", pComp );
79 {
81 {
82 Abc_Print( 1, "Something did not work out with the command \"%s\".\n", Command );
83 return NULL;
84 }
85 }
86 else
87 {
90 {
91 Abc_Print( 1, "Something did not work out with the command \"%s\".\n", Command );
92 return NULL;
93 }
95 }
97 if ( Gia_ManAndNum(pNew) > Gia_ManAndNum(pTemp) )
98 {
99 Gia_ManStop( pNew );
100 pNew = Gia_ManDup( pTemp );
101 fChange = 1;
102 iIterLast = i;
103 }
104 else if ( Gia_ManAndNum(pNew) + Gia_ManAndNum(pNew)/10 < Gia_ManAndNum(pTemp) )
105 {
106 //printf( "Updating\n" );
107 //Abc_FrameUpdateGia( Abc_FrameGetGlobalFrame(), Gia_ManDup(pNew) );
108 }
109 if ( fChange && fVerbose )
110 {
111 printf( "Iter %6d : ", i );
112 printf( "Time %8.2f sec : ", (float)1.0*(Abc_Clock() - clkStart)/CLOCKS_PER_SEC );
113 printf( "And = %6d ", Gia_ManAndNum(pNew) );
114 printf( "Lev = %3d ", Gia_ManLevelNum(pNew) );
115 if ( fChange )
116 printf( "<== best : " );
117 else if ( fVerbose )
118 printf( " " );
119 printf( "%s", Command );
120 printf( "\n" );
121 }
122 if ( nTimeToStop && Abc_Clock() > nTimeToStop )
123 {
124 if ( !Abc_FrameIsBatchMode() )
125 printf( "Runtime limit (%d sec) is reached after %d iterations.\n", TimeOut, i );
126 break;
127 }
128 if ( i - iIterLast > nNoImpr )
129 {
130 printf( "Completed %d iterations without improvement in %.2f seconds.\n",
131 nNoImpr, (float)1.0*(Abc_Clock() - clkStart)/CLOCKS_PER_SEC );
132 break;
133 }
134 }
135 if ( i == IterMax )
136 printf( "Iteration limit (%d iters) is reached after %.2f seconds.\n", IterMax, (float)1.0*(Abc_Clock() - clkStart)/CLOCKS_PER_SEC );
137 else if ( nAnds && nAndsMin <= nAnds )
138 printf( "Quality goal (%d nodes <= %d nodes) is achieved after %d iterations and %.2f seconds.\n",
139 nAndsMin, nAnds, i, (float)1.0*(Abc_Clock() - clkStart)/CLOCKS_PER_SEC );
140 return pNew;
141}
142Gia_Man_t * Gia_ManDeepSyn( Gia_Man_t * pGia, int nIters, int nNoImpr, int TimeOut, int nAnds, int Seed, int fUseTwo, int fVerbose )
143{
144 Gia_Man_t * pInit = Gia_ManDup(pGia);
145 Gia_Man_t * pBest = Gia_ManDup(pGia);
146 Gia_Man_t * pThis;
147 int i;
148 for ( i = 0; i < nIters; i++ )
149 {
151 pThis = Gia_ManDeepSynOne( nNoImpr, TimeOut, nAnds, Seed+i, fUseTwo, fVerbose );
152 if ( Gia_ManAndNum(pBest) > Gia_ManAndNum(pThis) )
153 {
154 Gia_ManStop( pBest );
155 pBest = pThis;
156 }
157 else
158 Gia_ManStop( pThis );
159
160 }
161 Gia_ManStop( pInit );
162 return pBest;
163}
164
176Gia_Man_t * Gia_ManRandSyn( Gia_Man_t * p, unsigned random_seed )
177{
178 char * pCompress2rs = "balance -l; resub -K 6 -l; rewrite -l; resub -K 6 -N 2 -l; refactor -l; resub -K 8 -l; balance -l; resub -K 8 -N 2 -l; rewrite -l; resub -K 10 -l; rewrite -z -l; resub -K 10 -N 2 -l; balance -l; resub -K 12 -l; refactor -z -l; resub -K 12 -N 2 -l; rewrite -z -l; balance -l";
179 unsigned Rand = random_seed;
180 int fDch = Rand & 1;
181 //int fCom = (Rand >> 1) & 3;
182 int fCom = (Rand >> 1) & 1;
183 int fFx = (Rand >> 2) & 1;
184 int fUseTwo = 0;
185 int KLut = fUseTwo ? 2 + (Rand % 5) : 3 + (Rand % 4);
186 //int fChange = 0;
187 char Command[2000];
188 char pComp[1000];
189 if ( fCom == 3 )
190 sprintf( pComp, "; &put; %s; %s; %s; &get", pCompress2rs, pCompress2rs, pCompress2rs );
191 else if ( fCom == 2 )
192 sprintf( pComp, "; &put; %s; %s; &get", pCompress2rs, pCompress2rs );
193 else if ( fCom == 1 )
194 sprintf( pComp, "; &put; %s; &get", pCompress2rs );
195 else if ( fCom == 0 )
196 sprintf( pComp, "; &dc2" );
197 sprintf( Command, "&dch%s; &if -a -K %d; &mfs -e -W 20 -L 20%s%s",
198 fDch ? " -f" : "", KLut, fFx ? "; &fx; &st" : "", pComp );
201 if ( Abc_FrameIsBatchMode() )
202 {
204 {
205 Abc_Print( 1, "Something did not work out with the command \"%s\".\n", Command );
206 return NULL;
207 }
208 }
209 else
210 {
213 {
214 Abc_Print( 1, "Something did not work out with the command \"%s\".\n", Command );
215 return NULL;
216 }
218 }
221 return pRes;
222}
223
227
228
230
void Abc_FrameUpdateGia(Abc_Frame_t *pAbc, Gia_Man_t *pNew)
Definition abc.c:824
Gia_Man_t * Abc_FrameGetGia(Abc_Frame_t *pAbc)
Definition abc.c:869
ABC_INT64_T abctime
Definition abc_global.h:332
unsigned Abc_Random(int fReset)
Definition utilSort.c:1004
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
ABC_DLL Abc_Frame_t * Abc_FrameGetGlobalFrame()
Definition mainFrame.c:643
ABC_DLL void Abc_FrameSetBatchMode(int Mode)
Definition mainFrame.c:111
ABC_DLL Gia_Man_t * Abc_FrameReadGia(Abc_Frame_t *p)
Definition mainFrame.c:343
ABC_DLL int Abc_FrameIsBatchMode()
Definition mainFrame.c:110
ABC_DLL int Cmd_CommandExecute(Abc_Frame_t *pAbc, const char *sCommand)
Definition cmdApi.c:193
Cube * p
Definition exorList.c:222
Gia_Man_t * Gia_ManDeepSyn(Gia_Man_t *pGia, int nIters, int nNoImpr, int TimeOut, int nAnds, int Seed, int fUseTwo, int fVerbose)
Definition giaDeep.c:142
ABC_NAMESPACE_IMPL_START Gia_Man_t * Gia_ManDeepSynOne(int nNoImpr, int TimeOut, int nAnds, int Seed, int fUseTwo, int fVerbose)
DECLARATIONS ///.
Definition giaDeep.c:46
Gia_Man_t * Gia_ManRandSyn(Gia_Man_t *p, unsigned random_seed)
Definition giaDeep.c:176
void Gia_ManStop(Gia_Man_t *p)
Definition giaMan.c:82
Gia_Man_t * Gia_ManDup(Gia_Man_t *p)
Definition giaDup.c:720
struct Gia_Man_t_ Gia_Man_t
Definition gia.h:96
int Gia_ManLevelNum(Gia_Man_t *p)
Definition giaUtil.c:546
char * sprintf()