opengen.constraints package
Submodules
opengen.constraints.ball1 module
- class opengen.constraints.ball1.Ball1(center=None, radius: float = 1.0)
Bases:
Constraint
Ball1 aka Norm-1 Ball
Ball-1 with given radius, that is
\(\mathcal{B}_{1}(x_0, r) = \{x\in{\rm I\!R}^n {}:{} \|x - x_0\|_1 \leq r\}\)
- __init__(center=None, radius: float = 1.0)
Constructor for a Ball1
- Parameters
radius – ball radius (default: 1)
- Returns
New instance of Ball1 with given radius
- property center
Returns the center of the ball
- distance_squared(u)
Squared distance of a given point to the set
- Parameters
u – given point
- Returns
squared distance
- Return type
float
- is_compact()
Whether the set is compact
- is_convex()
Whether the set is convex
- project(u)
Project on the current Ball-1
- Parameters
u – vector u
- Returns
projection of u onto the current ball-1
- property radius
Returns the radius of this ball
opengen.constraints.ball2 module
- class opengen.constraints.ball2.Ball2(center=None, radius: float = 1.0)
Bases:
Constraint
A Euclidean ball constraint
A constraint of the form \(\|u-u_0\| \leq r\), where \(u_0\) is the center of the ball and r is its radius
- __init__(center=None, radius: float = 1.0)
Constructor for a Euclidean ball constraint
- Parameters
center – center of the ball; if this is equal to Null, the ball is centered at the origin
radius – radius of the ball
- Returns
New instance of Ball2 with given center and radius
- property center
Returns the center of the ball
- distance_squared(u)
Computes the squared distance between a given point u and this ball
- Parameters
u – given point; can be a list of float, a numpy n-dim array (ndarray) or a CasADi SX/MX symbol
- Returns
distance from set as a float or a CasADi symbol
- is_compact()
Whether the set is compact
- is_convex()
Whether the set is convex
- project(u)
Project a given point onto the set
- Parameters
u – given point
- Returns
projection of u onto this set
- property radius
Returns the radius of the ball
opengen.constraints.ball_inf module
- class opengen.constraints.ball_inf.BallInf(center=None, radius: float = 1.0)
Bases:
Constraint
Norm-ball of norm infinity translated by given vector
Centered inf-ball around given point, that is
\(\mathcal{B}_{\infty}(x_0, r) = \{x\in{\rm I\!R}^n {}:{} \|x - x_0\|_{\infty} \leq r\}\)
- __init__(center=None, radius: float = 1.0)
Constructor for an infinity ball constraint
- Parameters
center – center of the ball; if this is equal to Null, the ball is centered at the origin
radius – radius of the ball
- Returns
New instance of Ballinf with given center and radius
- property center
Returns the center of the ball
- distance_squared(u)
Squared distance of a given point to the set
- Parameters
u – given point
- Returns
squared distance
- Return type
float
- is_compact()
Whether the set is compact
- is_convex()
Whether the set is convex
- project(u)
Project a given point onto the set
- Parameters
u – given point
- Returns
projection of u onto this set
- property radius
Returns the radius of the ball
opengen.constraints.cartesian module
- class opengen.constraints.cartesian.CartesianProduct(segments: List[int], constraints: List[Constraint])
Bases:
Constraint
- __init__(segments: List[int], constraints: List[Constraint])
Cartesian product
\(X = X_1 \times X_1 \times \ldots \times X_s.\)
Construct a Cartesian product of constraints by providing a list of sets and their dimensions as follows: an n-dimensional vector x can be partitioned into subvectors as \(x = (x_{[1]}, x_{[2]}, ..., x_{[s]})\), where each \(x_{[i]}\) has dimension \(m_i\).
For example consider the 5-dimensional vector \(x = (x_0, x_1, x_2, x_3, x_4)\), which can be partitioned into \(x_{[1]} = (x_0, x_1)\) and \(x_{[2]} = (x_2, x_3, x_4)\). We can associate with \(x_{[1]}\) the indices [0, 1] and with \(x_{[2]}\) the indices [2, 3, 4]. The segment ids are the indices 1 and 4.
- Example:
In this example we shall define the set \(X = \mathcal{B}_{1.5} \times R \times {\rm I\!R}^{5}\), where \(\mathcal{B}_{1.5}\) is a Euclidean ball of dimension 2 with radius 1.5, \(R\) is a 3-dimensional rectangle with \(x_{\min} = (-1, -2, -3)\) and \(x_{\max} = (0, 10, -1)\). Here the segments are [1, 4, 9].
>>> ball = og.constraints.Ball2(None, 1.5) >>> rect = og.constraints.Rectangle(xmin=[-1,-2,-3], xmax=[0, 10, -1]) >>> free = og.constraints.NoConstraints() >>> segment_ids = [1, 4, 9] >>> my_set = og.constraints.CartesianProduct(segment_ids, [ball, rect, free])
- Parameters
segments – ids of segments
constraints – list of sets
- property constraints
- Returns
list of constraints comprising the current instance of CartesianProduct
- distance_squared(u)
Squared distance of given vector, u, from the current instance of CartesianProduct :param u: vector u :return: squared distance (float)
- is_compact()
Whether the set is compact
- is_convex()
Whether the set is convex
- project(u)
Project a given point onto the set
- Parameters
u – given point
- Returns
projection of u onto this set
- segment_dimension(i)
Dimension of segment i
- Parameters
i – index of segment (starts at 0)
- Returns
dimension of i-th index
- property segments
- Returns
list of segments
opengen.constraints.constraint module
- class opengen.constraints.constraint.Constraint
Bases:
object
- distance_squared(u)
Squared distance of a given point to the set
- Parameters
u – given point
- Returns
squared distance
- Return type
float
- is_compact()
Whether the set is compact
- is_convex()
Whether the set is convex
- project(u)
Project a given point onto the set
- Parameters
u – given point
- Returns
projection of u onto this set
opengen.constraints.finite_set module
- class opengen.constraints.finite_set.FiniteSet(points=None)
Bases:
Constraint
Finite set
A set of the form \(A = \{a_1, a_2, \ldots, a_K\}\)
- __init__(points=None)
Constructor for a finite set
- Parameters
points (list of lists) – the elements of the set
- cardinality()
Cardinality of the set
- dimension()
Dimension of the set
- distance_squared(u)
Squared distance of a given point to the set
- Parameters
u – given point
- Returns
squared distance
- Return type
float
- is_compact()
Whether the set is compact
- is_convex()
Whether the set is convex
- property points
List of points of this set
- project(u)
Project a given point onto the set
- Parameters
u – given point
- Returns
projection of u onto this set
opengen.constraints.halfspace module
- class opengen.constraints.halfspace.Halfspace(normal_vector, offset: float)
Bases:
Constraint
Halfspace constraint
A halfspace is a set of the form \(H = \{c^\intercal x \leq b\}\), where c is a given vector and b is a constant scalar.
- __init__(normal_vector, offset: float)
Construct a new halfspace \(H = \{c^\intercal x \leq b\}\)
- Parameters
normal_vector – vector c
offset – parameter b
- dimension()
Dimension of the halfspace
- Returns
length/dimension of normal vector
- distance_squared(u)
Squared distance of a given point to the set
- Parameters
u – given point
- Returns
squared distance
- Return type
float
- is_compact()
Whether the set is compact
H is compact iff \(b < 0\) and \(c = 0\), in which case H is empty
- is_convex()
A halfspace is a convex set
- Returns
True
- property normal_vector
Vector c
- property offset
Parameter b
- project(u)
Project a given point onto the set
- Parameters
u – given point
- Returns
projection of u onto this set
opengen.constraints.no_constraints module
- class opengen.constraints.no_constraints.NoConstraints
Bases:
Constraint
This is the entire \({\rm I\!R}^n\)
- __init__()
- distance_squared(u)
Squared distance of a given point to the set
- Parameters
u – given point
- Returns
squared distance
- Return type
float
- is_compact()
Whether the set is compact
- is_convex()
Whether the set is convex
- project(u)
Project a given point onto the set
- Parameters
u – given point
- Returns
projection of u onto this set
opengen.constraints.rectangle module
- class opengen.constraints.rectangle.Rectangle(xmin, xmax)
Bases:
Constraint
A Rectangle (Box) constraint
A set of the form
\(X = \{x\in{\mathrm{I\!R}}^n {}:{} x_{\mathrm{min}} \leq x \leq x_{\mathrm{max}}\}\)
- __init__(xmin, xmax)
Construct a new instance of Rectangle
- Parameters
xmin – minimum bounds (can be
None
)xmax – maximum bounds (can be
None
)
- Raises
Exception – if both
xmin
andxmax
isNone
Exception – if
xmin
andxmax
are both notNone
and not a listException – if
xmin
andxmax
have incompatible lengthsException – if
xmin(i) > xmax(i)
for somei
(empty set)
- Returns
A new instance of Rectangle
- dimension()
Dimension of this rectangle (inferred by the dimensions of
xmin
andxmax
)
- distance_squared(u)
Squared distance to this rectangle
- Parameters
u – given point
- Returns
squared distance of
u
to this rectangle
- idx_bound_finite_all()
Coordinates where both bounds are finite
- Returns
list of coordinates
- idx_infinite_only_xmax()
Coordinates at which
xmax
is infinity andxmin
is finite- Returns
list of coordinates
- idx_infinite_only_xmin()
Coordinates at which
xmin
is minus infinity andxmax
is finite- Returns
list of coordinates
- is_compact()
Whether the set is compact
- is_convex()
Whether the set is convex
- is_orthant()
Whether this rectangle is an orthant
An orthant is a rectangle whose projection on every coordinate is an interval of the form \([0, \infty)\) or \((-\infty, 0]\).
- Return type
boolean
- project(u)
Project a given point onto the set
- Parameters
u – given point
- Returns
projection of u onto this set
- property xmax
Maximum bound
- property xmin
Minimum bound
opengen.constraints.simplex module
- class opengen.constraints.simplex.Simplex(alpha: float = 1.0)
Bases:
Constraint
Simplex constraint
A set of the form
\(X = \left\{x \in \mathrm{I\!R}^n : \sum_{i=1}^{n} x_i = \alpha, x \geq 0\right\}\)
where \(\alpha\) is a positive constant.
- __init__(alpha: float = 1.0)
Constructor for a Simplex constraint
- Parameters
alpha – size parameter of simplex (default: 1)
- Returns
new instance of Simplex with given alpha
- property alpha
Returns the simplex value alpha
- distance_squared(u)
Squared distance of a given point to the set
- Parameters
u – given point
- Returns
squared distance
- Return type
float
- is_compact()
Whether the set is compact (True)
- is_convex()
Whether the set is convex (True)
- project(y)
Computes the projection of a given point \(y\in{\rm I\!R}^n\) onto the current simplex.
- Parameters
y – given point; must be a list of numbers (float, int) or a numpy n-dim array (ndarray)
- Returns
the projection point in \({\rm I\!R}^n\) as a numpy array of float64s
opengen.constraints.soc module
- class opengen.constraints.soc.SecondOrderCone(a: float = 1.0)
Bases:
Constraint
A Second-Order Cone given by \(C = \{u = (x, r): a\|x\| \leq r\}\)
Second-order cones are used in conic optimisation to describe inequalities that involve quadratic terms
- __init__(a: float = 1.0)
Constructor for a Second-Order Cone set
- Parameters
a – parameter a
- Returns
New instance of a SOC with given parameter a
- property a
Returns the value of parameter a
- distance_squared(u)
Computes the squared distance between a given point u and this second-order cone
- param u
given point; can be a list of float, a numpy n-dim array (ndarray) or a CasADi SX/MX symbol
- return
distance from set as a float or a CasADi symbol
- is_compact()
Whether the set is compact
- is_convex()
Whether the set is convex
- project(u)
Project a given point onto the set
- Parameters
u – given point
- Returns
projection of u onto this set
opengen.constraints.zero module
- class opengen.constraints.zero.Zero
Bases:
Constraint
A set that contains only the origin
The singleton \(\{0\}\)
- __init__()
Constructor for set \(Z = \{0\}\)
- distance_squared(u)
Squared distance of a given point to the set
- Parameters
u – given point
- Returns
squared distance
- Return type
float
- is_compact()
Whether the set is compact
- is_convex()
Whether the set is convex
- project(u)
Project a given point onto the set
- Parameters
u – given point
- Returns
projection of u onto this set