- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
您好,以下代码中的任何一处,make_edge_writer
函数无法在 gcc4.9 中推断类型。我的代码基于此处找到的以下答案 How to print a graph in graphviz with multiple properties displayed .
#include <boost/graph/graphviz.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <string>
#include <tuple>
#include <iostream>
#include <iomanip>
#include <map>
#include <random>
#include <cmath>
#include <fstream>
#include <utility>
#include <boost/graph/iteration_macros.hpp>
#include <boost/graph/graph_utility.hpp>
using namespace boost;
struct vert{
std::string name;
};
struct edge{
int capacity;
int weight;
};
template <class WeightMap,class CapacityMap>
class edge_writer
{
public:
edge_writer(WeightMap w, CapacityMap c) : wm(w),cm(c) {}
template <class Edge>
void operator()(ostream &out, const Edge& e) const {
out << "[label=\"" << wm[e] << "\", taillabel=\"" << cm[e] << "\"]";
}
private:
WeightMap wm;
CapacityMap cm;
};
template <class WeightMap, class CapacityMap>
inline edge_writer<WeightMap,CapacityMap>
make_edge_writer(WeightMap w,CapacityMap c)
{
return edge_writer<WeightMap,CapacityMap>(w,c);
}
int main(int a,char **b)
{
typedef adjacency_list<listS, vecS, undirectedS, vert, edge> Graph;
Graph g;
vector<int,int> ele;
edge prop;
prop.weight = 5;
prop.capacity = 4;
add_edge(ele.first,ele.second, prop, g);
std::random_device rd;
// Choose a random mean between 1 and 100
std::default_random_engine e1(rd());
std::uniform_int_distribution<int> uniform_dist(1, 100);
for (int a=0;a<20;++a){
edge prop1;
prop1.weight = uniform_dist(e1);
prop1.capacity = uniform_dist(e1);
add_edge(ele.first,ele.second, prop1, g);
}
std::ofstream dot("graph.dot");
write_graphviz(
dot,
g,
boost::make_label_writer(
boost::get(&vert::name, g)
),
make_edge_writer(
boost::get(&edge::weight,g),
boost::get(&edge::capacity,g)
)
);
}
最佳答案
您遇到了评论中提到的语法问题,并且将所有具有相同未初始化源和目标的边从 ele
插入(应该是 std::pair<int, int>
?)。
如果您想生成随机图,可以使用 boost::generate_random_graph
:
int main() {
typedef b::adjacency_list<b::listS, b::vecS, b::undirectedS, vert, edge> Graph;
Graph g;
b::generate_random_graph(g, 10 /*100*/, 5 /*20*/, rng);
std::ofstream dot("graph.dot");
write_graphviz(dot, g, boost::make_label_writer(boost::get(&vert::name, g)),
make_edge_writer(boost::get(&edge::weight, g), boost::get(&edge::capacity, g)));
}
为简单起见,我使用类内初始化程序来生成随机权重/容量:
struct edge {
int capacity = uniform_dist(rng);
int weight = uniform_dist(rng);
};
例如
或
关于c++ - boost bgl write_graphviz VertexPropertyWriter 和 EdgePropertyWriter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28522967/
我想使用并行 MST 算法 dense_boruvka_minimum_spanning_tree从 boost 。 该算法接口(interface)的一个必需参数是“必须是顶点列表图和分布式边列表图
这个问题是关于Boost Graph Library的。 假设我的图形类型定义如下: using Graph = boost::adjacency_list; 现在,如果我理解正确的话,可以将新的St
我似乎无法弄清楚如何让 BGL 的推送重新标记最大流量算法与捆绑属性一起使用。 像这样设置图表: struct VertexProperties{ }; struct EdgeProperties{
我想用子图实现加权无向图。这是我对该图的初始化代码: #include #include typedef boost::property EdgeWeightProperty; typedef b
下面是一些使用 bgl 创建图形并遍历顶点的示例代码。我想以随机顺序进行此迭代 - 换句话说:循环应该操纵每个顶点,但是对于主函数的每次调用,顶点的顺序应该是随机的。我怎样才能做到这一点? 我用 st
我正在尝试通过编写自定义 DFS 访问器(class TarjanVisitor : public default_dfs_visitor)在 BGL 中实现桥接检测算法 (tarjan),并且我正在
我开始使用 BGL 来完成一些与图形相关的任务。我有很多边,每条边都有几个属性,其中之一就是它的权重。 (所有属性都是 float 和整数)。由于我以前从未使用过 BGL(和/或类似的 CPP 库),
我想让所有边都具有属性、重量和容量。我发现 BGL 已经定义了这些。所以我为图定义了 Edge 和 Vertex 属性 typedef property VertexProperty; typed
我的要求是有一个图形结构,其中每个顶点都由 boost::uuids::uuid 唯一标识。 .所有顶点都有一个颜色属性,相似类别的顶点将根据该颜色属性进行分组。我不是在静态 map 上工作,顶点和边
我正在努力从我的图中删除所有没有连接边的节点(使用定义的模式 here )。到目前为止,我的 (MWE) 代码如下: //g++ -O3 question.cpp -o question.exe #i
我是 BGL( boost 图形库)的新手。我正在学习breadth_first_search 界面,它看起来很方便。但是,在我的应用程序中,当满足其他一些终止条件(例如搜索空间节点数满足最大值)时,
借鉴this回复,我试过如下实现介数中心性: typedef struct vpr_ { int id; } VProp; typedef boost::adjacency_l
我尝试使用boost的transitive_reduction,但是我不知道怎么用。 我有一个图表定义为: typedef boost::adjacency_list Graph; typedef G
我想知道是否有一种方法可以在不使用 lambda 函数的情况下获得 boost 图边缘的排序 vector 。 即我目前正在这样排序: std::vector edgs = ...; std::sor
在 bgl iteration_makros.hpp , 它说 Use the _T versions when the graph type is a template parameter or d
所以我目前正在研究一个单词阶梯问题的项目,我已经构建了用于在其中存储所有字典单词的图形并在其中添加了边,我使用 boost 图形库完成了此操作。 但令我困惑的是 breadth_first_searc
我想在检查边缘时更改边缘权重,但它告诉 error: assignment of member ‘EdgeProperty::weight’ in read-only object g[e].weig
Example code来自 BGL: breadth_first_search(g, vertex(s, g), color_map(get(&VertexProps::color, g)).vis
我正在阅读某人的代码。这是来自 boost 图形库的函数。这是原始函数定义。 void dijkstra_shortest_paths (const Graph& g, t
我希望多线程使用BGL的dijkstra_shortest_paths和astar_search函数,然后读取结果顶点和边的属性映射。 我想知道我是否应该使用互斥锁来确保线程安全。 所以这是我的问题:
我是一名优秀的程序员,十分优秀!