Если у меня есть n элементов, определенных с классом CElement, как можно создать вершины из этих элементов с помощью boost graph - и соединить их также? Я видел ускоренный реквизит, но я просто не могу понять этого.
Добавление пользовательских вершин в графу форсирования
Ответ 1
Я не понимаю, что вы хотите сделать точно. Вы хотите связать некоторые данные с вершинами? Затем используйте связанные свойства.
//Define a class that has the data you want to associate to every vertex and edge
struct Vertex{ int foo;}
struct Edge{std::string blah;}
//Define the graph using those classes
typedef boost::adjacency_list<boost::listS, boost::vecS, boost::directedS, Vertex, Edge > Graph;
//Some typedefs for simplicity
typedef boost::graph_traits<Graph>::vertex_descriptor vertex_t;
typedef boost::graph_traits<Graph>::edge_descriptor edge_t;
//Instanciate a graph
Graph g;
// Create two vertices in that graph
vertex_t u = boost::add_vertex(g);
vertex_t v = boost::add_vertex(g);
// Create an edge conecting those two vertices
edge_t e; bool b;
boost::tie(e,b) = boost::add_edge(u,v,g);
// Set the properties of a vertex and the edge
g[u].foo = 42;
g[e].blah = "Hello world";
Другие способы установить свойства, но там есть пример для загрузки.
Надеюсь, я не понял этого вопроса.