Unfortunately this is only half of the story. You will not be able to load this results object via instance.load(results) because it lacks what we call a symbol map. Fortunately, you can create one using the 'mytol.row' and 'mytol.col' files. For instance, parsing the 'mytol.col' file, will give you a mapping from a symbol inside the results object you just created above to variable name in your instance. The 'mytoy.row' file works the same for constraints and the objective, where the last name in the file is for the objective. Rather than going into more detail, here is the rest of the code that you would need to generate these symbols and load the results:
# Parse row and col files
with open('mytoy.col') as f:
varnames = [line.strip() for line in f.readlines()]
with open('mytoy.row') as f:
connames = [line.strip() for line in f.readlines()]
objname = connames.pop()
# Create symbol map identical to that generated by
# the NL file interface
symbol_map = SymbolMap(instance)
symbol_list = []
for cntr, name in enumerate(varnames):
symbol = 'v'+str(cntr)
component = instance.find_component(name)
symbol_list.append((component, symbol))
for cntr, name in enumerate(connames):
symbol = 'c'+str(cntr)
component = instance.find_component(name)
symbol_list.append((component, symbol))
symbol = 'o'+str(cntr)
component = instance.find_component(objname)
symbol_list.append((component, symbol))
symbol_map.updateSymbols(symbol_list)
# Add symbol_map to results object and load results
results._symbol_map = symbol_map
instance.load(results)
This is clearly a hack for your use case, and will look much different if you decide to use a different solver interface (e.g., LP files), so don't expect this to work in all cases and note that it is subject to break at any point in the future if we update Pyomo.
Gabe