Add files via upload
This commit is contained in:
parent
9471030908
commit
35574b0ee8
125
source/MAIN.cpp
125
source/MAIN.cpp
|
@ -6,8 +6,14 @@
|
|||
#include "ABC.h"
|
||||
#include "Circuit.h"
|
||||
#include <dirent.h>
|
||||
#include <queue>
|
||||
#include <assert.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
#define inf (1e20)
|
||||
|
||||
using namespace std;
|
||||
|
||||
void get_file_name(string path, vector<string> &files) {
|
||||
|
@ -16,22 +22,137 @@ void get_file_name(string path, vector<string> &files) {
|
|||
while ((ptr = readdir(dir)) != NULL) {
|
||||
if (ptr->d_name[0] != '.') { // skip . and ..
|
||||
files.push_back(ptr->d_name);
|
||||
cout << ptr->d_name << endl;
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
}
|
||||
|
||||
void Output(Circuit c) {
|
||||
queue <string> Q;
|
||||
int area = 0;
|
||||
for (string s : c.output)
|
||||
Q.push(s);
|
||||
while (!Q.empty()) {
|
||||
string now = Q.front();
|
||||
Q.pop();
|
||||
if (c.graph[now]->pre.size() == 0) continue;
|
||||
cout << "input:\n";
|
||||
for (string st : c.graph[now]->Rcut) {
|
||||
cout << st << " ";
|
||||
Q.push(st);
|
||||
}
|
||||
cout << "\noutput:\n" << now << endl;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
vector<string> benchmark;
|
||||
queue <string> Q;
|
||||
map<string, int> ind;
|
||||
int Luts = 4;
|
||||
string dir = "benchmark/IWLS93";
|
||||
get_file_name(dir, benchmark);
|
||||
|
||||
for (string s : benchmark) {
|
||||
for (string str : benchmark) {
|
||||
double total_time;
|
||||
clock_t start = clock();
|
||||
|
||||
Circuit circuit(dir + "/" + s); // already synthesized
|
||||
Circuit c = Circuit(dir + "/" + str); // already synthesized
|
||||
//c.write_dot();
|
||||
|
||||
for (pair<string, Var*> p : c.graph)
|
||||
ind[p.first] = p.second->pre.size();
|
||||
|
||||
for (string s : c.input) { // Initial queue
|
||||
c.graph[s]->cuts.insert(set<string>{s});
|
||||
c.graph[s]->mindep = 0;
|
||||
c.graph[s]->Area = 0;
|
||||
c.graph[s]->AreaFlow = 0;
|
||||
for (string nt : c.graph[s]->suc) {
|
||||
ind[nt]--;
|
||||
if (ind[nt] == 0) Q.push(nt);
|
||||
}
|
||||
}
|
||||
|
||||
//Enumerate Cuts
|
||||
while (!Q.empty()) {
|
||||
string now = Q.front();
|
||||
//cout << now << endl;
|
||||
Q.pop();
|
||||
c.graph[now]->cuts.insert(set<string>{now});
|
||||
assert(c.graph[now]->pre.size() <= 2);
|
||||
if (c.graph[now]->pre.size() == 2) {
|
||||
string input1 = c.graph[now]->pre[0];
|
||||
string input2 = c.graph[now]->pre[1];
|
||||
|
||||
for (set<string> c1 : c.graph[input1]->cuts) {
|
||||
for (set<string> c2: c.graph[input2]->cuts) {
|
||||
set<string> st = c1;
|
||||
st.insert(c2.begin(), c2.end());
|
||||
if (st.size() > (unsigned)Luts) continue;
|
||||
c.graph[now]->cuts.insert(st);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (c.graph[now]->pre.size() == 1) {
|
||||
string input1 = c.graph[now]->pre[0];
|
||||
for (set<string> c1 : c.graph[input1]->cuts)
|
||||
c.graph[now]->cuts.insert(c1);
|
||||
}
|
||||
|
||||
for (string nt : c.graph[now]->suc) {
|
||||
ind[nt]--;
|
||||
if (ind[nt] == 0) Q.push(nt);
|
||||
}
|
||||
|
||||
/*Calculate dep, areaflow, exact area*/
|
||||
c.graph[now]->mindep = INF;
|
||||
c.graph[now]->Area = INF;
|
||||
c.graph[now]->AreaFlow = inf;
|
||||
for (set<string> ct : c.graph[now]->cuts) {
|
||||
int dep = 0, area = 0;
|
||||
double AF = 0;
|
||||
for (string nt : ct) {
|
||||
dep = max(dep, c.graph[nt]->mindep);
|
||||
area += c.graph[nt]->Area;
|
||||
AF += c.graph[nt]->AreaFlow;
|
||||
}
|
||||
dep++, area++;
|
||||
AF /= max(1.0, 1.0 * c.graph[now]->suc.size());
|
||||
|
||||
/*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*/
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Output(c);
|
||||
clock_t finish = clock();
|
||||
total_time = (double) (finish - start) / CLOCKS_PER_SEC;
|
||||
cout << "Run time: " << total_time << "s" << endl;
|
||||
|
|
Loading…
Reference in New Issue