无向图上顶点和边的变化
changes in vertices and edges on undirected graph
Im using visual studio c++, boost.
假设我有无向图。 每 t 秒我需要检查它是否发生了变化(顶点\边删除\添加)。
时间复杂度非常重要。
这是构建图形的示例:
typedef adjacency_matrix<undirectedS> UGraph;
UGraph G(9);
add_edge(1, 2, G);
add_edge(2, 5, G);
add_edge(5, 1, G);
add_edge(3, 6, G);
add_edge(3, 4, G);
add_edge(7, 8, G);
因为我使用adjacency_matrix
,add_edge()
、remove_edge()
、add_vertex()
和remove_vertex()
的时间复杂度是O(1)。
我想使用 add_edge()
通过其返回值来检查该边缘是否已经存在:
retVal = add_edge(1, 2, G);
if(already exist)
//do something
else
//do something else
retVal = add_vertex(1,G);
if(already exist)
//do something
else
//do something else
但据我了解,如果我将边缘添加到现有边缘(在无向图中),它将并行添加到现有边缘。
那么,有没有一种胖方法(我的方式或其他方式)来检查两个无向图之间的变化(顶点和边)?
谢谢。
> ok.k
经过一些阅读,这是我发现的:
检查边缘是否存在-
graph_traits<UGraph>::edge_descriptor e; //UGraph is the undirected graph
bool found = false;
boost::tie(e, found) = edge(1, 2, G); //found = true
boost::tie(e, found) = edge(1, 3, G); //found = false
boost::tie(e, found) = edge(2, 1, G); //found = true
另一种方式:
found = edge(1, 2, G).second; //found = true
found = edge(1, 3, G).second; //found = false
检查顶点是否存在-
我没有找到任何内置函数,但可以在adjacency_matrix
上找到特定的顶点
相关文章:
- 如何循环打印顶点结构
- C++取消引用指针.为什么会发生变化
- 为什么在读取文件大小时文件IO速度会发生变化
- 为什么cudaMemGetInfo报告设备内存总量的变化
- D3D11-将混合权重和索引传递到顶点着色器
- 从返回的顶点缓冲区查询顶点结构
- Vulkan 中的动态顶点缓冲区格式设置
- 在顶点着色器中使用 OpenGl 的未声明标识符,我在顶点着色器中绘制三角形时遇到问题
- 如何避免LED在循环状态变化中闪烁?
- 当 I2C 值在C++中发生变化时收到通知
- Gtkmm 会不断检查 Gtk::日历上的所选日期是否发生变化
- 如何将一半传递给顶点着色器?
- 当我调用对象的方法时,对象的成员会发生变化
- 为什么向量内部的指针在从函数返回时会发生变化?
- 在 DirectX 11 中从 GPU 读回顶点缓冲区(并获取顶点)
- QT QOpenGLWidget:如何在不使用数据块复制的情况下修改VBO中的单个顶点值?
- 使用 OpenGL 4.5 更改所选顶点的颜色
- 如何在 c++ 中循环中使用频率变化的声音?
- 无向图上顶点和边的变化
- (DirectX 11)动态顶点/索引缓冲区实现恒定的场景内容变化