#pragma once #include "option.h" #include #include #include #include #include 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 fan_outs; std::vector fan_ins; std::vector pre_stems; std::vector 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 PIs; std::vector POs; std::vector gates; std::vector rtopo_gates; std::vector stems; // PIs and POs are stems by default std::unordered_map id2gate; std::unordered_map 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(); int ls_pick(); Gate* ls_pick_falsified(); void ls_flip_var(int var); void ls_flip_stem(Gate* stem); ll ls_pick_score(int var); ll ls_circuit_score(); int flip_cnt = 0; double flip_time = 0; int update_cnt = 0; double update_time = 0; };