From ed1ddea83b13127afe99ec3d8dbf3ecf445cca6c Mon Sep 17 00:00:00 2001 From: Clifford Wolf Date: Thu, 7 Mar 2013 17:54:18 +0100 Subject: Added portmapping support to subcircuit userCompareNodes() api --- libs/subcircuit/subcircuit.cc | 50 ++++++++++++++++++++++++------------------- libs/subcircuit/subcircuit.h | 2 +- 2 files changed, 29 insertions(+), 23 deletions(-) (limited to 'libs') diff --git a/libs/subcircuit/subcircuit.cc b/libs/subcircuit/subcircuit.cc index 79aa346b..a4f86d4e 100644 --- a/libs/subcircuit/subcircuit.cc +++ b/libs/subcircuit/subcircuit.cc @@ -766,7 +766,7 @@ class SubCircuit::SolverWorker return true; } - bool matchNodes(const Graph &needle, int needleNodeIdx, const Graph &haystack, int haystackNodeIdx) const + bool matchNodes(const GraphData &needle, int needleNodeIdx, const GraphData &haystack, int haystackNodeIdx) const { // Rules for matching nodes: // @@ -783,8 +783,8 @@ class SubCircuit::SolverWorker // - the haystack edge must have the same number of components as the needle edge // - the haystack edge must not be extern - const Graph::Node &nn = needle.nodes[needleNodeIdx]; - const Graph::Node &hn = haystack.nodes[haystackNodeIdx]; + const Graph::Node &nn = needle.graph.nodes[needleNodeIdx]; + const Graph::Node &hn = haystack.graph.nodes[haystackNodeIdx]; assert(nn.typeId == hn.typeId || (compatibleTypes.count(nn.typeId) > 0 && compatibleTypes.at(nn.typeId).count(hn.typeId) > 0)); @@ -793,26 +793,28 @@ class SubCircuit::SolverWorker std::map currentCandidate; - for (const auto &port : needle.nodes[needleNodeIdx].ports) + for (const auto &port : needle.graph.nodes[needleNodeIdx].ports) currentCandidate[port.portId] = port.portId; - if (swapPorts.count(needle.nodes[needleNodeIdx].typeId) == 0) + if (swapPorts.count(needle.graph.nodes[needleNodeIdx].typeId) == 0) { - if (matchNodePorts(needle, needleNodeIdx, haystack, haystackNodeIdx, currentCandidate)) + if (matchNodePorts(needle.graph, needleNodeIdx, haystack.graph, haystackNodeIdx, currentCandidate) && + userSolver->userCompareNodes(needle.graphId, nn.nodeId, nn.userData, haystack.graphId, hn.nodeId, hn.userData, currentCandidate)) return true; - if (swapPermutations.count(needle.nodes[needleNodeIdx].typeId) > 0) - for (const auto &permutation : swapPermutations.at(needle.nodes[needleNodeIdx].typeId)) { + if (swapPermutations.count(needle.graph.nodes[needleNodeIdx].typeId) > 0) + for (const auto &permutation : swapPermutations.at(needle.graph.nodes[needleNodeIdx].typeId)) { std::map currentSubCandidate = currentCandidate; applyPermutation(currentSubCandidate, permutation); - if (matchNodePorts(needle, needleNodeIdx, haystack, haystackNodeIdx, currentCandidate)) + if (matchNodePorts(needle.graph, needleNodeIdx, haystack.graph, haystackNodeIdx, currentCandidate) && + userSolver->userCompareNodes(needle.graphId, nn.nodeId, nn.userData, haystack.graphId, hn.nodeId, hn.userData, currentCandidate)) return true; } } else { std::vector> thisSwapPorts; - for (const auto &ports : swapPorts.at(needle.nodes[needleNodeIdx].typeId)) { + for (const auto &ports : swapPorts.at(needle.graph.nodes[needleNodeIdx].typeId)) { std::vector portsVector; for (const auto &port : ports) portsVector.push_back(port); @@ -824,14 +826,16 @@ class SubCircuit::SolverWorker { permutateVectorToMapArray(currentCandidate, thisSwapPorts, i); - if (matchNodePorts(needle, needleNodeIdx, haystack, haystackNodeIdx, currentCandidate)) + if (matchNodePorts(needle.graph, needleNodeIdx, haystack.graph, haystackNodeIdx, currentCandidate) && + userSolver->userCompareNodes(needle.graphId, nn.nodeId, nn.userData, haystack.graphId, hn.nodeId, hn.userData, currentCandidate)) return true; - if (swapPermutations.count(needle.nodes[needleNodeIdx].typeId) > 0) - for (const auto &permutation : swapPermutations.at(needle.nodes[needleNodeIdx].typeId)) { + if (swapPermutations.count(needle.graph.nodes[needleNodeIdx].typeId) > 0) + for (const auto &permutation : swapPermutations.at(needle.graph.nodes[needleNodeIdx].typeId)) { std::map currentSubCandidate = currentCandidate; applyPermutation(currentSubCandidate, permutation); - if (matchNodePorts(needle, needleNodeIdx, haystack, haystackNodeIdx, currentCandidate)) + if (matchNodePorts(needle.graph, needleNodeIdx, haystack.graph, haystackNodeIdx, currentCandidate) && + userSolver->userCompareNodes(needle.graphId, nn.nodeId, nn.userData, haystack.graphId, hn.nodeId, hn.userData, currentCandidate)) return true; } } @@ -856,10 +860,9 @@ class SubCircuit::SolverWorker const Graph::Node &hn = haystack.graph.nodes[j]; if (initialMappings.count(nn.nodeId) > 0 && initialMappings.at(nn.nodeId).count(hn.nodeId) == 0) continue; - if (!matchNodes(needle.graph, i, haystack.graph, j)) + if (!matchNodes(needle, i, haystack, j)) continue; - if (userSolver->userCompareNodes(needle.graphId, nn.nodeId, nn.userData, haystack.graphId, hn.nodeId, hn.userData)) - enumerationMatrix[i].insert(j); + enumerationMatrix[i].insert(j); } if (compatibleTypes.count(nn.typeId) > 0) @@ -868,10 +871,9 @@ class SubCircuit::SolverWorker const Graph::Node &hn = haystack.graph.nodes[j]; if (initialMappings.count(nn.nodeId) > 0 && initialMappings.at(nn.nodeId).count(hn.nodeId) == 0) continue; - if (!matchNodes(needle.graph, i, haystack.graph, j)) + if (!matchNodes(needle, i, haystack, j)) continue; - if (userSolver->userCompareNodes(needle.graphId, nn.nodeId, nn.userData, haystack.graphId, hn.nodeId, hn.userData)) - enumerationMatrix[i].insert(j); + enumerationMatrix[i].insert(j); } } } @@ -961,7 +963,11 @@ class SubCircuit::SolverWorker assert(enumerationMatrix[idx].size() == 1); int idxHaystack = *enumerationMatrix[idx].begin(); - if (!matchNodePorts(needle.graph, idx, haystack.graph, idxHaystack, currentCandidate)) + const Graph::Node &nn = needle.graph.nodes[idx]; + const Graph::Node &hn = haystack.graph.nodes[idxHaystack]; + + if (!matchNodePorts(needle.graph, idx, haystack.graph, idxHaystack, currentCandidate) || + !userSolver->userCompareNodes(needle.graphId, nn.nodeId, nn.userData, haystack.graphId, hn.nodeId, hn.userData, currentCandidate)) return false; for (const auto &it_needle : needle.adjMatrix.at(idx)) @@ -1556,7 +1562,7 @@ protected: friend class Solver; }; -bool Solver::userCompareNodes(const std::string&, const std::string&, void*, const std::string&, const std::string&, void*) +bool Solver::userCompareNodes(const std::string&, const std::string&, void*, const std::string&, const std::string&, void*, const std::map&) { return true; } diff --git a/libs/subcircuit/subcircuit.h b/libs/subcircuit/subcircuit.h index 80eafbc3..d673af88 100644 --- a/libs/subcircuit/subcircuit.h +++ b/libs/subcircuit/subcircuit.h @@ -118,7 +118,7 @@ namespace SubCircuit protected: virtual bool userCompareNodes(const std::string &needleGraphId, const std::string &needleNodeId, void *needleUserData, - const std::string &haystackGraphId, const std::string &haystackNodeId, void *haystackUserData); + const std::string &haystackGraphId, const std::string &haystackNodeId, void *haystackUserData, const std::map &portMapping); virtual std::string userAnnotateEdge(const std::string &graphId, const std::string &fromNodeId, void *fromUserData, const std::string &toNodeId, void *toUserData); -- cgit v1.2.3