-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathfinite_set.py
More file actions
63 lines (51 loc) · 1.55 KB
/
finite_set.py
File metadata and controls
63 lines (51 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import casadi.casadi as cs
import numpy as np
from .constraint import Constraint
import opengen.functions as fn
class FiniteSet(Constraint):
"""Finite set
A set of the form :math:`A = \\{a_1, a_2, \\ldots, a_K\\}`
"""
def __init__(self, points=None):
"""Constructor for a finite set
:param points: the elements of the set
:type points: list of lists
"""
if points is not None and len(points) > 0:
first_point_len = len(points[0])
for point in points[1:]:
point_len = len(point)
if point_len != first_point_len:
raise Exception(
"Invalid input (points have unequal dimensions)")
self.__points = None if points is None else [
[float(x) for x in p] for p in points]
@property
def points(self):
"""
List of points of this set
"""
return self.__points
def dimension(self):
"""
Dimension of the set"""
p = self.points
if p is None or len(p) == 0:
return 0
return len(p[0])
def cardinality(self):
"""
Cardinality of the set
"""
p = self.points
if p is None:
return 0
return len(p)
def distance_squared(self, u):
raise NotImplementedError()
def project(self, u):
raise NotImplementedError()
def is_convex(self):
return self.cardinality() == 1 and self.dimension() > 0
def is_compact(self):
return True