简体   繁体   English

Python PuLP 递归错误

[英]Python PuLP RecursionError

I'm working in a LP problem with the PuLP Library and I have some strange that I can't explain by myself.我正在处理 PuLP 库的 LP 问题,我有一些我自己无法解释的奇怪问题。 I have nearly 100 variables and constraints, and I want to put it in my model, but I can't.我有近 100 个变量和约束,我想把它放在我的模型中,但我不能。 It tells me它告诉我

RecursionError: maximum recursion depth exceeded in comparison

First, I've tried to parse it in a for loop:首先,我尝试在 for 循环中解析它:

for cent_artic in df_demand['REQUIRED']:
    display(df_offers[df_offers['REQUIRED']==cent_artic])
    lista = list(df_ofertas1[df_ofertas1['REQUERIDO']==cent_artic]['OFERTADO'])
    display(lista)
    prob += lpSum(lista) >= cent_artic_dict[cent_artic], "Restriccion para cent_artic "+cent_artic 

And the RecursionError showed up. RecursionError 出现了。

I've tried to pass only one restriction to the problem:我试图只通过一个限制来解决这个问题:

prob += lpSum(['c-1_a-2757_p-13','c-1_a-2757_p-12','c-1_a-2757_p-188']) >= cent_artic_dict['c-1_a-2757']

And it's the same.这是一样的。 I can't understand why Python tell me something about a Error of Recursion, if I try to pass only one equation...我不明白为什么 Python 会告诉我一些关于递归错误的信息,如果我试图只传递一个方程......

cent_artic_dict = {'c-5_a-17372_p-188': var_c_5_a_17372_p_188,
                   'c-179_a-2757_p-188': var_c_179_a_2757_p_188,
                   'c-18_a-17372_p-188': var_c_18_a_17372_p_188,
                   'c-26_a-2757_p-18': var_c_26_a_2757_p_18,
                   'c-41_a-2757_p-18': var_c_41_a_2757_p_18,
                   'c-156_a-2757_p-188': var_c_156_a_2757_p_188,
                   'c-24_a-17372_p-188': var_c_24_a_17372_p_188, 
                   ...
                  }

Now, the dataframe of df_offers have a shape of (89,6).现在,df_offers 的数据框的形状为 (89,6)。 At the beginning, it was (89,21)一开始是(89,21)

Could anybody explain why I'm having the RecursionError?有人可以解释为什么我有 RecursionError 吗? Thank you.谢谢你。

I've seen another question about it, but it doesn't have answer, only an advice我看过另一个关于它的问题,但它没有答案,只有一个建议

I have very little idea what you are doing but i can point out that我不知道你在做什么,但我可以指出

prob += lpSum(['c-1_a-2757_p-13','c-1_a-2757_p-12','c-1_a-2757_p-188']) >= cent_artic_dict['c-1_a-2757']

is not valid because lpSum needs lists of LpVariables not strings是无效的,因为lpSum需要的名单LpVariables不是字符串

I had a similar issue and was getting the identical recursion error.我有一个类似的问题,并得到相同的递归错误。

For me, I had a data type issue, and my constraint value was stored as a string and not a number!对我来说,我有一个数据类型问题,我的约束值存储为字符串而不是数字! This is equivalent to the value in cent_artic_dict['c-1_a-2757'] in the original question.这相当于原始问题中cent_artic_dict['c-1_a-2757']中的值。 Once my right-hand side constraint was a number I was good to go.一旦我的右侧约束是一个数字,我就可以开始了。 Based on comments I think Krakenudo might have been facing a similar situation.根据评论,我认为 Krakenudo 可能面临类似的情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM