From 51685e602a685b2d6ab320a740f71438ed81817c Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Fri, 3 May 2024 11:33:51 +0200 Subject: Remove OptVariableExpression, just return a VariableExpression with OptVariableMixin --- sumofsquares/optvariable.py | 33 ++++----------------------------- 1 file changed, 4 insertions(+), 29 deletions(-) diff --git a/sumofsquares/optvariable.py b/sumofsquares/optvariable.py index cf4e99b..4c687de 100644 --- a/sumofsquares/optvariable.py +++ b/sumofsquares/optvariable.py @@ -3,7 +3,7 @@ from typing_extensions import override from dataclasses import replace from dataclassabc import dataclassabc -from polymatrix.expression.expression import Expression, init_expression +from polymatrix.expression.expression import VariableExpression, init_variable_expression from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin from polymatrix.expressionstate.abc import ExpressionState from polymatrix.polymatrix.abc import PolyMatrix @@ -39,36 +39,11 @@ class OptVariableImpl(OptVariableMixin): def init_opt_variable_expr(name, shape): return OptVariableImpl(name, shape) - -class OptVariableExpression(Expression, Variable): - """ - Expression that is an optimization (decision) variable, i.e. an expression - that cannot be reduced further. - """ - @override - @property - def name(self): - return self.underlyng.name - - @override - @property - def shape(self): - return self.underlyng.shape - - -@dataclassabc(frozen=True) -class OptVariableExpressionImpl(OptVariableExpression): - underlying: ExpressionBaseMixin - - def copy(self, underlying: ExpressionBaseMixin) -> Expression: - return init_expression(underlying) - - -def init_opt_variable_expression(underlying: OptVariableMixin) -> OptVariableExpression: - return OptVariableExpressionImpl(underlying=underlying) +def init_opt_variable_expression(underlying: OptVariableMixin) -> VariableExpression: + return init_variable_expression(underlying=underlying) -def from_names(names: str, shape: tuple[int, int] = (1,1)) -> tuple[OptVariableExpression] | OptVariableExpression: +def from_names(names: str, shape: tuple[int, int] = (1,1)) -> tuple[VariableExpression] | VariableExpression: """ Construct one or multiple variables from comma separated a list of names. """ variables = tuple(init_opt_variable_expression( underlying=init_opt_variable_expr(name.strip(), shape)) -- cgit v1.2.1