From 35574b0ee896cc74940c4cff35626f6448a22190 Mon Sep 17 00:00:00 2001 From: PKU-ZLR <55825746+PKU-ZLR@users.noreply.github.com> Date: Tue, 8 Oct 2019 01:30:33 +0800 Subject: [PATCH] Add files via upload --- source/MAIN.cpp | 125 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 123 insertions(+), 2 deletions(-) diff --git a/source/MAIN.cpp b/source/MAIN.cpp index c7dfb04..a12e0b5 100644 --- a/source/MAIN.cpp +++ b/source/MAIN.cpp @@ -6,8 +6,14 @@ #include "ABC.h" #include "Circuit.h" #include +#include +#include #include #include +#include + +#define inf (1e20) + using namespace std; void get_file_name(string path, vector &files) { @@ -16,22 +22,137 @@ void get_file_name(string path, vector &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 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 benchmark; + queue Q; + map 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 p : c.graph) + ind[p.first] = p.second->pre.size(); + + for (string s : c.input) { // Initial queue + c.graph[s]->cuts.insert(set{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{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 c1 : c.graph[input1]->cuts) { + for (set c2: c.graph[input2]->cuts) { + set 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 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 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;