import numpy as np
from scipy import linalg
from cvxpy import *
#Denote for A Matrix
A = np.matrix([[1, 1, 1, 0, 0],
[-1, 1, 0, 1, 0],
[1, -1, 0, 0, 1]])
#Denoting b for constraints
b = np.array([3, 2, 0])
#Denoting C for objective function coefficient values
c = np.array([-2, 0, 0, 0, 0])
def compute_basic_solutions(val1, val2, val3):
val1 -= 1
val2 -= 1
val3 -= 1
A_B = A[:, (val1, val2, val3)]
c_B = c[(val1, val2, val3),]
print("A_B = ")
print(A_B)
print("c_B = ")
print(c_B)
x_B = linalg.inv(A_B).dot(b)
print("x_B = [x_{0}, x_{1}, x_{2}] = ".format(val1 + 1, val2 + 1, val3 + 1))
print(x_B)
print(compute_basic_solutions(1,3,4))
A_B = [[ 1 1 0] [-1 0 1] [ 1 0 0]] c_B = [-2 0 0] x_B = [x_1, x_3, x_4] = [0. 3. 2.] None
print(compute_basic_solutions(1,2,5))
A_B = [[ 1 1 0] [-1 1 0] [ 1 -1 1]] c_B = [-2 0 0] x_B = [x_1, x_2, x_5] = [0.5 2.5 2. ] None
print(compute_basic_solutions(1,4,5))
A_B = [[ 1 0 0] [-1 1 0] [ 1 0 1]] c_B = [-2 0 0] x_B = [x_1, x_4, x_5] = [ 3. 5. -3.] None
print(compute_basic_solutions(1,2,4))
A_B = [[ 1 1 0] [-1 1 1] [ 1 -1 0]] c_B = [-2 0 0] x_B = [x_1, x_2, x_4] = [1.5 1.5 2. ] None
print(compute_basic_solutions(2,3,4))
A_B = [[ 1 1 0] [ 1 0 1] [-1 0 0]] c_B = [0 0 0] x_B = [x_2, x_3, x_4] = [0. 3. 2.] None
print(compute_basic_solutions(2,4,5))
A_B = [[ 1 0 0] [ 1 1 0] [-1 0 1]] c_B = [0 0 0] x_B = [x_2, x_4, x_5] = [ 3. -1. 3.] None
print(compute_basic_solutions(3,4,5))
A_B = [[1 0 0] [0 1 0] [0 0 1]] c_B = [0 0 0] x_B = [x_3, x_4, x_5] = [3. 2. 0.] None