if __name__ == '__main__': G = nx.DiGraph() G.add_node('1', demand = -40) G.add_node('2', demand = 0) G.add_node('3', demand = 0) G.add_node('4', demand = 0) G.add_node('5', demand = 0) G.add_node('6', demand = 0) G.add_node('7', demand = 30) G.add_node('8', demand = 10) G.add_edge('1', '2', weight = 3, capacity = 20) G.add_edge('1', '3', weight = 5, capacity = 25) G.add_edge('2', '4', weight = 2, capacity = 15) G.add_edge('2', '5', weight = 2, capacity = 20) G.add_edge('3', '4', weight = 3, capacity = 20) G.add_edge('3', '6', weight = 3, capacity = 15) G.add_edge('4', '7', weight = 3, capacity = 30) G.add_edge('5', '7', weight = 2, capacity = 20) G.add_edge('6', '8', weight = 4, capacity = 15) flowCost, flowDict = nx.network_simplex(G) flowCost flowDict
|