Source code for picos.constraints.con_rsoc

# coding: utf-8

# ------------------------------------------------------------------------------
# Copyright (C) 2018-2019 Maximilian Stahlberg
# This file is part of PICOS.
# PICOS is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# PICOS is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <>.
# ------------------------------------------------------------------------------

"""Rotated second order cone constraints."""

from collections import namedtuple

from .. import glyphs
from ..apidoc import api_end, api_start
from .constraint import Constraint

_API_START = api_start(globals())
# -------------------------------

[docs]class RSOCConstraint(Constraint): """Rotated second order cone membership constraint."""
[docs] def __init__(self, normedExpression, upperBoundFactor1, upperBoundFactor2=None, customString=None): """Construct a :class:`RSOCConstraint`. :param ~picos.expressions.AffineExpression normedExpression: Expression under the norm. :param ~picos.expressions.AffineExpression upperBoundFactor1: First of the two scalar factors that make the upper bound on the normed expression. :param ~picos.expressions.AffineExpression upperBoundFactor2: Second of the two scalar factors that make the upper bound on the normed expression. :param str customString: Optional string description. """ from ..expressions import AffineExpression if upperBoundFactor2 is None: upperBoundFactor2 = AffineExpression.from_constant(1) assert isinstance(normedExpression, AffineExpression) assert isinstance(upperBoundFactor1, AffineExpression) assert isinstance(upperBoundFactor2, AffineExpression) assert len(upperBoundFactor1) == 1 assert len(upperBoundFactor2) == 1 = normedExpression self.ub1 = upperBoundFactor1 self.ub2 = upperBoundFactor2 super(RSOCConstraint, self).__init__( self._get_type_term(), customString, printSize=True)
def _get_type_term(self): return "RSOC" Subtype = namedtuple("Subtype", ("argdim",)) def _subtype(self): return self.Subtype(len( @classmethod def _cost(cls, subtype): return subtype.argdim + 2 def _expression_names(self): yield "ne" yield "ub1" yield "ub2" def _str(self): a = glyphs.le(glyphs.squared(glyphs.norm(, glyphs.clever_mul(self.ub1.string, self.ub2.string)) b =, 0) return glyphs.and_(a, b) def _get_size(self): return (len( + 2, 1) def _get_slack(self): return self.ub1.value * self.ub2.value - (abs(**2).value
# -------------------------------------- __all__ = api_end(_API_START, globals())