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

Speeding up Gurobi adding Constraint time

回答済み

コメント

4件のコメント

  • 正式なコメント
    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.
  • Michel Soares
    • Gurobi-versary
    • Thought Leader

    Hi,

    Take a look at addMConstr, in which you can add a matrix constraint. It should speed up your model building.

    0
  • Yen-Chun Liu
    • Gurobi-versary
    • First Comment
    • First Question

    Thank you for the reply. However I am confused - I have N(N-1)/2 1-dim constraint, each constraint resulting from the restriction of minimum distant between any (i,j), 1<=i<j<=N, pair of binary matrices. How can we reformulate it into a matrix constraint?

    0
  • Yen-Chun Liu
    • Gurobi-versary
    • First Comment
    • First Question

    ah! I fixed it by writing:

    It's much faster now! Thans

    for i in range(N-1):
        for k in range(i+1, N):
            g.addConstr(gu.quicksum((x[i,s,:] @ x[k,s,:].T) for s in range(q)) <= q*(1-C), name = "dist"+str(i)+str(k))
    
    0

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