C++ 如何在无向图中找到两条边的相等性?

C++ 如何在无向图中找到两条边的相等性?,c++,boost,boost-graph,C++,Boost,Boost Graph,使用boost graph library,我得到了这种类型的图形: typedef boost::adjacency_list< boost::vecS, //OutEdgeList boost::vecS, //VertexList boost::undirectedS //Directed > Gr

使用boost graph library,我得到了这种类型的图形:

typedef boost::adjacency_list<
    boost::vecS,                                //OutEdgeList
    boost::vecS,                                //VertexList
    boost::undirectedS                  //Directed
> Graph;
我想检查两个EGDE的“相等性”: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)));
std::pairEdge(boost::numeric_cast(boost::source(e,g)),boost::numeric_cast(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;
    }
模板
bool pairEquality(std::pair&lhs,std::pair&rhs){
//标准方式
如果(lhs==rhs){
返回true;
};
//排列
std::对lhsSwap(lhs.second,lhs.first);
如果(lhsSwap==rhs){
返回true;
}
返回false;
}

3) 通过堆栈的for循环检查等式

我的解决方案肯定不是最优雅的。以下是我所做的: 我将顶点成对放置,完成相等函数,然后检查对相等

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)));
std::pairEdge(boost::numeric_cast(boost::source(e,g)),boost::numeric_cast(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;
    }
模板
bool pairEquality(std::pair&lhs,std::pair&rhs){
//标准方式
如果(lhs==rhs){
返回true;
};
//排列
std::对lhsSwap(lhs.second,lhs.first);
如果(lhsSwap==rhs){
返回true;
}
返回false;
}

3) 通过堆栈的for循环检查相等性

为什么您认为需要它?您只需对OutEdgeList使用
boost::set
,就不会出现重复项。您认为为什么需要它?您只需对OutEdgeList使用
boost::set
,就不会出现重复。