修改部分数据结构

This commit is contained in:
YuhangQ 2023-02-16 18:51:31 +08:00
parent d613341d1c
commit 67443cbde9
6 changed files with 55 additions and 51 deletions

BIN
atpg

Binary file not shown.

View File

@ -3,7 +3,19 @@
#include <queue>
#include <unordered_map>
void Circuit::cal_topo_index() {
void Circuit::init_stems() {
for(auto& gate: gates) {
if(gate->outputs.size() >= 2) {
stems.push_back(gate);
}
}
for(auto &gate : PIs) {
stems.push_back(gate);
}
}
void Circuit::init_topo_index() {
int topo = 1;
std::queue<Gate*> q;
@ -80,4 +92,6 @@ int Circuit::cal_gate_value(const Gate* &gate) {
break;
}
return res;
}
}

View File

@ -14,14 +14,31 @@ public:
std::vector<Gate*> inputs;
};
class Fault {
public:
Gate* gate;
enum Type { SA0, SA1 } type;
Fault(Gate* gate, Type type):gate(gate),type(type) {}
};
class Circuit {
public:
std::vector<Gate*> PIs;
std::vector<Gate*> POs;
std::vector<Gate*> gates;
std::vector<Gate*> stems;// PI + stems
std::unordered_map<std::string, Gate*> name2gate;
void parse_from_file(const char *filename);
int cal_gate_value(const Gate* &gate);
void cal_topo_index();
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);
};

28
ls.cpp
View File

@ -1,35 +1,17 @@
#include "ls.h"
#include "circuit.h"
std::vector<int> local_search(Circuit* circuit) {
std::vector<int> Circuit::local_search(const std::vector<Fault*> &faults) {
// local search vector
std::vector<Gate*> vec;
init_vector(circuit, &vec);
init_circuit(circuit);
ls_init_circuit();
printf("local search!\n");
return std::vector<int>();
}
void init_circuit(Circuit* circuit) {
for(auto pi : circuit->PIs) {
void Circuit::ls_init_circuit() {
for(auto pi : PIs) {
pi->value = rand() % 2;
}
}
void init_vector(Circuit* circuit, std::vector<Gate*> *vec) {
for(auto pi : circuit->PIs) {
vec->push_back(pi);
}
for(auto gate : circuit->gates) {
// fanout stem
if(gate->outputs.size() >= 2) {
vec->push_back(gate);
}
}
}

9
ls.h
View File

@ -1,9 +0,0 @@
#pragma once
#include "circuit.h"
std::vector<int> local_search(Circuit* circuit);
// private
void init_circuit(Circuit* circuit);
void init_vector(Circuit* circuit, std::vector<Gate*> *vec);

View File

@ -3,7 +3,6 @@
#include <assert.h>
#include "circuit.h"
#include "ls.h"
int main(int args, char* argv[]) {
@ -12,31 +11,32 @@ int main(int args, char* argv[]) {
exit(1);
}
srand(19260817);
Circuit circuit;
printf("parsing file %s...\n", argv[1]);
printf("parsing file %s ...", argv[1]);
circuit.parse_from_file(argv[1]);
circuit.init_stems();
circuit.init_topo_index();
printf(" Done.\n");
printf("====== Circuit Statistics ====== \n");
printf("PI:\t%ld\n", circuit.PIs.size());
printf("PO:\t%ld\n", circuit.POs.size());
printf("Gates:\t%ld\n", circuit.name2gate.size());
printf("Gate:\t%ld\n", circuit.name2gate.size());
printf("Stem:\t%ld\n", circuit.stems.size());
printf("================================ \n");
int cnt = 0;
for(auto& gate: circuit.gates) {
if(gate->outputs.size() > 2) {
cnt++;
}
}
printf("Stem:\t%d\n", cnt);
std::vector<Fault*> faults;
printf("cal topo index ...\n");
circuit.cal_topo_index();
for(Gate* gate : circuit.gates) {
assert(gate->topo > 0);
// init faults
for(auto stem : circuit.stems) {
faults.push_back(new Fault(stem, Fault::SA0));
faults.push_back(new Fault(stem, Fault::SA1));
}
srand(19260817);
local_search(&circuit);
auto pattern = circuit.local_search(faults);
return 0;
}