Advertisement
Eternoseeker

Sarthak-Ass6-BranchnBound

Nov 24th, 2023
577
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.68 KB | Source Code | 0 0
  1. import numpy as np
  2.  
  3. def sum_min_del(m,i,j):
  4.     m=np.delete(m,i,axis=1)
  5.     m=np.delete(m,j,axis=0)
  6.     return sum(np.min(m,axis=0))
  7.  
  8. def club_ass(m):
  9.     vis=[-1]*len(m)# index is job
  10.  
  11.     for i in range(len(m)):
  12.         mini=float('inf')
  13.         k=0
  14.         for j in range(len(m)):
  15.             s=sum_min_del(m,i,j)+m[i][j]
  16.             if s<mini and vis[j]==-1:
  17.                 mini=s
  18.                 k=j
  19.         vis[k]=i
  20.     return vis
  21.    
  22.  
  23. job_person=np.array([
  24.     [9, 2, 7, 8],
  25.     [6, 4, 3, 7],
  26.     [5, 8, 1, 8],
  27.     [7, 6, 9, 4]
  28. ])
  29.  
  30. alloted_person = club_ass(job_person)
  31. for idx,person in enumerate(alloted_person):
  32.     print(f'job {idx} person{person}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement