更新代码
This commit is contained in:
parent
39e218b333
commit
181e57aa7f
42
.vscode/settings.json
vendored
Normal file
42
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"array": "cpp",
|
||||
"*.tcc": "cpp",
|
||||
"cctype": "cpp",
|
||||
"chrono": "cpp",
|
||||
"clocale": "cpp",
|
||||
"cmath": "cpp",
|
||||
"compare": "cpp",
|
||||
"concepts": "cpp",
|
||||
"cstdint": "cpp",
|
||||
"cstdio": "cpp",
|
||||
"cstdlib": "cpp",
|
||||
"ctime": "cpp",
|
||||
"cwchar": "cpp",
|
||||
"cwctype": "cpp",
|
||||
"deque": "cpp",
|
||||
"unordered_map": "cpp",
|
||||
"unordered_set": "cpp",
|
||||
"vector": "cpp",
|
||||
"exception": "cpp",
|
||||
"functional": "cpp",
|
||||
"initializer_list": "cpp",
|
||||
"iosfwd": "cpp",
|
||||
"istream": "cpp",
|
||||
"limits": "cpp",
|
||||
"new": "cpp",
|
||||
"numbers": "cpp",
|
||||
"ostream": "cpp",
|
||||
"ratio": "cpp",
|
||||
"sstream": "cpp",
|
||||
"stdexcept": "cpp",
|
||||
"streambuf": "cpp",
|
||||
"string": "cpp",
|
||||
"string_view": "cpp",
|
||||
"system_error": "cpp",
|
||||
"type_traits": "cpp",
|
||||
"tuple": "cpp",
|
||||
"typeinfo": "cpp",
|
||||
"utility": "cpp"
|
||||
}
|
||||
}
|
53
ls.cpp
53
ls.cpp
@ -8,7 +8,6 @@
|
||||
#include <chrono>
|
||||
|
||||
|
||||
|
||||
bool Circuit::local_search(std::unordered_set<Fault*> &faults) {
|
||||
|
||||
// 初始化并重置所有 ls 数据结构
|
||||
@ -29,30 +28,29 @@ bool Circuit::local_search(std::unordered_set<Fault*> &faults) {
|
||||
Gate* stem = nullptr;
|
||||
ll max_score = 0;
|
||||
|
||||
std::vector<Gate*> stems_random;
|
||||
std::vector<Gate*> candidates;
|
||||
// std::vector<Gate*> stems_random;
|
||||
// std::vector<Gate*> candidates;
|
||||
|
||||
for(int i=0; i<stems.size(); i++) {
|
||||
if(CC[stems[i]->id]) {
|
||||
stems_random.push_back(stems[i]);
|
||||
}
|
||||
}
|
||||
for(int i=0; i<stems_random.size(); i++) {
|
||||
std::swap(stems_random[i], stems_random[rand()%stems_random.size()]);
|
||||
}
|
||||
// for(int i=0; i<stems.size(); i++) {
|
||||
// if(CC[stems[i]->id]) {
|
||||
// stems_random.push_back(stems[i]);
|
||||
// }
|
||||
// }
|
||||
// for(int i=0; i<stems_random.size(); i++) {
|
||||
// std::swap(stems_random[i], stems_random[rand()%stems_random.size()]);
|
||||
// }
|
||||
|
||||
const int T = 50;
|
||||
int t = 0;
|
||||
|
||||
for(int i=0; i<stems_random.size(); i++) {
|
||||
Gate* t_stem = stems_random[i];
|
||||
for(int i=0; i<T; i++) {
|
||||
Gate* t_stem = stems[rand()%stems.size()];
|
||||
if(!CC[t_stem->id]) continue;
|
||||
|
||||
ll t_score = ls_pick_score(t_stem);
|
||||
if(t_score > max_score) {
|
||||
max_score = t_score;
|
||||
stem = t_stem;
|
||||
}
|
||||
if(t_score > 0) t++;
|
||||
if(i >= T) break;
|
||||
}
|
||||
|
||||
if(max_score > 0) {
|
||||
@ -78,17 +76,18 @@ bool Circuit::local_search(std::unordered_set<Fault*> &faults) {
|
||||
} else {
|
||||
ls_update_weight();
|
||||
|
||||
while(!flip_update_queue.empty()) {
|
||||
Gate* g = flip_update_queue.back();
|
||||
flip_update_queue.pop_back();
|
||||
if(!flip_need_update[g->id]) continue;
|
||||
flip_need_update[g->id] = false;
|
||||
flip_total_weight -= flip_weight[g->id];
|
||||
flip_total_cnt -= 1;
|
||||
ls_update(g);
|
||||
}
|
||||
|
||||
|
||||
if(stem_total_cnt == stems.size() && flip_total_cnt == 0) {
|
||||
if(stem_total_cnt == stems.size()) {
|
||||
while(!flip_update_queue.empty()) {
|
||||
Gate* g = flip_update_queue.back();
|
||||
flip_update_queue.pop_back();
|
||||
if(!flip_need_update[g->id]) continue;
|
||||
flip_need_update[g->id] = false;
|
||||
flip_total_weight -= flip_weight[g->id];
|
||||
flip_total_cnt -= 1;
|
||||
ls_update(g);
|
||||
}
|
||||
//printf("FIND SOLUTION!\n");
|
||||
printf("[SOL] 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);
|
||||
break;
|
||||
@ -237,7 +236,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_score;
|
||||
ll score = - flip_total_weight - stem_total_weight + fault_propagate_score + fault_total_weight;
|
||||
return score;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user