【发布时间】:2018-01-03 14:16:09
【问题描述】:
我有一个提升图(带有捆绑属性)。我想查找图中是否已经存在具有特定值的顶点。有人可以帮我弄这个吗?在这里,我展示了我现有代码的 MWE:
#include <iostream>
#include <string>
#include <vector>
#include <boost/graph/adjacency_list.hpp>
struct mytuple
{
int e1;
int e2;
int s;
bool operator==(const mytuple& a) const
{
return ((e1 == a.e1) && (e2 == a.e2) && (s == a.s));
}
};
struct MyVertex {
std::string comments;
int field1;
mytuple value;
MyVertex(std::string comments = std::string()) : comments(comments) {}
};
struct MyEdge {
std::string label;
MyEdge(std::string label = std::string()) : label(label) {}
};
// Define the graph with the vertex as a mytuple and the vertices container as a vector
using MyTree = boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, MyVertex, MyEdge>;
using Vertex = boost::graph_traits<MyTree>::vertex_descriptor; // Define Vertex
using VertexItr = boost::graph_traits<MyTree>::vertex_iterator; // Define Vertex iterator
using Edge = std::pair<boost::graph_traits<MyTree>::edge_descriptor, bool>; // Define Edge
using EdgeItr = boost::graph_traits<MyTree>::edge_iterator; // Define Edge Iterator
int main()
{
MyTree mytree;
Vertex v1 = boost::add_vertex(mytree);
mytree[v1].value = {1, 1, 1};
Vertex v2 = boost::add_vertex(mytree);
mytree[v2].value = {2, 2, 2};
Vertex v3 = boost::add_vertex(mytree);
mytree[v3].value = {3, 3, 3};
// Perhaps add some edges
std::cout << "I want to find if my graph has a vertex containing the value {1, 1, 1}";
// mytree.findvertex(with value {1, 1, 1})
}
【问题讨论】: