2022-10-14 14:04:57 +08:00
|
|
|
#ifndef sweep_hpp_INCLUDED
|
|
|
|
#define sweep_hpp_INCLUDED
|
|
|
|
#include <chrono>
|
|
|
|
#include <bits/stdc++.h>
|
|
|
|
#include <cstring>
|
|
|
|
#include "vec.hpp"
|
|
|
|
|
|
|
|
namespace CaDiCaL {
|
|
|
|
struct Solver;
|
|
|
|
}
|
|
|
|
struct aiger;
|
|
|
|
struct circuit;
|
|
|
|
|
2022-10-21 19:34:18 +08:00
|
|
|
|
2022-10-14 14:04:57 +08:00
|
|
|
class Graph {
|
|
|
|
public:
|
|
|
|
struct Edge {
|
|
|
|
int from;
|
|
|
|
int to;
|
|
|
|
int neg;
|
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<std::vector<Edge>> edge;
|
|
|
|
std::vector<std::vector<Edge>> redge;
|
|
|
|
void add(int u, int v, int w) {
|
|
|
|
edge.resize(std::max(std::max(u, v)+1, (int)edge.size()));
|
|
|
|
redge.resize(std::max(std::max(u, v)+1, (int)redge.size()));
|
|
|
|
|
|
|
|
edge[u].push_back(Edge{u, v, w});
|
|
|
|
redge[v].push_back(Edge{v, u, w});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Sweep {
|
|
|
|
public:
|
|
|
|
FILE* file;
|
|
|
|
Graph graph;
|
|
|
|
|
2022-10-21 19:34:18 +08:00
|
|
|
int maxvar, output;
|
2022-10-14 14:04:57 +08:00
|
|
|
|
2022-10-21 19:34:18 +08:00
|
|
|
int *used, *det_v, *seen, *sum_pos, *sum_neg, *del;
|
2022-10-14 14:04:57 +08:00
|
|
|
int det_v_sz = 0;
|
|
|
|
int rounds;
|
|
|
|
|
|
|
|
std::chrono::high_resolution_clock::time_point clk_st = std::chrono::high_resolution_clock::now();
|
|
|
|
|
|
|
|
circuit *C;
|
|
|
|
aiger *aig;
|
2022-10-21 19:34:18 +08:00
|
|
|
CaDiCaL::Solver * solver;
|
2022-10-14 14:04:57 +08:00
|
|
|
std::map<int, int> topo_index;
|
2022-10-21 19:34:18 +08:00
|
|
|
std::map<int, int> rtopo_index;
|
|
|
|
std::set<std::pair<int, int>> eqp;
|
|
|
|
std::vector<std::vector<int>> classes;
|
|
|
|
std::vector<std::pair<int, std::pair<int, int>> > pairs;
|
|
|
|
vec<int> *inv_C;
|
2022-10-14 14:04:57 +08:00
|
|
|
|
|
|
|
void solve();
|
|
|
|
|
|
|
|
void aiger_preprocess();
|
|
|
|
|
|
|
|
void cal_topo_index();
|
|
|
|
|
|
|
|
void propagate(int* input, int* result);
|
2022-10-21 19:34:18 +08:00
|
|
|
|
|
|
|
void circuit_propagate(int* input, int* result);
|
2022-10-14 14:04:57 +08:00
|
|
|
|
|
|
|
void random_simulation();
|
|
|
|
|
|
|
|
void simulation();
|
|
|
|
|
|
|
|
bool check_var_equal(int x, int y, int assume);
|
|
|
|
|
|
|
|
bool check_constant(int x, int val);
|
|
|
|
|
|
|
|
void check_entire_problem(aiger* aig);
|
|
|
|
|
|
|
|
void check_with_SAT();
|
|
|
|
|
|
|
|
void identify();
|
|
|
|
|
|
|
|
bool match_xor(int x);
|
|
|
|
|
|
|
|
bool match_majority(int x);
|
|
|
|
|
|
|
|
void adjust_not();
|
|
|
|
|
|
|
|
void match_HA();
|
|
|
|
|
|
|
|
void match_FA();
|
|
|
|
|
|
|
|
bool line_positive(int to);
|
|
|
|
|
|
|
|
void recalculate_outs();
|
|
|
|
|
|
|
|
void to_multi_input_gates();
|
|
|
|
|
|
|
|
void simplify();
|
|
|
|
|
|
|
|
void miter();
|
|
|
|
|
|
|
|
void to_dot_graph(const char* filename, int end_point);
|
|
|
|
|
|
|
|
int get_time();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|