File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
docs/src/interfaces/python Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -67,3 +67,32 @@ h.readModel(filename)
6767h.run()
6868print (' Model ' , filename, ' has status ' , h.getModelStatus())
6969```
70+
71+ ## Extracting values efficiently
72+
73+ When arrays of values are returned by ` highspy ` , accessing them
74+ entry-by-entry can be very slow. Such arrays should first be converted
75+ into lists. The following example illustrates how the method
76+ ` getSolution() ` is used to obtain the solution of a model.
77+
78+ ``` python
79+ import highspy
80+
81+ h = highspy.Highs()
82+ h.readModel(' model.mps' )
83+ h.run()
84+
85+ solution = h.getSolution()
86+ num_vars = len (solution.col_value)
87+
88+ value = [solution.col_value[icol]
89+ for icol in range (num_vars)]
90+
91+ col_value = list (solution.col_value)
92+ value = [col_value[icol]
93+ for icol in range (num_vars)]
94+ ```
95+
96+ For an example LP that is solved in 0.025s, accessing the values
97+ directly from ` solution.col_value ` takes 0.04s. Forming the list
98+ ` col_value ` and accessing the values directly from it takes 0.0001s.
You can’t perform that action at this time.
0 commit comments