本文整理汇总了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)