gate 增加了 level 字段
This commit is contained in:
parent
8f2262eaee
commit
77a4984f3a
31
circuit.cpp
31
circuit.cpp
@ -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() {
|
||||
static const char* type2name[9] = {"AND", "NAND", "OR", "NOR", "XOR", "XNOR", "NOT", "BUF", "IN"};
|
||||
for(Gate* gate : gates) {
|
||||
|
@ -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<Gate*> 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;
|
||||
|
4
ls.cpp
4
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;
|
||||
|
2
main.cpp
2
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<Fault*> faults;
|
||||
|
Loading…
x
Reference in New Issue
Block a user