在boost图lib中,如何在不迭代顶点的所有外边缘的情况下获得该顶点的特定外边缘
in boost graph lib, how do I get a specific out-edge of a vertex without iterating over all the out-edges of that vertex?
假设我有一个图,每个边都包含一个字符。从一个顶点,我想得到一个具有特定字符的特定外边缘。由于边缘容器可以设置为一个集或一个哈希集,我认为有一种方法可以做到这一点,而无需迭代顶点的外边缘。我还假设/希望边缘容器是基于边缘包含的类型设置的。
#include <boost/graph/adjacency_list.hpp>
using namespace boost;
typedef boost::adjacency_list<setS, vecS, directedS, std::string, char> MyGraph;
typedef boost::graph_traits<MyGraph>::vertex_descriptor Vertex;
typedef boost::graph_traits<MyGraph>::edge_descriptor Edge;
MyGraph g;
//setup
add_vertex(std::string("xxx"), g);
Vertex currentVertex = g.vertex_set()[0];
Vertex endVertex = add_vertex(std::string("yyy"), g);
add_edge(currentVertex, endVertex, 'i', g);
//later...
//Now I want that edge containing the letter 'i'.
//out_edges returns a pair of edge iterators.
std::pair<iterator, iterator> iterators = out_edges(currentVertex, g); // do not want!
Edge iEdge = how_do_I_get_This?(currentVertex, g); // want!
有没有办法做到这一点,或者迭代外边缘是唯一的选择?
更新:
我想这会给我集装箱的。
std::set<?> edges = g.out_edge_list(currentVertex);
现在我想不通是什么?模板类型为.
更新2:
这似乎是编译的,但我需要一个edge_descriptor,而不是传递给目标的edge_property。
std::set<boost::detail::stored_edge_property<long unsigned int, char> > edges = fGraph.out_edge_list(currentVertex);
更新3:
我想我不需要边缘描述符。得到了我需要的东西:
std::set<boost::detail::stored_edge_property<long unsigned int, char> > edges = fGraph.out_edge_list(currentVertex);
std::_Rb_tree_const_iterator<boost::detail::stored_edge_property<long unsigned int, char> > edge = edges.find(*i);
Vertex target = edge.get_target();
这一切都经过编译,似乎可以工作,但它非常丑陋。
您正在寻找如何使用边缘描述符吗?
Edge i_edge = add_edge(currentVertex, endVertex, 'i', g).first;
CCD_ 1是CCD_ 2边的顶点描述符。
// later...
// Now I want that edge containing the letter 'i'.
char yougotit = g[i_edge];
检查:
assert('i' == yougotit);
查看Coliru直播
如果你真的想搜索,并且可以使用c++1y,你可能会发现这个优雅的:还活着
#include <boost/graph/adjacency_list.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>
#include <iostream>
using namespace boost::adaptors;
using namespace boost;
typedef boost::adjacency_list<setS, vecS, directedS, std::string, char> MyGraph;
typedef boost::graph_traits<MyGraph>::vertex_descriptor Vertex;
typedef boost::graph_traits<MyGraph>::edge_descriptor Edge;
int main() {
MyGraph g;
// setup
add_vertex(std::string("xxx"), g);
Vertex currentVertex = g.vertex_set()[0];
Vertex endVertex = add_vertex(std::string("yyy"), g);
add_edge(currentVertex, endVertex, 'i', g);
for (auto matching : boost::edges(g) | filtered([&g](auto const& e) { return g[e] == 'i'; }))
std::cout << matching << " --> " << g[matching] << "n";
}
输出:
(0,1) --> i
相关文章:
- 如何循环打印顶点结构
- D3D11-将混合权重和索引传递到顶点着色器
- 从返回的顶点缓冲区查询顶点结构
- Vulkan 中的动态顶点缓冲区格式设置
- 在顶点着色器中使用 OpenGl 的未声明标识符,我在顶点着色器中绘制三角形时遇到问题
- 如何获取边缘窗口句柄 (HWND)?
- 如何将一半传递给顶点着色器?
- 提升如何在图形可视化中写入边缘的权重?
- 在 c++ 中使用 Tensorflow Lite 在边缘 TPU 上运行"mobilenet_ssd_v2_coco_quant_postprocess_edgetpu.tflite"时出现问题
- 分数背包边缘箱
- 在 DirectX 11 中从 GPU 读回顶点缓冲区(并获取顶点)
- QT QOpenGLWidget:如何在不使用数据块复制的情况下修改VBO中的单个顶点值?
- 使用 OpenGL 4.5 更改所选顶点的颜色
- Boost:列出GraphMl中指定的顶点和边缘属性
- Boost:如何移除顶点的所有外边缘
- 将边缘节点添加到没有边缘的顶点时出现 Seg 错误
- 如何访问图中顶点边缘的数据
- 如何使用boost::graph算法与listS,setS作为顶点/边缘容器
- 在boost图lib中,如何在不迭代顶点的所有外边缘的情况下获得该顶点的特定外边缘
- 在边缘上迭代并使用OpenMesh获得顶点