Общие подграфы

Я хочу использовать первую часть кода, чтобы найти общие компоненты подграфов во второй части кода. Поэтому я не хочу изменять вторую часть кода, я хочу изменить первую, чтобы она работала с использованием графиков, определенных во второй части. Я не знаю, с чего начать.

#include <fstream>
#include <iostream>
#include <string>

#include <boost/lexical_cast.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/filtered_graph.hpp>
#include <boost/graph/graph_utility.hpp>
#include <boost/graph/iteration_macros.hpp>
#include <boost/graph/mcgregor_common_subgraphs.hpp>
#include <boost/property_map/shared_array_property_map.hpp>

using namespace boost;

// Callback that looks for the first common subgraph whose size
// matches the user's preference.
template <typename Graph>
struct example_callback {

typedef typename graph_traits<Graph>::vertices_size_type VertexSizeFirst;

example_callback(const Graph& graph1) :
m_graph1(graph1) { }

template <typename CorrespondenceMapFirstToSecond,
typename CorrespondenceMapSecondToFirst>

bool operator()(CorrespondenceMapFirstToSecond correspondence_map_1_to_2,
CorrespondenceMapSecondToFirst correspondence_map_2_to_1,
VertexSizeFirst subgraph_size) {

// Fill membership map for first graph
typedef typename property_map<Graph, vertex_index_t>::type VertexIndexMap;
typedef shared_array_property_map<bool, VertexIndexMap> MembershipMap;

MembershipMap membership_map1(num_vertices(m_graph1),
get(vertex_index, m_graph1));

fill_membership_map<Graph>(m_graph1, correspondence_map_1_to_2, membership_map1);

// Generate filtered graphs using membership map
typedef typename membership_filtered_graph_traits<Graph, MembershipMap>::graph_type
MembershipFilteredGraph;

MembershipFilteredGraph subgraph1 =
make_membership_filtered_graph(m_graph1, membership_map1);

// Print the graph out to the console
std::cout << "Found common subgraph (size " << subgraph_size << ")" << std::endl;
print_graph(subgraph1);
std::cout << std::endl;
// Explore the entire space
return (true);
}

private:
const Graph& m_graph1;
VertexSizeFirst m_max_subgraph_size;
};

int main (int argc, char *argv[]) {

// Using a vecS graph here so that we don't have to mess around with
// a vertex index map; it will be implicit.
typedef adjacency_list<listS, vecS, directedS,
property<vertex_name_t, unsigned int,
property<vertex_index_t, unsigned int> >,
property<edge_name_t, unsigned int> > Graph;

typedef property_map<Graph, vertex_name_t>::type VertexNameMap;

// Test maximum and unique variants on known graphs
Graph graph_simple1, graph_simple2, graph_simple3, graph_simple4;
example_callback<Graph> user_callback(graph_simple1);

VertexNameMap vname_map_simple1 = get(vertex_name, graph_simple1);
VertexNameMap vname_map_simple2 = get(vertex_name, graph_simple2);
VertexNameMap vname_map_simple3 = get(vertex_name, graph_simple3);
VertexNameMap vname_map_simple4 = get(vertex_name, graph_simple4);// Graph that looks like a triangle
put(vname_map_simple1, add_vertex(graph_simple1), 1);
put(vname_map_simple1, add_vertex(graph_simple1), 2);
put(vname_map_simple1, add_vertex(graph_simple1), 3);

add_edge(0, 1, graph_simple1);
add_edge(0, 2, graph_simple1);
add_edge(1, 2, graph_simple1);

std::cout << "First graph:" << std::endl;
print_graph(graph_simple1);
std::cout << std::endl;

// Triangle with an extra vertex
put(vname_map_simple2, add_vertex(graph_simple2), 1);
put(vname_map_simple2, add_vertex(graph_simple2), 2);
put(vname_map_simple2, add_vertex(graph_simple2), 3);
put(vname_map_simple2, add_vertex(graph_simple2), 4);

add_edge(0, 1, graph_simple2);
add_edge(0, 2, graph_simple2);
add_edge(1, 2, graph_simple2);
add_edge(1, 3, graph_simple2);

std::cout << "Second graph:" << std::endl;
print_graph(graph_simple2);
std::cout << std::endl;

// Triangle with an extra vertex
put(vname_map_simple3, add_vertex(graph_simple3), 1);
put(vname_map_simple3, add_vertex(graph_simple3), 2);
put(vname_map_simple3, add_vertex(graph_simple3), 3);
put(vname_map_simple3, add_vertex(graph_simple3), 4);

add_edge(0, 1, graph_simple3);
add_edge(0, 2, graph_simple3);
add_edge(1, 2, graph_simple3);
add_edge(2, 3, graph_simple3);std::cout << "Third graph:" << std::endl;
print_graph(graph_simple3);
std::cout << std::endl;// Maximum, unique subgraphs
std::cout << "mcgregor_common_subgraphs_maximum_unique:" << std::endl;
mcgregor_common_subgraphs_maximum_unique
(graph_simple1, graph_simple2, true, user_callback,
vertices_equivalent(make_property_map_equivalent(vname_map_simple1,
vname_map_simple2)));

return 0;
}#include <boost/config.hpp>
#include <boost/graph/mcgregor_common_subgraphs.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graph_utility.hpp>
#include <boost/graph/lookup_edge.hpp>
#include <boost/graph/subgraph.hpp>
#include <iostream>
#include <vector>

using namespace boost;

typedef subgraph<adjacency_list<vecS, vecS, undirectedS,
property<vertex_color_t, int>, property<edge_index_t, int>>>
Graph;
int main() {
const int N = 6;
enum { A, B, C, D, E, F };
// for conveniently refering to vertices in G0

Graph G0(N);
Graph& G1 = G0.create_subgraph();
Graph& G2 = G0.create_subgraph();
Graph& G3 = G0.create_subgraph();
Graph& G4 = G0.create_subgraph();
Graph& G5 = G0.create_subgraph();
Graph& G6 = G0.create_subgraph();
Graph& G7 = G0.create_subgraph();

enum { A1, B1, C1 }; // for conveniently refering to vertices in G1
enum { A2, B2 };     // for conveniently refering to vertices in G2
enum { A3, B3 };
enum { A4, B4, C4 };
enum { A5, B5 };
enum { A6, B6, C6 };
enum { A7, B7 };

add_vertex(C, G1); // global vertex C becomes local A1 for G1
add_vertex(E, G1); // global vertex E becomes local B1 for G1
add_vertex(F, G1); // global vertex F becomes local C1 for G1

add_vertex(A, G2); // global vertex A becomes local A1 for G2
add_vertex(B, G2); // global vertex B becomes local B1 for G2

add_vertex(B, G3); // ...-||-...
add_vertex(C, G3);

add_vertex(A, G4);
add_vertex(B, G4);
add_vertex(E, G4);

add_vertex(F, G5);
add_vertex(D, G5);

add_vertex(B, G6);
add_vertex(D, G6);
add_vertex(E, G6);

add_vertex(F, G7);
add_vertex(B, G7);
add_vertex(D, G7);

add_edge(A, B, G0);
add_edge(B, C, G0);
add_edge(B, D, G0);
add_edge(E, B, G0);
add_edge(E, F, G0);
add_edge(F, D, G0);

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]