graph.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. /*!
  2. Temelia - Generic graph interface.
  3. This source file contains the implementation of the most known
  4. algorithms on graphs. Graph uses another layer consisting of the
  5. internal representation: adjacency matrix, adjacency list etc
  6. The representation can be user defined, see graph_matrix.h and
  7. graph_list.h for additional information.
  8. Copyright (C) 2008 Ceata (http://cod.ceata.org/proiecte/temelia).
  9. This program is free software; you can redistribute it and
  10. modify it under the terms of the GNU General Public License
  11. as published by the Free Software Foundation; either version 3
  12. of the License, or (at your option) any later version.
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. GNU General Public License for more details.
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  20. */
  21. #ifndef GRAPH_H_
  22. #define GRAPH_H_
  23. #include "common.h"
  24. #include "vertex.h"
  25. #include "edge.h"
  26. #include "linked_list.h"
  27. #include "vector.h"
  28. #include "matrix.h"
  29. /*!
  30. * @brief Common interface for graph implementation.
  31. * It contains pointers to functions; you may initialize
  32. * them with the values you want to hook in the library's
  33. * graph algorithms.
  34. *
  35. * Graph algorithms uses this interface to build generic
  36. * solution, instead of depending on the graph implementation.
  37. *
  38. * Temelia comes with two default implementations: adjacency matrix
  39. * and adjancency list. You can define your own implementation by
  40. * implementing the functions in this interface - look at
  41. * current solutions for details.
  42. *
  43. * The core concept is that at the upper layer I want to
  44. * work with unsigned int, instead of vertex_t; thus, the library
  45. * should automatically box/unbox unsigned int from/to vertex_t
  46. */
  47. struct _graph_implementation_t
  48. {
  49. // Returns an empty graph with given size
  50. void *(*new)(int size);
  51. // Frees the memory occupied by graph
  52. void (*delete)(void *graph);
  53. // Actualizes graph's size
  54. void (*resize)(void *graph, int size);
  55. /*!
  56. * @brief Loads source graph into destination graph.
  57. * The load operation should consists of edge references duplication.
  58. * Notice that this operation does not require any memory allocation.
  59. * @param Source graph
  60. * @param Destination graph
  61. */
  62. void (*load)(void *graph_src, void *graph_dest);
  63. /*!
  64. * @brief Duplicates source graph and returns the clone. In a common example,
  65. * the returned value, graph_dest, will be used to with load(graph_src, graph_dest).
  66. * @param Source graph
  67. */
  68. void *(*store)(void *graph_src);
  69. // Adds new edge to graph
  70. void (*add_edge)(void *graph, unsigned int vertex1, unsigned int vertex2,
  71. edge_t edge);
  72. // Removes edge from graph
  73. edge_t (*remove_edge)(void *graph, unsigned int vertex1,
  74. unsigned int vertex2);
  75. // Retrives the reference of edge from graph
  76. edge_t (*get_edge)(void *graph, unsigned int vertex1, unsigned int vertex2);
  77. // === [Start] Iterator over vertice's neighbors ===
  78. /*!
  79. * @brief Returns the first neighbor vertex of given vertex in graph
  80. * @param Graph implementation
  81. * @param Vertex
  82. * @param Pointer to context; here your implementation
  83. * may save a context (what's the current vertex, other references etc)
  84. */
  85. vertex_t (*first_vertex)(void *graph, unsigned int vertex, void **context);
  86. /*!
  87. * @brief Deteles the allocated context for iterating on neighbors;
  88. * you should call this function if you don't want full neighbors iterating.
  89. * At the end of iterating, next_vertex returns NULL, this function is automatically
  90. * called.
  91. * @param Context
  92. */
  93. void (*delete_vertex_context)(void **context);
  94. /*!
  95. * @brief Returns the next neighbor vertex of given vertex in graph
  96. * @param Graph implementation
  97. * @param Vertex
  98. * @param Pointer to context; information about the last visited
  99. * neighbor should be here and it may be actualized
  100. */
  101. vertex_t (*next_vertex)(void *graph, unsigned int vertex, void **context);
  102. // === [Stop] Iterator over vertice's neighbors ===
  103. // === [Start] Iterator over vertice's out edges ===
  104. /*!
  105. * @brief Returns the first out edge of given vertex in graph
  106. * @param Graph implementation
  107. * @param Vertex
  108. * @param Pointer to context; here your implementation
  109. * may save a context (what's the current vertex, other references etc)
  110. */
  111. edge_t (*first_edge)(void *graph, unsigned int vertex, void **context);
  112. /*!
  113. * @brief Deteles the allocated context for iterating on neighbors;
  114. * you should call this function if you don't want full neighbors iterating.
  115. * At the end of iterating, next_vertex returns NULL, this function is automatically
  116. * called.
  117. * @param Context
  118. */
  119. void (*delete_edge_context)(void **context);
  120. /*!
  121. * @brief Returns the next out edge of given vertex in graph
  122. * @param Graph implementation
  123. * @param Vertex
  124. * @param Pointer to context; information about the last visited
  125. * neighbor should be here and it may be actualized
  126. */
  127. edge_t (*next_edge)(void *graph, unsigned int vertex, void **context);
  128. // === [Stop] Iterator over out edge's ===
  129. /*!
  130. * @brief Iterates over the edges of graph
  131. * @param Graph
  132. * @param Edge iterating function
  133. * @param Iterating context
  134. */
  135. void (*iterate_edges)(void *graph, void edge_handler(edge_t e,
  136. void *context), void *context);
  137. /*!
  138. * @brief Transposes graph
  139. * @param Graph
  140. */
  141. void (*transpose)(void *graph);
  142. // == [Start] [Optimization] Optional functions ==
  143. /*!
  144. * Generic graph implementation computes, the results of
  145. * the following functions, if NULL pointers are in the structure.
  146. * Saving non-NULL pointers in the structure makes the library
  147. * call those functions, instead of the default implementation.
  148. */
  149. /*!
  150. * @brief Computes degree, in degree or out degree of a vertex
  151. * in graph.
  152. *
  153. * in degree(u) = count{ v | (v, u) is an edge}
  154. *
  155. * out degree(u) = count{ v | (u, v) is an edge}
  156. *
  157. * degree = in degree + out degree
  158. *
  159. * @param Graph
  160. * @param Vertex identifier
  161. */
  162. unsigned int (*vertex_degree)(void *graph, unsigned int vertex);
  163. unsigned int (*vertex_in_degree)(void *graph, unsigned int vertex);
  164. unsigned int (*vertex_out_degree)(void *graph, unsigned int vertex);
  165. /*!
  166. * @brief Computes the dimension of the graph - number of edges
  167. * @param Graph
  168. */
  169. unsigned int (*dimension)(void *graph);
  170. /*!
  171. * @brief Removes and deletes all the edges containing vertex
  172. * @param Graph
  173. * @param Vertex identifier
  174. * @param Edge destructor
  175. */
  176. void (*delete_vertex_edges)(void *graph, unsigned int vertex,
  177. void(*edge_delete)(edge_t edge));
  178. // == [Stop] [Optimization] Optional functions ==
  179. };
  180. typedef struct _graph_implementation_t *graph_implementation_t;
  181. struct _graph_t;
  182. typedef struct _graph_t *graph_t;
  183. /*!
  184. * @brief Constructor - returns an empty graph_t with maximum size.
  185. * Complexity O(1)
  186. *
  187. * @param Maximum vertices number
  188. * @param Implementation layer
  189. * @param Vertex destructor; if you pass NULL then vertex_delete will
  190. * be used
  191. * @param Edge destructor; if you pass NULL then edge_delete will be
  192. * used
  193. */
  194. DECLSPEC graph_t graph_new(unsigned int max, graph_implementation_t implementation,
  195. void(*m_vertex_delete)(vertex_t), void(*m_edge_delete)(edge_t));
  196. /*!
  197. * @brief Frees the memory occupied by graph_t. Remember it only frees the pointers allocated
  198. * by the library, none of your pointers, please free them in order to avoid memory leaks.
  199. * Complexity O(V + E)
  200. *
  201. * @param Graph
  202. */
  203. DECLSPEC void graph_delete(graph_t graph);
  204. /*!
  205. * @brief Adds new vertex with a given label.
  206. * Complexity O(V)
  207. *
  208. * @param Graph
  209. * @param Vertex label
  210. * @param Key stored in the label
  211. * @return Vertex identifier. In the future, use this instead of vertex label
  212. */
  213. DECLSPEC unsigned int graph_add_vertex(graph_t graph, char *label, void *key);
  214. /*!
  215. * @brief Removes vertex from graph_t by giving it's identifier.
  216. * Complexity O(1)
  217. *
  218. * @param Graph
  219. * @param Vertex identifier
  220. * @return Pointer to removed vertex; it's your job to free the memory occupied
  221. * by the container and by it's content: label and key
  222. */
  223. DECLSPEC vertex_t graph_remove_vertex(graph_t graph, unsigned int identifier);
  224. /*!
  225. * @brief Verifies if vertex given by it's identifier is in graph.
  226. * Complexity O(1)
  227. *
  228. * @param Graph
  229. * @param Vertex identifier
  230. * @return 1 if it's in the graph_t and 0 if not; -1 if an error occurred.
  231. */
  232. DECLSPEC int graph_is_vertex(graph_t graph, unsigned int identifier);
  233. /*!
  234. * @brief Returns the vertex structure associated with identifier.
  235. * Complexity O(1)
  236. *
  237. * @param Graph
  238. * @param Vertex identifier
  239. */
  240. DECLSPEC vertex_t graph_get_vertex(graph_t graph, unsigned int identifier);
  241. /*!
  242. * @brief Adds an edge between two vertices given by their identifiers.
  243. * Complexity depends on the graph implementation; it may be O(V) or O(1)
  244. *
  245. * @param Graph
  246. * @param First vertex identifier
  247. * @param Second vertex identifier
  248. * @param Edge cost
  249. * @param Edge label
  250. * @param Key stored in edge
  251. */
  252. DECLSPEC void graph_add_edge(graph_t graph, unsigned int vertex, unsigned int vertex2,
  253. double cost, char *label, void *key);
  254. /*!
  255. * @brief Removes an edge from graph.
  256. * Complexity depends on the graph implementation; it may be O(V) or O(1)
  257. *
  258. * @param Graph
  259. * @param First vertex
  260. * @param Second vertex
  261. * @return Pointer to removed edge; it's you job the free the memory allocated for the edge,
  262. * and for it's content: label and key
  263. */
  264. DECLSPEC edge_t graph_remove_edge(graph_t graph, unsigned int vertex1,
  265. unsigned int vertex2);
  266. /*!
  267. * @brief Verifies if there is an edge between two vertices.
  268. * Complexity depends on the graph implementation; it may be O(V) or O(1)
  269. *
  270. * @param Graph
  271. * @param First vertex identifier
  272. * @param Second vertex identifier
  273. * @return 1 if there exists an edge between vertices, 0 if not or -1 if an error occurred
  274. */
  275. DECLSPEC int graph_is_edge(graph_t graph, unsigned int vertex1, unsigned int vertex2);
  276. /*!
  277. * @brief Returns the edge structure associated with pair of identifiers.
  278. * Complexity depends on the graph implementation; it may be O(1) or O(V)
  279. *
  280. * @param Graph
  281. * @param Vertex1 identifier
  282. * @param Vertex2 identifier
  283. */
  284. DECLSPEC edge_t graph_get_edge(graph_t graph, unsigned int identifier1,
  285. unsigned int identifier2);
  286. /*!
  287. * @brief Verifies is graph_t is empty: it contains 0 vertices.
  288. * Complexity O(1)
  289. *
  290. * @param Graph
  291. * @return 1 if it's empty, 0 if not or -1 an error occurred
  292. */
  293. DECLSPEC int graph_is_empty(graph_t graph);
  294. /*!
  295. * @brief Returns graph's size (order): number of nodes.
  296. * Complexity O(1)
  297. *
  298. * @param Graph
  299. */
  300. DECLSPEC unsigned int graph_get_size(graph_t graph);
  301. /*!
  302. * @brief Returns graph's dimension : number of edges.
  303. * Complexity depends on the graph implementation; it may be O(E) or O(V*V)
  304. *
  305. * @param Graph
  306. */
  307. DECLSPEC unsigned int graph_get_dimension(graph_t graph);
  308. /*!
  309. * @brief Returns the degree of vertex given by it's identifier.
  310. * Complex O(V)
  311. *
  312. * @param Graph
  313. * @param Vertex identifier
  314. * @return Number of neighbors
  315. */
  316. DECLSPEC unsigned int graph_vertex_degree(graph_t graph, unsigned int identifier);
  317. /*!
  318. * @brief Returns the out degree of vertex given by it's identifier.
  319. * Complexity O(V)
  320. *
  321. * @param Graph
  322. * @param Vertex identifier
  323. * @return Number of edges from vertex to it's neighbors
  324. */
  325. DECLSPEC unsigned int graph_vertex_out_degree(graph_t graph, unsigned int identifier);
  326. /*!
  327. * @brief Returns the in degree of vertex given by it's identifier.
  328. * Complexity O(V)
  329. *
  330. * @param Graph
  331. * @param Vertex identifier
  332. * @return Number of edges from neighbors to vertex
  333. */
  334. DECLSPEC unsigned int graph_vertex_in_degree(graph_t graph, unsigned int identifier);
  335. /*!
  336. * @brief Iterates over graph's vertices and call the callback function for each entity.
  337. * Complexity O(V)
  338. *
  339. * @param Graph
  340. * @param Iterating function
  341. * @param Iterating context
  342. */
  343. DECLSPEC void graph_iterate_vertices(graph_t graph, void vertex_handler(vertex_t vertex,
  344. void *context), void *context);
  345. /*!
  346. * @brief Iterates over graph's edges and call the callback function for each entity.
  347. * Complexity depends on the graph implementation; it may be O(E) or O(V*V).
  348. *
  349. * @param Graph
  350. * @param Iterating function
  351. * @param Iterating context
  352. */
  353. DECLSPEC void graph_iterate_edges(graph_t graph, void edge_handler(edge_t edge,
  354. void *context), void *context);
  355. /*!
  356. * @brief Transposes the graph.
  357. * Complexity depends on the graph implementation; in general,
  358. * it's O(V*V)
  359. *
  360. * @param Graph
  361. */
  362. DECLSPEC void graph_transpose_graph(graph_t graph);
  363. /*!
  364. * @brief Synchronization methods. Get and sets the value of current time.
  365. */
  366. DECLSPEC void graph_set_current_time(unsigned int time);
  367. DECLSPEC int graph_get_current_time();
  368. /*!
  369. * @brief Checks if graph is undirected. User should know that his graph is directed or undirected
  370. * and should not access this function directly. It is used as an assert on algorithms applied
  371. * only to directed graphs, if the user wants this.
  372. * Complexity O(V*V)
  373. *
  374. * @param Graph
  375. */
  376. DECLSPEC int graph_is_undirected(graph_t graph);
  377. /*!
  378. * @brief Adjusts vertices parameters values by depth-first-search traveling this graph,
  379. * starting from start vertex, given by it's identifier. If the start vertex is -1
  380. * then the function does a complete DFS travel. The algorithm is picking nodes is lexicographic order, by
  381. * identifiers. The variable changing is the vector of vertices.
  382. * Complexity O(E) if vertex = -1 and O(V) is vertex is a valid identifier
  383. *
  384. * @param Graph
  385. * @param Start vertex
  386. */
  387. DECLSPEC void graph_dfs(graph_t graph, unsigned int start_vertex_identifier);
  388. /*!
  389. * @brief Adjusts vertices parameters values by breadth-first-search traveling this graph,
  390. * starting from start vertex, given by it's identifier. If the start vertex is -1
  391. * then the function does a complete DFS travel. The algorithm is picking nodes is lexicographic order, by
  392. * identifiers. The variable changing is the vector of vertices.
  393. * Complexity O(E) if vertex = -1 and O(V) is vertex is a valid identifier
  394. *
  395. * @param Graph
  396. * @param Start vertex
  397. */
  398. DECLSPEC void graph_bfs(graph_t graph, unsigned int start_vertex_identifier);
  399. /*!
  400. * @brief Classifies edges from DFS point of view.
  401. * Complexity O(E)
  402. *
  403. * @param Graph
  404. */
  405. DECLSPEC void graph_dfs_edges_classification(graph_t graph);
  406. /*!
  407. * @brief Classifies edges from BFS point of view.
  408. * Complexity O(E)
  409. *
  410. * @param Graph
  411. */
  412. DECLSPEC void graph_bfs_edges_classification(graph_t graph);
  413. /*!
  414. * @brief Reset vertices parameters to default values : unvisited, colored with white, not discovered,
  415. * travel not ended and parent nil (-1).
  416. * Complexity O(V)
  417. *
  418. * @param Graph
  419. */
  420. DECLSPEC void graph_reset_vertices(graph_t graph);
  421. /*!
  422. * @brief Checks if graph is bipartite : exists subgraphs A and B , A has nothing in common
  423. * with B, such that A U B = G. You should call this function with empty linked lists
  424. * as parameters because there is stored the result.
  425. * @param Graph
  426. * @param Pointer to first vertices set
  427. * @param Pointer to second vertices set
  428. * @return 0 if the graph_t is bipartite, 1 if not and -1 if an error occurred
  429. */
  430. DECLSPEC int graph_bipartite(graph_t graph, linked_list_t first_set,
  431. linked_list_t second_set);
  432. /*!
  433. * @brief Returns the diameter of graph.
  434. * @param Graph
  435. * @param Pointer to first node; here the function will store first node of diameter
  436. * @param Pointer to second node; here the function will store second node of diameter
  437. */
  438. DECLSPEC unsigned int graph_diameter(graph_t graph, unsigned int *first_node,
  439. unsigned int *second_node);
  440. /*!
  441. * @brief Calculates the articulation points.
  442. * @param Graph
  443. * @param Articulation points list
  444. */
  445. DECLSPEC void
  446. graph_articulation_points(graph_t graph, linked_list_t articulation_points);
  447. /*!
  448. * @brief Computes the bridges from graph. Each key of bridges is a pair of unsigned int, unsigned int.
  449. * @param Graph
  450. * @param Bridges list
  451. */
  452. DECLSPEC void graph_bridges(graph_t graph, linked_list_t bridges);
  453. /*!
  454. * @brief Computes the biconex components from graph. Each key of biconex_components is a
  455. * linked list of unsigned int.
  456. * @param Graph
  457. * @param Biconex components list
  458. */
  459. DECLSPEC void graph_biconex_components(graph_t graph, linked_list_t biconex_components);
  460. /*!
  461. * @brief Finds the simple cycles from graph.
  462. * @param Graph
  463. * @param Cycles list; each key of list is a linked list containing vertices identifiers
  464. * as keys
  465. */
  466. DECLSPEC void graph_cycles(graph_t graph, linked_list_t cycles);
  467. /*!
  468. * @brief Finds the connected components from graph. Depends on the last parameter, the function
  469. * will check is the given graph is undirected. After the function finishes the vertices parameters
  470. * will be reseted, because it's doing DFS travels for each unvisited vertices.
  471. * @param Graph
  472. * @param Linked list, which will contain the connected components; a connected component
  473. * is a linked list with vertices' identifiers as keys
  474. * @param 1 if you want to check the graph it's undirected and 0 if you know this in advance;
  475. * pay attention, this function works correctly only for undirected graphs
  476. */
  477. DECLSPEC void graph_connected_components(graph_t graph,
  478. linked_list_t connected_components, char check);
  479. /*!
  480. * @brief Finds the strongly connected components from graph
  481. * @param Graph
  482. * @param Linked list which will contain the result
  483. * @see graph_connected_components
  484. */
  485. DECLSPEC void graph_strongly_connected_components(graph_t graph,
  486. linked_list_t strongly_connected_components);
  487. /*!
  488. * @brief Sorts in topological order the keys of graph
  489. * and returns a linked list containing vertices in sorted order.
  490. * Your graph should be acyclic and direct (DAG - direct acyclic graph)
  491. * @param Graph
  492. * @param Linked list which will store the result
  493. * @return 0 if graph can be sorted this way and -1 if not
  494. */
  495. DECLSPEC char graph_topological_sort(graph_t graph, linked_list_t sort);
  496. /*!
  497. * @brief Executes Dijkstra's algorithm for computing minimum distance vector of graph
  498. * @param Graph
  499. * @param Source vertex
  500. * @param Minimum distances vector
  501. * @param Parents vector
  502. */
  503. DECLSPEC void graph_dijkstra(graph_t graph, unsigned int source, vector_t distances,
  504. vector_t parents);
  505. /*!
  506. * @brief Executes Bellman-Ford algorithm for computing minimum distance vector of graph
  507. * @param Pointer to graph
  508. * @param Source vertex
  509. * @param Reference to minimum distances vector
  510. * @param Reference to parents vector
  511. * @return 1 if success, 0 if not and -1 if an error occurred, negative
  512. * cycle detected for example
  513. */
  514. DECLSPEC int graph_bellman_ford(graph_t graph, unsigned int source, vector_t distances,
  515. vector_t parents);
  516. /*!
  517. * @brief Executes Floyd-Warshall algorithm for computing minimum distance matrix of graph
  518. * @param Graph
  519. * @param Reference to minimum distances matrix. Each key should be a valid double *
  520. * @param Reference to parents matrix
  521. */
  522. DECLSPEC void graph_floyd_warshall(graph_t graph, matrix_t distances, matrix_t parents);
  523. /*!
  524. * @brief Executes Johnson algorithm for computing minimum distance matrix of graph
  525. * @param Graph
  526. * @param Minimum distances matrix
  527. * @param Parents matrix
  528. * @return 1 if success, 0 if not and -1 if an error occurred - negative
  529. * cycle detected for example
  530. */
  531. DECLSPEC int graph_johnson(graph_t graph, matrix_t distances, matrix_t parents);
  532. /*!
  533. * @brief Executes Prim's algorithm for computing minimum spanning tree of graph
  534. * @param Graph
  535. * @param Starting vertex
  536. * @param Minimum spanning tree. The function will store here a linked list
  537. * of edges (pair of vertices).
  538. * @return The cost of the minimum spanning tree - the sum of edges cost.
  539. */
  540. DECLSPEC double graph_prim(graph_t graph, unsigned int start_vertex_identifier,
  541. linked_list_t minimum_spanning_tree);
  542. /*!
  543. * @brief Executes Kruskal's algorithm for computing minimum spanning tree of graph.
  544. * Minimum spanning tree is a linked list of vertices identifiers, where two
  545. * consecutive vertices form an edge. For example u1, u2, u3 => [u1, u2], [u2, u3]
  546. * @see graph_prim for more details
  547. */
  548. DECLSPEC double graph_kruskal(graph_t graph, unsigned int start_vertex_identifier,
  549. linked_list_t *minimum_spanning_tree);
  550. /*!
  551. * @brief Executes Ford-Fulkerson algorithm for computing max-flow in graph
  552. * It uses DFS travel for exploring possible flow increasing paths.
  553. * @param Graph
  554. * @param Source vertex
  555. * @param Destination vertex
  556. * @param Flow matrix where the result is written; the matrix should have allocated double pointers
  557. * @return Maximum flow in graph between source and destination
  558. */
  559. DECLSPEC double graph_ford_fulkerson(graph_t graph, unsigned int source,
  560. unsigned int destination, matrix_t max_flow);
  561. /*!
  562. * @brief Executes Edmonds-Karp algorithm for computing max-flow in graph.
  563. * It uses BFS travel for exploring possible flow increasing paths
  564. * @param Graph
  565. * @param Source vertex
  566. * @param Destination vertex
  567. * @param Reference to flow matrix, where the result is written
  568. * @return Maximum flow in graph_t between source and destination
  569. */
  570. DECLSPEC double graph_edmonds_karp(graph_t graph, unsigned int source,
  571. unsigned int destination, matrix_t max_flow);
  572. #endif /* GRAPH_H_ */