Skip to main content

How to get the square root(sum of binary decission variable)

Answered

Comments

1 comment

  • Riley Clement
    Gurobi Staff Gurobi Staff

    Hi Mohd,

    You can decompose √(∑(open)) into two constraints:

    sum_open = model.addVar(ub=ub1, vtype="I")
    sqrt_sum_open = model.addVar(ub=ub2)

    model.addConstr(sum_open == df["open"].sum())
    model.addConstr(sum_open == sqrt_sum_open**2)

    Note that if there is a limit to how many "open" binary variables can be 1 in an optimal solution then you should use this value for ub1, and sqrt(ub1) for ub2.

    Note, if your objective function is simply sqrt_sum_open then you don't actually need the square root, you can use sum_open instead.

    - Riley

    0

Please sign in to leave a comment.