diff --git a/circuit.cpp b/circuit.cpp index 44c5d50..162208c 100644 --- a/circuit.cpp +++ b/circuit.cpp @@ -190,4 +190,6 @@ bool Circuit::is_valid_circuit() { } return true; -} \ No newline at end of file +} + + diff --git a/circuit.h b/circuit.h index 5f1447c..a74276c 100644 --- a/circuit.h +++ b/circuit.h @@ -93,6 +93,7 @@ int** fault_weight; int** fault_detected; void ls_init_circuit(); +void ls_init_stem(Gate* stem); void ls_init_weight(const std::unordered_set &faults); void ls_update_weight(); void ls_init_data_structs(); diff --git a/ls.cpp b/ls.cpp index 1ee4749..67ba230 100644 --- a/ls.cpp +++ b/ls.cpp @@ -18,6 +18,8 @@ bool Circuit::local_search(std::unordered_set &faults) { // 随机生成初始电路 ls_init_circuit(); + + assert(is_valid_circuit()); printf("local search!\n"); @@ -77,7 +79,7 @@ bool Circuit::local_search(std::unordered_set &faults) { flip_need_update[g->id] = false; flip_total_weight -= flip_weight[g->id]; flip_total_cnt -= 1; - ls_update(g); + ls_init_stem(g); } if(stem_total_cnt == stems.size() && flip_total_cnt == 0) { @@ -115,16 +117,6 @@ bool Circuit::local_search(std::unordered_set &faults) { } } - while(!flip_update_queue.empty()) { - Gate* g = flip_update_queue.back(); - flip_update_queue.pop_back(); - if(!flip_need_update[g->id]) continue; - flip_need_update[g->id] = false; - flip_total_weight -= flip_weight[g->id]; - flip_total_cnt -= 1; - ls_update(g); - } - static int original_faults = -1; if(original_faults == - 1) { original_faults = faults.size(); @@ -412,6 +404,8 @@ void Circuit::ls_block_recal(Gate* stem) { } } + + void Circuit::ls_init_weight(const std::unordered_set &faults) { for(Gate* s : stems) { stem_weight[s->id] = 1; @@ -426,9 +420,6 @@ void Circuit::ls_init_weight(const std::unordered_set &faults) { } void Circuit::ls_init_circuit() { - // for(auto pi : PIs) { - // pi->value = rand() % 2; - // } for(Gate* g : gates) { g->sa[0] = 0; @@ -440,11 +431,9 @@ void Circuit::ls_init_circuit() { } for(int i=stems.size()-1; i>=0; i--) { - ls_update(stems[i]); + ls_init_stem(stems[i]); } - //printf("flip: %lld, stem: %lld, fault:%lld\n", flip_total_weight, stem_total_weight, fault_total_weight); - while(!flip_update_queue.empty()) { Gate* g = flip_update_queue.back(); flip_update_queue.pop_back(); @@ -452,7 +441,7 @@ void Circuit::ls_init_circuit() { flip_need_update[g->id] = false; flip_total_weight -= flip_weight[g->id]; flip_total_cnt -= 1; - ls_update(g); + ls_init_stem(g); } } @@ -500,4 +489,154 @@ void Circuit::ls_init_data_structs() { fault_detected[i][0] = 0; fault_detected[i][1] = 0; } +} + + +void Circuit::ls_init_stem(Gate* stem) { + if(flip_need_update[stem->id]) { + flip_need_update[stem->id] = false; + flip_total_weight -= flip_weight[stem->id]; + flip_total_cnt -= 1; + } + + if(stem->cal_value() == stem->value && !stem_satisfied[stem->id]){ + stem_satisfied[stem->id] = true; + stem_total_weight -= stem_weight[stem->id]; + stem_total_cnt += 1; + } + + if(stem->cal_value() != stem->value && stem_satisfied[stem->id]) { + stem_satisfied[stem->id] = false; + stem_total_weight += stem_weight[stem->id]; + stem_total_cnt -= 1; + } + + //printf("flip: %s\n", stem->name.c_str()); + + //stem->value = !stem->value; + + if(stem->isPO) { + + if(stem->sa[!stem->value] == false) { + fault_total_weight += fault_weight[stem->id][!stem->value]; + fault_total_cnt += 1; + stem->sa[!stem->value] = true; + } + + if(stem->sa[stem->value] == true) { + fault_total_weight -= fault_weight[stem->id][stem->value]; + fault_total_cnt -= 1; + stem->sa[stem->value] = false; + } + } + + std::queue q; + std::unordered_map used; + std::vector suc_stems; + + q.push(stem); + + while(!q.empty()) { + Gate* g = q.front(); + q.pop(); + used[g] = false; + for(Gate* out : g->outputs) { + if(out->stem) { + suc_stems.push_back(out); + continue; + } + out->value = out->cal_value(); + if(!used[out]) { + used[out] = true; + q.push(out); + } + } + } + + assert(q.empty()); + used.clear(); + + for(Gate* stem : suc_stems) { + q.push(stem); + + if(stem->cal_value() == stem->value && !stem_satisfied[stem->id]){ + stem_satisfied[stem->id] = true; + stem_total_weight -= stem_weight[stem->id]; + stem_total_cnt += 1; + } + + if(stem->cal_value() != stem->value && stem_satisfied[stem->id]) { + stem_satisfied[stem->id] = false; + stem_total_weight += stem_weight[stem->id]; + stem_total_cnt -= 1; + } + } + + while(!q.empty()) { + Gate *g = q.front(); + q.pop(); + + used[g] = false; + + bool right_value = (g->cal_value() == g->value); + for(Gate* in : g->inputs) { + in->value = !in->value; + bool input_detected = (g->cal_value() != g->value); + in->value = !in->value; + + bool sa0 = right_value && input_detected && g->sa[!g->value] && in->value; + bool sa1 = right_value && input_detected && g->sa[!g->value] && !in->value; + + in->sa_by_out[g] = std::make_pair(sa0, sa1); + + bool old_sa[2]; + old_sa[0] = in->sa[0]; + old_sa[1] = in->sa[1]; + + in->sa[0] = in->sa[1] = 0; + for(Gate* out : in->outputs) { + auto &p = in->sa_by_out[out]; + in->sa[0] |= p.first; + in->sa[1] |= p.second; + } + + if(in->stem && !in->isPI && (in->sa[0] != old_sa[0] || in->sa[1] != old_sa[1])) { + + for(Gate* pre : in->pre_stems) { + if(flip_need_update[pre->id]) continue; + + flip_need_update[pre->id] = true; + flip_update_queue.push_back(pre); + + flip_total_weight += flip_weight[pre->id]; + flip_total_cnt += 1; + } + } + + if(old_sa[0] != in->sa[0]) { + if(in->sa[0]) { + fault_total_weight += fault_weight[in->id][0]; + fault_total_cnt += 1; + } else { + fault_total_weight -= fault_weight[in->id][0]; + fault_total_cnt -= 1; + } + } + + if(old_sa[1] != in->sa[1]) { + if(in->sa[1]) { + fault_total_weight += fault_weight[in->id][1]; + fault_total_cnt += 1; + } else { + fault_total_weight -= fault_weight[in->id][1]; + fault_total_cnt -= 1; + } + } + + if(!in->stem && !used[in]) { + used[in] = true; + q.push(in); + } + } + } } \ No newline at end of file diff --git a/report/atalanta_b10000_iscas85.txt b/report/atalanta_b10000_iscas85.txt new file mode 100644 index 0000000..5e8aa64 --- /dev/null +++ b/report/atalanta_b10000_iscas85.txt @@ -0,0 +1,15 @@ +-------------------------------------------------------------------------------------------------------------------- +| data | fault coverage(Atalanta) | time(Atalanta) | cube(Atalanta) | pattern(Atalanta) | +| ------------------------- | ------------------------ | -------------------- | -------------- | ----------------- | +| ./ISCAS85/new/c17.bench | 100.000 | 0.013962984085083008 | 7 | 7 | +| ./ISCAS85/new/c499.bench | 98.945 | 0.02384662628173828 | 103 | 60 | +| ./ISCAS85/new/c880.bench | 100.000 | 0.02523946762084961 | 200 | 149 | +| ./ISCAS85/new/c1355.bench | 99.492 | 0.03112053871154785 | 139 | 97 | +| ./ISCAS85/new/c3540.bench | 96.004 | 0.09344315528869629 | 366 | 266 | +| ./ISCAS85/new/c432.bench | 99.237 | 0.10678768157958984 | 86 | 63 | +| ./ISCAS85/new/c5315.bench | 98.897 | 0.14236044883728027 | 780 | 599 | +| ./ISCAS85/new/c1908.bench | 99.521 | 0.21341204643249512 | 197 | 130 | +| ./ISCAS85/new/c6288.bench | 99.406 | 2.9288134574890137 | 65 | 34 | +| ./ISCAS85/new/c2670.bench | 95.741 | 3.0761640071868896 | 512 | 440 | +| ./ISCAS85/new/c7552.bench | 98.159 | 18.162944793701172 | 599 | 455 | +-------------------------------------------------------------------------------------------------------------------- \ No newline at end of file diff --git a/report/atalanta_b1000_itc99.txt b/report/atalanta_b1000_itc99.txt new file mode 100644 index 0000000..41f3382 --- /dev/null +++ b/report/atalanta_b1000_itc99.txt @@ -0,0 +1,20 @@ +----------------------------------------------------------------------------------------------------------------- +| data | fault coverage(atalanta) | time(atalanta) | cube(atalanta) | pattern(atalanta) | +| ---------------------- | ------------------------ | -------------------- | -------------- | ----------------- | +| ./ITC99BENCH/b01.bench | 98.561 | 0.015755891799926758 | 21 | 18 | +| ./ITC99BENCH/b02.bench | 100.000 | 0.014572620391845703 | 14 | 12 | +| ./ITC99BENCH/b06.bench | 100.000 | 0.015142202377319336 | 23 | 20 | +| ./ITC99BENCH/b09.bench | 99.543 | 0.021707773208618164 | 111 | 96 | +| ./ITC99BENCH/b08.bench | 99.552 | 0.022001981735229492 | 104 | 78 | +| ./ITC99BENCH/b10.bench | 100.000 | 0.02209782600402832 | 117 | 85 | +| ./ITC99BENCH/b03.bench | 100.000 | 0.02145862579345703 | 111 | 90 | +| ./ITC99BENCH/b13.bench | 97.467 | 0.027521848678588867 | 177 | 133 | +| ./ITC99BENCH/b11.bench | 97.689 | 0.038506269454956055 | 152 | 123 | +| ./ITC99BENCH/b07.bench | 99.270 | 0.03971529006958008 | 191 | 137 | +| ./ITC99BENCH/b12.bench | 99.788 | 0.16275811195373535 | 577 | 445 | +| ./ITC99BENCH/b04.bench | 99.095 | 0.20319676399230957 | 266 | 199 | +| ./ITC99BENCH/b21.bench | 97.715 | 142.42899465560913 | 3602 | 2451 | +| ./ITC99BENCH/b20.bench | 97.614 | 190.66407656669617 | 3647 | 2535 | +| ./ITC99BENCH/b22.bench | 97.132 | 461.6779782772064 | 5325 | 3533 | +| ./ITC99BENCH/b17.bench | Time Out | 1000.0061409473419 | -*- | -*- | +----------------------------------------------------------------------------------------------------------------- \ No newline at end of file diff --git a/report/atalanta_b20_itc99.txt b/report/atalanta_b20_itc99.txt new file mode 100644 index 0000000..90a98b7 --- /dev/null +++ b/report/atalanta_b20_itc99.txt @@ -0,0 +1,20 @@ +----------------------------------------------------------------------------------------------------------------- +| data | fault coverage(atalanta) | time(atalanta) | cube(atalanta) | pattern(atalanta) | +| ---------------------- | ------------------------ | -------------------- | -------------- | ----------------- | +| ./ITC99BENCH/b01.bench | 98.561 | 0.0153656005859375 | 21 | 18 | +| ./ITC99BENCH/b02.bench | 100.000 | 0.012772798538208008 | 14 | 12 | +| ./ITC99BENCH/b06.bench | 100.000 | 0.01336359977722168 | 23 | 20 | +| ./ITC99BENCH/b10.bench | 100.000 | 0.018052339553833008 | 117 | 85 | +| ./ITC99BENCH/b09.bench | 99.543 | 0.02073192596435547 | 111 | 96 | +| ./ITC99BENCH/b08.bench | 99.552 | 0.021052122116088867 | 104 | 78 | +| ./ITC99BENCH/b03.bench | 100.000 | 0.020677804946899414 | 111 | 91 | +| ./ITC99BENCH/b13.bench | 97.467 | 0.02591991424560547 | 177 | 133 | +| ./ITC99BENCH/b07.bench | 99.270 | 0.036518096923828125 | 191 | 138 | +| ./ITC99BENCH/b11.bench | 97.610 | 0.03897380828857422 | 151 | 121 | +| ./ITC99BENCH/b04.bench | 98.887 | 0.07049202919006348 | 265 | 200 | +| ./ITC99BENCH/b12.bench | 99.753 | 0.14285016059875488 | 576 | 444 | +| ./ITC99BENCH/b20.bench | 97.345 | 15.317137479782104 | 3620 | 2522 | +| ./ITC99BENCH/b21.bench | 97.536 | 15.674558162689209 | 3572 | 2432 | +| ./ITC99BENCH/b22.bench | 96.868 | 39.12464189529419 | 5260 | 3493 | +| ./ITC99BENCH/b17.bench | Runtime Error | 79.67364525794983 | -*- | -*- | +----------------------------------------------------------------------------------------------------------------- \ No newline at end of file diff --git a/report/atalanta_itc99.txt b/report/atalanta_itc99.txt new file mode 100644 index 0000000..6baa837 --- /dev/null +++ b/report/atalanta_itc99.txt @@ -0,0 +1,19 @@ +----------------------------------------------------------------------------------------------------------------- +| data | fault coverage(atalanta) | time(atalanta) | cube(atalanta) | pattern(atalanta) | +| ---------------------- | ------------------------ | -------------------- | -------------- | ----------------- | +| ./ITC99BENCH/b01.bench | 98.561 | 0.015408039093017578 | 21 | 18 | +| ./ITC99BENCH/b02.bench | 100.000 | 0.014245271682739258 | 14 | 11 | +| ./ITC99BENCH/b06.bench | 100.000 | 0.014031171798706055 | 23 | 20 | +| ./ITC99BENCH/b09.bench | 99.543 | 0.02111530303955078 | 111 | 96 | +| ./ITC99BENCH/b03.bench | 100.000 | 0.020703554153442383 | 111 | 90 | +| ./ITC99BENCH/b08.bench | 99.552 | 0.023227214813232422 | 104 | 78 | +| ./ITC99BENCH/b10.bench | 100.000 | 0.02262282371520996 | 117 | 84 | +| ./ITC99BENCH/b13.bench | 97.467 | 0.026297807693481445 | 177 | 133 | +| ./ITC99BENCH/b07.bench | 99.270 | 0.038182973861694336 | 191 | 138 | +| ./ITC99BENCH/b11.bench | 97.610 | 0.04403829574584961 | 152 | 121 | +| ./ITC99BENCH/b04.bench | 98.817 | 0.07393932342529297 | 264 | 198 | +| ./ITC99BENCH/b12.bench | 99.753 | 0.17892765998840332 | 575 | 445 | +| ./ITC99BENCH/b20.bench | 97.264 | 13.491502046585083 | 3602 | 2504 | +| ./ITC99BENCH/b21.bench | 97.488 | 13.514089345932007 | 3575 | 2437 | +| ./ITC99BENCH/b17.bench | Runtime Error | 63.14472818374634 | -*- | -*- | +----------------------------------------------------------------------------------------------------------------- \ No newline at end of file diff --git a/report/tgpro_iscas85.txt b/report/tgpro_iscas85.txt new file mode 100644 index 0000000..cc25d54 --- /dev/null +++ b/report/tgpro_iscas85.txt @@ -0,0 +1,15 @@ +---------------------------------------------------------------------------------------------------------- +| data | fault coverage(TGPro) | time(TGPro) | cube(TGPro) | pattern(TGPro) | +| ------------------------- | --------------------- | ------------------- | ----------- | -------------- | +| ./ISCAS85/new/c17.bench | 100.0% | 0.03130531311035156 | -*- | -*- | +| ./ISCAS85/new/c432.bench | 100.0% | 0.421616792678833 | -*- | -*- | +| ./ISCAS85/new/c880.bench | 100.0% | 0.5790646076202393 | -*- | -*- | +| ./ISCAS85/new/c499.bench | 100.0% | 0.6056439876556396 | -*- | -*- | +| ./ISCAS85/new/c1355.bench | 100.0% | 2.035560131072998 | -*- | -*- | +| ./ISCAS85/new/c1908.bench | 100.0% | 3.4597091674804688 | -*- | -*- | +| ./ISCAS85/new/c2670.bench | 100.0% | 5.268458127975464 | -*- | -*- | +| ./ISCAS85/new/c5315.bench | 100.0% | 9.907253980636597 | -*- | -*- | +| ./ISCAS85/new/c3540.bench | 100.0% | 12.589468002319336 | -*- | -*- | +| ./ISCAS85/new/c7552.bench | 100.0% | 19.07117533683777 | -*- | -*- | +| ./ISCAS85/new/c6288.bench | 100.0% | 74.87688040733337 | -*- | -*- | +---------------------------------------------------------------------------------------------------------- \ No newline at end of file diff --git a/report/tgpro_itc99.txt b/report/tgpro_itc99.txt new file mode 100644 index 0000000..b8eea69 --- /dev/null +++ b/report/tgpro_itc99.txt @@ -0,0 +1,20 @@ +----------------------------------------------------------------------------------------------------------------- +| data | fault coverage(tgpro) | time(tgpro) | cube(tgpro) | pattern(tgpro) | +| ---------------------- | ------------------------ | -------------------- | -------------- | ----------------- | +| ./ITC99BENCH/b02.bench | 100.0% | 0.027261972427368164 | -*- | -*- | +| ./ITC99BENCH/b06.bench | 100.0% | 0.046559810638427734 | -*- | -*- | +| ./ITC99BENCH/b01.bench | 100.0% | 0.05464935302734375 | -*- | -*- | +| ./ITC99BENCH/b03.bench | 100.0% | 0.19752788543701172 | -*- | -*- | +| ./ITC99BENCH/b09.bench | 100.0% | 0.21236872673034668 | -*- | -*- | +| ./ITC99BENCH/b10.bench | 100.0% | 0.24873757362365723 | -*- | -*- | +| ./ITC99BENCH/b13.bench | 100.0% | 0.2486283779144287 | -*- | -*- | +| ./ITC99BENCH/b08.bench | 100.0% | 0.2590677738189697 | -*- | -*- | +| ./ITC99BENCH/b07.bench | 100.0% | 1.0742580890655518 | -*- | -*- | +| ./ITC99BENCH/b04.bench | 100.0% | 1.452695369720459 | -*- | -*- | +| ./ITC99BENCH/b11.bench | 100.0% | 1.9521455764770508 | -*- | -*- | +| ./ITC99BENCH/b12.bench | 100.0% | 2.7416207790374756 | -*- | -*- | +| ./ITC99BENCH/b20.bench | Runtime Error | 100.00541162490845 | -*- | -*- | +| ./ITC99BENCH/b17.bench | Runtime Error | 100.00695204734802 | -*- | -*- | +| ./ITC99BENCH/b22.bench | Runtime Error | 100.00703549385071 | -*- | -*- | +| ./ITC99BENCH/b21.bench | Runtime Error | 100.00721907615662 | -*- | -*- | +----------------------------------------------------------------------------------------------------------------- \ No newline at end of file diff --git a/report/tgpro_itc99_cutoff1000.txt b/report/tgpro_itc99_cutoff1000.txt new file mode 100644 index 0000000..168e18d --- /dev/null +++ b/report/tgpro_itc99_cutoff1000.txt @@ -0,0 +1,20 @@ +----------------------------------------------------------------------------------------------------------------- +| data | fault coverage(tgpro) | time(tgpro) | cube(tgpro) | pattern(tgpro) | +| ---------------------- | ------------------------ | -------------------- | -------------- | ----------------- | +| ./ITC99BENCH/b02.bench | 100.0% | 0.026658058166503906 | -*- | -*- | +| ./ITC99BENCH/b06.bench | 100.0% | 0.04587388038635254 | -*- | -*- | +| ./ITC99BENCH/b01.bench | 100.0% | 0.05449795722961426 | -*- | -*- | +| ./ITC99BENCH/b03.bench | 100.0% | 0.19013261795043945 | -*- | -*- | +| ./ITC99BENCH/b09.bench | 100.0% | 0.2168121337890625 | -*- | -*- | +| ./ITC99BENCH/b10.bench | 100.0% | 0.24273467063903809 | -*- | -*- | +| ./ITC99BENCH/b13.bench | 100.0% | 0.2440180778503418 | -*- | -*- | +| ./ITC99BENCH/b08.bench | 100.0% | 0.26444005966186523 | -*- | -*- | +| ./ITC99BENCH/b07.bench | 100.0% | 1.0087356567382812 | -*- | -*- | +| ./ITC99BENCH/b04.bench | 100.0% | 1.4730556011199951 | -*- | -*- | +| ./ITC99BENCH/b11.bench | 100.0% | 2.0080699920654297 | -*- | -*- | +| ./ITC99BENCH/b12.bench | 100.0% | 2.3151326179504395 | -*- | -*- | +| ./ITC99BENCH/b20.bench | 100.0% | 349.1050033569336 | -*- | -*- | +| ./ITC99BENCH/b21.bench | 100.0% | 367.34935879707336 | -*- | -*- | +| ./ITC99BENCH/b22.bench | 100.0% | 553.576010465622 | -*- | -*- | +| ./ITC99BENCH/b17.bench | Time Out | 1000.0099585056305 | -*- | -*- | +----------------------------------------------------------------------------------------------------------------- \ No newline at end of file