import highspy
import numpy as np
h = highspy.Highs()
inf = highspy.kHighsInf
print("\nLoading the model from an MPS file")
filename = 'model.mps'
h.readModel(filename)
h.run()
print("\nBuilding a model using single variables and constraints")
h.clear()
lower = 0
upper = 4
h.addVar(lower, upper)
h.addVar(1, inf)
cost = 1
h.changeColCost(0, cost)
h.changeColCost(1, 1)
lower = -inf
upper = 7
num_nz = 1
index = 1
value = 1
h.addRow(lower, upper, num_nz, index, value)
num_nz = 2
index = np.array([0, 1])
value = np.array([1, 2], dtype=np.double)
h.addRow(5, 15, num_nz, index, value)
num_nz = 2
value = np.array([3, 2], dtype=np.double)
h.addRow(6, inf, num_nz, index, value)
lp = h.getLp()
num_nz = h.getNumNz()
print('LP has ', lp.num_col_, ' columns', lp.num_row_, ' rows and ', num_nz, ' nonzeros')
h.clear()
print("\nBuilding a model using multiple variables and constraints")
cost = np.array([1, 1], dtype=np.double)
lower = np.array([0, 1], dtype=np.double)
upper = np.array([4, inf], dtype=np.double)
num_nz = 0
start = 0
index = 0
value = 0
h.addCols(2, cost, lower, upper, num_nz, start, index, value)
lower = np.array([-inf, 5, 6], dtype=np.double)
upper = np.array([7, 15, inf], dtype=np.double)
num_nz = 5
start = np.array([0, 1, 3])
index = np.array([1, 0, 1, 0, 1])
value = np.array([1, 1, 2, 3, 2], dtype=np.double)
h.addRows(3, lower, upper, num_nz, start, index, value)
h.writeModel("")
h.run()
h.clear()
print("Passing the model via HighsLp")
lp = highspy.HighsLp()
lp.num_col_ = 2;
lp.num_row_ = 3;
lp.col_cost_ = np.array([1, 1], dtype=np.double)
lp.col_lower_ = np.array([0, 1], dtype=np.double)
lp.col_upper_ = np.array([4, inf], dtype=np.double)
lp.row_lower_ = np.array([-inf, 5, 6], dtype=np.double)
lp.row_upper_ = np.array([7, 15, inf], dtype=np.double)
lp.a_matrix_.start_ = np.array([0, 2, 5])
lp.a_matrix_.index_ = np.array([1, 2, 0, 1, 2])
lp.a_matrix_.value_ = np.array([1, 3, 1, 2, 2], dtype=np.double)
h.passModel(lp)
h.writeModel("")
h.run()