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

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

回答済み

コメント

3件のコメント

  • 正式なコメント
    Simranjit Kaur
    • Gurobi Staff
    This post is more than two years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum, or try Gurobot, our chatbot interface offering instant, expert-level support.
  • Riley Clement
    • 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

投稿コメントは受け付けていません。