1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 #ifndef BIPARTITE_GRAPH_INTERNAL
19 #define BIPARTITE_GRAPH_INTERNAL 1
20
21 struct opal_bp_graph_edge_t {
22 opal_object_t super;
23
24 opal_list_item_t outbound_li;
25 opal_list_item_t inbound_li;
26
27
28 int source;
29
30
31 int target;
32
33
34 int64_t cost;
35
36
37
38
39
40 int capacity;
41
42
43 void *e_data;
44 };
45
46 struct opal_bp_graph_vertex_t {
47
48 int v_index;
49
50
51 void *v_data;
52
53
54 opal_list_t out_edges;
55
56
57 opal_list_t in_edges;
58 };
59
60 struct opal_bp_graph_t {
61
62 int num_vertices;
63
64
65 opal_pointer_array_t vertices;
66
67
68 int source_idx;
69
70
71 int sink_idx;
72
73
74 opal_bp_graph_cleanup_fn_t v_data_cleanup_fn;
75
76
77 opal_bp_graph_cleanup_fn_t e_data_cleanup_fn;
78 };
79
80
81 #define LIST_FOREACH_CONTAINED(item, list, type, member) \
82 for (item = container_of( (list)->opal_list_sentinel.opal_list_next, type, member ); \
83 &item->member != &(list)->opal_list_sentinel; \
84 item = container_of( \
85 ((opal_list_item_t *) (&item->member))->opal_list_next, type, member ))
86
87 #define LIST_FOREACH_SAFE_CONTAINED(item, next, list, type, member) \
88 for (item = container_of( (list)->opal_list_sentinel.opal_list_next, type, member ), \
89 next = container_of( \
90 ((opal_list_item_t *) (&item->member))->opal_list_next, type, member ); \
91 &item->member != &(list)->opal_list_sentinel; \
92 item = next, \
93 next = container_of( \
94 ((opal_list_item_t *) (&item->member))->opal_list_next, type, member ))
95
96 #define NUM_VERTICES(g) (g->num_vertices)
97
98 #define CHECK_VERTEX_RANGE(g,v) \
99 do { \
100 if ((v) < 0 || \
101 (v) >= NUM_VERTICES(g)) { \
102 return OPAL_ERR_BAD_PARAM; \
103 } \
104 } while (0)
105
106
107
108 #define V_ID_TO_PTR(g, v_id) \
109 ((opal_bp_graph_vertex_t *) \
110 opal_pointer_array_get_item((opal_pointer_array_t *)&g->vertices, v_id))
111
112 #define FOREACH_OUT_EDGE(g,v_id,e_ptr) \
113 LIST_FOREACH_CONTAINED(e_ptr, \
114 &(V_ID_TO_PTR(g, v_id)->out_edges), \
115 opal_bp_graph_edge_t, \
116 outbound_li)
117
118 #define FOREACH_IN_EDGE(g,v_id,e_ptr) \
119 LIST_FOREACH_CONTAINED(e_ptr, \
120 &(V_ID_TO_PTR(g, v_id)->in_edges), \
121 opal_bp_graph_edge_t, \
122 inbound_li)
123
124
125
126
127
128
129 #define FOREACH_UV_ON_PATH(pred, source, sink, u, v) \
130 for (u = pred[sink], v = sink; u != -1; v = u, u = pred[u])
131
132
133 bool opal_bp_graph_bellman_ford(opal_bp_graph_t *gx,
134 int source,
135 int target,
136 int *pred);
137
138 int opal_bp_graph_bipartite_to_flow(opal_bp_graph_t *g);
139
140 #endif