fork download
  1. import itertools
  2. import pandas as pd
  3.  
  4. costs = {
  5. 'D1': {'P1':45,'P2':50,'P3':55,'P4':60,'P5':65},
  6. 'D2': {'P1':52,'P2':48,'P3':47,'P4':55,'P5':58},
  7. 'D3': {'P1':50,'P2':46,'P3':54,'P4':57,'P5':56},
  8. 'D4': {'P1':47,'P2':53,'P3':51,'P4':49,'P5':59},
  9. 'D5': {'P1':55,'P2':52,'P3':50,'P4':48,'P5':46}
  10. }
  11.  
  12. divs=list(costs.keys())
  13. projs=list(costs['D1'].keys())
  14.  
  15. best=None
  16. best_cost=1e9
  17.  
  18. for perm in itertools.permutations(projs):
  19. total=sum(costs[divs[i]][perm[i]] for i in range(5))
  20. if total<best_cost:
  21. best_cost=total
  22. best=dict(zip(divs,perm))
  23.  
  24. best, best_cost
  25.  
Success #stdin #stdout 3.59s 77920KB
stdin
30 499887702
128990795 137274936
575374246 989051853
471048785 85168425
640066776 856699603
819841327 611065509
704171581 22345022import itertools
import pandas as pd

costs = {
    'D1': {'P1':45,'P2':50,'P3':55,'P4':60,'P5':65},
    'D2': {'P1':52,'P2':48,'P3':47,'P4':55,'P5':58},
    'D3': {'P1':50,'P2':46,'P3':54,'P4':57,'P5':56},
    'D4': {'P1':47,'P2':53,'P3':51,'P4':49,'P5':59},
    'D5': {'P1':55,'P2':52,'P3':50,'P4':48,'P5':46}
}

divs=list(costs.keys())
projs=list(costs['D1'].keys())

best=None
best_cost=1e9

for perm in itertools.permutations(projs):
    total=sum(costs[divs[i]][perm[i]] for i in range(5))
    if total<best_cost:
        best_cost=total
        best=dict(zip(divs,perm))

best, best_cost

536108301 678298936
119980848 616908153
117241527 28801762
325850062 478675378
623319578 706900574
998395208 738510039
475707585 135746508
863910036 599020879
340559411 738084616
122579234 545330137
696368935 86797589
665665204 592749599
958833732 401229830
371084424 523386474
463433600 5310725
210508742 907821957
685281136 565237085
619500108 730556272
88215377 310581512
558193168 136966252
475268130 132739489
303022740 12425915
122379996 137199296
304092766 23505143
stdout
Standard output is empty