Skip to content

Commit db50752

Browse files
committed
Made use of solution in Python examples, stressing the inefficiency of not converting to a list in each ocurrence
1 parent 7f2df19 commit db50752

File tree

3 files changed

+44
-6
lines changed

3 files changed

+44
-6
lines changed

examples/call_highs_from_python.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,12 +328,11 @@ def user_callback(
328328
solution = h.getSolution()
329329
basis = h.getBasis()
330330
info = h.getInfo()
331-
#
332-
col_status = basis.col_status
333-
col_value = list(solution.col_value)
334331
# basis.col_status is already a list, but accessing values in
335332
# solution.col_value directly is very inefficient, so convert it to a
336333
# list
334+
col_status = basis.col_status
335+
col_value = list(solution.col_value)
337336
model_status = h.getModelStatus()
338337
print("Model status = ", h.modelStatusToString(model_status))
339338
print("Optimal objective = ", info.objective_function_value)

examples/call_highs_from_python_highspy.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
print()
3636

3737
# Print solution information
38-
# solution = h.getSolution()
39-
# basis = h.getBasis()
38+
solution = h.getSolution()
39+
basis = h.getBasis()
4040
info = h.getInfo()
4141
model_status = h.getModelStatus()
4242

@@ -49,4 +49,23 @@
4949
h.solutionStatusToString(info.dual_solution_status))
5050
print('Basis validity = ', h.basisValidityToString(info.basis_validity))
5151

52+
# basis.col_status is already a list, but accessing values in
53+
# solution.col_value directly is very inefficient, so convert it to a
54+
# list
55+
col_status = basis.col_status
56+
row_status = basis.row_status
57+
col_value = list(solution.col_value)
58+
row_value = list(solution.row_value)
59+
60+
num_var = h.getNumCol()
61+
num_row = h.getNumRow()
62+
print("Variables")
63+
for icol in range(num_var):
64+
print(icol, col_value[icol],
65+
h.basisStatusToString(col_status[icol]))
66+
print("Constraints")
67+
for irow in range(num_row):
68+
print(irow, row_value[irow],
69+
h.basisStatusToString(row_status[irow]))
70+
5271
h.clear()

examples/call_highs_from_python_mps.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# Initialize an instance of Highs
1313
# h = highspy.Highs()
1414
# Here we are re-using the one from above.
15-
h.readModel('check/instances/25fv47.mps')
15+
h.readModel('check/instances/avgas.mps')
1616

1717
# Print
1818
lp = h.getLp()
@@ -37,3 +37,23 @@
3737
print('Dual solution status = ',
3838
h.solutionStatusToString(info.dual_solution_status))
3939
print('Basis validity = ', h.basisValidityToString(info.basis_validity))
40+
41+
# basis.col_status is already a list, but accessing values in
42+
# solution.col_value directly is very inefficient, so convert it to a
43+
# list
44+
col_status = basis.col_status
45+
row_status = basis.row_status
46+
col_value = list(solution.col_value)
47+
row_value = list(solution.row_value)
48+
49+
num_var = h.getNumCol()
50+
num_row = h.getNumRow()
51+
print("Variables")
52+
for icol in range(num_var):
53+
print(icol, col_value[icol],
54+
h.basisStatusToString(col_status[icol]))
55+
print("Constraints")
56+
for irow in range(num_row):
57+
print(irow, row_value[irow],
58+
h.basisStatusToString(row_status[irow]))
59+

0 commit comments

Comments
 (0)