2012-06-30 38 views
5

我希望所有边都具有属性,权重和容量。我发现BGL已经定义了这些。所以我定义图形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个属性我知道这将是道具= 5;然而,有两个我对格式化感到困惑。

这里是我收到的错误:

graph.cc: In function ‘void con_graph()’: 
graph.cc:172: warning: left-hand operand of comma has no effect 

回答

5

如果你看看boost::property实施,你会看到一个属性值不能这样初始化。即使如此,您拥有(weight, capacity)的语法也是无效的,因此,如果可以初始化该属性,它将被编写为EdgeProperty prop = EdgeProperty(weight, capacity);EdgeProperty prop(weight, capacity);。但是,再一次,这是行不通的。从技术上讲,这是你需要初始化属性值的方法:

EdgeProperty prop = EdgeProperty(weight, property<edge_capacity_t, int>(capacity)); 

但是,这是一种丑陋的性能增加的数量。因此,这将是清洁剂缺省方式构造边缘属性,然后手动设置每个单独属性:

EdgeProperty prop; 
get_property_value(prop, edge_weight_t) = weight; 
get_property_value(prop, edge_capacity_t) = capacity; 

当然,更好的办法是使用的,而不是上了年纪的boost ::财产链绑定属性。

+0

你能举一个例子为最新升压图形库的捆绑性? –

0

正确的形式是:

EdgeProperty prop; 
get_property_value(prop, edge_weight) = weight; 
get_property_value(prop, edge_capacity) = capacity;