Advertisement
Oppaceted

main

May 27th, 2024
384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.73 KB | None | 0 0
  1. from drawing import *
  2. from reduction_to_canonical_form import *
  3. from CreateW import *
  4. from os import system
  5.  
  6. N = int(input("Введите число переменных: "))
  7. M = int(input("Введите количество уравнения: "))
  8. Functional_koeff = []
  9. for i in range(N):
  10.     Functional_koeff.append(float(input(f"L_{i+1}: ") ) )
  11. print("f = ", end= "")
  12. ShowFunctional(N, Functional_koeff)
  13. B = [] #вектор
  14. A = [] #матрица
  15.  
  16. for i in range(M):
  17.     A.append([])
  18.     for j in range(N):
  19.         A[i].append("*")
  20.  
  21. for i in range(M):
  22.     for j in range(N):
  23.         system("cls")
  24.         ShowMatrixElement(A, i, j)
  25.         A[i][j]=(float(input(f"A_{i+1,j+1}=")))
  26. system("cls")
  27. ShowMatrixElement(A, -1, -1)
  28. input()
  29. system("cls")
  30. for i in range(M):
  31.     B.append(float(input(f"B_{i+1}=")))
  32.  
  33. #print(A)#отладка
  34. #print(B)#отладка
  35. input()
  36. while(True):
  37.     system("cls")
  38.     enter = input('Определите ограничение: ')
  39.     if(enter ==  "Больше"):
  40.         more = True
  41.         break
  42.     elif(enter ==  "Меньше"):
  43.         more = False
  44.         break
  45.     #more = True if enter == "Больше" else False if enter == "Меньше" else exit(0)
  46.     #Это тернарный оператор. Он нужен, чтобы писать в одну стрчоку вместо нескольких
  47.  
  48. for i in range(M):
  49.     for j in range(N):
  50.         print(f"{A[i][j]}x_{j+1}", end = " ")
  51.         print(end=( (f"\u2265 {B[i]}\n" if more else f"\u2264 {B[i]}\n" ) if (j == N-1) else "+ " ) )
  52. print("F = ", end ="");ShowFunctional(N, Functional_koeff)
  53.  
  54. SetToCanon(A, N, M, more)
  55. input()
  56. system("cls")
  57.  
  58. for i in range(M):
  59.     for j in range( len( A[0] ) ):
  60.         print(f"{A[i][j]}x_{j+1}", end = " ")
  61.         if j != ( len(A[0])-1 ):
  62.             print(end=" +  ")
  63.     print(f"={B[i]}", end="\n\n")
  64.  
  65. for i in range(M):
  66.     for j in range( len( A[0] ) ):
  67.         A[i][j] = A[i][j]*-1
  68.  
  69. headers = []        
  70. for j in range(len(A[0])):
  71.     headers.append(f'x_{j+1}')
  72. column = []        
  73. for i in range(len(A)):
  74.     column.append(f'y_{i+1}')
  75.  
  76.  
  77. input_W = CreateW(A, B, column, headers)    
  78. ShowTable(A, B, column, headers, input_W)
  79. for i in range(M):
  80.     u=ChooseVariables(A, B, CreateW(A, B, column, headers))
  81.     ChangeVariables(A, B, u[0], u[1], column, headers, True)
  82.    
  83. G = RemoveExtraVars(A, B, N, column, headers)
  84. A = G[0]
  85. B = G[1]
  86. column = G[2]
  87. headers = G[3]
  88.  
  89. Functional_koeff = ChangeFunctional(column, Functional_koeff)
  90.  
  91. input_F = CreateF(A, B, Functional_koeff)
  92. ShowTable(A, B, column, headers, input_F)
  93.  
  94. while CheckCondition(input_F):
  95.     u = ChooseVariables(A, B, input_F)
  96.     ChangeVariables(A, B, u[0], u[1], column, headers, False, input_F)
  97.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement