-
Notifications
You must be signed in to change notification settings - Fork 212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Function mcgregor_common_subgraphs cannot correctly find subgraph #212
Comments
Also, it is not correct to make sure ALL edges from existing to new vertices are equivalent. At least one edge from existing to new vertices is equivalent is enough. |
Hi, I noticed the same issue. For what it's worth, here is the example given in the 1982 McGregor paper "Backtrack Search Algorithms and the Maximal Common Subgraph Problem" I.e., the correspondence here should be
(*) It appears that
I tried to reproduce this with the boost implementation (note that code uses 0-based indexing, whereas the paper is 1-based): #include <iostream>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/mcgregor_common_subgraphs.hpp>
using namespace boost;
typedef adjacency_list<vecS, vecS, undirectedS> Graph;
typedef adjacency_list<> DiGraph;
template<typename GraphFirst,
typename GraphSecond>
struct print_callback {
print_callback(const GraphFirst &graph1,
const GraphSecond &graph2) :
m_graph1(graph1), m_graph2(graph2) {}
template<typename CorrespondenceMapFirstToSecond,
typename CorrespondenceMapSecondToFirst>
bool operator()(CorrespondenceMapFirstToSecond correspondence_map_1_to_2,
CorrespondenceMapSecondToFirst correspondence_map_2_to_1,
typename graph_traits<GraphFirst>::vertices_size_type subgraph_size) {
// Print out correspondences between vertices
BGL_FORALL_VERTICES_T(vertex1, m_graph1, GraphFirst) {
// Skip unmapped vertices
if (get(correspondence_map_1_to_2, vertex1) != graph_traits<GraphSecond>::null_vertex()) {
std::cout << vertex1 << " <-> " << get(correspondence_map_1_to_2, vertex1) << std::endl;
}
}
std::cout << "---" << std::endl;
return (true);
}
private:
const GraphFirst &m_graph1;
const GraphSecond &m_graph2;
};
int main() {
std::vector<std::pair<int, int>> g1_edges = {
{0, 1}, {0, 2}, {1, 2}, {1, 3}, {1, 4}, {2, 5}, {2, 7}, {3, 6}, {4, 6}, {4, 7}
};
std::vector<std::pair<int, int>> g2_edges = {
{0, 1}, {0, 2}, {1, 3}, {1, 4}, {2, 5}, {3, 6}, {4, 5}, {4, 7}
};
Graph G1(g1_edges.begin(), g1_edges.end(), 8);
Graph G2(g2_edges.begin(), g2_edges.end(), 8);
std::cout << "Graph G1:" << std::endl;
for (auto v : G1.vertex_set()) {
std::cout << "\t" << v << ": ";
for (auto e: G1.out_edge_list(v)) {
std::cout << e.get_target() << ", ";
}
std::cout << std::endl;
}
std::cout << "Graph G2:" << std::endl;
for (auto v : G2.vertex_set()) {
std::cout << "\t" << v << ": ";
for (auto e: G2.out_edge_list(v)) {
std::cout << e.get_target() << ", ";
}
std::cout << std::endl;
}
print_callback<Graph, Graph> my_callback(G1, G2);
mcgregor_common_subgraphs_maximum_unique(G1, G2, false, my_callback);
return 0;
} |
what is your cmake setting and your boost version? Are you using boost managed by conda environment? |
If you don't know the solution to the problem, you can still help greatly by creating a pull request with a good unit test that demonstrates the problem. Sometimes, that's half-way to fixing it. |
Here is my code. My code is trying to find common subgraph between graph1 and graph2 with specific number of vertices.
It is clear that 11->12->13->10 should be a common subgraph with 4 vertices while result size is 0. I looked at source code of function mcgregor_common_subgraphs and I believe the reason is in below code segment.
Here when subgraph is a graph containing nodes 11,12,13 and we want to extend node 10, mcgregor_common_subgraphs finds out there is an edge between 10 and 11 in subgraph2 while ther e is no edge between 10 and 11 in subgraph1. Hence can_extend_graph will return false. I believe the implementation of mcgregor_common_subgraphs now can only find subgraphs that appears "fully" in both graphs, which will miss many common subgraphs.
The text was updated successfully, but these errors were encountered: