我想知道是否有一些预定义的函数可以将这两个测试结果作为BOOST中的布尔值,然后我将放置代码(在UPDATE中)。
1-如果图g1是g2的子图(通过给出g1和g2作为函数参数)。
此处http://www.boost.org/doc/libs/1_57_0/libs/graph/doc/subgraph.html子图用作类而不是函数。
2-图g连通性(通过给出g作为函数参数)。
在这里的官方文档http://www.boost.org/doc/libs/1_57_0/libs/graph/doc/connected_components.html中,我发现connected_components函数计算图中连接组件的数量,并为每个组件分配一个整数标签。然后,算法通过在组件属性映射中记录组件编号来记录图中每个顶点所属的组件。
答案 0 :(得分:1)
嗯,这是两个例子:
测试图g1是否是g2的子图(通过给出g1和g2作为函数参数):
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/vf2_sub_graph_iso.hpp>
using namespace std;
using namespace boost;
struct my_callback
{
template <typename CorrespondenceMap1To2, typename CorrespondenceMap2To1>
bool operator()(CorrespondenceMap1To2 f, CorrespondenceMap2To1 g) const
{
return false;
}
};
int main() {
typedef adjacency_list<setS, vecS, bidirectionalS> graph_type;
// Build graph1
int num_vertices1 = 8; graph_type graph1(num_vertices1);
add_edge(0, 6, graph1);
add_edge(0, 7, graph1);
add_edge(1, 5, graph1);
add_edge(1, 7, graph1);
add_edge(2, 4, graph1);
add_edge(2, 5, graph1);
add_edge(2, 6, graph1);
add_edge(3, 4, graph1);
// Build graph2
int num_vertices2 = 9; graph_type graph2(num_vertices2);
add_edge(0, 6, graph2);
add_edge(0, 8, graph2);
add_edge(1, 5, graph2);
add_edge(1, 7, graph2);
add_edge(2, 4, graph2);
add_edge(2, 7, graph2);
add_edge(2, 8, graph2);
add_edge(3, 4, graph2);
add_edge(3, 5, graph2);
add_edge(3, 6, graph2);
// Create callback to print mappings
//vf2_print_callback<graph_type, graph_type> callback(graph1, graph2);
// Print out all subgraph isomorphism mappings between graph1 and graph2.
// Vertices and edges are assumed to be always equivalent.
cout<<vf2_subgraph_iso(graph1, graph2,my_callback())<<endl;
return 0;
}
测试图g连接性(通过给g作为函数参数):
bool graphconnexe(Graph const& g) {
return num_edges(g) >= num_vertices(g) - 1;
}