java boost_如何使用get()boost图

回答你的问题

您可以使用顶点描述符而不是迭代器 .

在您的情况下,因为您使用的是捆绑属性,所以可以在图表上使用 operator[descriptor] 简写 .

只要图形不是常量,就可以使用它来更改捆绑的属性 .

代码

实际上我不清楚你的问题中的代码应该说明什么 . 我将简单地回复一段代码,这些代码是从那里构建的,并向您展示了一些可能具有启发性的东西:)

Live On Coliru

#include

#include

#include

#include

#include

static std::mt19937 s_rng { std::random_device{}() };

static std::uniform_int_distribution<> s_coord(-10,10);

static std::uniform_real_distribution s_double(-1.,1.);

static int gen_coord() { return s_coord(s_rng); }

static int gen_gh () { return s_double(s_rng); }

struct Point { // struct point with vertex properties

int x = gen_coord(), y = gen_coord();

int parentx = gen_coord(), parenty = gen_coord();

double g = gen_gh();

double h = gen_gh();

friend std::ostream &operator<

};

// declarations

typedef boost::property<:edge_weight_t double> Weight;

using Graph = boost::adjacency_list<:sets boost::vecs boost::undirecteds point weight>;

using vertex_descriptor = Graph::vertex_descriptor;

int main() {

Graph lattuce;

using namespace boost;

generate_random_graph(lattuce, 10, 20, s_rng);

vertex_descriptor origin = vertex(0, lattuce);

vertex_descriptor end_vertex = vertex(9, lattuce);

typedef boost::property_map::type WeightMap;

WeightMap weights = boost::get(boost::edge_weight_t(), lattuce);

for (Graph::edge_descriptor edge : make_iterator_range(edges(lattuce))) {

std::cout << boost::get(weights, edge) << " " << edge << " ";

vertex_descriptor src = source(edge, lattuce);

vertex_descriptor trg = target(edge, lattuce);

Point& src_bundle = lattuce[src];

Point& trg_bundle = lattuce[trg];

std::cout << "Edge: " << src_bundle << " -- " << trg_bundle << "\n";

src_bundle.g *= 1.1;

src_bundle.h *= -1.1;

//double weight = get(weights, edge);

}

(void) origin; // unused

(void) end_vertex; // unused

}

打印,例如:

0 (7,5) Edge: [-5,-5] -- [-9,-6]

0 (9,2) Edge: [3,2] -- [-3,3]

0 (3,4) Edge: [-4,-10] -- [-10,-5]

0 (1,6) Edge: [3,4] -- [-7,7]

0 (9,4) Edge: [3,2] -- [-10,-5]

0 (3,8) Edge: [-4,-10] -- [-6,0]

0 (1,9) Edge: [3,4] -- [3,2]

0 (5,9) Edge: [-9,-6] -- [3,2]

0 (6,9) Edge: [-7,7] -- [3,2]

0 (0,1) Edge: [-9,8] -- [3,4]

0 (1,4) Edge: [3,4] -- [-10,-5]

0 (0,2) Edge: [-9,8] -- [-3,3]

0 (9,3) Edge: [3,2] -- [-4,-10]

0 (2,4) Edge: [-3,3] -- [-10,-5]

0 (7,6) Edge: [-5,-5] -- [-7,7]

0 (1,2) Edge: [3,4] -- [-3,3]

0 (0,9) Edge: [-9,8] -- [3,2]

0 (4,7) Edge: [-10,-5] -- [-5,-5]

0 (1,5) Edge: [3,4] -- [-9,-6]

0 (0,7) Edge: [-9,8] -- [-5,-5]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值