How to get squre root of QuadExpr
回答済みThis is a mean-variance optimization problem, where w is a vector of n*1, Omiga is a covariance matrix of n*n. in this problem,I can't get the
code is as follows,
vars_risk=m.addVar(obj=1,vtype=GRB.CONTINUOUS,name='risk')
om=np.multiply(sigma,np.identity(n))
om_risk=om.dot(vars).dot(vars)
objectfun= portfolio_return - lambda1/2*portfolio_risk - k*vars_risk
m.setObjective(objectfun, GRB.MAXIMIZE)
m.addGenConstrPow( om_risk, vars_risk,0.5 )
AttributeError: 'gurobipy.QuadExpr' object has no attribute '__cindex__'
-
正式なコメント
This post is more than three 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 why not try our AI Gurobot?. -
is put as
0 -
The addGenConstrPow method requires a single variable as xvar argument and not a QuadExpr object. Thus, you need to introduce an additional optimization variable and an additional equality constraint.
aux_var = m.addVar(vtype=GRB.CONTINUOUS, name="aux_var")
m.addConstr(om_risk == add_var, name="aux_eq")
m.addGenConstrPow(aux_var, vars_risk, 0.5)Best regards,
Jaromił0
投稿コメントは受け付けていません。
コメント
3件のコメント