测试
This commit is contained in:
parent
85cd5aa62b
commit
482069812f
@ -3,12 +3,10 @@
|
|||||||
int Circuit::check_circuit() {
|
int Circuit::check_circuit() {
|
||||||
|
|
||||||
int sum_value_unsatisfied_cost = 0;
|
int sum_value_unsatisfied_cost = 0;
|
||||||
|
int sum_fault_need_update_cost = 0;
|
||||||
|
|
||||||
int sum_fault_propagated_weight = 0;
|
int sum_fault_propagated_weight = 0;
|
||||||
int sum_fault_propagated_unsatisfied_cost = 0;
|
|
||||||
|
|
||||||
int sum_fault_detected_weight = 0;
|
int sum_fault_detected_weight = 0;
|
||||||
int sum_fault_detected_unsatisfied_cost = 0;
|
|
||||||
|
|
||||||
for(Gate* g : gates) {
|
for(Gate* g : gates) {
|
||||||
|
|
||||||
@ -19,39 +17,31 @@ int Circuit::check_circuit() {
|
|||||||
|
|
||||||
assert(g->value_satisfied == ( g->cal_value() == g->value ));
|
assert(g->value_satisfied == ( g->cal_value() == g->value ));
|
||||||
|
|
||||||
assert(g->fault_detected_satisfied[0] == ( g->cal_fault_detected(0) == g->fault_detected[0] ));
|
int changed = 0;
|
||||||
assert(g->fault_detected_satisfied[1] == ( g->cal_fault_detected(1) == g->fault_detected[1] ));
|
if(!changed && g->cal_fault_detected(0) != g->fault_detected[0]) changed = 1;
|
||||||
|
if(!changed && g->cal_fault_detected(1) != g->fault_detected[1]) changed = 1;
|
||||||
|
if(!changed && g->cal_propagate_len(0) != g->cal_propagate_len(0)) changed = 1;
|
||||||
|
if(!changed && g->cal_propagate_len(1) != g->cal_propagate_len(1)) changed = 1;
|
||||||
|
|
||||||
assert(g->fault_propagated_satisfied[0] == ( g->cal_propagate_len(0) == g->fault_propagated_len[0]));
|
assert(changed == g->fault_need_update);
|
||||||
|
|
||||||
|
|
||||||
// if(g->fault_propagated_satisfied[1] != ( g->cal_propagate_len(1) == g->fault_propagated_len[1])) {
|
|
||||||
// printf("pl: %s\n", g->name.c_str());
|
|
||||||
// print_gates();
|
|
||||||
// }
|
|
||||||
assert(g->fault_propagated_satisfied[1] == ( g->cal_propagate_len(1) == g->fault_propagated_len[1]));
|
|
||||||
|
|
||||||
if(!g->value_satisfied) sum_value_unsatisfied_cost += g->value_unsatisfied_cost;
|
if(!g->value_satisfied) sum_value_unsatisfied_cost += g->value_unsatisfied_cost;
|
||||||
|
if(g->fault_need_update) sum_fault_need_update_cost += g->fault_need_update_cost;
|
||||||
|
|
||||||
if(g->fault_detected[0]) sum_fault_detected_weight += g->fault_detected_weight[0];
|
if(g->fault_detected[0]) sum_fault_detected_weight += g->fault_detected_weight[0];
|
||||||
if(g->fault_detected[1]) sum_fault_detected_weight += g->fault_detected_weight[1];
|
if(g->fault_detected[1]) sum_fault_detected_weight += g->fault_detected_weight[1];
|
||||||
|
|
||||||
if(!g->fault_detected_satisfied[0]) sum_fault_detected_unsatisfied_cost += g->fault_detected_unsatisfied_cost[0];
|
|
||||||
if(!g->fault_detected_satisfied[1]) sum_fault_detected_unsatisfied_cost += g->fault_detected_unsatisfied_cost[1];
|
|
||||||
|
|
||||||
sum_fault_propagated_weight += g->fault_propagated_len[0] * g->fault_propagated_weight[0];
|
sum_fault_propagated_weight += g->fault_propagated_len[0] * g->fault_propagated_weight[0];
|
||||||
sum_fault_propagated_weight += g->fault_propagated_len[1] * g->fault_propagated_weight[1];
|
sum_fault_propagated_weight += g->fault_propagated_len[1] * g->fault_propagated_weight[1];
|
||||||
|
|
||||||
if(!g->fault_propagated_satisfied[0]) sum_fault_propagated_unsatisfied_cost += g->fault_propagated_unsatisfied_cost[0];
|
|
||||||
if(!g->fault_propagated_satisfied[1]) sum_fault_propagated_unsatisfied_cost += g->fault_propagated_unsatisfied_cost[1];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int circuit_score = sum_fault_propagated_weight + sum_fault_detected_weight
|
int circuit_score = sum_fault_propagated_weight + sum_fault_detected_weight
|
||||||
- sum_fault_propagated_unsatisfied_cost - sum_fault_detected_unsatisfied_cost - sum_value_unsatisfied_cost;
|
- sum_value_unsatisfied_cost - sum_fault_need_update_cost;
|
||||||
|
|
||||||
printf("svuc: %d, sfpw: %d, sfpuc: %d, sfdw: %d, sfduc: %d\n",
|
printf("svuc: %d, sfpw: %d, sfpuc: %d, sfdw: %d, sfduc: %d\n",
|
||||||
sum_value_unsatisfied_cost, sum_fault_propagated_weight, sum_fault_propagated_unsatisfied_cost,
|
sum_value_unsatisfied_cost,
|
||||||
sum_fault_detected_weight, sum_fault_detected_unsatisfied_cost);
|
sum_fault_propagated_weight, sum_fault_detected_weight);
|
||||||
|
|
||||||
return circuit_score;
|
return circuit_score;
|
||||||
}
|
}
|
@ -31,15 +31,12 @@ public:
|
|||||||
|
|
||||||
int fault_propagated_len[2];
|
int fault_propagated_len[2];
|
||||||
int fault_propagated_weight[2];
|
int fault_propagated_weight[2];
|
||||||
|
|
||||||
int fault_propagated_satisfied[2];
|
|
||||||
int fault_propagated_unsatisfied_cost[2];
|
|
||||||
|
|
||||||
int fault_detected[2];
|
int fault_detected[2];
|
||||||
int fault_detected_weight[2];
|
int fault_detected_weight[2];
|
||||||
|
|
||||||
int fault_detected_satisfied[2];
|
int fault_need_update;
|
||||||
int fault_detected_unsatisfied_cost[2];
|
int fault_need_update_cost;
|
||||||
|
|
||||||
int CC;
|
int CC;
|
||||||
|
|
||||||
@ -68,12 +65,9 @@ public:
|
|||||||
int score;
|
int score;
|
||||||
|
|
||||||
int score_value_unsatisfied_cost;
|
int score_value_unsatisfied_cost;
|
||||||
|
|
||||||
int score_fault_propagated_weight[2];
|
int score_fault_propagated_weight[2];
|
||||||
int score_fault_propagated_unsatisfied_cost[2];
|
|
||||||
|
|
||||||
int score_fault_detected_weight[2];
|
int score_fault_detected_weight[2];
|
||||||
int score_fault_detected_unsatisfied_cost[2];
|
int score_fault_update_cost;
|
||||||
|
|
||||||
// score calculation function
|
// score calculation function
|
||||||
|
|
||||||
@ -83,11 +77,9 @@ public:
|
|||||||
|
|
||||||
int cal_score_fault_propagated_weight(int sa);
|
int cal_score_fault_propagated_weight(int sa);
|
||||||
|
|
||||||
int cal_score_fault_propagated_unsatisfied_cost(int sa);
|
|
||||||
|
|
||||||
int cal_score_fault_detected_weight(int sa);
|
int cal_score_fault_detected_weight(int sa);
|
||||||
|
|
||||||
int cal_score_fault_detected_unsatisfied_cost(int sa);
|
int cal_score_fault_update_cost();
|
||||||
};
|
};
|
||||||
|
|
||||||
class Fault {
|
class Fault {
|
||||||
|
@ -12,10 +12,6 @@ void Gate::update_gate_property() {
|
|||||||
|
|
||||||
void Gate::update_gate_statistics() {
|
void Gate::update_gate_statistics() {
|
||||||
value_satisfied = ( cal_value() == value );
|
value_satisfied = ( cal_value() == value );
|
||||||
fault_detected_satisfied[0] = ( cal_fault_detected(0) == fault_detected[0] );
|
|
||||||
fault_detected_satisfied[1] = ( cal_fault_detected(1) == fault_detected[1] );
|
|
||||||
fault_propagated_satisfied[0] = ( cal_propagate_len(0) == fault_propagated_len[0] );
|
|
||||||
fault_propagated_satisfied[1] = ( cal_propagate_len(1) == fault_propagated_len[1] );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Gate::cal_propagate_len(bool x) {
|
int Gate::cal_propagate_len(bool x) {
|
||||||
|
35
src/ls.cpp
35
src/ls.cpp
@ -113,40 +113,17 @@ void Circuit::ls_flip(Gate* gate) {
|
|||||||
int cal_cnt = 0;
|
int cal_cnt = 0;
|
||||||
|
|
||||||
for(Gate* g : gate->fanouts) {
|
for(Gate* g : gate->fanouts) {
|
||||||
// printf("cal2: %s\n", g->name.c_str());
|
|
||||||
t.insert(g);
|
|
||||||
g->score = g->cal_score();
|
g->score = g->cal_score();
|
||||||
cal_cnt++;
|
}
|
||||||
for(Gate* in : g->fanins) {
|
|
||||||
t.insert(in);
|
for(Gate* g : gate->reigon) {
|
||||||
in->score = in->cal_score();
|
g->score = g->cal_score();
|
||||||
cal_cnt++;
|
|
||||||
for(Gate *out : in->fanouts) {
|
|
||||||
t.insert(out);
|
|
||||||
out->score = out->cal_score();
|
|
||||||
cal_cnt++;
|
|
||||||
for(Gate *in : out->fanins) {
|
|
||||||
t.insert(in);
|
|
||||||
in->score = in->cal_score();
|
|
||||||
cal_cnt++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for(Gate* g : gate->fanins) {
|
for(Gate* g : gate->fanins) {
|
||||||
t.insert(g);
|
|
||||||
g->score = g->cal_score();
|
g->score = g->cal_score();
|
||||||
cal_cnt++;
|
|
||||||
for(Gate* out : g->fanouts) {
|
for(Gate* out : g->fanouts) {
|
||||||
t.insert(out);
|
|
||||||
out->score = out->cal_score();
|
out->score = out->cal_score();
|
||||||
cal_cnt++;
|
|
||||||
for(Gate* in : out->fanins) {
|
|
||||||
t.insert(in);
|
|
||||||
in->score = in->cal_score();
|
|
||||||
cal_cnt++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,11 +157,11 @@ void Circuit::ls_init_circuit(std::unordered_set<Fault*> &faults) {
|
|||||||
// init value, weight and cost
|
// init value, weight and cost
|
||||||
for(Gate* g : gates) {
|
for(Gate* g : gates) {
|
||||||
g->value = rand() % 2;
|
g->value = rand() % 2;
|
||||||
|
g->fault_need_update = 0;
|
||||||
g->value_unsatisfied_cost = 1;
|
g->value_unsatisfied_cost = 1;
|
||||||
|
g->fault_need_update_cost = 1;
|
||||||
g->fault_propagated_weight[0] = g->fault_propagated_weight[1] = 0;
|
g->fault_propagated_weight[0] = g->fault_propagated_weight[1] = 0;
|
||||||
g->fault_propagated_unsatisfied_cost[0] = g->fault_propagated_unsatisfied_cost[1] = 1;
|
|
||||||
g->fault_detected_weight[0] = g->fault_detected_weight[1] = 0;
|
g->fault_detected_weight[0] = g->fault_detected_weight[1] = 0;
|
||||||
g->fault_detected_unsatisfied_cost[0] = g->fault_detected_unsatisfied_cost[1] = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for(Fault* f : faults) {
|
for(Fault* f : faults) {
|
||||||
|
109
src/score.cpp
109
src/score.cpp
@ -5,39 +5,49 @@ int Gate::cal_score(int debug) {
|
|||||||
|
|
||||||
value ^= 1;
|
value ^= 1;
|
||||||
|
|
||||||
if(debug) {
|
// if(debug) {
|
||||||
// printf("lala: %s\n", this->name.c_str());
|
// // printf("lala: %s\n", this->name.c_str());
|
||||||
assert(score_value_unsatisfied_cost == cal_value_unsatisfied_cost());
|
// assert(score_value_unsatisfied_cost == cal_value_unsatisfied_cost());
|
||||||
assert(score_fault_propagated_weight[0] == cal_score_fault_propagated_weight(0));
|
// assert(score_fault_propagated_weight[0] == cal_score_fault_propagated_weight(0));
|
||||||
assert(score_fault_propagated_weight[1] == cal_score_fault_propagated_weight(1));
|
// assert(score_fault_propagated_weight[1] == cal_score_fault_propagated_weight(1));
|
||||||
assert(score_fault_propagated_unsatisfied_cost[0] == cal_score_fault_propagated_unsatisfied_cost(0));
|
// assert(score_fault_propagated_unsatisfied_cost[0] == cal_score_fault_propagated_unsatisfied_cost(0));
|
||||||
assert(score_fault_propagated_unsatisfied_cost[1] == cal_score_fault_propagated_unsatisfied_cost(1));
|
// assert(score_fault_propagated_unsatisfied_cost[1] == cal_score_fault_propagated_unsatisfied_cost(1));
|
||||||
assert(score_fault_detected_weight[0] == cal_score_fault_detected_weight(0));
|
// assert(score_fault_detected_weight[0] == cal_score_fault_detected_weight(0));
|
||||||
assert(score_fault_detected_weight[1] == cal_score_fault_detected_weight(1));
|
// assert(score_fault_detected_weight[1] == cal_score_fault_detected_weight(1));
|
||||||
assert(score_fault_detected_unsatisfied_cost[0] == cal_score_fault_detected_unsatisfied_cost(0));
|
// assert(score_fault_detected_unsatisfied_cost[0] == cal_score_fault_detected_unsatisfied_cost(0));
|
||||||
assert(score_fault_detected_unsatisfied_cost[1] == cal_score_fault_detected_unsatisfied_cost(1));
|
// assert(score_fault_detected_unsatisfied_cost[1] == cal_score_fault_detected_unsatisfied_cost(1));
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
int origin_fault_detected[2];
|
||||||
|
origin_fault_detected[0] = this->fault_detected[0];
|
||||||
|
origin_fault_detected[1] = this->fault_detected[1];
|
||||||
|
this->fault_detected[0] = this->cal_fault_detected(0);
|
||||||
|
this->fault_detected[1] = this->cal_fault_detected(1);
|
||||||
|
|
||||||
|
int origin_fault_propagated_len[2];
|
||||||
|
origin_fault_propagated_len[0] = this->fault_propagated_len[0];
|
||||||
|
origin_fault_propagated_len[1] = this->fault_propagated_len[1];
|
||||||
|
this->fault_propagated_len[0] = this->cal_propagate_len(0);
|
||||||
|
this->fault_propagated_len[1] = this->cal_propagate_len(1);
|
||||||
|
|
||||||
score_value_unsatisfied_cost = cal_value_unsatisfied_cost();
|
score_value_unsatisfied_cost = cal_value_unsatisfied_cost();
|
||||||
score_fault_propagated_weight[0] = cal_score_fault_propagated_weight(0);
|
score_fault_propagated_weight[0] = cal_score_fault_propagated_weight(0);
|
||||||
score_fault_propagated_weight[1] = cal_score_fault_propagated_weight(1);
|
score_fault_propagated_weight[1] = cal_score_fault_propagated_weight(1);
|
||||||
|
|
||||||
score_fault_propagated_unsatisfied_cost[0] = cal_score_fault_propagated_unsatisfied_cost(0);
|
|
||||||
score_fault_propagated_unsatisfied_cost[1] = cal_score_fault_propagated_unsatisfied_cost(1);
|
|
||||||
|
|
||||||
score_fault_detected_weight[0] = cal_score_fault_detected_weight(0);
|
score_fault_detected_weight[0] = cal_score_fault_detected_weight(0);
|
||||||
score_fault_detected_weight[1] = cal_score_fault_detected_weight(1);
|
score_fault_detected_weight[1] = cal_score_fault_detected_weight(1);
|
||||||
|
|
||||||
score_fault_detected_unsatisfied_cost[0] = cal_score_fault_detected_unsatisfied_cost(0);
|
score_fault_update_cost = cal_score_fault_update_cost();
|
||||||
score_fault_detected_unsatisfied_cost[1] = cal_score_fault_detected_unsatisfied_cost(1);
|
|
||||||
|
|
||||||
value ^= 1;
|
value ^= 1;
|
||||||
|
this->fault_propagated_len[0] = origin_fault_propagated_len[0];
|
||||||
|
this->fault_propagated_len[1] = origin_fault_propagated_len[1];
|
||||||
|
this->fault_detected[0] = origin_fault_detected[0];
|
||||||
|
this->fault_detected[1] = origin_fault_detected[1];
|
||||||
|
|
||||||
return - score_value_unsatisfied_cost
|
return - score_value_unsatisfied_cost - score_fault_update_cost
|
||||||
+ score_fault_propagated_weight[0] + score_fault_propagated_weight[1]
|
+ score_fault_propagated_weight[0] + score_fault_propagated_weight[1]
|
||||||
- score_fault_propagated_unsatisfied_cost[0] - score_fault_propagated_unsatisfied_cost[1]
|
+ score_fault_detected_weight[0] + score_fault_detected_weight[1];
|
||||||
+ score_fault_detected_weight[0] + score_fault_detected_weight[1]
|
|
||||||
- score_fault_detected_unsatisfied_cost[0] - score_fault_detected_unsatisfied_cost[1];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Gate::cal_value_unsatisfied_cost() {
|
int Gate::cal_value_unsatisfied_cost() {
|
||||||
@ -65,62 +75,31 @@ int Gate::cal_score_fault_propagated_weight(int sa) {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Gate::cal_score_fault_propagated_unsatisfied_cost(int sa) {
|
|
||||||
int res = 0;
|
|
||||||
int origin_fault_propagated_len[2];
|
|
||||||
origin_fault_propagated_len[0] = this->fault_propagated_len[0];
|
|
||||||
origin_fault_propagated_len[1] = this->fault_propagated_len[1];
|
|
||||||
this->fault_propagated_len[0] = this->cal_propagate_len(0);
|
|
||||||
this->fault_propagated_len[1] = this->cal_propagate_len(1);
|
|
||||||
|
|
||||||
if(!this->fault_propagated_satisfied[sa]) {
|
|
||||||
res -= this->fault_propagated_unsatisfied_cost[sa];
|
|
||||||
}
|
|
||||||
|
|
||||||
for(Gate* g : this->reigon) {
|
|
||||||
if(g->fault_propagated_satisfied[sa] && g->cal_propagate_len(sa) != g->fault_propagated_len[sa]) {
|
|
||||||
res += g->fault_propagated_unsatisfied_cost[sa];
|
|
||||||
}
|
|
||||||
if(!g->fault_propagated_satisfied[sa] && g->cal_propagate_len(sa) == g->fault_propagated_len[sa]) {
|
|
||||||
res -= g->fault_propagated_unsatisfied_cost[sa];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this->fault_propagated_len[0] = origin_fault_propagated_len[0];
|
|
||||||
this->fault_propagated_len[1] = origin_fault_propagated_len[1];
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
int Gate::cal_score_fault_detected_weight(int sa) {
|
int Gate::cal_score_fault_detected_weight(int sa) {
|
||||||
int res = 0;
|
int res = 0;
|
||||||
res += ( this->cal_fault_detected(sa) - this->fault_detected[sa] ) * this->fault_detected_weight[sa];
|
res += ( this->cal_fault_detected(sa) - this->fault_detected[sa] ) * this->fault_detected_weight[sa];
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Gate::cal_score_fault_detected_unsatisfied_cost(int sa) {
|
int Gate::cal_score_fault_update_cost() {
|
||||||
int res = 0;
|
int res = 0;
|
||||||
|
|
||||||
int origin_fault_detected[2];
|
if(this->fault_need_update) {
|
||||||
origin_fault_detected[0] = this->fault_detected[0];
|
res -= this->fault_need_update_cost;
|
||||||
origin_fault_detected[1] = this->fault_detected[1];
|
|
||||||
this->fault_detected[0] = this->cal_fault_detected(0);
|
|
||||||
this->fault_detected[1] = this->cal_fault_detected(1);
|
|
||||||
|
|
||||||
if(!fault_detected_satisfied[sa]) {
|
|
||||||
res -= this->fault_detected_unsatisfied_cost[sa];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for(Gate* g : this->reigon) {
|
for(Gate* g : fanins) {
|
||||||
if(g->fault_detected_satisfied[sa] && g->cal_fault_detected(sa) != g->fault_detected[sa]) {
|
bool changed = 0;
|
||||||
res += g->fault_detected_unsatisfied_cost[sa];
|
if(!changed && g->cal_fault_detected(0) != g->fault_detected[0]) changed = 1;
|
||||||
}
|
if(!changed && g->cal_fault_detected(1) != g->fault_detected[1]) changed = 1;
|
||||||
if(!g->fault_detected_satisfied[sa] && g->cal_fault_detected(sa) == g->fault_detected[sa]) {
|
if(!changed && g->cal_propagate_len(0) != g->cal_propagate_len(0)) changed = 1;
|
||||||
res -= g->fault_detected_unsatisfied_cost[sa];
|
if(!changed && g->cal_propagate_len(1) != g->cal_propagate_len(1)) changed = 1;
|
||||||
|
|
||||||
|
if(!g->fault_need_update && changed) {
|
||||||
|
res += g->fault_need_update_cost;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this->fault_detected[0] = origin_fault_detected[0];
|
|
||||||
this->fault_detected[1] = origin_fault_detected[1];
|
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user