メインコンテンツへスキップ

gurobipy.GurobiError: Name too long (maximum name length is 255 characters (python)

回答済み

コメント

2件のコメント

  • Riley Clement
    Gurobi Staff Gurobi Staff

    Hi Chao,

    One option is to supply all the names as a list to the addVars function.  As and example, instead of

    A = ["mylongindexname_a", "mylongindexname_b", "mylongindexname_c"]
    B = [1,2]

    x = m.addVars(A,B, name="my_var")

    use

    import itertools

    def make_name(key):
        indexA, indexB = key
        return f"my_var_{indexA.split('_')[1]}_{indexB}"

    names = [make_name(key) for key in itertools.product(A,B)]
    x = m.addVars(itertools.product(A,B), name=names)

    You will need to define your make_name function to map the keys to your desired (and simplified) name structure.

    - Riley

    0
  • Chao Guo
    Gurobi-versary
    First Comment
    First Question

    Dear Riley,

     

    Thank you so much for your help! My problem is perfectly solved.

     

    -Chao

    0

サインインしてコメントを残してください。