How to get the square root(sum of binary decission variable)
AnsweredHi Team,
Hope you are doing well.
In this df i have defined the decission binary variable
| origin | fixed_cost | var_cost | cap | open |
| chennai | $ 50,000 | $ 2.23 | 400,000 | <gurobi.Var *Awaiting Model Update*> |
| bhopal | $ 56,000 | $ 2.32 | 240,000 | <gurobi.Var *Awaiting Model Update*> |
| jaipur | $ 65,000 | $ 2.25 | 300,000 | <gurobi.Var *Awaiting Model Update*> |
| kolkata | $ 65,000 | $ 2.45 | 200,000 | <gurobi.Var *Awaiting Model Update*> |
| nasik | $ 55,000 | $ 2.21 | 300,000 | <gurobi.Var *Awaiting Model Update*> |
| pune | $ 89,000 | $ 2.56 | 300,000 | <gurobi.Var *Awaiting Model Update*> |
| sonipat | $ 95,000 | $ 2.78 | 240,000 | <gurobi.Var *Awaiting Model Update*> |
My goal is to get the square root of (sum of "open") variable (√(∑(open)) )
I am looking forward to get resolved this shortly
Thanks
Munasib
0
-
Official comment
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. -
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
Post is closed for comments.
Comments
2 comments