[英]how to write GraphViz subgraphs with boost::write_graphviz
[英]Boost how to write edge's weight in graphviz?
通過 boost,我試圖以 graphviz 格式編寫一個非常大且密集的圖,它是adjacency_matrix
。 圖本身: boost::adjacency_matrix<boost::undirectedS, boost::no_property, boost::property<boost::edge_weight_t, float>, boost::no_property>
。
我在 StackOverflow、Google 中搜索,要么我不理解代碼,要么它是 LABEL 編寫器而不是 WEIGHT 編寫器。
我的 boost 版本是 1.72.0。
如果我犯了錯誤,我為我的英語感到抱歉。 先感謝您。
標簽編寫器也是PropertyWriter
。 PropertyWriters
用於寫入權重(或任何其他邊/頂點屬性)。
但是,我強烈建議使用dynamic_properties
來簡化過程。 這是我在本網站上的20 多個使用示例。
這是我能想到的ajacency_matrix
上最簡單的應用程序:
#include <boost/graph/adjacency_matrix.hpp>
#include <boost/graph/graphviz.hpp>
#include <iostream>
using EP = boost::property<boost::edge_weight_t, float>;
using G = boost::adjacency_matrix<boost::undirectedS, boost::no_property, EP>;
int main() {
G g(5);
add_edge(1, 2, 3.5f, g);
add_edge(2, 3, 4.5f, g);
boost::dynamic_properties dp;
dp.property("node_id", get(boost::vertex_index, g));
dp.property("weight", get(boost::edge_weight, g));
boost::write_graphviz_dp(std::cout, g, dp);
}
印刷:
graph G {
0;
1;
2;
3;
4;
2--1 [weight=3.5];
3--2 [weight=4.5];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.