我有一个提升图定义为
typedef boost::adjacency_list<boost::setS, boost::listS,
boost::undirectedS, CoordNode, CoordSegment> BGraph;
typedef boost::graph_traits<BGraph>::vertex_descriptor VertexDesc;
BGraph _graph;
Run Code Online (Sandbox Code Playgroud)
我想知道同一张图的连通分量
int num = boost::connected_components(_graph, propMap);
Run Code Online (Sandbox Code Playgroud)
我已经尝试创建所需的可写属性映射 (propMap)
typedef std::map<VertexDesc, size_t> IndexMap;
IndexMap mapIndex;
boost::associative_property_map<IndexMap> propMap(mapIndex);
VertexIterator di, dj;
boost::tie(di, dj) = boost::vertices(_graph);
for(di; di != dj; ++di){
boost::put(propMap, (*di), 0);
}
Run Code Online (Sandbox Code Playgroud)
但这不起作用;我收到编译错误。
如果顶点容器是 vecS,那就更容易了,因为一个简单的数组或向量就足够了。但是如果我有 listS 作为顶点容器,我应该传递给这个函数什么?
如何创建必要的可写属性映射?有人可以举个例子吗?
我正在阅读boost :: graph文档以供将来使用.我对A*算法特别感兴趣.
看看boost :: graph :: astar_search用法示例,似乎停止算法的方法是抛出异常并将其捕获到算法之外.
因为我不想抛出任何异常,导致C++中的异常处理非常复杂且效率不高,我想知道boost :: graph是否提出了另一种方法来在达到目标时停止算法.
有没有人有一个不使用任何例外的替代例子?
我正在尝试使用Boost Ggraph库.在我的程序的每次迭代中,我有一组点,例如{1,2,3,4,5,6,7,8,9,10}在迭代1和{1,2,3,... ,1000}迭代二,......
对于每个点,我知道它连接到哪些其他点,例如在迭代时,每个点连接如下:
c(1)={3,5,7,8}
c(2)={}
c(3)={1,4,10}
c(4)={3}
c(5)={1,9}
c(6)={}
c(7)={1,8}
c(8)={1,7}
c(9)={5}
c(10)={3}
Run Code Online (Sandbox Code Playgroud)
每个点都有一个属性,例如p(1)= 10,p(2)= 100,p(3)= 20,...
如何在Boost中创建无向图并迭代连接的组件?
我不知道如何从 adjacency_list 图中设置和获取 graph_name 作为属性。我能够放置和获取顶点和边缘属性。
任何帮助,将不胜感激。
问题
帖子底部的代码打印出来:
Vertices in g = [ 0 1 2 3 4 ]
Vertices in g' = [ 0 1 ]
Run Code Online (Sandbox Code Playgroud)
我预计输出为:
Vertices in g = [ 0 1 2 3 4 ]
Vertices in g' = [ 3 4 ]
Run Code Online (Sandbox Code Playgroud)
这是 boost::subgraph 中的错误还是我对库的理解?
有问题的代码
#include <sstream>
#include <iostream>
#include <boost/graph/subgraph.hpp>
#include <boost/graph/adjacency_list.hpp>
using namespace std;
using namespace boost;
// Underlying graph representation and implementation
typedef adjacency_list_traits<vecS, vecS, directedS> Traits;
// Graph representation
typedef subgraph< adjacency_list<vecS, vecS, directedS,
property<vertex_color_t, int>, …Run Code Online (Sandbox Code Playgroud) 我无法理解这个功能的文档,我已经多次看到以下内容
tie (ei,ei_end) = out_edges(*(vi+a),g);
**g**<-graph
**vi**<-beginning vertex of graph
**a**<- a node
**ei and ei_end** <- edge iterators
Run Code Online (Sandbox Code Playgroud)
函数返回什么,它做什么,什么时候可以使用?
我可以找到节点的所有边缘吗?
我正在尝试使用 Boost.Graph 库来运行 Goldberg 的 Max-Flow 算法。Boost.Graph 称之为push_relabel_max_flow。
但是,我很难理解库及其类型系统。我在上面链接的文档提供了示例代码。但在该示例中,图形是从文件中读取的。我想在运行时生成图形。这是我到目前为止的代码(主要是从示例中复制的):
typedef boost::adjacency_list_traits<boost::vecS, boost::vecS, boost::directedS> Traits;
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS,
boost::property<boost::vertex_name_t, std::string>,
boost::property<boost::edge_capacity_t, long,
boost::property<boost::edge_residual_capacity_t, long,
boost::property<boost::edge_reverse_t, Traits::edge_descriptor>>>> DirectedGraph;
DirectedGraph g;
Traits::vertex_descriptor s, t;
s = boost::add_vertex(g);
t = boost::add_vertex(g);
boost::add_vertex(g);
boost::add_vertex(g);
Run Code Online (Sandbox Code Playgroud)
在我向图中添加 4 个顶点后,我应该“连接”它们,即制作具有容量、剩余容量和反向值的边。此任务的功能是,boost::add_edge()但我不知道如何传递我的参数。示例代码没有显示,因为正如我所说,数据是从文件中读取的,然后直接解析为图形。也许有 Boost.Graph 库经验的人可以告诉我怎么做。
我想加载一个tiff图像(带有浮点值的像素的GEOTIFF),如boost C++中的图形(我是C++中的新手).我的目标是使用从源A到目标B的双向Dijkstra来获得更高的性能.
Boost:GIL load tiif images:
std::string filename( "raster_clip.tif" );
rgb8_image_t img;
read_image( filename, img, tiff_tag() );
Run Code Online (Sandbox Code Playgroud)
但是如何转换为Boost图?我正在阅读文档并查找示例,但我还没有实现它.
我发现的类似问题和例子:
http://www.geeksforgeeks.org/shortest-path-for-directed-acyclic-graphs/
我目前正在使用scikit-image库并使用skimage.graph.route_through_array函数在python中加载带数组的图形.我用GDAL通过在该示例@ustroetz的建议以获得由负载图像的阵列这里:
raster = gdal.Open("raster.tiff")
band = raster.GetRasterBand(1)
array = band.ReadAsArray()
Run Code Online (Sandbox Code Playgroud)
我目前正在尝试在现有的c ++项目中使用提升图库。我想将自定义类的对象存储在增强图中。下面是一个带有自定义类定义的小示例,该类包含两个成员(一个字符串和一个int)及其对应的getter方法。
我有几个问题:
boost::make_label_writer但我不确定我的示例是否可以用于此(我使用的是自定义类和共享指针)。boost::setS但这会导致编译器出现非常长的错误消息...假设我创建了一个自定义类的新对象:如何检查它是否已经存储在图形中?
#include <iostream>
#include <boost/graph/graphviz.hpp>
class my_custom_class {
public:
my_custom_class(const std::string &my_string,
int my_int) : my_string(my_string),
my_int(my_int) {}
virtual ~my_custom_class() {
}
std::string get_my_string() const {
return my_string;
}
int get_int() const {
return my_int;
}
bool operator==(const my_custom_class &rhs) const {
return my_string == rhs.my_string &&
my_int == rhs.my_int;
}
bool operator!=(const my_custom_class &rhs) const {
return !(rhs == *this);
}
private:
std::string my_string;
int my_int;
};
namespace …Run Code Online (Sandbox Code Playgroud)我想从具有边权重的顶点创建一个最小生成树,并以深度优先的顺序遍历图形。我可以构建图形和最小生成树,但我无法编写自定义访问者。
#include <iostream>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/kruskal_min_spanning_tree.hpp>
#include <boost/graph/depth_first_search.hpp>
#include <boost/graph/graph_traits.hpp>
#include <vector>
#include <string>
typedef boost::property<boost::edge_weight_t, double> EdgeWeightProperty;
typedef boost::adjacency_list <
boost::listS,
boost::vecS,
boost::undirectedS,
boost::no_property,
EdgeWeightProperty> MyGraph;
typedef MyGraph::edge_descriptor Edge;
class MyVisitor : public boost::default_dfs_visitor
{
public:
void tree_edge(Edge e, const MyGraph& g) const {
}
};
void mst() {
MyGraph g;
boost::add_edge(0, 1, 0.7, g);
boost::add_edge(0, 2, 0.1, g);
boost::add_edge(1, 2, 0.3, g);
boost::add_edge(1, 0, 0.7, g);
boost::add_edge(1, 3, 0.8, g);
boost::add_edge(1, 4, 0.2, g);
boost::add_edge(2, 1, 0.3, …Run Code Online (Sandbox Code Playgroud)