File: call_highs_from_python_mps.py

package info (click to toggle)
scipy 1.16.3-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 236,092 kB
  • sloc: cpp: 503,720; python: 345,302; ansic: 195,677; javascript: 89,566; fortran: 56,210; cs: 3,081; f90: 1,150; sh: 857; makefile: 792; pascal: 284; csh: 135; lisp: 134; xml: 56; perl: 51
file content (39 lines) | stat: -rw-r--r-- 1,072 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

# The path to the MPS file instance assumes that this is run 
# from the root directory.

import highspy
import numpy as np

# Highs h
h = highspy.Highs()

# Solve from mps file
# Initialize an instance of Highs
# h = highspy.Highs()
# Here we are re-using the one from above.
h.readModel('check/instances/25fv47.mps')

# Print
lp = h.getLp()
num_nz = h.getNumNz()
print('LP has ', lp.num_col_, ' columns',
      lp.num_row_, ' rows and ', num_nz, ' nonzeros')

# Solve the problem
h.run()

# Print solution information
solution = h.getSolution()
basis = h.getBasis()
info = h.getInfo()
model_status = h.getModelStatus()
print('Model status = ', h.modelStatusToString(model_status))
print()
print('Optimal objective = ', info.objective_function_value)
print('Iteration count = ', info.simplex_iteration_count)
print('Primal solution status = ',
      h.solutionStatusToString(info.primal_solution_status))
print('Dual solution status = ',
      h.solutionStatusToString(info.dual_solution_status))
print('Basis validity = ', h.basisValidityToString(info.basis_validity))