如何在无向图中找到2个边缘的平等

How to find equality of 2 edges in an undirected Graph?

本文关键字:2个 边缘      更新时间:2023-10-16

使用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)通过堆栈的循环检查平等