Skip to main content

Gurobipy addMConstr() raises GurobiError: Name too long when passing list of names

Answered

Comments

7 comments

  • Jaromił Najman
    Gurobi Staff Gurobi Staff

    Could you please post a minimal reproducible example? Which Gurobi version are you using?

    0
  • Christian Perau
    Gurobi-versary
    Curious
    Conversationalist

    Sure, following code will raise the described error:

    import gurobipy as gp
    import scipy.sparse as sp
    import numpy as np
    model = gp.Model()
    n = 1000
    data = np.full(n, 1)
    row = np.arange(n)
    col = np.arange(n)
    sense = np.full(n, '=')
    b = np.full(n, 1)
    names = list(map(str, range(n)))
    A = sp.csr_matrix((data, (row, col)))
    x = model.addMVar(A.get_shape()[1])
    model.addMConstr(A, x, sense, b, names)

    I am using gurobipy 9.5.2 and guroby version 912 on windows 10. 

    0
  • Jaromił Najman
    Gurobi Staff Gurobi Staff

    Thank you for posting this example.

    I can reproduce the issue and am investigating. I will post here about my findings.

    0
  • Jaromił Najman
    Gurobi Staff Gurobi Staff

    After investigation, the \(\texttt{name}\) argument is indeed meant to be exactly 1 string, which will then be automatically indexed \(\texttt{name[i]}\) for each constraint. The current documentation does not properly reflect this.

    I marked this as a feature request and this will probably be implemented in a future release.

    0
  • Christian Perau
    Gurobi-versary
    Curious
    Conversationalist

    Thanks for the quick response! I´m not sure I got this right, though. The problem is the implementation via gurobipy or in gurobi itself? Do you know where I could have a look in the future if I want to see if this has been implemented? Until now I have only found release notes for main relases of gurobipy (like 9.5) but since I guess this is more of a minor feature I am not sure where to look for it in the future. Thanks in advance!

    0
  • Jaromił Najman
    Gurobi Staff Gurobi Staff

    The problem is the implementation via gurobipy or in gurobi itself?

    Currently, there is no problem with either implementation. The addMVar function is not meant to accept a list of strings for constraint names but rather only a single string which will be automatically used for name generation. The documentation does not make it clear enough and will be improved with the upcoming release.

    Do you know where I could have a look in the future if I want to see if this has been implemented?

    Changes in the API will only be implemented in a major version and will be mentioned in the corresponding release notes. Minor changes in the documentation usually do not make it into the release notes.

    0
  • Christian Perau
    Gurobi-versary
    Curious
    Conversationalist

    For anyone wondering: From version 10.0.0 this is implemented and working correctly.

    2

Please sign in to leave a comment.