Skip to main content

Speeding up Gurobi adding Constraint time

Answered

Comments

3 comments

  • 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
    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
    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

Please sign in to leave a comment.