生成具有负边权重且无负循环的随机图
Generating random graphs with negative edge weight, and without negative cycle
负循环中边权重的总和为负。有了这个概念,有没有办法生成具有随机正边和负边权重且没有负循环的图形?此类图形对于测试bellman_ford_shortest_paths
方法很有用。
注意:在这篇文章中,他们使用库生成没有这些条件boost
图形。
我建议使用 generate_random_graph
来...生成随机图并修复任何负循环作为后处理步骤。
例如:
住在科里鲁
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/random.hpp>
#include <random>
#include <iostream>
using Graph = boost::adjacency_list<
boost::vecS,
boost::vecS,
boost::directedS,
boost::no_property,
boost::property<boost::edge_weight_t, double> >;
int main()
{
std::mt19937 prng;
Graph g;
generate_random_graph(g, 100, 200, prng);
// find cycles with negative sum and just add a large enough value to one
// of the participating edges to make it postive
}
相关文章:
- 循环中的随机函数
- C++在乘法图中放置随机值(嵌套循环)
- 如何在循环中随机化不同的值?c ++
- 骰子滚轮随机循环每次运行时都保持相同的值
- C 编程:在循环时运行 2 并从 loop1 获取数据的随机结果
- 随机函数在循环中调用时返回相同的数字!C++
- C++ 通过 range for 循环将整数输入到矢量中;随机 0
- 随机返回相同的循环值
- 用于随机访问和元素循环的最佳数据结构(C++)
- 随机密码生成器的C++循环错误"以非零状态退出"
- 线程在循环的中间随机停止
- 执行随机for循环并每次保存随机值
- for循环导致随机分段错误C++
- 生成具有负边权重且无负循环的随机图
- C++随机化和循环困难
- 随机化不会在 while 循环中发生。如何解决这个问题?C++
- 每次循环进行临时均匀随机分布的效率如何
- C++循环,直到随机生成等于某个数字
- 来自大群体的随机样本进入无限循环
- c++循环随机剪切