簡體   English   中英

使用graphviz繪制自定義BGL圖

[英]drawing custom BGL graph with graphviz

我是Boost圖形庫的新手,我嘗試使用graphviz繪制圖形。

#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graphviz.hpp>
#include <boost/utility.hpp>                // for boost::tie
#include <iostream>
#include <utility>                          // for std::pair

using namespace boost;
using namespace std;

class V {};
class C {};

void draw_test(){
    typedef boost::adjacency_list<boost::listS, boost::listS, boost::bidirectionalS, V, C > MyGraph;
        typedef boost::graph_traits<MyGraph>::vertex_descriptor vertex_descriptor;
    MyGraph g;
    vertex_descriptor a = add_vertex(V(), g);
    vertex_descriptor b = add_vertex(V(), g);
    add_edge(a, b, g);
    write_graphviz(std::cout, g);
}

int main() {
    draw_test();

    return 0;
}

但是我收到以下錯誤:

http://pastebin.com/KmTyyUHh

我將非常感謝您的幫助

你可以找到在這個問題(完全相同的問題12 )。 問題是write_graphviz需要一個頂點索引屬性映射(就像許多其他Boost.Graph函數一樣)。 默認情況下,以listS作為其VertexList的adjacency_list沒有一個。 除非您確實需要listS否則只需在第二個模板參數中使用vecS 在第一個鏈接的答案中可以找到的另一種選擇是創建並初始化外部頂點索引屬性映射,然后使用write_graphviz的重載允許您顯式傳遞它。 當您需要在圖形中使用listSsetS時,這對於多種算法非常有用。

暫無
暫無

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

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