#pragma once

#include "fault.h"
#include "lut.h"

using ll = long long;

class Simulator;

class LUTCircuit {
public:
std::vector<LUT*> PIs;
std::vector<LUT*> POs;
std::vector<LUT*> luts;
std::vector<LUT*> rtopo_luts;

int step;

void print();

std::vector<LUT*> good_luts;

// local search

void ls_update();
LUT* ls_pick();
void ls_flip(LUT *lut);
void ls_main();

// checker

int check();


Simulator *simulator;

};

class Circuit {
public:
std::vector<Gate*> PIs;
std::vector<Gate*> POs;
std::vector<Gate*> gates;
std::vector<Gate*> rtopo_gates;

std::unordered_map<std::string, Gate*> name2gate;

void parse_from_file(const char *filename);
LUTCircuit* build_lut_circuit();

void init_topo_index();

};