Naming constraints error

Hello,
I have an optimization model, for which I’m trying to give names to its constraints so that I can write them to an lp file and find them easily. However, I’m having some trouble.
The constraint specifically that I’m trying to name looks like this:

@constraint(m, [ms in millStorageDayIndexes, pm in prodMills], millStorageDayLevel[ms] == pm.amountDay0)

where millStorageDayIndexes and prodMIills are both tuples with multiple fields each. I’ve tried to put a name, in the following way:

@constraint(m, millStorageConst[ms in millStorageDayIndexes, pm in prodMills], millStorageDayLevel[ms] == pm.amountDay0)

but I get the error: ERROR: Gurobi Error 10003: Name too long (maximum name length is 255 characters)
which I understand corresponds to the fact that the tuples used as indexes are too long to be a name.

Is there anyway I can choose specific fields of the tuple to use for the name, instead of the whole tuple, or anyother way of giving them a name?

Hi @irene_ub, welcome to the forum :smile:

Here’s an error that I don’t see often. Typically, people don’t have such long names!

You can change the name of a constraint: Constraints · JuMP

Perhaps something like this:

@constraint(m, millStorageConst[ms in millStorageDayIndexes, pm in prodMills], millStorageDayLevel[ms] == pm.amountDay0)
for con in millStorageConst
    set_name(con, name(con)[1:255])
end

I’ll open an issue in Gurobi.jl so we don’t run into this issue in future.

But it might be easier just to disable passing the names to Gurobi:

using JuMP, Gurobi
model = Model(Gurobi.Optimizer)
set_string_names_on_creation(model, false)