得到提振图的副本反转 [英] Get a copy of a boost graph that is reversed

查看:159
本文介绍了得到提振图的副本反转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个

typedef boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, VertexInfo, EdgeInfo > Graph;

这是我想要的所有边缘逆转的副本。我要一个副本,而不是一个视图,因为我想改变这个图的边权重,而无需修改原始数据结构。

That I want a copy of with all edges reversed. I want a copy and not a view since I want to change the edge weights of this graph without modifying the original data structure.

升压:: reverse_graph给出的图(具有不同的类型)

boost::reverse_graph gives a view (with a different type)

推荐答案

您可以使用 make_reverse_graph

例如。输入

Graph read() {
    Graph g;

    using namespace boost;
    dynamic_properties dp;
    dp.property("node_id", get(&VertexInfo::label, g));
    read_graphviz("digraph { a -> b; a -> c; b -> d; b -> e; e -> f; e -> c; }", g, dp);

    return g;
}

图:

反转:

int main() {
    using namespace boost;

    auto g = read();
    auto r = make_reverse_graph(g);

    write_graphviz(std::cout, r, make_label_writer(get(&VertexInfo::label, r)));
}

<大骨节病> 住在Coliru

#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graphviz.hpp>
#include <boost/graph/reverse_graph.hpp>
#include <libs/graph/src/read_graphviz_new.cpp>

struct VertexInfo {
    std::string label;
};

struct EdgeInfo {
};

typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, VertexInfo, EdgeInfo> Graph;

Graph read() {
    Graph g;

    using namespace boost;
    dynamic_properties dp;
    dp.property("node_id", get(&VertexInfo::label, g));
    read_graphviz("digraph { a -> b; a -> c; b -> d; b -> e; e -> f; e -> c; }", g, dp);

    return g;
}

int main() {
    using namespace boost;

    auto g = read();
    auto r = make_reverse_graph(g);

    write_graphviz(std::cout, r, make_label_writer(get(&VertexInfo::label, r)));
}

这篇关于得到提振图的副本反转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