1

I am using boost library to find maximum flow (push relabel) , and there is a file read_dimacs.hpp read the data but stdin. the problem is my data file is too big and i want to read data file in direct way from file . Can any one help me.the code is below

#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;
}
sehe
  • 374,641
  • 47
  • 450
  • 633
  • 1
    stdin has no size limit. You can do `./myprog < thefile` and it makes no difference how large the input is. Perhaps I'm not understanding your question well? – John Zwinck Feb 01 '15 at 11:56
  • What do you mean by “my data file is too big”? Is your system running out of memory (throwing `std::bad_alloc`)? Does your program work as expected for smaller inputs? Can you show how it does so? – 5gon12eder Feb 01 '15 at 12:47
  • my data file as dimacs.dat file as nodes and arcs more than 1000 vertices there fore how can i read it in the algorithm ? this algorithm read data as stdin and i want the algorithm read the data from my file. – Haeder ALjoburey Feb 02 '15 at 11:22
  • I have data as dimacs.dat file and I want find a maximum flow between any two vertices , I want push_relabel algorithm read this data in my file but the algorithm read data as stdin not from my file . Can I doing some changes in the algorithm so as read my data? – Haeder ALjoburey Feb 02 '15 at 11:48

1 Answers1

0

You can

  1. store the underlying container in shared memory/memory mapped file.

    An example of this is here: Using boost::iostreams::mapped_file_source with std::multimap

    Of course you'll need to tie it in with Boost Graph. If you post with a SSCCE, I could see whether it's easy to adapt

  2. you could distribute the load by using Boost Parallel Graph library

    http://www.boost.org/doc/libs/1_57_0/libs/graph_parallel/doc/html/index.html

    I don't have experience with this, enough, to know whether it makes sense to use with your algoritm needs. (I know you can still compile it, but it might be suboptimal if the algorithm essentially runs in one process, pulling in the data. Memory mapped files would be way faster there)

Community
  • 1
  • 1
sehe
  • 374,641
  • 47
  • 450
  • 633
  • I have data as dimacs.dat file and I want find a maximum flow between any two vertices , I want push_relabel algorithm read this data in my file but the algorithm read data as stdin not from my file . Can I doing some changes in the algorithm so as read my data? – Haeder ALjoburey Feb 02 '15 at 11:51
  • @HaederALjoburey See this: _"If you post with a SSCCE, I could see whether it's easy to adapt"_ – sehe Feb 02 '15 at 11:58
  • That's something easily googled. http://sscce.org/ and http://meta.stackexchange.com/a/22762/159703 – sehe Feb 02 '15 at 12:59