簡體   English   中英

使用boost :: successive_shortest_path_nonnegative_weights的最小成本最大流量

[英]Min-cost-max-flow with boost::successive_shortest_path_nonnegative_weights

我需要使用計算流量網絡的最小成本最大流量

boost::successive_shortest_path_nonnegative_weights()

BGL中可用的功能(v 1_60_0)。 文檔中所述,

必須增加表示網絡的有向圖G =(V,E)以包括E中每個邊的反向邊。即,輸入圖應為Gin =(V,{EU ET})。 [...] CapacityEdgeMap參數上限必須將E中的每個邊緣映射到正數,並將ET中的每個邊緣映射到0. WeightMap必須將每個邊緣從E映射到非負數,並且每個邊緣從ET到-weight的權重它的反轉邊緣。

我有一個簡單的功能,對於添加到圖表中的每個邊緣,添加一個具有上述指定的容量和重量的反向邊緣:

void add_edge_and_reverse(vertex_desc& source, vertex_desc& target, Edge& edge, flow_network_t& fn, boost::associative_property_map<std::map<edge_desc, edge_desc>>& rev_map)
{
    std::pair<edge_desc, bool> e = boost::add_edge(source, target, edge, fn);
    Edge reverse_edge(-edge.cost, 0);
    std::pair<edge_desc, bool> e_rev = boost::add_edge(target, source, reverse_edge, fn);
    rev_map[e.first] = e_rev.first;
    rev_map[e_rev.first] = e.first;
}

現在,圖形包含反向邊緣,它們具有負權重,這與我正在使用的算法的名稱形成鮮明對比。 因此,當我執行算法時,我收到此錯誤:

ValueError: The graph may not contain an edge with negative weight.

我究竟做錯了什么?

剛遇到同樣的問題。 經過幾分鍾的調試后,我發現了問題。 我使用浮動類型作為權重。 因此,對於數值誤差,修改的邊緣權重(負權重的dijkstra的版本)可能略微低於0。 可能的解決方案可能會重寫“successive_shortest_path_nonnegative_weights.hpp”,以便將小的負值四舍五入

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM