2015-12-03 94 views
0

在我的项目中,我使用一个存储所有边的文件;另一个存储边缘概率。我想使用Boost图库和unordered_map作为概率。我有以下代码。在没有图形的情况下创建边描述符

typedef boost::adjacency_list <boost::vecS, boost::vecS, boost::bidirectionalS> DiGraph; 
typedef boost::graph_traits<SubGraph>::vertex_descriptor vertex_t; 
typedef boost::graph_traits<SubGraph>::edge_descriptor edge_t; 

unordered_map<edge_t, double> P; 

ifstream infile(prob_filename); 
double p; 
int u, v; 
while (infile >> u >> v >> p) { 
    P[make_pair(u, v)] = p; 
} 

不过,我并不需要做一对作为重点,而是一个边描述符edge_t。我如何创建给定两个值的边描述符uv

回答

0

From boost graph concepts

DirectedGraph digraph(V); 
    { 
    boost::graph_traits<DirectedGraph>::vertex_descriptor u, v; 
    u = vertex(0, digraph); // read these instead 0,1 from from your file 
    v = vertex(1, digraph); 
    // populate graph 
    add_edge(digraph, u, v, Weight(1.2)); // read weight (prob) instead from from your file 

    boost::graph_traits<DirectedGraph>::edge_descriptor e; 
    bool found; 
    boost::tie(e, found) = edge(u, v, digraph); 

    //use property map 
    property_map<DirectedGraph, edge_weight_t>::type 
     weight = get(edge_weight, digraph); 

    cout << "weight[(u,v)] = " << get(weight, e) << endl; 

    } 
相关问题