如何在无向图中找到2个边缘的平等
How to find equality of 2 edges in an undirected Graph?
使用boost图库,我有这种类型的图形:
typedef boost::adjacency_list<
boost::vecS, //OutEdgeList
boost::vecS, //VertexList
boost::undirectedS //Directed
> Graph;
并添加几个2边:
boost::add_edge(0, 1, g);
boost::add_edge(0, 2, g);
boost::add_edge(1, 0, g);
boost::add_edge(2, 4, g);
boost::add_edge(4, 3, g);
boost::add_edge(3, 1, g);
我想检查2 egdes的"平等":0-1和1-0。
我需要实现的起点。
谢谢
我的解决方案当然不是最优雅的。这是我所做的:我将顶点置于成对,完成平等函数,然后检查对均等。
1)将顶点与:
配对std::pair<unsigned int, unsigned int> pairEdge( boost::numeric_cast<unsigned int>(boost::source(e, g)), boost::numeric_cast<unsigned int>(boost::target(e, g)));
2)完成平等函数
template <typename T1, typename T2>
bool pairEquality(std::pair<T1, T2> &lhs, std::pair<T1, T2> &rhs) {
//standard way
if (lhs == rhs) {
return true;
};
//permutation
std::pair<T1, T2> lhsSwap(lhs.second, lhs.first);
if (lhsSwap == rhs) {
return true;
}
return false;
}
3)通过堆栈的循环检查平等
相关文章:
- 比较并显示使用最小值(a,b)和最大值(a、b)升序排列的4个数字
- 删除一个线程上有数百万个字符串的大型哈希映射会影响另一个线程的性能
- 如何在C++中从两个单独的for循环中添加两个数组
- 为什么两个不同的未命名名称空间可以共存于一个cpp文件中
- 模板-模板参数推导:三个不同的编译器三种不同的行为
- 处理多个异常集合的C++方法
- 什么时候在C++中返回常量引用是个好主意
- 给定n个元素的m个集合.在C++中找到出现在最大集合数中的元素
- 当在同一名称空间中有两个具有相同签名的函数时,会发生什么
- 尝试通过多个向量访问变量时,向量下标超出范围
- Ardunio UNO解决了多个重叠的定时器循环
- 如何返回一个类的两个对象相加的结果
- 如何使用OpenCV将RBG图像转换为HSV,并将H、S和V值保存为C++中的3个独立图像
- 是否可以通过C++扩展强制多个python进程共享同一内存
- 检查两个矩形是否重叠或边缘是否接触
- 修改贝尔曼-福特以支持第二个边缘重量
- 如何在无向图中找到2个边缘的平等
- 如何在图中找到3个边缘的负加权周期
- 是否有删除半个双向链表边缘的名称
- 如何确定两个 3D 边缘是否相同