我正在为一些项目使用Boost Graph库,我想在图中找到边重复的次数.例如,
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, Node_Info, Edge_Info > Graph_t;
//node_info and Edge_info are external node and edge properties (structures)
Run Code Online (Sandbox Code Playgroud)
假设我有两个节点,node1和node2,它们之间有一条边(node1,node2).每个边的edge属性包含一个时间戳start,end ..并且图中可能有许多这样的边具有不同的时间戳.例如.
edge1 = (node1, node2) with start = 100, end = 200.
edge2 = (node1, node2) with start = 250, end = 400.
Run Code Online (Sandbox Code Playgroud)
我知道在增强图中,给定两个顶点,我们可以使用以下内容查找图中是否存在边.
std::pair < edge_t, bool > p = boost::edge( node1, node2, myGraph );
if(p.second == 1) cout << "edge exists!" << endl;
else cout << " does not exist " << endl;
Run Code Online (Sandbox Code Playgroud)
但这可能意味着即使多个边缘存在不同的边缘属性,它也只会返回任何一个边缘 - >问题
任何人都可以建议如何在两个给定节点之间获得这样的多边?谢谢!
参考我之前提出的有关 boost::bimaps 和 boost 关联属性映射接口的问题,我想为我的 bimap 使用 Put 和 Get 辅助函数。
\n\n参考此处给出的示例代码,我尝试添加以下内容,但由于断言失败而出现很长的编译错误...这是代码:
\n\n#include <boost/bimap.hpp> \n#include <boost/property_map/property_map.hpp> \n#include <boost/bimap/property_map/set_support.hpp>\n#include <iostream> \n\nusing namespace boost; \n\nint main() \n{\n typedef int vertex_descriptor_t;\n typedef boost::bimaps::bimap< vertex_descriptor_t, size_t > vd_idx_bimap_t;\n typedef boost::associative_property_map<vd_idx_bimap_t::left_map> asso_vd_idx_bimap_t;\n\n // define bimap\n vd_idx_bimap_t my_bimap;\n asso_vd_idx_bimap_t my_asso_bimap(my_bimap.left);\n\n typedef typename vd_idx_bimap_t::value_type value_type; \n my_bimap.insert( value_type( 1, 100 ) );\n // print bimap\n for(auto t = my_bimap.left.begin(); t != my_bimap.left.end(); ++t)\n std::cout << t->first << " " << t->second …Run Code Online (Sandbox Code Playgroud) 我有一个const函数对象,并且对于时间,它返回无效.但可以返回int或double.我正在用c ++ 11样式编写代码,并且只是尝试使用auto作为返回类型.虽然代码编译,但我不确定它是否100%正确.这是代码.
template <typename graph_t>
struct my_func {
public:
my_func() { }
my_func (graph_t& _G) : G(_G) { }
template <typename edge_t>
auto operator()(edge_t edge) -> void const {
//do something with the edge.
} //operator
private:
graph_t& G;
};
//call the functor: (pass graph G as template parameter)
std::for_each(beginEdge, endEdge, my_func<Graph>(G));
Run Code Online (Sandbox Code Playgroud)
此代码完美地编译并在串行模式下工作.现在我尝试使用intel TBB parallel_for_each()并行化上面的for_each.这要求函数对象为const.意味着不应该允许线程修改或更改函数对象的私有变量.
//tbb::parallel_for_each
tbb::paralle_for_each(beginEdge, endEdge, my_func<Graph>(G));
Now, the compiler error comes:
passing const my_func< ... > .. discards qualifiers
Run Code Online (Sandbox Code Playgroud)
所以我不得不将operator()()更改为以下内容:
template <typename edge_t>
void operator()(edge_t edge) …Run Code Online (Sandbox Code Playgroud)