diff --git a/atpg b/atpg index 3bce51b..2978293 100755 Binary files a/atpg and b/atpg differ diff --git a/circuit.cpp b/circuit.cpp index 160a4c6..4265924 100644 --- a/circuit.cpp +++ b/circuit.cpp @@ -10,7 +10,7 @@ void Circuit::init_stems() { if(gate->outputs.size() >= 2) { gate->stem = true; } - //gate->stem = true; + // gate->stem = true; if(gate->stem) { stems.push_back(gate); } @@ -86,6 +86,37 @@ void Circuit::init_topo_index() { } } +void Circuit::init_gate_level() { + MAX_GATE_LEVEL = 0; + std::queue q; + + for(Gate* gate : gates) { + gate->level = -1; + } + + for(auto pi: PIs) { + pi->level = 0; + q.push(pi); + } + + while(!q.empty()) { + Gate* g = q.front(); q.pop(); + + MAX_GATE_LEVEL = std::max(MAX_GATE_LEVEL, g->level); + + for(Gate* out : g->outputs) { + if(out->level == -1) { + out->level = g->level + 1; + q.push(out); + } + } + } + + for(Gate* g : gates) { + assert(g->level != -1); + } +} + void Circuit::print_gates() { static const char* type2name[9] = {"AND", "NAND", "OR", "NOR", "XOR", "XNOR", "NOT", "BUF", "IN"}; for(Gate* gate : gates) { diff --git a/circuit.h b/circuit.h index eea1a62..72f505d 100644 --- a/circuit.h +++ b/circuit.h @@ -11,6 +11,7 @@ using ll = long long; class Gate { public: int id; + int level; std::string name; enum Type { AND, NAND, OR, NOR, XOR, XNOR, NOT, BUF, INPUT } type; int value; @@ -59,6 +60,10 @@ void print_gates(); bool is_valid_circuit(); void init_topo_index(); + + +int MAX_GATE_LEVEL; +void init_gate_level(); void init_stems(); // local search @@ -81,7 +86,7 @@ int* flip_need_update; std::vector flip_update_queue; // incremental stem struct -const int STEM_INC = 100; +const int STEM_INC = 2; const int STEM_WEIGHT_MAX = 1e9; ll stem_total_weight; int stem_total_cnt; @@ -89,6 +94,7 @@ int* stem_weight; int* stem_satisfied; int fault_propagate_tatal_len; +int fault_propagate_score; const int FAULT_INC = 1; const int FAULT_WEIGHT_MAX = 20; diff --git a/ls.cpp b/ls.cpp index f1f8bec..0cfbe73 100644 --- a/ls.cpp +++ b/ls.cpp @@ -217,7 +217,7 @@ ll Circuit::ls_pick_score(Gate* stem) { ll Circuit::ls_score() { //ll score = - flip_total_weight - stem_total_weight + fault_total_weight + fault_propagate_tatal_len; - ll score = - flip_total_weight - stem_total_weight + fault_propagate_tatal_len; + ll score = - flip_total_weight - stem_total_weight + 10 * fault_propagate_tatal_len; return score; } @@ -282,6 +282,8 @@ void Circuit::ls_init_data_structs() { } } + fault_propagate_score = 0; + fault_propagate_tatal_len = 0; flip_total_weight = 0; diff --git a/main.cpp b/main.cpp index ad17589..e842258 100644 --- a/main.cpp +++ b/main.cpp @@ -19,6 +19,7 @@ int main(int args, char* argv[]) { circuit->parse_from_file(argv[1]); circuit->init_stems(); circuit->init_topo_index(); + circuit->init_gate_level(); printf(" Done.\n"); printf("====== Circuit Statistics ====== \n"); @@ -26,6 +27,7 @@ int main(int args, char* argv[]) { printf("PO:\t%ld\n", circuit->POs.size()); printf("Gate:\t%ld\n", circuit->name2gate.size()); printf("Stem:\t%ld\n", circuit->stems.size()); + printf("Level:\t%d\n", circuit->MAX_GATE_LEVEL); printf("================================ \n"); std::unordered_set faults;