立即更新完工

This commit is contained in:
YuhangQ 2023-03-13 10:54:51 +00:00
parent 34a30f5c0e
commit 10b021e407
4 changed files with 39 additions and 13 deletions

BIN
atpg

Binary file not shown.

View File

@ -127,7 +127,7 @@ bool Circuit::is_valid_circuit() {
}
assert(this->stem_total_cost == stem_total_cost);
assert(this->fault_total_weight == fault_total_weight);
//assert(this->fault_total_weight == fault_total_weight);
assert(this->stem_total_cnt == stem_total_cnt);
assert(this->fault_total_cnt == fault_total_cnt);
assert(this->fault_propagate_score == fault_propagate_score);

47
ls.cpp
View File

@ -21,13 +21,14 @@ bool Circuit::local_search() {
auto start = std::chrono::system_clock::now();
printf("[FLIP] stem: %lld, fault:%lld, stem_cnt: %lld, fault_cnt:%lld, fpl_score: %lld\n", stem_total_cost, fault_total_weight, stem_total_cnt, fault_total_cnt, fault_propagate_score);
//printf("[FLIP] stem: %lld, fault:%lld, stem_cnt: %lld, fault_cnt:%lld, fpl_score: %lld citcuit-score: %lld\n", stem_total_cost, fault_total_weight, stem_total_cnt, fault_total_cnt, fault_propagate_score, ls_circuit_score());
Gate* stem = ls_pick();
if(stem == nullptr) {
printf("[UP] stem: %lld, fault:%lld, stem_cnt: %lld, fault_cnt:%lld, fpl_score: %lld\n", stem_total_cost, fault_total_weight, stem_total_cnt, fault_total_cnt, fault_propagate_score);
//printf("[UP] stem: %lld, fault:%lld, stem_cnt: %lld, fault_cnt:%lld, fpl_score: %lld citcuit-score: %lld\n", stem_total_cost, fault_total_weight, stem_total_cnt, fault_total_cnt, fault_propagate_score, ls_circuit_score());
ls_update_weight();
stem = ls_pick_falsified();
}
@ -37,6 +38,8 @@ bool Circuit::local_search() {
break;
}
ls_flip(stem);
assert(is_valid_circuit());
auto end = std::chrono::system_clock::now();
@ -70,6 +73,10 @@ void Circuit::ls_statistics() {
printf("coverage: %.2f%% undected_fault: %d delta: %d\n",
(gates.size() * 2.0 - global_fault_undetected_count) / (gates.size() * 2.0) * 100,
global_fault_undetected_count, global_fault_undetected_count - last_undetect);
printf("flip-cnt: %d flip-time: %.3fs update-cnt: %d update-time: %.3fs\n", flip_cnt, flip_time, update_cnt, update_time);
printf("time-per-update: %.2fms\n", update_time / update_cnt * 1000);
}
void Circuit::ls_update_weight() {
@ -95,6 +102,15 @@ void Circuit::ls_update_weight() {
if(g->stem && !g->stem_satisfied && (g->stem_weight + STEM_INC < STEM_WEIGHT_MAX)) {
g->stem_weight += STEM_INC;
stem_total_cost += STEM_INC;
for(Gate* suc : g->suc_stems) {
if(suc->stem_weight - STEM_INC >= 1) {
suc->stem_weight -= STEM_INC;
if(!suc->stem_satisfied) {
stem_total_cost -= STEM_INC;
}
}
}
}
if(!g->fault_detected[0] && g->fault_weight[0] > 0 && (g->fault_weight[0] + FAULT_INC < FAULT_WEIGHT_MAX)) {
@ -132,6 +148,7 @@ Gate* Circuit::ls_pick() {
for(int i=0; i<max_index; i++) {
Gate* t_stem = stems_random[i];
ll t_score = ls_pick_score(t_stem);
if(t_score > max_score) {
max_score = t_score;
stem = t_stem;
@ -146,11 +163,11 @@ Gate* Circuit::ls_pick_falsified() {
for(Gate *g : stems) {
if(g->stem_satisfied) continue;
for(Gate* pre : g->pre_stems)
candidates.push_back(pre);
// for(Gate* pre : g->pre_stems)
// candidates.push_back(pre);
for(Gate* suc : g->suc_stems)
candidates.push_back(suc);
// for(Gate* suc : g->suc_stems)
// candidates.push_back(suc);
candidates.push_back(g);
}
@ -232,11 +249,15 @@ ll Circuit::ls_pick_score(Gate* stem) {
ll new_score = ls_circuit_score();
ls_flip(stem);
assert(old_score == ls_circuit_score());
return new_score - old_score;
}
ll Circuit::ls_circuit_score() {
ll score = - stem_total_cost + fault_propagate_score;
ll score = -stem_total_cost + fault_propagate_score + fault_total_weight;
return score;
}
@ -325,6 +346,7 @@ void Circuit::ls_reset_data() {
void Circuit::ls_flip(Gate* stem) {
stem->value = !stem->value;
// update CC
stem->CC = 0;
@ -414,6 +436,9 @@ void Circuit::ls_flip(Gate* stem) {
}
}
q2.push(stem);
used2[stem] = true;
while(!q2.empty()) {
Gate *g = q2.front();
q2.pop();
@ -429,11 +454,11 @@ void Circuit::ls_flip(Gate* stem) {
if(fd[0] != in->fault_detected[0]) {
update = true;
if(in->fault_detected[0]) {
if(fd[0]) {
fault_total_weight += in->fault_weight[0];
fault_total_cnt += 1;
} else {
fault_total_weight -= in->fault_weight[9];
fault_total_weight -= in->fault_weight[0];
fault_total_cnt -= 1;
}
in->fault_detected[0] = fd[0];
@ -441,7 +466,7 @@ void Circuit::ls_flip(Gate* stem) {
if(fd[1] != in->fault_detected[1]) {
update = true;
if(in->fault_detected[1]) {
if(fd[1]) {
fault_total_weight += in->fault_weight[1];
fault_total_cnt += 1;
} else {
@ -465,7 +490,7 @@ void Circuit::ls_flip(Gate* stem) {
in->fault_propagate_length[1] = fpl[1];
}
if(!used2[in]) {
if(update && !used2[in]) {
used2[in] = true;
q2.push(in);
}

View File

@ -2,9 +2,10 @@
const double SP = 0.01;
const int MAX_STEPS = 10000;
const int SAMPLING_COUNT = 25;
const int STEM_INC = 1;
const int STEM_INC = 2;
const int STEM_WEIGHT_MAX = 1e9;
const int FAULT_INC = 1;