Advertisement
999ms

simplex for gays!

Apr 27th, 2020
645
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.27 KB | None | 0 0
  1. def read_matrix():
  2.     return [list(map(float, input().split())) for _ in range(3)]
  3.  
  4. def transponse(a):
  5.     return [[a[j][i] for j in range(3)] for i in range(3)]
  6.  
  7. a = transponse(read_matrix())
  8.  
  9. # sum(aik * zi) >= 1
  10. # sum(zi) -> min
  11.  
  12. min_val = 1e18
  13. ans = [0, 0, 0]
  14.  
  15. def func(a, z1, z2, z3):
  16.     for i in range(3):
  17.         if a[i][0] * z1 + a[i][1] * z2 + a[i][2] * z3 < 1:
  18.             return 1e18
  19.     return z1 + z2 + z3
  20.  
  21. for i in range(101):
  22.     for j in range(101):
  23.         for k in range(101):
  24.             res = func(a, i / 100, j / 100, k / 100)
  25.             if res < min_val:
  26.                 min_val = res
  27.                 ans = [i / 100, j / 100, k / 100]
  28.  
  29. print(min_val)
  30. print(ans)
  31. print([ans[i] / min_val for i in range(3)])
  32.  
  33. a = transponse(a)
  34.  
  35. max_val = -1e18
  36. ans = [0, 0, 0]
  37.  
  38. def func(a, z1, z2, z3):
  39.     for i in range(3):
  40.         if a[i][0] * z1 + a[i][1] * z2 + a[i][2] * z3 > 1:
  41.             return -1e18
  42.     return z1 + z2 + z3
  43.  
  44. for i in range(101):
  45.     for j in range(101):
  46.         for k in range(101):
  47.             res = func(a, i / 100, j / 100, k / 100)
  48.             if res > max_val:
  49.                 max_val = res
  50.                 ans = [i / 100, j / 100, k / 100]
  51.  
  52. print(max_val)
  53. print(ans)
  54. print([ans[i] / max_val for i in range(3)])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement