Skip to main content

how to write this objective function in python

Answered

Comments

1 comment

  • Simranjit Kaur
    Gurobi Staff Gurobi Staff

    Hi,

    You can model your objective function with the help of adding general constraints that model the exponential function (for example, with the method addGenConstrExp if using the Python API), and using the trick in the article How do I divide by a variable in Gurobi?. Specifically, you can do something like below, where aux, exp, z, and q are helper variables:

    m.addConstrs( aux[i] == gp.quicksum( (a[i] + p[i,j] - b[i]*w[i,j]) * y[i,j] for j in range(N) ) for i in range(M))

    for i in range(M):
    m.addGenConstrExp(exp[i], aux[i])
      m.addConstr( z[i] * (1+exp[i]) == 1)
    m.addConstr( q[i] == exp[i] * z[i])

    obj = gp.quicksum( p[i,j] * q[i] for i in range(M) for j in range(N))
    m.setObjective(obj)

    Best regards,
    Simran

    0

Please sign in to leave a comment.