Hi so I have seen the ortools webpage ortools where it states that you can solve the assignment problem with the min cost flow algorithm, however when I try to reproduce this process with networkx I get an error. Can somebody point me to what am I doing wrong?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
workersList = [ 's1' , 's2' , 's3' , 's4' ] tasksList = [ 'c1' , 'c2' , 'c3' , 'c4' ] costs = [[ 90 , 76 , 75 , 70 ], [ 35 , 85 , 55 , 65 ], [ 125 , 95 , 90 , 105 ], [ 45 , 110 , 95 , 115 ]] import networkx as nx G = nx.DiGraph() G.add_node( 'Start' , demand = len (workersList)) G.add_node( 'End' , demand = - len (workersList)) G.add_nodes_from(workersList) G.add_nodes_from(tasksList) for worker in workersList: G.add_edge( 'Start' , work, weight = 0 , capacity = 1 ) for task in tasksList: G.add_edge(task, 'End' , weigth = 0 , capacity = 1 ) for i, worker in enumerate (workersList): for j, task in enumerate (tasksList): if costs[i][j] ! = 'NA' : G.add_edge(worker, task, weight = costs[i][j], capacity = 1 ) flowDict = nx.min_cost_flow(G) print (flowDict) |