当前位置: 首页>>代码示例>>Python>>正文


Python cvxpy.vstack方法代码示例

本文整理汇总了Python中cvxpy.vstack方法的典型用法代码示例。如果您正苦于以下问题:Python cvxpy.vstack方法的具体用法?Python cvxpy.vstack怎么用?Python cvxpy.vstack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cvxpy的用法示例。


在下文中一共展示了cvxpy.vstack方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: synth_h2_state_feedback_LMI

# 需要导入模块: import cvxpy [as 别名]
# 或者: from cvxpy import vstack [as 别名]
def synth_h2_state_feedback_LMI(A, Binput, Bdist, C1, D12):
    #Dullerud p 217 (?)
    
    n = A.shape[0]  #num states
    m = Binput.shape[1]  #num control inputs
    q = C1.shape[0]  #num outputs to "be kept small"

    X = cvxpy.Variable(n,n)
    Y = cvxpy.Variable(m,n)
    Z = cvxpy.Variable(q,q)
    
    tmp1 = cvxpy.hstack(X, (C1*X+D12*Y).T)
    tmp2 = cvxpy.hstack((C1*X+D12*Y), Z)
    tmp  = cvxpy.vstack(tmp1, tmp2)

    constraints = [A*X + Binput*Y + X*A.T + Y.T*Binput.T + Bdist*Bdist.T == -cvxpy.Semidef(n),
                   tmp == cvxpy.Semidef(n+q),
                  ]

    obj = cvxpy.Minimize(cvxpy.trace(Z))

    prob = cvxpy.Problem(obj, constraints)
    
    prob.solve(solver='CVXOPT', kktsolver='robust')
    
    K = -Y.value*np.linalg.inv(X.value)
    return K 
开发者ID:markwmuller,项目名称:controlpy,代码行数:29,代码来源:test_synth.py

示例2: get_constraints

# 需要导入模块: import cvxpy [as 别名]
# 或者: from cvxpy import vstack [as 别名]
def get_constraints(self, X_v, U_v, X_last_p, U_last_p):
        """
        Get model specific constraints.

        :param X_v: cvx variable for current states
        :param U_v: cvx variable for current inputs
        :param X_last_p: cvx parameter for last states
        :param U_last_p: cvx parameter for last inputs
        :return: A list of cvx constraints
        """
        # Boundary conditions:
        constraints = [
            X_v[:, 0] == self.x_init,
            X_v[:, -1] == self.x_final,

            U_v[:, 0] == 0,
            U_v[:, -1] == 0
        ]

        # Input conditions:
        constraints += [
            0 <= U_v[0, :],
            U_v[0, :] <= self.v_max,
            cvx.abs(U_v[1, :]) <= self.w_max,
        ]

        # State conditions:
        constraints += [
            X_v[0:2, :] <= self.upper_bound - self.robot_radius,
            X_v[0:2, :] >= self.lower_bound + self.robot_radius,
        ]

        # linearized obstacles
        for j, obst in enumerate(self.obstacles):
            p = obst[0]
            r = obst[1] + self.robot_radius

            lhs = [(X_last_p[0:2, k] - p) / (cvx.norm((X_last_p[0:2, k] - p)) + 1e-6) * (X_v[0:2, k] - p)
                   for k in range(K)]
            constraints += [r - cvx.vstack(lhs) <= self.s_prime[j]]
        return constraints 
开发者ID:EmbersArc,项目名称:SCvx,代码行数:43,代码来源:diffdrive_2d.py

示例3: cost

# 需要导入模块: import cvxpy [as 别名]
# 或者: from cvxpy import vstack [as 别名]
def cost(self):
        T, S = self.terminals[0].power_var.shape
        if self.final_energy_price is not None:
            if self.energy is None:
                self.energy = cvx.Variable(self.terminals[0].power_var.shape)
            cost = np.zeros((T - 1, S))
            final_cost = cvx.reshape(
                self.energy[-1, :] * self.final_energy_price[0, 0], (1, S))
            cost = cvx.vstack([cost, final_cost])
        else:
            cost = np.zeros(T, S)
        return cost 
开发者ID:cvxgrp,项目名称:cvxpower,代码行数:14,代码来源:devices.py

示例4: get_constraints

