传播状态独立,但是效果不好

This commit is contained in:
YuhangQ 2023-03-01 07:14:23 +00:00
parent 2dffd855c5
commit 73023786dd
8 changed files with 3367 additions and 7950 deletions

BIN
atpg

Binary file not shown.

View File

@ -19,8 +19,9 @@ void Circuit::init_stems() {
for(auto& gate: gates) { for(auto& gate: gates) {
if(gate->outputs.size() >= 2) { if(gate->outputs.size() >= 2) {
gate->stem = true;
} }
gate->stem = true;
if(gate->stem) { if(gate->stem) {
stems.push_back(gate); stems.push_back(gate);
} }

View File

@ -80,12 +80,12 @@ void init_stems();
// local search // local search
// shared info // shared info
static const int STEM_INC = 10; static const int STEM_INC = 20;
static const int STEM_COST_MAX = 1e9; static const int STEM_COST_MAX = 1e9;
static ll stem_total_cost; static ll stem_total_cost;
static int stem_falsified_cnt; static int stem_falsified_cnt;
static const int PROPAGATE_INC = 10; static const int PROPAGATE_INC = 20;
static const int PROPAGATE_COST_MAX = 1e9; static const int PROPAGATE_COST_MAX = 1e9;
static ll propagate_total_cost; static ll propagate_total_cost;
static int propagate_falsified_cnt; static int propagate_falsified_cnt;

1398
cost.txt Normal file

File diff suppressed because it is too large Load Diff

View File

@ -11,6 +11,11 @@
// } // }
bool Gate::cal_sa(bool x) { bool Gate::cal_sa(bool x) {
if(po) {
if(x == 0) return value;
else return !value;
}
bool sa0 = 0; bool sa0 = 0;
bool sa1 = 0; bool sa1 = 0;

54
ls.cpp
View File

@ -29,8 +29,8 @@ bool Circuit::local_search(std::unordered_set<Fault*> &faults) {
picked_stem = ls_pick_falsified_var(value, propagate); picked_stem = ls_pick_falsified_var(value, propagate);
printf("[UP] propagate: %lld, stem: %lld, fault:%lld. propagate_cnt: %d, stem_cnt: %d, fault_cnt:%d\n", propagate_total_cost, stem_total_cost, fault_total_cost, propagate_falsified_cnt, stem_falsified_cnt, fault_falsified_cnt); printf("[UP] propagate: %lld, stem: %lld, fault:%lld. propagate_cnt: %d, stem_cnt: %d, fault_cnt:%d\n", propagate_total_cost, stem_total_cost, fault_total_cost, propagate_falsified_cnt, stem_falsified_cnt, fault_falsified_cnt);
} else { } else {
printf("pick: %s value: %d propagate: %d\n", picked_stem->name.c_str(), value, propagate); // printf("pick: %s value: %d propagate: %d\n", picked_stem->name.c_str(), value, propagate);
printf("[LS] propagate: %lld, stem: %lld, fault:%lld. propagate_cnt: %d, stem_cnt: %d, fault_cnt:%d\n", propagate_total_cost, stem_total_cost, fault_total_cost, propagate_falsified_cnt, stem_falsified_cnt, fault_falsified_cnt); // printf("[LS] propagate: %lld, stem: %lld, fault:%lld. propagate_cnt: %d, stem_cnt: %d, fault_cnt:%d\n", propagate_total_cost, stem_total_cost, fault_total_cost, propagate_falsified_cnt, stem_falsified_cnt, fault_falsified_cnt);
} }
picked_stem->value = value; picked_stem->value = value;
@ -45,6 +45,26 @@ bool Circuit::local_search(std::unordered_set<Fault*> &faults) {
printf("[SOL] propagate: %lld, stem: %lld, fault:%lld. propagate_cnt: %d, stem_cnt: %d, fault_cnt:%d\n", propagate_total_cost, stem_total_cost, fault_total_cost, propagate_falsified_cnt, stem_falsified_cnt, fault_falsified_cnt); printf("[SOL] propagate: %lld, stem: %lld, fault:%lld. propagate_cnt: %d, stem_cnt: %d, fault_cnt:%d\n", propagate_total_cost, stem_total_cost, fault_total_cost, propagate_falsified_cnt, stem_falsified_cnt, fault_falsified_cnt);
break; break;
} }
if(fault_total_cost == 6340 && propagate_falsified_cnt == 19 && stem_falsified_cnt == 1 && fault_falsified_cnt == 317) {
static int cnt = 0;
cnt++;
if(cnt == 100) {
print_gates();
for(Gate* s: stems) {
if(!s->propagate_satisfied) {
printf(" > propagate falsified: %s\n", s->name.c_str());
printf("s0: %d s1: %d, cal_s0: %d, cal_s1: %d\n", s->fault_satisfied[0], s->fault_satisfied[1], s->cal_sa(0), s->cal_sa(1));
printf("score: %lld\n", ls_pick_score(s, 1, 0));
}
}
exit(0);
}
}
} }
static int original_faults = -1; static int original_faults = -1;
@ -75,6 +95,7 @@ Gate* Circuit::ls_pick_falsified_var(bool &value, bool &propagate) {
for(Gate *g : stems) { for(Gate *g : stems) {
if(g->po) continue; if(g->po) continue;
if(g->stem_satisified) continue; if(g->stem_satisified) continue;
if(g->propagate_satisfied) continue;
candidates.push_back(g); candidates.push_back(g);
} }
@ -83,6 +104,11 @@ Gate* Circuit::ls_pick_falsified_var(bool &value, bool &propagate) {
} }
Gate* pick = candidates[rand()%candidates.size()]; Gate* pick = candidates[rand()%candidates.size()];
value = !pick->value;
propagate = !propagate;
return pick; return pick;
} }
@ -104,7 +130,7 @@ Gate* Circuit::ls_pick_good_var(bool &value, bool &propagate) {
std::swap(stems_random[i], stems_random[rand()%stems_random.size()]); std::swap(stems_random[i], stems_random[rand()%stems_random.size()]);
} }
const int T = 100; const int T = 25;
for(int i=0; i < stems_random.size() && i < T; i++) { for(int i=0; i < stems_random.size() && i < T; i++) {
Gate* t_stem = stems_random[i]; Gate* t_stem = stems_random[i];
@ -140,12 +166,23 @@ void Circuit::ls_update_weight() {
if(g->stem && !g->propagate_satisfied && (g->propagate_cost + PROPAGATE_INC <= PROPAGATE_COST_MAX)) { if(g->stem && !g->propagate_satisfied && (g->propagate_cost + PROPAGATE_INC <= PROPAGATE_COST_MAX)) {
g->propagate_cost += PROPAGATE_INC; g->propagate_cost += PROPAGATE_INC;
propagate_total_cost += PROPAGATE_INC; propagate_total_cost += PROPAGATE_INC;
for(Gate* pre : g->pre_stems) {
if(pre->propagate_cost - PROPAGATE_INC >= 1) {
pre->propagate_cost -= PROPAGATE_INC;
if(!pre->propagate_satisfied) {
propagate_total_cost -= PROPAGATE_INC;
}
}
}
} }
if(g->stem && !g->stem_satisified && (g->stem_cost + STEM_INC <= STEM_COST_MAX)) { if(g->stem && !g->stem_satisified && (g->stem_cost + STEM_INC <= STEM_COST_MAX)) {
g->stem_cost += STEM_INC; g->stem_cost += STEM_INC;
stem_total_cost += STEM_INC; stem_total_cost += STEM_INC;
if(g->stem_satisified)
for(Gate* suc : g->suc_stems) { for(Gate* suc : g->suc_stems) {
if(suc->stem_cost - STEM_INC >= 1) { if(suc->stem_cost - STEM_INC >= 1) {
suc->stem_cost -= STEM_INC; suc->stem_cost -= STEM_INC;
@ -200,8 +237,8 @@ ll Circuit::ls_pick_score(Gate* stem, bool value, bool propagate) {
ll old_score1 = ls_score(); ll old_score1 = ls_score();
// print_gates(); // print_gates();
// printf("--------------"); // printf("--------------");
// printf("[wrong] propagate: %lld, stem: %lld, fault:%lld\n", Circuit::propagate_total_cost, Circuit::stem_total_cost, Circuit::fault_total_cost); //printf("[before] propagate: %lld, stem: %lld, fault:%lld\n", Circuit::propagate_total_cost, Circuit::stem_total_cost, Circuit::fault_total_cost);
// printf("[wrong] propagate_cnt: %d, stem_cnt: %d, fault_cnt:%d\n", Circuit::propagate_falsified_cnt, Circuit::stem_falsified_cnt, Circuit::fault_falsified_cnt); //printf("[before] propagate_cnt: %d, stem_cnt: %d, fault_cnt:%d\n", Circuit::propagate_falsified_cnt, Circuit::stem_falsified_cnt, Circuit::fault_falsified_cnt);
bool old_value = stem->value; bool old_value = stem->value;
bool old_propagate = stem->propagate; bool old_propagate = stem->propagate;
@ -215,6 +252,9 @@ ll Circuit::ls_pick_score(Gate* stem, bool value, bool propagate) {
// print_gates(); // print_gates();
// printf("--------------"); // printf("--------------");
//printf("[now] propagate: %lld, stem: %lld, fault:%lld\n", Circuit::propagate_total_cost, Circuit::stem_total_cost, Circuit::fault_total_cost);
//printf("[now] propagate_cnt: %d, stem_cnt: %d, fault_cnt:%d\n", Circuit::propagate_falsified_cnt, Circuit::stem_falsified_cnt, Circuit::fault_falsified_cnt);
stem->value = old_value; stem->value = old_value;
stem->propagate = old_propagate; stem->propagate = old_propagate;
@ -228,8 +268,7 @@ ll Circuit::ls_pick_score(Gate* stem, bool value, bool propagate) {
// if(old_score1 != old_score2) { // if(old_score1 != old_score2) {
// printf("old1: %lld old2: %lld\n", old_score1, old_score2); // printf("old1: %lld old2: %lld\n", old_score1, old_score2);
// printf("[wrong] propagate: %lld, stem: %lld, fault:%lld\n", Circuit::propagate_total_cost, Circuit::stem_total_cost, Circuit::fault_total_cost); //ed_cnt);
// printf("[wrong] propagate_cnt: %d, stem_cnt: %d, fault_cnt:%d\n", Circuit::propagate_falsified_cnt, Circuit::stem_falsified_cnt, Circuit::fault_falsified_cnt);
// exit(-1); // exit(-1);
// } // }
@ -238,6 +277,7 @@ ll Circuit::ls_pick_score(Gate* stem, bool value, bool propagate) {
ll Circuit::ls_score() { ll Circuit::ls_score() {
ll score = - propagate_total_cost - stem_total_cost - fault_total_cost; ll score = - propagate_total_cost - stem_total_cost - fault_total_cost;
//ll score = - stem_total_cost - fault_total_cost;
return score; return score;
} }

1000
new.txt Normal file

File diff suppressed because it is too large Load Diff

8853
output.txt

File diff suppressed because it is too large Load Diff