I'm trying to output the model variables after solving the optimization. I however would like only the variables values to go into the output file as opposed to the whole model. (It's a very large model with many large constraints and I would do better cutting down to just what I need)
I've tried:
(1) one shot print call:
model.component_objects(Var, descend_into=True).pprint(filename='fin_soln.txt')
(2) iterative printing (with appending .txt files being the next step)
f = open("fin_soln_2.txt","a+")
for v in model.component_objects(Var, descend_into=True):
print("FOUND VAR:" + v.name)
f.write("FOUND VAR:" + v.name + "\n")
v.pprint(filename=(v.name +'.txt'))
f.close()
As there are dozens of variables and the model is still being developed I would like something which is flexible and I don't have to keep updating as i add/delete variables from the model.
Thank you for your help.