解决 stuck 问题
This commit is contained in:
parent
acfeb1be4b
commit
c8031934fb
@ -7,12 +7,9 @@
|
||||
|
||||
void Circuit::init_stems() {
|
||||
for(auto& gate: gates) {
|
||||
if(rand() % 10 <= 2) {
|
||||
if(gate->outputs.size() >= 2) {
|
||||
gate->stem = true;
|
||||
}
|
||||
// if(gate->outputs.size() >= 3) {
|
||||
|
||||
// }
|
||||
if(gate->stem) {
|
||||
stems.push_back(gate);
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ int* flip_need_update;
|
||||
std::vector<Gate*> flip_update_queue;
|
||||
|
||||
// incremental stem struct
|
||||
const int STEM_INC = 100;
|
||||
int STEM_INC = 0;
|
||||
const int STEM_WEIGHT_MAX = 1e9;
|
||||
ll stem_total_weight;
|
||||
int stem_total_cnt;
|
||||
|
62
ls.cpp
62
ls.cpp
@ -8,6 +8,8 @@
|
||||
|
||||
bool Circuit::local_search(std::unordered_set<Fault*> &faults) {
|
||||
|
||||
STEM_INC = 0;
|
||||
|
||||
// 初始化并重置所有 ls 数据结构
|
||||
ls_init_data_structs();
|
||||
|
||||
@ -51,8 +53,8 @@ bool Circuit::local_search(std::unordered_set<Fault*> &faults) {
|
||||
}
|
||||
|
||||
if(max_score > 0) {
|
||||
// printf("FLIP: %s\n", stem->name.c_str());
|
||||
printf("[LS] flip: %lld, stem: %lld, fault:%lld. flip_cnt: %d, stem_cnt: %d, fault_cnt:%d\n", flip_total_weight, stem_total_weight, fault_total_weight, flip_total_cnt, stem_total_cnt, fault_total_cnt);
|
||||
// printf("FLIP: %s (+%lld)\n", stem->name.c_str(), max_score);
|
||||
// printf("[LS] flip: %lld, stem: %lld, fault:%lld. flip_cnt: %d, stem_cnt: %d, fault_cnt:%d\n", flip_total_weight, stem_total_weight, fault_total_weight, flip_total_cnt, stem_total_cnt, fault_total_cnt);
|
||||
ls_flip(stem);
|
||||
|
||||
CC[stem->id] = 0;
|
||||
@ -123,7 +125,6 @@ bool Circuit::local_search(std::unordered_set<Fault*> &faults) {
|
||||
ls_update(g);
|
||||
}
|
||||
|
||||
|
||||
static int original_faults = -1;
|
||||
if(original_faults == - 1) {
|
||||
original_faults = faults.size();
|
||||
@ -148,20 +149,23 @@ bool Circuit::local_search(std::unordered_set<Fault*> &faults) {
|
||||
}
|
||||
|
||||
void Circuit::ls_update_weight() {
|
||||
|
||||
STEM_INC++;
|
||||
|
||||
if(rand() % 10000 <= SP * 10000) {
|
||||
// for(Gate* g : gates) {
|
||||
// if(g->stem && stem_satisfied[g->id] && (stem_weight[g->id] - STEM_INC >= 1)) {
|
||||
// stem_weight[g->id] -= STEM_INC;
|
||||
// for(Gate* suc : g->suc_stems) {
|
||||
// if(stem_weight[suc->id] + STEM_INC <= STEM_WEIGHT_MAX) {
|
||||
// stem_weight[suc->id] += STEM_INC;
|
||||
// if(!stem_satisfied[suc->id]) {
|
||||
// stem_total_weight += STEM_INC;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
for(Gate* g : gates) {
|
||||
if(g->stem && stem_satisfied[g->id] && (stem_weight[g->id] - STEM_INC >= 1)) {
|
||||
stem_weight[g->id] -= STEM_INC;
|
||||
for(Gate* suc : g->suc_stems) {
|
||||
if(stem_weight[suc->id] + STEM_INC <= STEM_WEIGHT_MAX) {
|
||||
stem_weight[suc->id] += STEM_INC;
|
||||
if(!stem_satisfied[suc->id]) {
|
||||
stem_total_weight += STEM_INC;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for(Gate* g : gates) {
|
||||
if(flip_need_update[g->id] && (flip_weight[g->id] + FLIP_INC < FLIP_WEIGHT_MAX)) {
|
||||
@ -181,14 +185,23 @@ void Circuit::ls_update_weight() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(Gate* pre : g->pre_stems) {
|
||||
if(stem_weight[pre->id] + STEM_INC < STEM_WEIGHT_MAX) {
|
||||
stem_weight[pre->id] += STEM_INC;
|
||||
if(!stem_satisfied[pre->id]) {
|
||||
stem_total_weight += STEM_INC;
|
||||
}
|
||||
for(int i=0; i<=1; i++) {
|
||||
if(!fault_weight[g->id][i]) continue;
|
||||
for(Gate* suc : g->suc_stems) {
|
||||
int inc = std::max(1, fault_weight[g->id][i]);
|
||||
|
||||
if(fault_weight[suc->id][0] + inc <= FAULT_WEIGHT_MAX) {
|
||||
fault_weight[suc->id][0] += inc;
|
||||
if(suc->sa[0]) fault_total_weight += inc;
|
||||
}
|
||||
|
||||
if(fault_weight[suc->id][1] + inc <= FAULT_WEIGHT_MAX) {
|
||||
fault_weight[suc->id][1] += inc;
|
||||
if(suc->sa[1]) fault_total_weight += inc;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -217,18 +230,21 @@ void Circuit::ls_update(Gate* stem) {
|
||||
}
|
||||
ll Circuit::ls_pick_score(Gate* stem) {
|
||||
|
||||
ll old_score = ls_score();
|
||||
|
||||
ls_flip(stem);
|
||||
|
||||
ll new_score = ls_score();
|
||||
|
||||
ls_flip(stem);
|
||||
|
||||
ll old_score = ls_score();
|
||||
old_score = std::max(old_score, ls_score());
|
||||
|
||||
return new_score - old_score;
|
||||
}
|
||||
|
||||
ll Circuit::ls_score() {
|
||||
//ll score = -flip_total_weight -stem_total_weight + fault_total_weight;
|
||||
ll score = -flip_total_weight -stem_total_weight + fault_total_weight;
|
||||
return score;
|
||||
}
|
||||
|
9702
output.txt
Normal file
9702
output.txt
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user