我不确定这是否是您要查找的内容,但这是在某些脚本中打印一些变量的一种方式。
from pyomo.environ import *from pyomo.opt import SolverFactoryfrom pyomo.core import VarM = AbstractModel()opt = SolverFactory('glpk')# Vars, Params, Objective, Constraints....instance = M.create_instance('input.dat') # reading in a datafileresults = opt.solve(instance, tee=True)results.write()instance.solutions.load_from(results)for v in instance.component_objects(Var, active=True): print ("Variable",v) varobject = getattr(instance, str(v)) for index in varobject: print (" ",index, varobject[index].value)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)