Advertisement
Oppaceted

main

May 26th, 2024
566
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.86 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.  
  34. print(A)#отладка
  35. print(B)#отладка
  36. input()
  37. while(True):
  38.     system("cls")
  39.     enter = input('Определите ограничение: ')
  40.     if(enter ==  "Больше"):
  41.         more = True
  42.         break
  43.     elif(enter ==  "Меньше"):
  44.         more = False
  45.         break
  46.     #more = True if enter == "Больше" else False if enter == "Меньше" else exit(0)
  47.     #Это тернарный оператор. Он нужен, чтобы писать в одну стрчоку вместо нескольких
  48.  
  49. for i in range(M):
  50.     for j in range(N):
  51.         print(f"{A[i][j]}x_{j+1}", end = " ")
  52.         print(end=( (f"\u2265 {B[i]}\n" if more else f"\u2264 {B[i]}\n" ) if (j == N-1) else "+ " ) )
  53. print("F = ", end ="");ShowFunctional(N, Functional_koeff)
  54.  
  55. SetToCanon(A, N, M, more)
  56. input()
  57. system("cls")
  58.  
  59. for i in range(M):
  60.     for j in range( len( A[0] ) ):
  61.         print(f"{A[i][j]}x_{j+1}", end = " ")
  62.         if j != ( len(A[0])-1 ):
  63.             print(end=" +  ")
  64.     print(f"={B[i]}", end="\n\n")
  65.  
  66. for i in range(M):
  67.     for j in range( len( A[0] ) ):
  68.         A[i][j] = A[i][j]*-1
  69.  
  70. headers = []        
  71. for j in range(len(A[0])):
  72.     headers.append(f'x_{j+1}')
  73. column = []        
  74. for i in range(len(A)):
  75.     column.append(f'y_{i+1}')
  76.  
  77. #W = []
  78. #ShowTable(A, B, W, column, headers)
  79. input_W = CreateW(A, B, column, headers)    
  80. ShowTable(A, B, column, headers, input_W)
  81. for i in range(M):
  82.     u=ChooseVariables(A, B, CreateW(A, B, column, headers))
  83.     #print(headers[u[1]])#отладка
  84.     ChangeVariables(A, B, u[0], u[1], column, headers, True)
  85.    
  86. G = RemoveExtraVars(A, B, N, column, headers)
  87. A = G[0]
  88. B = G[1]
  89. column = G[2]
  90. headers = G[3]
  91.  
  92. Functional_koeff = ChangeFunctional(column, Functional_koeff)
  93.  
  94. input_F = CreateF(A, B, Functional_koeff)
  95. ShowTable(A, B, column, headers, input_F)
  96.  
  97. count = 0
  98. while(CheckCondition(input_F) and count <= 20):
  99.     count += 1
  100.     u = ChooseVariables(A, B, input_F)
  101.     ChangeVariables(A, B, u[0], u[1], column, headers, False, input_F)
  102.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement