Pyomo / pyomo

An object-oriented algebraic modeling language in Python for structured optimization problems.
https://www.pyomo.org
Other
2.01k stars 518 forks source link

Indexing error #2764

Closed Malena205 closed 1 year ago

Malena205 commented 1 year ago

Hi, when trying to add an extra constraint I get the following error: raise DeveloperError( pyomo.common.errors.DeveloperError: Internal Pyomo implementation error: 'Unknown problem encountered when trying to retrieve index for component assign_to_open_cstr' Please report this to the Pyomo Developers.

This happens due to the following code: m.travel_pairs = pyo.Set(initialize=[(i, j) for i in m.set1 for j in m.set2]) m.assign_to_open_cstr = pyo.Constraint(m.pairs, rule=assign_to_open_cstr) And then later I try to add constraints: for (i,j) in new_pairs: m.assign_to_open_cstr.add(expr=assign_to_open_cstr(m,i,j), index=[i,j])

I think the way I format the index might just be wrong, but since the error told me to report this, this what I am doing.

jsiirola commented 1 year ago

Thank you for reporting this! The bugfix is up as #2765, but in the meantime, you can fix your model by changing

 m.assign_to_open_cstr.add(expr=assign_to_open_cstr(m,i,j), index=[i,j])

to

 m.assign_to_open_cstr.add(expr=assign_to_open_cstr(m, i, j), index=(i, j))

or

 m.assign_to_open_cstr[i, j] = assign_to_open_cstr(m, i, j)