BGL 添加具有多个属性的边
BGL Adding an edge with multiple properties
我想让所有边缘都具有属性、重量和容量。 我发现BGL已经定义了这两个。 所以我为图形定义了边和顶点属性
typedef property<vertex_name_t, string> VertexProperty;
typedef property<edge_weight_t, int, property<edge_capacity_t, int> > EdgeProperty;
typedef adjacency_list<listS,vecS, undirectedS, VertexProperty, EdgeProperty > Graph;
这是我尝试将边缘添加到图形中的地方:
172: EdgeProperty prop = (weight, capacity);
173: add_edge(vertex1,vertex2, prop, g);
如果我只有 1 个属性,我知道它将是 prop = 5;但是,对于两个,我对格式感到困惑。
这是我收到的错误:
graph.cc: In function ‘void con_graph()’:
graph.cc:172: warning: left-hand operand of comma has no effect
如果你看一下boost::p roperty的实现,你会发现属性值不能以这种方式初始化。即便如此,您(weight, capacity)
的语法无论如何都是无效的,因此,如果可以像这样初始化属性,它将编写EdgeProperty prop = EdgeProperty(weight, capacity);
或只是EdgeProperty prop(weight, capacity);
。但是,同样,这是行不通的。从技术上讲,这是您需要初始化属性值的方式:
EdgeProperty prop = EdgeProperty(weight, property<edge_capacity_t, int>(capacity));
但随着属性数量的增加,这有点丑陋。因此,默认构造 edge-属性,然后手动设置每个单独的属性会更干净:
EdgeProperty prop;
get_property_value(prop, edge_weight_t) = weight;
get_property_value(prop, edge_capacity_t) = capacity;
当然,更好的选择是使用捆绑属性而不是旧的 boost::p roperty 链。
正确的形式是:
EdgeProperty prop;
get_property_value(prop, edge_weight) = weight;
get_property_value(prop, edge_capacity) = capacity;
相关文章:
- 如何在Qt C++中向自定义控件添加属性?
- OpenGL - 添加第二个着色器属性会导致空白屏幕
- 递归添加子树以提升属性树
- 将具有 xml 属性的子树添加到提升属性树
- 我创建了deque<CObject*>并添加了不同类型的元素。如何更改此元素的属性?
- 如何向类添加属性
- 如何将按钮添加到节点的属性编辑器面板,该面板调用该节点内的方法?
- 如何在Boost Graph库中的Grid_graph的边缘添加自定义属性
- 如何使用属性包添加边缘以提升::adjacency_matrix
- 如何在虚幻引擎4中将属性添加到变换类别
- 为什么Clang自动将属性添加到我的功能中
- cmake 如何在项目的 vcxproj 属性组中添加自定义条目?
- Clang在发出LLVM IR时向所有函数添加noinline属性
- 将属性添加到QT C 中的Qpushbutton
- 为什么对象属性的值在 c++ 中将其指针添加到映射后返回零
- 向向下转换结构添加属性值会导致分段错误
- 如何删除自动添加的 IPropertyStorage LOCALE 属性
- QTreeWidgterItem-隐藏值或添加属性
- WritePrivateProfileString未将属性添加到末尾
- 将自定义属性添加到Boost图库中的网格顶点