
# The lpLib library is a LP-library that can easily load UB, LB and EQ constraints

import lpLib as LP
isMinProblem = False
LP.coefficients([-5,4,-3,5],isMinProblem)
LP.equalityConstraint(-3,[ 4, -1, 3, -1])
LP.upperBound(15, [1, 1, 4, -2])
LP.lowerBound(3, [-2,3,-2,2])                
res = LP.lpSolve()
if not res.success:
    print("No solution found")

    

import simplexLib as LP
LP.coefficients([-5,4,-3,5]) # Define ojecive function. Default for SIMPLEX is to MAXIMIZE!
LP.printProblem()
LP.equalityConstraint(-3,[ 4, -1, 3, -1]) # For an quality constraint, there is usually no corrsponding "basic variable", use Big M to add a basic variable
LP.printProblem()

LP.upperBound(15, [1, 1, 4, -2]) # For the upper bound constraint, we add a slack varaible, which acts as a basic variable
LP.printProblem()

LP.lowerBound(3, [-2,3,-2,2]) # For a lower bound constraint, we add a surpulus variable, but also need a basic variable, again use Big M


LP.unboundVar(3) # Variable x_4 is not restricted to sign, we splitt into to variables. Note that coefficient for the (negative) "twin" is mutiplied with -1
'''

logical variables x_1,x_2,...,x_4 goes to x[0],x[1],...,x[3]
x[4] = First basic variables with "Big M" created by the equalityConstraint() functino
x[5] = Slack variable, becomes the second basic variable, no need for "Big M"
x[6] = Surpulus variable, cannot be used as basic variable
x[7] = Third basic variable, created by "Big M" together with x[6] by the lowerBound() function
x[8] = Variable created as a "negative twin" to x_4, i.e., x[3]. This means that if x[8]
       ends up with a positive value, x_4 is then equal to -x[8]

By the function calls above, the entire model will be on cannoncial form. To see the model, use printProblem()

'''

detailed = 2
LP.printProblem()
LP.SIMPLEX(detailed)  
    
