2023-02-12 18:14:12 +08:00
|
|
|
#pragma once
|
|
|
|
|
2023-02-11 21:52:59 +08:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
class Gate {
|
|
|
|
public:
|
2023-02-12 16:22:32 +08:00
|
|
|
int topo;
|
2023-02-11 21:52:59 +08:00
|
|
|
std::string name;
|
2023-02-12 18:14:12 +08:00
|
|
|
enum Type { AND, NAND, OR, NOR, XOR, XNOR, NOT, BUF, INPUT, OUTPUT } type;
|
|
|
|
int value;
|
2023-02-11 21:52:59 +08:00
|
|
|
std::vector<Gate*> outputs;
|
|
|
|
std::vector<Gate*> inputs;
|
|
|
|
};
|
|
|
|
|
2023-02-16 18:51:31 +08:00
|
|
|
class Fault {
|
|
|
|
public:
|
|
|
|
Gate* gate;
|
|
|
|
enum Type { SA0, SA1 } type;
|
|
|
|
Fault(Gate* gate, Type type):gate(gate),type(type) {}
|
|
|
|
};
|
|
|
|
|
2023-02-11 21:52:59 +08:00
|
|
|
class Circuit {
|
|
|
|
public:
|
|
|
|
std::vector<Gate*> PIs;
|
|
|
|
std::vector<Gate*> POs;
|
2023-02-12 16:22:32 +08:00
|
|
|
std::vector<Gate*> gates;
|
2023-02-16 18:51:31 +08:00
|
|
|
std::vector<Gate*> stems;// PI + stems
|
|
|
|
|
2023-02-11 21:52:59 +08:00
|
|
|
std::unordered_map<std::string, Gate*> name2gate;
|
|
|
|
void parse_from_file(const char *filename);
|
2023-02-12 18:14:12 +08:00
|
|
|
int cal_gate_value(const Gate* &gate);
|
2023-02-16 18:51:31 +08:00
|
|
|
void init_topo_index();
|
|
|
|
void init_stems();
|
|
|
|
|
|
|
|
// local search
|
|
|
|
std::vector<int> local_search(const std::vector<Fault*> &faults);
|
|
|
|
|
|
|
|
void ls_init_circuit();
|
|
|
|
void ls_init_vector(std::vector<Gate*> *vec);
|
|
|
|
|
2023-02-12 18:14:12 +08:00
|
|
|
|
2023-02-11 21:52:59 +08:00
|
|
|
};
|