Python Forum
Reproducing assignment with min cost flow in networkx
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Reproducing assignment with min cost flow in networkx
#1
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?

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)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Alicat Flow Meter data acquisition marenr 0 356 Sep-29-2023, 10:59 PM
Last Post: marenr
  Convert np Array A to networkx G IanAnderson 2 698 Jul-05-2023, 11:42 AM
Last Post: IanAnderson
  Node Flow Generation in Python Linenloid 0 659 Feb-21-2023, 07:09 PM
Last Post: Linenloid
  'networkx' Questions Trader 0 760 Dec-29-2022, 10:20 PM
Last Post: Trader
  networkx package is not visible in singularity container image erdemath 11 2,311 Oct-14-2022, 12:04 PM
Last Post: Larz60+
  Flow Control Help RoadToSensei 5 1,703 Feb-14-2022, 08:21 PM
Last Post: deanhystad
  Python Networkx: Visualize an edge weight with a bubble/circle uvw 0 2,017 Sep-01-2021, 06:26 AM
Last Post: uvw
  Total electric construction cost project SecondSandwich94 2 2,170 Jul-21-2021, 09:37 PM
Last Post: deanhystad
  Calculate and print the total cost isha_dx 7 11,662 Feb-10-2021, 04:56 PM
Last Post: nilamo
  Understanding Raspberry PI RTS/CTS flow control zazas321 2 3,652 Oct-30-2020, 09:55 AM
Last Post: zazas321

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020