43 for (
int i = 0; i < 4; i++) {
45 snprintf(
id, 100,
"mul_%d", i);
54 for (
int i = 0; i < 3; i++) {
56 snprintf(
id, 100,
"add_%d", i);
73 std::vector<std::string> cellIds;
76 for (
int i = 0; i < 45; i++) {
78 snprintf(
id, 100,
"cell_%02d", i);
79 haystack.
createNode(
id, i < 30 ?
"mul" :
"add");
83 cellIds.push_back(
id);
86 for (
int i = 0; i < int(cellIds.size()); i++) {
87 if (lrand48() % (i < 20 ? 3 : 2) != 0)
89 const std::string &
id = cellIds[i];
90 const std::string &id_left = cellIds[lrand48() % cellIds.size()];
91 const std::string &id_right = cellIds[lrand48() % cellIds.size()];
105 std::vector<SubCircuit::Solver::Result> results;
118 solver.
addGraph(
"haystack", haystack);
119 solver.
solve(results,
"needle",
"haystack");
121 for (
int i = 0; i < int(results.size()); i++) {
122 printf(
"\nMatch #%d: (%s in %s)\n", i, results[i].needleGraphId.c_str(), results[i].haystackGraphId.c_str());
123 for (
const auto &it : results[i].mappings) {
124 printf(
" %s -> %s", it.first.c_str(), it.second.haystackNodeId.c_str());
125 for (
const auto &it2 : it.second.portMapping)
126 printf(
" %s:%s", it2.first.c_str(), it2.second.c_str());
void addSwappablePorts(std::string needleTypeId, std::string portId1, std::string portId2, std::string portId3=std::string(), std::string portId4=std::string())
void createNode(std::string nodeId, std::string typeId, void *userData=NULL, bool shared=false)
void solve(std::vector< Result > &results, std::string needleGraphId, std::string haystackGraphId, bool allowOverlap=true, int maxSolutions=-1)
void addGraph(std::string graphId, const Graph &graph)
void markExtern(std::string nodeId, std::string portId, int bit=-1)
void createConnection(std::string fromNodeId, std::string fromPortId, int fromBit, std::string toNodeId, std::string toPortId, int toBit, int width=1)
void createPort(std::string nodeId, std::string portId, int width=1, int minWidth=-1)
void addCompatibleTypes(std::string needleTypeId, std::string haystackTypeId)