summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClifford Wolf <clifford@clifford.at>2013-03-07 17:54:18 +0100
committerClifford Wolf <clifford@clifford.at>2013-03-07 17:54:18 +0100
commited1ddea83b13127afe99ec3d8dbf3ecf445cca6c (patch)
tree80c7521c94bb3fd24349e9655324e117f162505e
parentb070b821876c2d277514f4ac6b0d62d0e26a500e (diff)
Added portmapping support to subcircuit userCompareNodes() api
-rw-r--r--libs/subcircuit/subcircuit.cc50
-rw-r--r--libs/subcircuit/subcircuit.h2
2 files changed, 29 insertions, 23 deletions
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<std::string, std::string> 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<std::string, std::string> 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<std::vector<std::string>> thisSwapPorts;
- for (const auto &ports : swapPorts.at(needle.nodes[needleNodeIdx].typeId)) {
+ for (const auto &ports : swapPorts.at(needle.graph.nodes[needleNodeIdx].typeId)) {
std::vector<std::string> 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<std::string, std::string> 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<std::string, std::string>&)
{
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<std::string, std::string> &portMapping);
virtual std::string userAnnotateEdge(const std::string &graphId, const std::string &fromNodeId, void *fromUserData, const std::string &toNodeId, void *toUserData);