PGROUTING  2.6
max_flow_driver.h File Reference
Include dependency graph for max_flow_driver.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void do_pgr_max_flow (pgr_edge_t *data_edges, size_t total_tuples, int64_t *source_vertices, size_t size_source_verticesArr, int64_t *sink_vertices, size_t size_sink_verticesArr, int algorithm, bool only_flow, pgr_flow_t **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
 

Function Documentation

void do_pgr_max_flow ( pgr_edge_t data_edges,
size_t  total_tuples,
int64_t *  source_vertices,
size_t  size_source_verticesArr,
int64_t *  sink_vertices,
size_t  size_sink_verticesArr,
int  algorithm,
bool  only_flow,
pgr_flow_t **  return_tuples,
size_t *  return_count,
char **  log_msg,
char **  notice_msg,
char **  err_msg 
)

Definition at line 43 of file max_flow_driver.cpp.

References pgrouting::graph::PgrFlowGraph::boykov_kolmogorov(), pgr_flow_t::edge, pgrouting::graph::PgrFlowGraph::edmonds_karp(), pgr_flow_t::flow, pgrouting::graph::PgrFlowGraph::get_flow_edges(), pgassert, pgr_alloc(), pgr_free(), pgr_msg(), pgrouting::graph::PgrFlowGraph::push_relabel(), pgr_flow_t::residual_capacity, pgr_flow_t::source, pgr_flow_t::target, and AssertFailedException::what().

Referenced by process().

53  {
54  std::ostringstream log;
55  std::ostringstream notice;
56  std::ostringstream err;
57 
58  try {
59  pgassert(data_edges);
60  pgassert(source_vertices);
61  pgassert(sink_vertices);
62 
63  std::vector<pgr_edge_t> edges(data_edges, data_edges + total_edges);
64  std::set<int64_t> sources(
65  source_vertices, source_vertices + size_source_verticesArr);
66  std::set<int64_t> targets(
67  sink_vertices, sink_vertices + size_sink_verticesArr);
68 
69  std::set<int64_t> vertices(sources);
70  vertices.insert(targets.begin(), targets.end());
71 
72  if (vertices.size()
73  != (sources.size() + targets.size())) {
74  *err_msg = pgr_msg("A source found as sink");
75  // TODO(vicky) return as hint the sources that are also sinks
76  return;
77  }
78 
79 
80 
82  edges, sources, targets, algorithm);
83  // digraph.create_flow_graph(edges, sources, targets, algorithm);
84 
85  int64_t max_flow;
86  if (algorithm == 1) {
87  max_flow = digraph.push_relabel();
88  } else if (algorithm == 3) {
89  max_flow = digraph.edmonds_karp();
90  } else if (algorithm == 2) {
91  max_flow = digraph.boykov_kolmogorov();
92  } else {
93  log << "Unspecified algorithm!\n";
94  *err_msg = pgr_msg(log.str().c_str());
95  (*return_tuples) = NULL;
96  (*return_count) = 0;
97  return;
98  }
99 
100 
101  std::vector<pgr_flow_t> flow_edges;
102 
103  if (only_flow) {
105  edge.edge = -1;
106  edge.source = -1;
107  edge.target = -1;
108  edge.flow = max_flow;
109  edge.residual_capacity = -1;
110  flow_edges.push_back(edge);
111  } else {
112  flow_edges = digraph.get_flow_edges();
113  }
114  (*return_tuples) = pgr_alloc(flow_edges.size(), (*return_tuples));
115  for (size_t i = 0; i < flow_edges.size(); ++i) {
116  (*return_tuples)[i] = flow_edges[i];
117  }
118  *return_count = flow_edges.size();
119 
120 
121  *log_msg = log.str().empty()?
122  *log_msg :
123  pgr_msg(log.str().c_str());
124  *notice_msg = notice.str().empty()?
125  *notice_msg :
126  pgr_msg(notice.str().c_str());
127  } catch (AssertFailedException &except) {
128  (*return_tuples) = pgr_free(*return_tuples);
129  (*return_count) = 0;
130  err << except.what();
131  *err_msg = pgr_msg(err.str().c_str());
132  *log_msg = pgr_msg(log.str().c_str());
133  } catch (std::exception &except) {
134  (*return_tuples) = pgr_free(*return_tuples);
135  (*return_count) = 0;
136  err << except.what();
137  *err_msg = pgr_msg(err.str().c_str());
138  *log_msg = pgr_msg(log.str().c_str());
139  } catch(...) {
140  (*return_tuples) = pgr_free(*return_tuples);
141  (*return_count) = 0;
142  err << "Caught unknown exception!";
143  *err_msg = pgr_msg(err.str().c_str());
144  *log_msg = pgr_msg(log.str().c_str());
145  }
146 }
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:126
Definition: trsp.h:31
int64_t source
Definition: pgr_flow_t.h:60
T * pgr_free(T *ptr)
Definition: pgr_alloc.hpp:77
int64_t edge
Definition: pgr_flow_t.h:59
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
int64_t flow
Definition: pgr_flow_t.h:62
char * pgr_msg(const std::string &msg)
Definition: pgr_alloc.cpp:30
T * pgr_alloc(std::size_t size, T *ptr)
allocates memory
Definition: pgr_alloc.hpp:66
int64_t target
Definition: pgr_flow_t.h:61
virtual const char * what() const
Definition: pgr_assert.cpp:53
int64_t residual_capacity
Definition: pgr_flow_t.h:63

Here is the call graph for this function:

Here is the caller graph for this function: