8
$\begingroup$

I've been using CPLEX on the NEOS server, via Pyomo, to solve a binary program I'm working on.

NEOS is amazing, but the documentation is somewhat lacking on the Pyomo side, so I haven't been able to find out how I can access the solve time for an optimisation run. If I use a local solver on my machine (CBC) I can access the solve time in the results, and I can see it from the solver output, neither of which I get with CPLEX on NEOS.

Does anyone know how to do this?

Thanks

$\endgroup$
4
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.