ACEC/sweep.hpp
2022-10-14 14:04:57 +08:00

100 lines
1.7 KiB
C++

#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;
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;
int maxvar, output, num_inputs;
int *used, *det_v, *is_cut, *sum_pos, *sum_neg, *del;
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;
std::map<int, int> topo_index;
void solve();
void aiger_preprocess();
void cal_topo_index();
void propagate(int* input, int* result);
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