file = "/home/jajhall/HiGHS/src/interfaces/highs_python_api.py"
exec(compile(open(file).read(), file, 'exec'))

import math
import numpy as np
from scipy.optimize import linprog
from scipy.sparse import load_npz
from scipy import __version__ as spv

print("Using SciPy version ", spv)

# Load the sparse matrix, RHS and cost vector of an LP
#
# min c^Tx subject to Ax<=b, x>=0
#
# Example is ISRAEL from Netlib
A=load_npz('A.npz')
b=np.load('b.npy')
c=np.load('c.npy')

num_row = len(b)
num_col = len(c)
print("LP has ", num_col, " variables (columns) and ", num_row, " constraints (rows)")

# Use linprog to solve the LP with the HiGHS dual simplex solver
result=linprog(c, A_ub=A, b_ub=b, method='highs-DS')
print("linprog HiGHS dual simplex   optimal objective = ", result.fun)

# Use linprog to solve the LP with the HiGHS interior point solver
result=linprog(c, A_ub=A, b_ub=b, method='highs-ipm')
print("linprog HiGHS interior point optimal objective = ", result.fun)

# To use HiGHS directly, extract the individual lists from the sparse
# compressed column (CSC) matrix
a_start = A.indptr
a_index = A.indices
a_value = A.data

# Construct bounds of [0, inf) on the variables
col_lower = [0]*num_col
col_upper = [math.inf]*num_col

# Construct bounds of (-inf, b] on the constraints
row_lower = [-math.inf]*num_row
row_upper = b

# Construct a list of costs with a better name ;-)
col_cost = c

# Find the continuous solution of the LP
return_status, model_status, col_value, col_dual, row_value, row_dual , col_basis, row_basis = Highs_lpCall(
    col_cost, col_lower, col_upper, row_lower, row_upper, a_start, a_index, a_value)

objective_function_value = col_cost @ col_value
print("Direct  HiGHS dual simplex   optimal objective = ", objective_function_value)

