diff --git a/atpg b/atpg index fcca67d..cb4983c 100755 Binary files a/atpg and b/atpg differ diff --git a/circuit.cpp b/circuit.cpp index 8dea274..6ad6907 100644 --- a/circuit.cpp +++ b/circuit.cpp @@ -3,7 +3,19 @@ #include #include -void Circuit::cal_topo_index() { + +void Circuit::init_stems() { + for(auto& gate: gates) { + if(gate->outputs.size() >= 2) { + stems.push_back(gate); + } + } + for(auto &gate : PIs) { + stems.push_back(gate); + } +} + +void Circuit::init_topo_index() { int topo = 1; std::queue q; @@ -80,4 +92,6 @@ int Circuit::cal_gate_value(const Gate* &gate) { break; } return res; -} \ No newline at end of file +} + + diff --git a/circuit.h b/circuit.h index 64d4ff7..7748f0b 100644 --- a/circuit.h +++ b/circuit.h @@ -14,14 +14,31 @@ public: std::vector inputs; }; +class Fault { +public: + Gate* gate; + enum Type { SA0, SA1 } type; + Fault(Gate* gate, Type type):gate(gate),type(type) {} +}; + class Circuit { public: std::vector PIs; std::vector POs; std::vector gates; +std::vector stems;// PI + stems + std::unordered_map name2gate; void parse_from_file(const char *filename); int cal_gate_value(const Gate* &gate); -void cal_topo_index(); +void init_topo_index(); +void init_stems(); + +// local search +std::vector local_search(const std::vector &faults); + +void ls_init_circuit(); +void ls_init_vector(std::vector *vec); + }; \ No newline at end of file diff --git a/ls.cpp b/ls.cpp index 0471d53..8b09a4f 100644 --- a/ls.cpp +++ b/ls.cpp @@ -1,35 +1,17 @@ -#include "ls.h" +#include "circuit.h" - -std::vector local_search(Circuit* circuit) { +std::vector Circuit::local_search(const std::vector &faults) { // local search vector - std::vector vec; - - init_vector(circuit, &vec); - - init_circuit(circuit); + ls_init_circuit(); printf("local search!\n"); return std::vector(); } - -void init_circuit(Circuit* circuit) { - for(auto pi : circuit->PIs) { +void Circuit::ls_init_circuit() { + for(auto pi : PIs) { pi->value = rand() % 2; } -} - -void init_vector(Circuit* circuit, std::vector *vec) { - for(auto pi : circuit->PIs) { - vec->push_back(pi); - } - for(auto gate : circuit->gates) { - // fanout stem - if(gate->outputs.size() >= 2) { - vec->push_back(gate); - } - } } \ No newline at end of file diff --git a/ls.h b/ls.h deleted file mode 100644 index 270c45c..0000000 --- a/ls.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -#include "circuit.h" - -std::vector local_search(Circuit* circuit); - -// private -void init_circuit(Circuit* circuit); -void init_vector(Circuit* circuit, std::vector *vec); \ No newline at end of file diff --git a/main.cpp b/main.cpp index 9954451..ba86ac3 100644 --- a/main.cpp +++ b/main.cpp @@ -3,7 +3,6 @@ #include #include "circuit.h" -#include "ls.h" int main(int args, char* argv[]) { @@ -12,31 +11,32 @@ int main(int args, char* argv[]) { exit(1); } + srand(19260817); + Circuit circuit; - printf("parsing file %s...\n", argv[1]); + printf("parsing file %s ...", argv[1]); circuit.parse_from_file(argv[1]); + circuit.init_stems(); + circuit.init_topo_index(); + printf(" Done.\n"); + printf("====== Circuit Statistics ====== \n"); printf("PI:\t%ld\n", circuit.PIs.size()); printf("PO:\t%ld\n", circuit.POs.size()); - printf("Gates:\t%ld\n", circuit.name2gate.size()); + printf("Gate:\t%ld\n", circuit.name2gate.size()); + printf("Stem:\t%ld\n", circuit.stems.size()); + printf("================================ \n"); - int cnt = 0; - for(auto& gate: circuit.gates) { - if(gate->outputs.size() > 2) { - cnt++; - } - } - printf("Stem:\t%d\n", cnt); + std::vector faults; - printf("cal topo index ...\n"); - circuit.cal_topo_index(); - for(Gate* gate : circuit.gates) { - assert(gate->topo > 0); + // init faults + for(auto stem : circuit.stems) { + faults.push_back(new Fault(stem, Fault::SA0)); + faults.push_back(new Fault(stem, Fault::SA1)); } - srand(19260817); - local_search(&circuit); + auto pattern = circuit.local_search(faults); return 0; } \ No newline at end of file