117 lines
2.0 KiB
C++
117 lines
2.0 KiB
C++
#pragma once
|
|
|
|
#include "option.h"
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
#include <unordered_map>
|
|
#include <unordered_set>
|
|
#include <queue>
|
|
|
|
|
|
using ll = long long;
|
|
|
|
class Gate {
|
|
public:
|
|
// 门的原始信息
|
|
int id;
|
|
int rtopo;
|
|
std::string name;
|
|
enum Type { AND, NAND, OR, NOR, XOR, XNOR, NOT, BUF, INPUT } type;
|
|
int value;
|
|
bool pi;
|
|
bool po;
|
|
std::vector<Gate*> fan_outs;
|
|
std::vector<Gate*> fan_ins;
|
|
|
|
std::vector<Gate*> pre_stems;
|
|
std::vector<Gate*> suc_stems;
|
|
|
|
// 记录全局已经发现的错误
|
|
bool global_fault_detected[2];
|
|
|
|
// atpg-ls 附加信息
|
|
int CC;
|
|
bool stem;
|
|
bool propagate;
|
|
|
|
int stem_weight;
|
|
bool stem_satisfied;
|
|
|
|
int fault_weight[2];
|
|
bool fault_detected[2];
|
|
|
|
int fault_propagate_length[2];
|
|
|
|
// 计算此门的信息
|
|
int recal_value();
|
|
void recal_fault(bool fd[2]);
|
|
void recal_propagate_len(int fpl[2]);
|
|
|
|
// 门的某个输入产生的错误是否可以通过这个门传播
|
|
bool is_detected(Gate* one_of_input);
|
|
};
|
|
|
|
class Circuit {
|
|
public:
|
|
|
|
// 电路的基本信息
|
|
std::vector<Gate*> PIs;
|
|
std::vector<Gate*> POs;
|
|
std::vector<Gate*> gates;
|
|
std::vector<Gate*> rtopo_gates;
|
|
std::vector<Gate*> stems; // PIs and POs are stems by default
|
|
|
|
std::unordered_map<std::string, Gate*> name2gate;
|
|
|
|
// 读入和输出电路
|
|
void parse_from_file(const char *filename);
|
|
void print_circuit();
|
|
|
|
|
|
// 初始化电路统计信息
|
|
int MAX_GATE_LEVEL;
|
|
void init_topo_index();
|
|
|
|
// 电路状态 checker
|
|
bool is_valid_circuit();
|
|
|
|
// local search
|
|
|
|
bool local_search();
|
|
|
|
int global_fault_undetected_count;
|
|
|
|
ll stem_total_cost;
|
|
int stem_total_cnt;
|
|
|
|
ll fault_propagate_score;
|
|
|
|
ll fault_total_weight;
|
|
int fault_total_cnt;
|
|
|
|
void ls_reset_data();
|
|
void ls_init_stems();
|
|
void ls_init_weight();
|
|
|
|
void ls_random_circuit();
|
|
|
|
void ls_statistics();
|
|
|
|
void ls_update_weight();
|
|
|
|
Gate* ls_pick();
|
|
Gate* ls_pick_falsified();
|
|
|
|
void ls_flip(Gate* stem);
|
|
|
|
ll ls_pick_score(Gate* stem);
|
|
|
|
ll ls_circuit_score();
|
|
|
|
int flip_cnt = 0;
|
|
double flip_time = 0;
|
|
|
|
int update_cnt = 0;
|
|
double update_time = 0;
|
|
}; |