一些修改

This commit is contained in:
YuhangQ 2023-03-22 02:37:08 +00:00
parent 798b266d25
commit 175723f66e
6 changed files with 27 additions and 17 deletions

2
.vscode/launch.json vendored
View File

@ -11,7 +11,7 @@
"program": "${workspaceFolder}/atpg", "program": "${workspaceFolder}/atpg",
"args": ["${workspaceFolder}/benchmark/c432.bench"], "args": ["${workspaceFolder}/benchmark/c432.bench"],
"stopAtEntry": false, "stopAtEntry": false,
"cwd": "${fileDirname}", "cwd": "${workspaceFolder}",
"environment": [], "environment": [],
"externalConsole": false, "externalConsole": false,
"MIMode": "gdb", "MIMode": "gdb",

BIN
atpg

Binary file not shown.

View File

@ -76,8 +76,6 @@ bool Circuit::is_valid_circuit() {
ll fault_propagate_score = 0; ll fault_propagate_score = 0;
//printf("flip: %d, stem: %d, fault:%d\n", flip_total_weight, stem_total_weight, fault_total_weight);
for(Gate* g : gates) { for(Gate* g : gates) {
if(g->propagate != (g->fault_detected[0] || g->fault_detected[1])) { if(g->propagate != (g->fault_detected[0] || g->fault_detected[1])) {

2
crun
View File

@ -8,6 +8,6 @@ if [ $? -ne 0 ]; then
echo "compile failed." echo "compile failed."
else else
echo "========================" echo "========================"
time ./atpg $1 2>&1 | tee output.txt time ./atpg $1
fi fi

34
ls.cpp
View File

@ -12,6 +12,8 @@
bool Circuit::local_search() { bool Circuit::local_search() {
//printf("[start ls]\n");
ls_reset_data(); ls_reset_data();
ls_init_stems(); ls_init_stems();
@ -22,15 +24,29 @@ bool Circuit::local_search() {
ls_random_circuit(); ls_random_circuit();
//printf("stem-cnt: %d\n", stem_total_cnt);
for(int i=0; i<MAX_STEPS; i++) { for(int i=0; i<MAX_STEPS; i++) {
auto start = std::chrono::system_clock::now(); auto start = std::chrono::system_clock::now();
//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, stems.size() - stem_total_cnt, fault_total_cnt, fault_propagate_score, ls_circuit_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, stems.size() - stem_total_cnt, fault_total_cnt, fault_propagate_score, ls_circuit_score());
int id = ls_pick(); int id;
double p = 0.8;
// if(rand() % 10000 <= p * 10000) {
// id = CCAnr::module_pick_var();
// } else {
// }
id = ls_pick();
CCAnr::module_flip_var(id); CCAnr::module_flip_var(id);
ls_flip_var(id); ls_flip_var(id);
if(stem_total_cnt == stems.size()) { if(stem_total_cnt == stems.size()) {
@ -152,12 +168,9 @@ int Circuit::ls_pick() {
int var_score = ls_pick_score(var); int var_score = ls_pick_score(var);
assert(var != -1); assert(var != -1);;
int ccanr_var = CCAnr::module_pick_var(); return var;
int ccanr_score = ls_pick_score(ccanr_var);
return ccanr_var;
} }
void Circuit::ls_init_stems() { void Circuit::ls_init_stems() {
@ -224,7 +237,6 @@ void Circuit::ls_init_stems() {
void Circuit::ls_flip_var(int var) { void Circuit::ls_flip_var(int var) {
ClauseLS::flip(var); ClauseLS::flip(var);
if(id2gate.count(var) && id2gate[var]->stem) { if(id2gate.count(var) && id2gate[var]->stem) {
ls_flip_stem(id2gate[var]); ls_flip_stem(id2gate[var]);
} }
@ -240,7 +252,7 @@ ll Circuit::ls_pick_score(int var) {
ls_flip_var(var); ls_flip_var(var);
//assert(old_score == ls_circuit_score()); assert(old_score == ls_circuit_score());
return new_score - old_score; return new_score - old_score;
} }
@ -269,7 +281,8 @@ void Circuit::ls_random_circuit() {
for(int i=1; i<=ClauseLS::num_vars; i++) { for(int i=1; i<=ClauseLS::num_vars; i++) {
int new_v = CCAnr::module_cur_soln()[i]; int new_v = CCAnr::module_cur_soln()[i];
if(new_v != ClauseLS::lit_value[i]) { if(new_v != ClauseLS::lit_value[i]) {
ls_flip_var(i); //ls_flip_var(i);
ClauseLS::flip(i);
} }
} }
@ -309,10 +322,9 @@ void Circuit::ls_random_circuit() {
fault_propagate_score += g->fault_weight[0] * g->fault_propagate_length[0]; fault_propagate_score += g->fault_weight[0] * g->fault_propagate_length[0];
fault_propagate_score += g->fault_weight[1] * g->fault_propagate_length[1]; fault_propagate_score += g->fault_weight[1] * g->fault_propagate_length[1];
} }
//assert(is_valid_circuit()); assert(is_valid_circuit());
} }
void Circuit::ls_reset_data() { void Circuit::ls_reset_data() {

View File

@ -7,8 +7,8 @@ OBJECTS := $(addprefix build/,$(SOURCES:%=%.o))
# 声明编译器和编译选项 # 声明编译器和编译选项
CC := gcc CC := gcc
CXX := g++ CXX := g++
CFLAGS := -Wall -Wextra -MMD -MP CFLAGS := -O0 -g -Wall -Wextra -MMD -MP
CXXFLAGS := -Wall -Wextra -MMD -MP CXXFLAGS := -O0 -g -Wall -Wextra -MMD -MP
# 默认目标,编译所有目标文件 # 默认目标,编译所有目标文件
atpg: $(OBJECTS) atpg: $(OBJECTS)