本文整理匯總了Python中function.Function.quad_expr方法的典型用法代碼示例。如果您正苦於以下問題:Python Function.quad_expr方法的具體用法?Python Function.quad_expr怎麽用?Python Function.quad_expr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類function.Function
的用法示例。
在下文中一共展示了Function.quad_expr方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: initialize_traj
# 需要導入模塊: from function import Function [as 別名]
# 或者: from function.Function import quad_expr [as 別名]
def initialize_traj(self, mode):
# see comment at top of ll_prob.py for mode options
if self.trust_region_cnt is not None:
self.model.remove(self.trust_region_cnt)
self.clean(self.trust_temp)
for constraint in self.constraints:
constraint.clean()
obj = grb.QuadExpr()
for var in self.vars:
if var.get_val() is not None and var.recently_sampled:
obj += 1e5 * self.l2_norm_diff_squared(self.model, var)
elif var.get_val() is not None and var.is_resampled:
obj += 1 * self.l2_norm_diff_squared(self.model, var)
if mode == "straight":
obj += grb.quicksum(self.obj_quad)
elif mode == "l2":
for var in self.vars:
if var.get_val() is not None:
obj += self.l2_norm_diff_squared(self.model, var)
elif mode == "minvel":
for var in self.vars:
if var.hl_param.is_traj:
K = var.hl_param.num_dofs()
T = var.hl_param.num_timesteps()
KT = K * T
v = -1 * np.ones((KT - K, 1))
d = np.vstack((np.ones((KT - K, 1)), np.zeros((K, 1))))
# [:,0] allows numpy to see v and d as one-dimensional so
# that numpy will create a diagonal matrix with v and d as a diagonal
P = np.diag(v[:, 0], K) + np.diag(d[:, 0])
# minimum-velocity finite difference
Q = np.dot(np.transpose(P), P)
obj += Function.quad_expr((var.get_grb_vars(self) - var.get_val()).flatten(order="f"), Q)
else:
raise NotImplementedError
return self.optimize(objective=obj)