gate 增加了 level 字段

This commit is contained in:
YuhangQ 2023-03-09 02:51:10 +00:00
parent 8f2262eaee
commit 77a4984f3a
5 changed files with 44 additions and 3 deletions

BIN
atpg

Binary file not shown.

View File

@ -10,7 +10,7 @@ void Circuit::init_stems() {
if(gate->outputs.size() >= 2) { if(gate->outputs.size() >= 2) {
gate->stem = true; gate->stem = true;
} }
//gate->stem = true; // gate->stem = true;
if(gate->stem) { if(gate->stem) {
stems.push_back(gate); stems.push_back(gate);
} }
@ -86,6 +86,37 @@ void Circuit::init_topo_index() {
} }
} }
void Circuit::init_gate_level() {
MAX_GATE_LEVEL = 0;
std::queue<Gate*> 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() { void Circuit::print_gates() {
static const char* type2name[9] = {"AND", "NAND", "OR", "NOR", "XOR", "XNOR", "NOT", "BUF", "IN"}; static const char* type2name[9] = {"AND", "NAND", "OR", "NOR", "XOR", "XNOR", "NOT", "BUF", "IN"};
for(Gate* gate : gates) { for(Gate* gate : gates) {

View File

@ -11,6 +11,7 @@ using ll = long long;
class Gate { class Gate {
public: public:
int id; int id;
int level;
std::string name; std::string name;
enum Type { AND, NAND, OR, NOR, XOR, XNOR, NOT, BUF, INPUT } type; enum Type { AND, NAND, OR, NOR, XOR, XNOR, NOT, BUF, INPUT } type;
int value; int value;
@ -59,6 +60,10 @@ void print_gates();
bool is_valid_circuit(); bool is_valid_circuit();
void init_topo_index(); void init_topo_index();
int MAX_GATE_LEVEL;
void init_gate_level();
void init_stems(); void init_stems();
// local search // local search
@ -81,7 +86,7 @@ int* flip_need_update;
std::vector<Gate*> flip_update_queue; std::vector<Gate*> flip_update_queue;
// incremental stem struct // incremental stem struct
const int STEM_INC = 100; const int STEM_INC = 2;
const int STEM_WEIGHT_MAX = 1e9; const int STEM_WEIGHT_MAX = 1e9;
ll stem_total_weight; ll stem_total_weight;
int stem_total_cnt; int stem_total_cnt;
@ -89,6 +94,7 @@ int* stem_weight;
int* stem_satisfied; int* stem_satisfied;
int fault_propagate_tatal_len; int fault_propagate_tatal_len;
int fault_propagate_score;
const int FAULT_INC = 1; const int FAULT_INC = 1;
const int FAULT_WEIGHT_MAX = 20; const int FAULT_WEIGHT_MAX = 20;

4
ls.cpp
View File

@ -217,7 +217,7 @@ ll Circuit::ls_pick_score(Gate* stem) {
ll Circuit::ls_score() { 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_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; return score;
} }
@ -282,6 +282,8 @@ void Circuit::ls_init_data_structs() {
} }
} }
fault_propagate_score = 0;
fault_propagate_tatal_len = 0; fault_propagate_tatal_len = 0;
flip_total_weight = 0; flip_total_weight = 0;

View File

@ -19,6 +19,7 @@ int main(int args, char* argv[]) {
circuit->parse_from_file(argv[1]); circuit->parse_from_file(argv[1]);
circuit->init_stems(); circuit->init_stems();
circuit->init_topo_index(); circuit->init_topo_index();
circuit->init_gate_level();
printf(" Done.\n"); printf(" Done.\n");
printf("====== Circuit Statistics ====== \n"); printf("====== Circuit Statistics ====== \n");
@ -26,6 +27,7 @@ int main(int args, char* argv[]) {
printf("PO:\t%ld\n", circuit->POs.size()); printf("PO:\t%ld\n", circuit->POs.size());
printf("Gate:\t%ld\n", circuit->name2gate.size()); printf("Gate:\t%ld\n", circuit->name2gate.size());
printf("Stem:\t%ld\n", circuit->stems.size()); printf("Stem:\t%ld\n", circuit->stems.size());
printf("Level:\t%d\n", circuit->MAX_GATE_LEVEL);
printf("================================ \n"); printf("================================ \n");
std::unordered_set<Fault*> faults; std::unordered_set<Fault*> faults;