Guest User

Untitled

a guest
Jul 17th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. costs = np.random.random((3,4))
  2.  
  3. config = [(0,0),(1,1),(2,2),(2,3)]
  4.  
  5. config = [(0,3),(1,3),(2,3),(2,3),(2,0),(2,1),(2,2)]
  6.  
  7. n0,n1 = costs.shape
  8.  
  9. def filterfn(config):
  10. # (1) each row but the last should be represented in the config
  11. cond1 = set(l[0] for l in config if l[0]!=n0-1) == set(range(n0-1))
  12. # (2) each column but the last should be represented in the config
  13. cond2 = set(l[1] for l in config if l[1]!=n1-1) == set(range(n1-1))
  14. # (3) each row but the last should be represented exactly once
  15. cond3 = len(set(l[0] for l in config if l[0]!=n0-1))==len([l[0] for l in config if l[0]!=n0-1])
  16. # (4) each column but the last should be represented exactly once
  17. cond4 = len(set(l[1] for l in config if l[1]!=n1-1))==len([l[1] for l in config if l[1]!=n1-1])
  18.  
  19. return cond1 and cond2 and cond3 and cond4
  20.  
  21. configs = []
  22. for r in range(max(s0,s1),s0+s1):
  23. r_configs = itertools.combinations(itertools.product(range(n0),range(n1)),r)
  24. r_configs = filter(lambda config: filterfn(config), r_configs)
  25. configs.extend(list(r_configs))
Add Comment
Please, Sign In to add comment