#pragma once #include #include #include #include #include #include #include using ll = long long; class Gate { public: // gate basic info int id; int level; int rtopo; std::string name; enum Type { AND, NAND, OR, NOR, XOR, XNOR, NOT, BUF, INPUT } type; int value; bool isPI; bool isPO; std::vector fanouts; std::vector fanins; std::vector reigon; // circuit-ls info int value_satisfied; int value_unsatisfied_cost; int fault_propagated_len[2]; int fault_propagated_weight[2]; int fault_detected[2]; int fault_detected_weight[2]; int fault_need_update; int fault_need_update_cost; int CC; bool is_propagated(); int cal_value(); bool cal_fault_detected(bool x); bool is_detected(Gate* one_of_input); int cal_propagate_len(bool x); void update_gate_property(); void update_gate_statistics(); // ( partical ) score // score(x) = for y in neibor(x) { ~V_x,V_y make - ~V_x,V_y break } // [ cal_FPL(~Vx, fanouts) - cal_FPL(Vx, fanouts) ] * FLP_WEIGHT(x) // [ cal_FD(~Vx, fanouts) - cal_FD(Vx, fanouts) ] * FD_WEIGHT(x) // [ cal_FPLS(~Vx, fanouts) - cal_FPLS(Vx, fanouts) ] * - FPLS_COST(x) // [ cal_FDS(~Vx, fanouts) - cal_FDS(Vx, fanouts) ] * - FDS_COST(x) int score; int score_value_unsatisfied_cost; int score_fault_propagated_weight[2]; int score_fault_detected_weight[2]; int score_fault_update_cost; // score calculation function int cal_score(int debug=0); int cal_value_unsatisfied_cost(); int cal_score_fault_propagated_weight(int sa); int cal_score_fault_detected_weight(int sa); int cal_score_fault_update_cost(); }; class Fault { public: Gate* gate; enum Type { SA0, SA1 } type; Fault(Gate* gate, Type type):gate(gate),type(type) {} }; class Circuit { public: std::vector PIs; std::vector POs; std::vector gates; std::vector rtopo_gates; std::unordered_map name2gate; // std::queue tmp; // std::unordered_map tmp_used; void init_topo_index(); int MAX_GATE_LEVEL; void init_gate_level(); void init_reigons(); void parse_from_file(const char *filename); void print_gates(); // local search bool local_search(std::unordered_set &faults); void ls_init_circuit(std::unordered_set &faults); void ls_update_weight(); Gate* ls_pick(); void ls_flip(Gate* stem); void ls_update(Gate* stem); // checker int check_circuit(); };