I found it hard, using Pyomo, to get that kind of information since Pyomo's results
object has a different structure depending on the solver that has been used.
To get around that, I consider that the ugly solution is still the most reliable one up to now, until someone shows me a better way.
Convert the results
object that was returned by the solve()
method into a String
using str(results)
. Find the text 'Time: '
in this string. Add all characters after the 'Time: '
substring that corresponds to a number and stop when you reach the \n
character. You now have the value you wanted.
Here is a function that I created and that I still use to get this kind of informations:
def get_info_from_results(results, info_string):
i = str(results).lower().find(info_string.lower()) + len(info_string)
value = ''
while str(results)[i] != '\n':
value = value + str(results)[i]
i += 1
return value
Using this function, you should get your solve time from your (let's call it) neos_results
object doing this:
solver_solve_time = get_info_from_results(neos_results, 'Time: ')
Keep in mind at this point that the value returned by this function is still considered by Python as a String
, so you might want to convert it to a number if you want to make calculations with it.