# 需要导入模块: import cvxpy [as 别名]
# 或者: from cvxpy import vstack [as 别名]
def get_constraints(self, X_v, U_v, X_last_p, U_last_p):
        """
        Get model specific constraints.

        :param X_v: cvx variable for current states
        :param U_v: cvx variable for current inputs
        :param X_last_p: cvx parameter for last states
        :param U_last_p: cvx parameter for last inputs
        :return: A list of cvx constraints
        """
        # Boundary conditions:
        constraints = [
            X_v[0, 0] == self.x_init[0],
            X_v[1:4, 0] == self.x_init[1:4],
            X_v[4:7, 0] == self.x_init[4:7],
            X_v[7:11, 0] == self.x_init[7:11],
            X_v[11:14, 0] == self.x_init[11:14],

            # X_[0, -1] == self.x_final[0], # final mass is free
            X_v[1:, -1] == self.x_final[1:],
            # U_v[1:3, -1] == 0,
        ]

        constraints += [
            # State constraints:
            X_v[0, :] >= self.m_dry,  # minimum mass
            cvx.norm(X_v[1: 3, :], axis=0) <= X_v[3, :] / self.tan_gamma_gs,  # glideslope
            cvx.norm(X_v[8:10, :], axis=0) <= np.sqrt((1 - self.cos_theta_max) / 2),  # maximum angle
            cvx.norm(X_v[11: 14, :], axis=0) <= self.w_B_max,  # maximum angular velocity

            # Control constraints:
            cvx.norm(U_v[0:2, :], axis=0) <= self.tan_delta_max * U_v[2, :],  # gimbal angle constraint
            # self.cos_delta_max * self.gamma <= U_v[2, :],

            cvx.norm(U_v, axis=0) <= self.T_max,  # upper thrust constraint
            # U_v[2, :] >= self.T_min  # simple lower thrust constraint

            # # Lossless convexification:
            # self.gamma <= self.T_max,
            # self.T_min <= self.gamma,
            # cvx.norm(U_v, axis=0) <= self.gamma
        ]

        # linearized lower thrust constraint
        lhs = [U_last_p[:, k] / (cvx.norm(U_last_p[:, k])) * U_v[:, k] for k in range(K)]
        constraints += [
            self.T_min - cvx.vstack(lhs) <= self.s_prime
        ]

        return constraints 
开发者ID:EmbersArc,项目名称:SCvx,代码行数:52,代码来源:rocket_landing_3d.py

示例5: get_constraints

# 需要导入模块: import cvxpy [as 别名]
# 或者: from cvxpy import vstack [as 别名]
def get_constraints(self, X_v, U_v, X_last_p, U_last_p):
        """
        Get model specific constraints.

        :param X_v: cvx variable for current states
        :param U_v: cvx variable for current inputs
        :param X_last_p: cvx parameter for last states
        :param U_last_p: cvx parameter for last inputs
        :return: A list of cvx constraints
        """
        # Boundary conditions:
        constraints = [
            X_v[0, 0] == self.x_init[0],
            X_v[1:4, 0] == self.x_init[1:4],
            X_v[4:7, 0] == self.x_init[4:7],
            # X_v[7:11, 0] == self.x_init[7:11],  # initial orientation is free
            X_v[11:14, 0] == self.x_init[11:14],

            # X_[0, -1] == self.x_final[0], # final mass is free
            X_v[1:, -1] == self.x_final[1:],
            U_v[1:3, -1] == 0,
        ]

        constraints += [
            # State constraints:
            X_v[0, :] >= self.m_dry,  # minimum mass
            cvx.norm(X_v[2: 4, :], axis=0) <= X_v[1, :] / self.tan_gamma_gs,  # glideslope
            cvx.norm(X_v[9:11, :], axis=0) <= np.sqrt((1 - self.cos_theta_max) / 2),  # maximum angle
            cvx.norm(X_v[11: 14, :], axis=0) <= self.w_B_max,  # maximum angular velocity

            # Control constraints:
            cvx.norm(U_v[1:3, :], axis=0) <= self.tan_delta_max * U_v[0, :],  # gimbal angle constraint
            cvx.norm(U_v, axis=0) <= self.T_max,  # upper thrust constraint
            # U_v[0, :] >= self.T_min  # simple lower thrust constraint
        ]

        # linearized lower thrust constraint
        rhs = [U_last_p[:, k] / cvx.norm(U_last_p[:, k]) * U_v[:, k] for k in range(X_v.shape[1])]
        constraints += [
            self.T_min <= cvx.vstack(rhs)
        ]

        return constraints 
开发者ID:EmbersArc,项目名称:SuccessiveConvexificationFreeFinalTime,代码行数:45,代码来源:model_6dof.py


注:本文中的cvxpy.vstack方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。