이 최적화 문제의 솔루션을 저장하려고 시도했지만 Nonetype
입니다. 그러므로 내가 float
로 변환 할하지만 난이 오류 얻을 :'Nonetype'에서 부동으로 변환 할 수없는 이유는 무엇입니까?
float() argument must be a string or a number, not 'NoneType'
그것은 드문 인해 results.write()
1 개에서 인쇄 된 솔루션에이 6.57142857142857입니다.
from coopr . pyomo import *
from pyomo.opt import SolverFactory
def create_model(N=[], M=[], c={}, a={}, b={}):
model = ConcreteModel()
model.x = Var(N, within=NonNegativeReals)
model.obj = Objective(expr=sum(c[i]*model.x[i] for i in N))
def con_rule(model, m):
return sum(a[i,m]*model.x[i] for i in N) >= b[m]
model.con = Constraint(M, rule=con_rule)
return model
model = create_model(N = [1,2], M = [1,2], c = {1:1, 2:2},
a = {(1,1):5, (2,1):4, (1,2):7, (2,2):3},
b = {1:11, 2:46})
#model.pprint()
instance = model.create()
#instance.pprint()
opt = SolverFactory("glpk")
results = opt.solve(instance, load_solutions=False)
results.write()
x_1=float(model.x[1].value)
#x_2=float(model.x[2].value or 0)