147
147
assert_equal(nx.min_cost_flow(G), soln)
148
148
assert_equal(nx.cost_of_flow(G, H), 150)
150
def test_digraph2(self):
151
# Example from ticket #430 from mfrasca. Original source:
152
# http://www.cs.princeton.edu/courses/archive/spr03/cs226/lectures/mincost.4up.pdf, slide 11.
154
G.add_edge('s', 1, capacity=12)
155
G.add_edge('s', 2, capacity=6)
156
G.add_edge('s', 3, capacity=14)
157
G.add_edge(1, 2, capacity=11)
158
G.add_edge(2, 3, capacity=9)
159
G.add_edge(1, 4, capacity=5)
160
G.add_edge(1, 5, capacity=2)
161
G.add_edge(2, 5, capacity=4)
162
G.add_edge(2, 6, capacity=2)
163
G.add_edge(3, 6, capacity=31)
164
G.add_edge(4, 5, capacity=18)
165
G.add_edge(5, 5, capacity=9)
166
G.add_edge(4, 't', capacity=3)
167
G.add_edge(5, 't', capacity=7)
168
G.add_edge(6, 't', capacity=22)
169
flow = nx.max_flow_min_cost(G, 's', 't')
170
soln = {1: {2: 5, 4: 5, 5: 2},
171
2: {3: 6, 5: 3, 6: 2},
176
's': {1: 12, 2: 6, 3: 14},
178
assert_equal(flow, soln)
180
def test_digraph3(self):
181
"""Combinatorial Optimization: Algorithms and Complexity,
182
Papadimitriou Steiglitz at page 140 has an example, 7.1, but that
183
admits multiple solutions, so I alter it a bit. From ticket #430
187
G.add_edge('s', 'a', {0: 2, 1: 4})
188
G.add_edge('s', 'b', {0: 2, 1: 1})
189
G.add_edge('a', 'b', {0: 5, 1: 2})
190
G.add_edge('a', 't', {0: 1, 1: 5})
191
G.add_edge('b', 'a', {0: 1, 1: 3})
192
G.add_edge('b', 't', {0: 3, 1: 2})
194
"PS.ex.7.1: testing main function"
195
sol = nx.max_flow_min_cost(G, 's', 't', capacity=0, weight=1)
196
flow = sum(v for v in sol['s'].values())
197
assert_equal(4, flow)
198
assert_equal(23, nx.cost_of_flow(G, sol, weight=1))
199
assert_equal(sol['s'], {'a': 2, 'b': 2})
200
assert_equal(sol['a'], {'b': 1, 't': 1})
201
assert_equal(sol['b'], {'a': 0, 't': 3})
202
assert_equal(sol['t'], {})