【发布时间】:2015-02-01 10:51:18
【问题描述】:
我正在使用 boost 库来查找最大流量 (push relabel) ,并且有一个文件 read_dimacs.hpp 读取数据但 stdin。问题是我的数据文件太大,我想直接从文件中读取数据文件。 谁能帮帮我。代码在下面
#include <boost/config.hpp>
#include <iostream>
#include <string>
#include <boost/graph/push_relabel_max_flow.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/read_dimacs.hpp>
int
main()
{
using namespace boost;
typedef adjacency_list_traits<vecS, vecS, directedS> Traits;
typedef adjacency_list<vecS, vecS, directedS,
property<vertex_name_t, std::string>,
property<edge_capacity_t, long,
property<edge_residual_capacity_t, long,
property<edge_reverse_t, Traits::edge_descriptor> > >
> Graph;
Graph g;
long flow;
property_map<Graph, edge_capacity_t>::type
capacity = get(edge_capacity, g);
property_map<Graph, edge_reverse_t>::type
rev = get(edge_reverse, g);
property_map<Graph, edge_residual_capacity_t>::type
residual_capacity = get(edge_residual_capacity, g);
Traits::vertex_descriptor s, t;
read_dimacs_max_flow(g, capacity, rev, s, t);
flow = push_relabel_max_flow(g, s, t);
std::cout << "c The total flow:" << std::endl;
std::cout << "s " << flow << std::endl << std::endl;
std::cout << "c flow values:" << std::endl;
graph_traits<Graph>::vertex_iterator u_iter, u_end;
graph_traits<Graph>::out_edge_iterator ei, e_end;
for (boost::tie(u_iter, u_end) = vertices(g); u_iter != u_end; ++u_iter)
for (boost::tie(ei, e_end) = out_edges(*u_iter, g); ei != e_end; ++ei)
if (capacity[*ei] > 0)
std::cout << "f " << *u_iter << " " << target(*ei, g) << " "
<< (capacity[*ei] - residual_capacity[*ei]) << std::endl;
system("pause");
return 0;
}
【问题讨论】:
-
标准输入没有大小限制。你可以做
./myprog < thefile,输入的大小没有区别。也许我没有很好地理解你的问题? -
“我的数据文件太大”是什么意思?您的系统是否内存不足(抛出
std::bad_alloc)?对于较小的输入,您的程序是否按预期工作?你能展示一下它是如何做到的吗? -
我的数据文件作为 dimacs.dat 文件作为节点和弧超过 1000 个顶点因此我如何在算法中读取它?该算法将数据读取为标准输入,我希望该算法从我的文件中读取数据。
-
我有数据作为 dimacs.dat 文件,我想找到任意两个顶点之间的最大流量,我希望 push_relabel 算法在我的文件中读取此数据,但该算法将数据作为标准输入读取,而不是从我的文件中读取。我可以对算法进行一些更改以读取我的数据吗?
标签: c++ boost graph push-relabel