Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. I have nearly 100 variables and constraints, and I want to put it in my model, but I can't. It tells me

RecursionError: maximum recursion depth exceeded in comparison

First, I've tried to parse it in a for loop:

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.

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...

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). At the beginning, it was (89,21)

Could anybody explain why I'm having the RecursionError? Thank you.

I've seen another question about it, but it doesn't have answer, only an advice

like image 311
Krakenudo Avatar asked Sep 26 '26 12:09

Krakenudo


1 Answers

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. 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.

like image 96
daddydan Avatar answered Sep 29 '26 01:09

daddydan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!