2017-06-18 49 views
0

偶尔我在运行pyomo时出现这个错误:“错误:将对象评估为数值:0.0”。它看起来有点像某些求解器返回时产生的错误,例如,0.0而不是0,这会导致在重新使用结果时出现错误,例如,在Var函数的= Binary关键字参数内。我不认为这是这种情况。任何人都可以给我一些想法,以什么可能会导致此错误?我当时正在使用glpk。什么可能导致这pyomo错误:“错误:评估对象为数值”?

这里有一些更多的信息。我正在逐次解决优化问题,每天一次。因此,昨天的解决方案成为了今天问题的一个输入。这里有一些简化代码spinets:

results = manager.solve(instance, kwargs...) 
instance.solutions.load_from(results) 
states_dict = get_next_states(instance, time, args...) 

def get_next_states(instance, time, args...): 
    states_dict = {} 
    for state in states: 
     var = getattr(instance, state) 
     for a in a_list: 
      value = var[a, time].value 
      states_dict[state, a] = force_domain(value, integer, tolerance) 
    return states_dict 

force_domain力值是整数和/或非负,这取决于整数和公差参数。评估force_domain时代码失败;有时会出现上述错误,有时还会出现TypeError异常:TypeError:无法订购的类型:NoneType()< int()。这里是force_domain:

def force_domain(x, integer, nonnegative): 
    y = x 
    if x < 0 and nonnegative: 
     y = chop_tiny(y, nonnegative) 
    if integer: 
     y = round_if_int(y) 
    return y 

def chop_tiny(x, tol): 
    if abs(x) > tol or isinstance(x, int): 
     return x 
    else: 
     return 0.0 

def round_if_int(x): 
    if isinstance(x, float) and (x).is_integer(): 
     return int(x) 
    else: 
     return x 

这些错误发生在2000次运行的小于1次。

这个额外信息是否帮助您回答我的问题?

+1

欢迎来到StackOverflow!你能否提供这些代码,因为它将有助于回答问题。我建议阅读[如何提出一个好问题](https://stackoverflow.com/questions/how-to-ask)。另外,一定要参加[tour](https://stackoverflow.com/tour)。 –

+0

是的,请显示一些代码,以便我们可以给您一个更明智的回应。 –

回答

相关问题