I am new in AMPL and Python and I am using amplpy to run an AMPL model, using lpopt solver. I need to get the output result of the solver in a way that I can act over it, i.e. I need to know if the optimal solution was found to decide if I can use the variables' final values or not; for lpopt, in the middle of all other outputs, it prints automatically "EXIT: Optimal Solution Found". I tried using the get_output_handler and OutputHandler classes, but I could not find a proper example on how it works and how to actually implement it. My idea is to get the "EXIT: ..." sentence and decide whether to save the variables' results or not, conceptually, it would look something like this:
'''
output_sentence = ampl.OutputHandler(...)
if output_sentence == "EXIT: Optimal Solution Found":
x = ampl.get_variable("x").get_values()
else:
x = nan
'''
Thank you in advance!