diff options
author | Nao Pross <np@0hm.ch> | 2024-03-20 12:18:24 +0100 |
---|---|---|
committer | Nao Pross <np@0hm.ch> | 2024-03-20 12:18:24 +0100 |
commit | 99c6d92b6194dc0d47927eda498c5dcffeb722ac (patch) | |
tree | 8142c97992f5427d8e2449d407d21ffcae9b9104 | |
parent | Reword comment (diff) | |
download | mdpoly-master.tar.gz mdpoly-master.zip |
-rw-r--r-- | mdpoly/sos/__init__.py | 0 | ||||
-rw-r--r-- | mdpoly/sos/problem.py | 33 | ||||
-rw-r--r-- | mdpoly/sos/representations.py | 39 |
3 files changed, 72 insertions, 0 deletions
diff --git a/mdpoly/sos/__init__.py b/mdpoly/sos/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/mdpoly/sos/__init__.py diff --git a/mdpoly/sos/problem.py b/mdpoly/sos/problem.py new file mode 100644 index 0000000..2787355 --- /dev/null +++ b/mdpoly/sos/problem.py @@ -0,0 +1,33 @@ +from __future__ import annotations +from typing import TYPE_CHECKING + +from typing import List +from dataclasses import dataclass + +from ..abc import Var, Rel +from ..expressions import Expression + +if TYPE_CHECKING: + pass + + +class OptVar(Var): + """ Leaf to represent an optimization variable. """ + + +@dataclass(frozen=True) +class Problem: + """ Optimization problem. """ + objective: Expression + variables: List[OptVar] + constraints: List[Rel] + + +@dataclass(frozen=True) +class SOSProblem(Problem): + ... + + +@dataclass(frozen=True) +class SOSCertProblem(Problem): + ... diff --git a/mdpoly/sos/representations.py b/mdpoly/sos/representations.py new file mode 100644 index 0000000..9261b82 --- /dev/null +++ b/mdpoly/sos/representations.py @@ -0,0 +1,39 @@ +from __future__ import annotations +from typing import TYPE_CHECKING + +from typing import Iterable +import cvxopt + +from ..abc import Repr + +if TYPE_CHECKING: + from ..index import MatrixIndex, PolyIndex, Number, Shape + + +class CVXOptSparseMatrixRepr(Repr): + data: cvxopt.spmatrix + + def __init__(self, shape: Shape): + self.data = cvxopt.spmatrix(0, size=shape) + + def at(self, entry: MatrixIndex, term: PolyIndex) -> Number: + """ Access polynomial coefficient. """ + return self.data[entry.row, entry.col] + + def set(self, entry: MatrixIndex, term: PolyIndex, value: Number) -> None: + """ Set value of polynomial coefficient. """ + raise NotImplementedError + + def set_zero(self, entry: MatrixIndex, term: PolyIndex) -> None: + """ Set a coefficient to zero (delete it). """ + raise NotImplementedError + + def entries(self) -> Iterable[MatrixIndex]: + """ Return indices to non-zero entries of the matrix. """ + raise NotImplementedError + + def terms(self, entry: MatrixIndex) -> Iterable[PolyIndex]: + """ Return indices to non-zero terms in the polynomial at the given + matrix entry. """ + raise NotImplementedError + |