Update MAIN.cpp

This commit is contained in:
PKU-ZLR 2019-10-29 20:46:10 +08:00 committed by GitHub
parent f5f308d1e8
commit dfec04e653
1 changed files with 87 additions and 54 deletions

View File

@ -14,10 +14,14 @@
#include <vector>
#include <algorithm>
#define MAXDEP 100
using namespace std;
FILE *out;
int Luts = 6;
map<string, bool> vis;
vector<string> L[MAXDEP];
void get_file_name(string path, vector<string> &files) {
struct dirent *ptr;
@ -32,21 +36,26 @@ void get_file_name(string path, vector<string> &files) {
bool cmp_Depth(Cut A, Cut B) {
return A.mindep < B.mindep || (A.mindep == B.mindep && A.AreaFlow < B.AreaFlow)
|| (A.mindep == B.mindep && A.AreaFlow == B.AreaFlow && A.Area < B.Area);
|| (A.mindep == B.mindep && A.AreaFlow == B.AreaFlow && A.Area < B.Area);
}
bool cmp_Depth2(Cut A, Cut B) {
return A.mindep < B.mindep || (A.mindep == B.mindep && A.Area < B.Area)
|| (A.mindep == B.mindep && A.Area == B.Area && A.AreaFlow < B.AreaFlow);
|| (A.mindep == B.mindep && A.Area == B.Area && A.AreaFlow < B.AreaFlow);
}
void Output(Circuit c) {
map<string, bool> Flag;
Flag.clear();
queue<string> Q;
vis.clear();
for (int i = 0; i < MAXDEP; i++)
L[i].clear();
int area = 0, dep = 0;
for (string s : c.output) {
Q.push(s);
vis[s] = 1;
//L[c.graph[s]->mindep].push_back(s);
dep = max(dep, c.graph[s]->mindep);
//cout << s << ":" << c.graph[s]->mindep << endl;
}
@ -55,36 +64,60 @@ void Output(Circuit c) {
Q.pop();
if (c.graph[now]->pre.size() == 0)
continue;
fprintf(out, "input:\n");
L[c.graph[now]->mindep].push_back(now);
//fprintf(out, "input:\n");
//cout << now << ":" << c.graph[now]->mindep << endl;
area++;
for (string st : c.graph[now]->Rcut) {
fprintf(out, "%s ", st.c_str());
//fprintf(out, "%s ", st.c_str());
if (!vis[st]) {
Q.push(st);
vis[st] = 1;
}
}
fprintf(out, "%s\n", ("\noutput:\n" + now).c_str());
//fprintf(out, "%s\n", ("\noutput:\n" + now).c_str());
}
fstream fout("result/overall.txt", ios::app);
fout << c.benchmark << ' ' << area << ' ' << c.abc_lut_area << endl;
fout.close();
//fprintf(stdout, "Area: %d\nDepth: %d\n", area, dep);
printf("HH\n");
for (int i = 1; i <= dep; i++)
for (string st1 : L[i])
for (string st2 : L[i]) {
if (st1 == st2) continue;
if (Flag[st1] || Flag[st2]) continue;
set<string> s1 = c.graph[st1]->Rcut;
set<string> s2 = c.graph[st2]->Rcut;
set<string> st = s1;
st.insert(s2.begin(), s2.end());
if (st.size() < (unsigned)Luts) {
Flag[st1] = 1, Flag[st2] = 1;
fprintf(out, "input:\n");
for (string str : st)
fprintf(out, "%s ", str.c_str());
fprintf(out, "%s\n", ("\noutput:\n" + st1 + " " + st2).c_str());
}
}
for (int i = 1; i <= dep; i++) {
for (string st : L[i])
if (!Flag[st]) {
fprintf(out, "input:\n");
for (string str : c.graph[st]->Rcut)
fprintf(out, "%s ", str.c_str());
fprintf(out, "%s\n", ("\noutput:\n" + st).c_str());
}
}
}
int main(int argc, char *argv[]) {
vector<string> benchmark;
queue<string> Q;
map<string, int> ind;
int Luts = 6;
unsigned int C = 15; // record the most C Cuts
string dir = "benchmark/ISCAS85";
string outdir = "result/ISCAS85";
get_file_name(dir, benchmark);
for (string str : benchmark) {
cout << str << endl;
cout << str << endl;
double total_time;
clock_t start = clock();
@ -95,8 +128,8 @@ int main(int argc, char *argv[]) {
for (pair<string, Var*> p : c.graph) {
ind[p.first] = p.second->pre.size();
p.second->mindep = 0;
}
p.second->mindep = 0;
}
for (string s : c.input) { // Initial queue
c.graph[s]->cuts[1].insert(set<string> { s });
@ -120,22 +153,22 @@ int main(int argc, char *argv[]) {
if (c.graph[now]->pre.size() == 2) {
string input1 = c.graph[now]->pre[0];
string input2 = c.graph[now]->pre[1];
for (int t = 1; t <= Luts; t++)
for (set<string> c1 : c.graph[input1]->cuts[t]) {
for (int k = 1; k <= Luts; k++)
for (set<string> c2 : c.graph[input2]->cuts[k]) {
for (int t = 1; t <= Luts; t++)
for (set<string> c1 : c.graph[input1]->cuts[t]) {
for (int k = 1; k <= Luts; k++)
for (set<string> c2 : c.graph[input2]->cuts[k]) {
set<string> st = c1;
st.insert(c2.begin(), c2.end());
if (st.size() > (unsigned) Luts)
continue;
c.graph[now]->cuts[st.size()].insert(st);
}
}
}
}
if (c.graph[now]->pre.size() == 1) {
string input1 = c.graph[now]->pre[0];
for (int k = 1; k <= Luts; k++)
for (int k = 1; k <= Luts; k++)
for (set<string> c1 : c.graph[input1]->cuts[k])
c.graph[now]->cuts[k].insert(c1);
}
@ -151,8 +184,8 @@ int main(int argc, char *argv[]) {
c.graph[now]->mindep = INF;
c.graph[now]->Area = INF;
c.graph[now]->AreaFlow = inf;
for (int k = 1; k <= Luts; k++)
for (set<string> ct : c.graph[now]->cuts[k]) {
for (int k = 1; k <= Luts; k++)
for (set<string> ct : c.graph[now]->cuts[k]) {
int dep = 0, area = 0;
double AF = 0;
for (string nt : ct) {
@ -164,52 +197,52 @@ int main(int argc, char *argv[]) {
AF /= max(1.0, 1.0 * c.graph[now]->suc.size());
Cuts[k].push_back(Cut(ct, dep, area, AF));
Ct.push_back(Cut(ct, dep, area, AF));
/*Compare dep*/
/*if (dep < c.graph[now]->mindep) {
c.graph[now]->mindep = dep;
c.graph[now]->AreaFlow = AF;
c.graph[now]->Area = area;
c.graph[now]->Rcut = ct;
continue;
}*/
Ct.push_back(Cut(ct, dep, area, AF));
/*Compare dep*/
/*if (dep < c.graph[now]->mindep) {
c.graph[now]->mindep = dep;
c.graph[now]->AreaFlow = AF;
c.graph[now]->Area = area;
c.graph[now]->Rcut = ct;
continue;
}*/
/*Compare Area Flow*/
/*if (dep == c.graph[now]->mindep && AF < c.graph[now]->AreaFlow) {
c.graph[now]->mindep = dep;
c.graph[now]->AreaFlow = AF;
c.graph[now]->Area = area;
c.graph[now]->Rcut = ct;
continue;
}*/
/*Compare Area Flow*/
/*if (dep == c.graph[now]->mindep && AF < c.graph[now]->AreaFlow) {
c.graph[now]->mindep = dep;
c.graph[now]->AreaFlow = AF;
c.graph[now]->Area = area;
c.graph[now]->Rcut = ct;
continue;
}*/
/*Compare Area*/
/*if (dep == c.graph[now]->mindep && AF == c.graph[now]->AreaFlow && area < c.graph[now]->Area) {
c.graph[now]->mindep = dep;
c.graph[now]->AreaFlow = AF;
c.graph[now]->Area = area;
c.graph[now]->Rcut = ct;
continue;
}*/
/*Compare Area*/
/*if (dep == c.graph[now]->mindep && AF == c.graph[now]->AreaFlow && area < c.graph[now]->Area) {
c.graph[now]->mindep = dep;
c.graph[now]->AreaFlow = AF;
c.graph[now]->Area = area;
c.graph[now]->Rcut = ct;
continue;
}*/
}
//if (now == "G473")
}
//if (now == "G473")
// cout << Cuts.size() << endl;
for (int k = 1; k <= Luts; k++) {
sort(Cuts[k].begin(), Cuts[k].end(), cmp_Depth2);
c.graph[now]->cuts[k].clear();
unsigned int len = Cuts[k].size();
//cout << "now:" << now << endl;
//cout << "now:" << now << endl;
for (unsigned int i = 0; i < min(C, len); i++) {
c.graph[now]->cuts[k].insert(Cuts[k][i].names);
//cout << Cuts[i].mindep << endl;
//cout << Cuts[i].mindep << endl;
}
}
//if (c.graph[now]->pre.size() != 1)
c.graph[now]->cuts[1].insert(set<string> { now });
/*for (string s : Cuts[0].names)
cout << s << endl;*/
sort(Ct.begin(), Ct.end(), cmp_Depth2);
cout << s << endl;*/
sort(Ct.begin(), Ct.end(), cmp_Depth2);
c.graph[now]->mindep = Ct[0].mindep;
c.graph[now]->AreaFlow = Ct[0].AreaFlow;
c.graph[now]->Area = Ct[0].Area;
@ -217,7 +250,7 @@ int main(int argc, char *argv[]) {
//cout << c.graph[now]->mindep << endl;
}
Output(c);
//cout << c.abc_lut_area << endl;
//cout << c.abc_lut_area << endl;
clock_t finish = clock();
total_time = (double) (finish - start) / CLOCKS_PER_SEC;
cout << "Run time: " << total_time << "s" << endl;