from scipy.optimize import linprog
# Define the problem:
c = [8, 10, 6, 3]
A = [[1, 1,1,1], [0, 1,1,0],[0,0,2,-1]]
b = [50, 20,40]
# Change to minimization problem since scipy.optimize only supports "minimize"
for i in range(len(c)): 
    c[i] *= -1
#Use linprog from scipy.optimize for the minimization: 
res = linprog(c, A_ub=A, b_ub=b)
print("\nLP-solution with linprog directly\nZ=","{:5.0f}".format(-res.fun))
x=res.x
for i in range(len(c)):
    print("x_"+str(i+1)," =","{:3.0f}".format(x[i]),sep='')


# The lpLib library is a LP-library that can easily load UB, LB and EQ constraints
import lpLib as LP
print("\nSolution when specifying each constraints one by one using lpLib")
c = [8, 10, 6, 3]
LP.coefficients(c,False)
for i in range(len(b)):
    LP.upperBound(b[i],A[i])
LP.lpSolve()


import simplexLib as LP
print("\nSolution by simplexLib")
c = [8, 10, 6, 3]
LP.coefficients(c)
for i in range(len(b)):
    LP.upperBound(b[i],A[i])
detailed = 2
LP.printProblem()
LP.SIMPLEX(detailed)
