From aacedb16c83a07fbeae9e54c59b6be6fbee44a5b Mon Sep 17 00:00:00 2001 From: "Matthias C. M. Troffaes" Date: Tue, 17 Sep 2024 16:33:04 +0100 Subject: [PATCH] Rename attribtes, remove 'type' where not needed. --- cython/_cdd.pyx | 4 +- cython/_cddgmp.pyx | 6 +- cython/pycddlib.pxi | 98 +++++++++++++------------- cython/pyenums.pxi | 14 ++-- docs/source/cdd.rst | 10 +-- docs/source/examples.rst | 24 +++---- src/cdd/__init__.pyi | 114 +++++++++++++++---------------- src/cdd/gmp.pyi | 58 ++++++++-------- test/gmp/test_enums.py | 4 +- test/test_adjacency_list.py | 8 +-- test/test_block_elimination.py | 6 +- test/test_enums.py | 20 +++--- test/test_fourier_elimination.py | 6 +- test/test_incidence.py | 8 +-- test/test_issue20.py | 2 +- test/test_issue25.py | 2 +- test/test_issue7.py | 2 +- test/test_linprog.py | 68 +++++++++--------- test/test_matrix.py | 16 ++--- test/test_matrix_canonicalize.py | 8 +-- test/test_pickle.py | 12 ++-- test/test_polyhedron.py | 34 ++++----- 22 files changed, 262 insertions(+), 262 deletions(-) diff --git a/cython/_cdd.pyx b/cython/_cdd.pyx index 34285c3..4b419cd 100644 --- a/cython/_cdd.pyx +++ b/cython/_cdd.pyx @@ -21,8 +21,8 @@ from typing import SupportsFloat -NumberType = float -SupportsNumberType = SupportsFloat +Number = float +SupportsNumber = SupportsFloat cdef extern from * nogil: "#undef GMPRATIONAL" diff --git a/cython/_cddgmp.pyx b/cython/_cddgmp.pyx index b4e72a6..9ec7a01 100644 --- a/cython/_cddgmp.pyx +++ b/cython/_cddgmp.pyx @@ -22,10 +22,10 @@ from fractions import Fraction from typing import Union -from cdd import LPObjType, LPSolverType, LPStatusType, RepType +from cdd import LPObj, LPSolver, LPStatus, Rep -NumberType = Fraction -SupportsNumberType = Union[Fraction, int] +Number = Fraction +SupportsNumber = Union[Fraction, int] cdef extern from * nogil: "#define GMPRATIONAL" diff --git a/cython/pycddlib.pxi b/cython/pycddlib.pxi index a70055b..ff7e848 100644 --- a/cython/pycddlib.pxi +++ b/cython/pycddlib.pxi @@ -124,11 +124,11 @@ cdef class Matrix: cdef dd_MatrixPtr dd_mat # hack for annotation of properties __annotations__ = dict( - array=Sequence[Sequence[NumberType]], + array=Sequence[Sequence[Number]], lin_set=Set[int], - rep_type=RepType, - obj_type=LPObjType, - obj_func=Sequence[NumberType], + rep=Rep, + obj=LPObj, + obj_func=Sequence[Number], ) @property @@ -176,23 +176,23 @@ cdef class Matrix: _set_set(self.dd_mat.linset, value) @property - def rep_type(self): + def rep(self): """Representation: inequalities (H-representation), generators (V-representation), or unspecified. """ - return RepType(self.dd_mat.representation) + return Rep(self.dd_mat.representation) - @rep_type.setter - def rep_type(self, dd_RepresentationType value): + @rep.setter + def rep(self, dd_RepresentationType value): self.dd_mat.representation = value @property - def obj_type(self): + def obj(self): """Linear programming objective: maximize, minimize, or none.""" - return LPObjType(self.dd_mat.objective) + return LPObj(self.dd_mat.objective) - @obj_type.setter - def obj_type(self, dd_LPObjectiveType value): + @obj.setter + def obj(self, dd_LPObjectiveType value): self.dd_mat.objective = value @property @@ -227,7 +227,7 @@ cdef class Matrix: def __reduce__(self): return ( matrix_from_array, - (self.array, self.lin_set, self.rep_type, self.obj_type, self.obj_func), + (self.array, self.lin_set, self.rep, self.obj, self.obj_func), ) @@ -277,11 +277,11 @@ cdef _get_array_from_matrix(mytype **pp, _Shape shape): # create matrix and wrap into Matrix class # https://cython.readthedocs.io/en/latest/src/userguide/extension_types.html#instantiation-from-existing-c-c-pointers def matrix_from_array( - array: Sequence[Sequence[SupportsNumberType]], + array: Sequence[Sequence[SupportsNumber]], lin_set: Container[int] = (), - rep_type: RepType = RepType.UNSPECIFIED, - obj_type: LPObjType = LPObjType.NONE, - obj_func: Optional[Sequence[SupportsNumberType]] = None, + rep: Rep = Rep.UNSPECIFIED, + obj: LPObj = LPObj.NONE, + obj_func: Optional[Sequence[SupportsNumber]] = None, ) -> Matrix: """Construct a matrix with the given attributes. @@ -297,8 +297,8 @@ def matrix_from_array( try: _set_matrix_from_array(dd_mat.matrix, shape, array) _set_set(dd_mat.linset, lin_set) - dd_mat.representation = rep_type.value - dd_mat.objective = obj_type.value + dd_mat.representation = rep.value + dd_mat.objective = obj.value if obj_func is not None: if len(obj_func) != dd_mat.colsize: raise ValueError( @@ -336,7 +336,7 @@ def matrix_canonicalize(mat: Matrix) -> tuple[Set[int], Set[int]]: cdef dd_ErrorType error = dd_NoError cdef dd_boolean success if mat.dd_mat.representation == dd_Unspecified: - raise ValueError("rep_type unspecified") + raise ValueError("rep unspecified") success = dd_MatrixCanonicalize( &mat.dd_mat, &impl_linset, &redset, &newpos, &error ) @@ -360,13 +360,13 @@ cdef class LinProg: """A linear program: a set of inequalities and an objective function to optimize.""" cdef dd_LPPtr dd_lp __annotations__ = dict( - array=Sequence[Sequence[NumberType]], - dual_solution=Sequence[tuple[int, NumberType]], - obj_type=LPObjType, - obj_value=NumberType, - primal_solution=Sequence[NumberType], - solver=LPSolverType, - status=LPStatusType, + array=Sequence[Sequence[Number]], + dual_solution=Sequence[tuple[int, Number]], + obj=LPObj, + obj_value=Number, + primal_solution=Sequence[Number], + solver=LPSolver, + status=LPStatus, ) @property @@ -388,23 +388,23 @@ cdef class LinProg: return _get_array_from_matrix(self.dd_lp.A, shape) @property - def obj_type(self): + def obj(self): """Whether we are minimizing or maximizing.""" - return LPObjType(self.dd_lp.objective) + return LPObj(self.dd_lp.objective) - @obj_type.setter - def obj_type(self, dd_LPObjectiveType value): + @obj.setter + def obj(self, dd_LPObjectiveType value): self.dd_lp.objective = value @property def solver(self): """The solver used when last solving the linear program.""" - return LPSolverType(self.dd_lp.solver) + return LPSolver(self.dd_lp.solver) @property def status(self): """The status of the linear program, after solving.""" - return LPStatusType(self.dd_lp.LPS) + return LPStatus(self.dd_lp.LPS) @property def obj_value(self): @@ -451,7 +451,7 @@ cdef class LinProg: self.dd_lp = NULL def __reduce__(self): - return linprog_from_array, (self.array, self.obj_type) + return linprog_from_array, (self.array, self.obj) cdef linprog_from_ptr(dd_LPPtr dd_lp): @@ -468,19 +468,19 @@ def linprog_from_matrix(mat: Matrix) -> LinProg: and its objective type must be set, otherwise a :exc:`ValueError` is raised. """ - # cddlib does not check if obj_type is valid + # cddlib does not check if obj is valid if mat.dd_mat.objective != dd_LPmax and mat.dd_mat.objective != dd_LPmin: - raise ValueError("obj_type must be MIN or MAX") + raise ValueError("obj must be MIN or MAX") # cddlib assumes H-representation if mat.dd_mat.representation != dd_Inequality: - raise ValueError("rep_type must be INEQUALITY") + raise ValueError("rep must be INEQUALITY") cdef dd_ErrorType error = dd_NoError # note: dd_Matrix2LP never reports error... so ignore return linprog_from_ptr(dd_Matrix2LP(mat.dd_mat, &error)) def linprog_from_array( - array: Sequence[Sequence[SupportsNumberType]], obj_type: LPObjType + array: Sequence[Sequence[SupportsNumber]], obj: LPObj ) -> LinProg: """Construct a linear program from *array*. @@ -489,11 +489,11 @@ def linprog_from_array( .. versionadded:: 3.0.0 """ - if obj_type != dd_LPmax and obj_type != dd_LPmin: - raise ValueError("obj_type must be MIN or MAX") + if obj != dd_LPmax and obj != dd_LPmin: + raise ValueError("obj must be MIN or MAX") cdef _Shape shape = _array_shape(array) cdef dd_LPPtr dd_lp = dd_CreateLPData( - obj_type, NUMBER_TYPE, shape.numrows, shape.numcols + obj, NUMBER_TYPE, shape.numrows, shape.numcols ) if dd_lp == NULL: raise MemoryError @@ -506,7 +506,7 @@ def linprog_from_array( def linprog_solve( - lp: LinProg, solver: LPSolverType = LPSolverType.DUAL_SIMPLEX + lp: LinProg, solver: LPSolver = LPSolver.DUAL_SIMPLEX ) -> None: """Solve the linear program *lp* using *solver*.""" cdef dd_ErrorType error = dd_NoError @@ -519,13 +519,13 @@ cdef class Polyhedron: """Representation of a polyhedron.""" cdef dd_PolyhedraPtr dd_poly __annotations__ = dict( - rep_type=RepType, + rep=Rep, ) @property - def rep_type(self): + def rep(self): """Representation type of the input.""" - return RepType(self.dd_poly.representation) + return Rep(self.dd_poly.representation) def __str__(self): cdef libc.stdio.FILE *pfile @@ -549,7 +549,7 @@ cdef polyhedron_from_ptr(dd_PolyhedraPtr dd_poly): def polyhedron_from_matrix( - mat: Matrix, row_order_type: Optional[RowOrderType] = None + mat: Matrix, row_order_type: Optional[RowOrder] = None ) -> Polyhedron: """Run the double description method to convert *mat* into a polyhedron, using *row_order_type* if specified. @@ -562,7 +562,7 @@ def polyhedron_from_matrix( mat.dd_mat.representation != dd_Inequality and mat.dd_mat.representation != dd_Generator ): - raise ValueError("rep_type must be INEQUALITY or GENERATOR") + raise ValueError("rep must be INEQUALITY or GENERATOR") cdef dd_ErrorType error = dd_NoError if row_order_type is None: dd_poly = dd_DDMatrix2Poly(mat.dd_mat, &error) @@ -663,7 +663,7 @@ def fourier_elimination(mat: Matrix) -> Matrix: .. versionadded:: 3.0.0 """ if mat.dd_mat.representation != dd_Inequality: - raise ValueError("rep_type must be INEQUALITY") + raise ValueError("rep must be INEQUALITY") cdef dd_ErrorType error = dd_NoError cdef dd_MatrixPtr dd_mat = dd_FourierElimination(mat.dd_mat, &error) if error != dd_NoError: @@ -686,7 +686,7 @@ def block_elimination(mat: Matrix, col_set: Container[int]) -> Matrix: .. versionadded:: 3.0.0 """ if mat.dd_mat.representation != dd_Inequality: - raise ValueError("rep_type must be INEQUALITY") + raise ValueError("rep must be INEQUALITY") cdef set_type dd_colset = NULL cdef dd_MatrixPtr dd_mat = NULL cdef dd_ErrorType error = dd_NoError diff --git a/cython/pyenums.pxi b/cython/pyenums.pxi index a3c940c..d4b4a02 100644 --- a/cython/pyenums.pxi +++ b/cython/pyenums.pxi @@ -22,19 +22,19 @@ from enum import IntEnum -class _AdjacencyTestType(IntEnum): +class _AdjacencyTest(IntEnum): COMBINATORIAL = dd_Combinatorial ALGEBRAIC = dd_Algebraic -class _NumberType(IntEnum): +class _Number(IntEnum): UNKNOWN = dd_Unknown REAL = dd_Real RATIONAL = dd_Rational INTEGER = dd_Integer -class RepType(IntEnum): +class Rep(IntEnum): """Type of representation. Use :attr:`INEQUALITY` for H-representation and :attr:`GENERATOR` for V-representation. @@ -44,7 +44,7 @@ class RepType(IntEnum): GENERATOR = dd_Generator -class RowOrderType(IntEnum): +class RowOrder(IntEnum): """Type of row order to use in the double description method.""" MAX_INDEX = dd_MaxIndex MIN_INDEX = dd_MinIndex @@ -83,20 +83,20 @@ class _CompStatus(IntEnum): REGION_EMPTY = dd_RegionEmpty -class LPObjType(IntEnum): +class LPObj(IntEnum): """Type of objective for a linear program.""" NONE = dd_LPnone MAX = dd_LPmax MIN = dd_LPmin -class LPSolverType(IntEnum): +class LPSolver(IntEnum): """Type of solver for a linear program.""" CRISS_CROSS = dd_CrissCross DUAL_SIMPLEX = dd_DualSimplex -class LPStatusType(IntEnum): +class LPStatus(IntEnum): """Status of a linear program.""" UNDECIDED = dd_LPSundecided OPTIMAL = dd_Optimal diff --git a/docs/source/cdd.rst b/docs/source/cdd.rst index e9b5d7d..7561c77 100644 --- a/docs/source/cdd.rst +++ b/docs/source/cdd.rst @@ -10,7 +10,7 @@ Enums .. autoclass has trouble finding attributes of enums, so list explicitly -.. autoclass:: LPObjType(value) +.. autoclass:: LPObj(value) :show-inheritance: .. attribute:: @@ -18,14 +18,14 @@ Enums MAX MIN -.. autoclass:: LPSolverType(value) +.. autoclass:: LPSolver(value) :show-inheritance: .. attribute:: CRISS_CROSS DUAL_SIMPLEX -.. autoclass:: LPStatusType(value) +.. autoclass:: LPStatus(value) :show-inheritance: .. attribute:: @@ -38,7 +38,7 @@ Enums UNBOUNDED DUAL_UNBOUNDED -.. autoclass:: RepType(value) +.. autoclass:: Rep(value) :show-inheritance: .. attribute:: @@ -46,7 +46,7 @@ Enums INEQUALITY GENERATOR -.. autoclass:: RowOrderType(value) +.. autoclass:: RowOrder(value) :show-inheritance: .. attribute:: diff --git a/docs/source/examples.rst b/docs/source/examples.rst index b74fad4..d9ca029 100644 --- a/docs/source/examples.rst +++ b/docs/source/examples.rst @@ -10,7 +10,7 @@ Canonicalizing Inequalities --------------------------- >>> array = [[2, 1, 2, 3], [0, 1, 2, 3], [3, 0, 1, 2], [0, -2, -4, -6]] ->>> mat = cdd.matrix_from_array(array, rep_type=cdd.RepType.INEQUALITY) +>>> mat = cdd.matrix_from_array(array, rep=cdd.Rep.INEQUALITY) >>> cdd.matrix_canonicalize(mat) ({1, 3}, {0}) >>> pprint(mat.array) @@ -26,9 +26,9 @@ Solving Linear Programs ... [0, 0, 1], # 0 <= y ... [0, 3, 4], # obj func: 3x+4y ... ] ->>> lp = cdd.linprog_from_array(array, obj_type=cdd.LPObjType.MAX) +>>> lp = cdd.linprog_from_array(array, obj=cdd.LPObj.MAX) >>> cdd.linprog_solve(lp) ->>> lp.status == cdd.LPStatusType.OPTIMAL +>>> lp.status == cdd.LPStatus.OPTIMAL True >>> lp.obj_value 3.666666... @@ -43,11 +43,11 @@ Calculating Extreme Points / Rays This is the :file:`sampleh1.ine` example that comes with cddlib. >>> array = [[2, -1, -1, 0], [0, 1, 0, 0], [0, 0, 1, 0]] ->>> mat = cdd.matrix_from_array(array, rep_type=cdd.RepType.INEQUALITY) +>>> mat = cdd.matrix_from_array(array, rep=cdd.Rep.INEQUALITY) >>> poly = cdd.polyhedron_from_matrix(mat) >>> ext = cdd.copy_generators(poly) ->>> ext.rep_type - +>>> ext.rep + >>> pprint(ext.array) # doctest: +NORMALIZE_WHITESPACE [[1.0, 0.0, 0.0, 0.0], [1.0, 2.0, 0.0, 0.0], @@ -65,12 +65,12 @@ Getting Adjacencies and Incidences >>> # 0 <= 1 - x1 (face 2) >>> # 0 <= 1 - x2 (face 3) >>> array = [[1, 1, 0], [1, 0, 1], [1, -1, 0], [1, 0, -1]] ->>> mat = cdd.matrix_from_array(array, rep_type=cdd.RepType.INEQUALITY) +>>> mat = cdd.matrix_from_array(array, rep=cdd.Rep.INEQUALITY) >>> poly = cdd.polyhedron_from_matrix(mat) >>> # The V-representation can be printed in the usual way: >>> gen = cdd.copy_generators(poly) ->>> gen.rep_type - +>>> gen.rep + >>> pprint(gen.array, width=40) [[1.0, 1.0, -1.0], [1.0, 1.0, 1.0], @@ -116,8 +116,8 @@ set() >>> cdd.matrix_append_to(gen, cdd.matrix_from_array([[1, 0, 2]])) >>> vpoly = cdd.polyhedron_from_matrix(gen) >>> vmat = cdd.copy_inequalities(vpoly) ->>> vmat.rep_type - +>>> vmat.rep + >>> pprint(vmat.array) [[1.0, 0.0, 1.0], [2.0, 1.0, -1.0], @@ -173,7 +173,7 @@ The next example is taken from ... [-7, 1, -5, 2], # -x+5y-2z<=-7 ... [12, 3, -2, -6], # -3x+2y+6z<=12 ... ] ->>> mat1 = cdd.matrix_from_array(array, rep_type=cdd.RepType.INEQUALITY) +>>> mat1 = cdd.matrix_from_array(array, rep=cdd.Rep.INEQUALITY) >>> mat2 = cdd.fourier_elimination(mat1) >>> mat2.array [[-1.0, 0.0, -1.25], [-1.0, -1.0, -1.0], [-1.5, 1.0, -2.833333...]] diff --git a/src/cdd/__init__.pyi b/src/cdd/__init__.pyi index 96ccdf4..cea612c 100644 --- a/src/cdd/__init__.pyi +++ b/src/cdd/__init__.pyi @@ -2,84 +2,84 @@ import enum from collections.abc import Container, Sequence, Set from typing import ClassVar, Optional, SupportsFloat -NumberType = float -SupportsNumberType = SupportsFloat +Number = float +SupportsNumber = SupportsFloat -class LPObjType(enum.IntEnum): - MAX: ClassVar[LPObjType] = ... - MIN: ClassVar[LPObjType] = ... - NONE: ClassVar[LPObjType] = ... +class LPObj(enum.IntEnum): + MAX: ClassVar[LPObj] = ... + MIN: ClassVar[LPObj] = ... + NONE: ClassVar[LPObj] = ... -class LPSolverType(enum.IntEnum): - CRISS_CROSS: ClassVar[LPSolverType] = ... - DUAL_SIMPLEX: ClassVar[LPSolverType] = ... +class LPSolver(enum.IntEnum): + CRISS_CROSS: ClassVar[LPSolver] = ... + DUAL_SIMPLEX: ClassVar[LPSolver] = ... -class LPStatusType(enum.IntEnum): - DUAL_INCONSISTENT: ClassVar[LPStatusType] = ... - DUAL_UNBOUNDED: ClassVar[LPStatusType] = ... - INCONSISTENT: ClassVar[LPStatusType] = ... - OPTIMAL: ClassVar[LPStatusType] = ... - STRUC_DUAL_INCONSISTENT: ClassVar[LPStatusType] = ... - STRUC_INCONSISTENT: ClassVar[LPStatusType] = ... - UNBOUNDED: ClassVar[LPStatusType] = ... - UNDECIDED: ClassVar[LPStatusType] = ... +class LPStatus(enum.IntEnum): + DUAL_INCONSISTENT: ClassVar[LPStatus] = ... + DUAL_UNBOUNDED: ClassVar[LPStatus] = ... + INCONSISTENT: ClassVar[LPStatus] = ... + OPTIMAL: ClassVar[LPStatus] = ... + STRUC_DUAL_INCONSISTENT: ClassVar[LPStatus] = ... + STRUC_INCONSISTENT: ClassVar[LPStatus] = ... + UNBOUNDED: ClassVar[LPStatus] = ... + UNDECIDED: ClassVar[LPStatus] = ... class LinProg: @property - def array(self) -> Sequence[Sequence[NumberType]]: ... + def array(self) -> Sequence[Sequence[Number]]: ... @property - def dual_solution(self) -> Sequence[tuple[int, NumberType]]: ... + def dual_solution(self) -> Sequence[tuple[int, Number]]: ... @property - def obj_type(self) -> LPObjType: ... - @obj_type.setter - def obj_type(self, value: LPObjType) -> None: ... + def obj(self) -> LPObj: ... + @obj.setter + def obj(self, value: LPObj) -> None: ... @property - def obj_value(self) -> NumberType: ... + def obj_value(self) -> Number: ... @property - def primal_solution(self) -> Sequence[NumberType]: ... + def primal_solution(self) -> Sequence[Number]: ... @property - def status(self) -> LPStatusType: ... + def status(self) -> LPStatus: ... @property - def solver(self) -> LPSolverType: ... + def solver(self) -> LPSolver: ... class Matrix: @property - def array(self) -> Sequence[Sequence[NumberType]]: ... + def array(self) -> Sequence[Sequence[Number]]: ... @property def lin_set(self) -> Set[int]: ... @lin_set.setter def lin_set(self, value: Container[int]) -> None: ... @property - def obj_func(self) -> Sequence[NumberType]: ... + def obj_func(self) -> Sequence[Number]: ... @obj_func.setter - def obj_func(self, value: Sequence[NumberType]) -> None: ... + def obj_func(self, value: Sequence[Number]) -> None: ... @property - def obj_type(self) -> LPObjType: ... - @obj_type.setter - def obj_type(self, value: LPObjType) -> None: ... + def obj(self) -> LPObj: ... + @obj.setter + def obj(self, value: LPObj) -> None: ... @property - def rep_type(self) -> RepType: ... - @rep_type.setter - def rep_type(self, value: RepType) -> None: ... + def rep(self) -> Rep: ... + @rep.setter + def rep(self, value: Rep) -> None: ... class Polyhedron: @property - def rep_type(self) -> RepType: ... + def rep(self) -> Rep: ... -class RepType(enum.IntEnum): - GENERATOR: ClassVar[RepType] = ... - INEQUALITY: ClassVar[RepType] = ... - UNSPECIFIED: ClassVar[RepType] = ... +class Rep(enum.IntEnum): + GENERATOR: ClassVar[Rep] = ... + INEQUALITY: ClassVar[Rep] = ... + UNSPECIFIED: ClassVar[Rep] = ... -class RowOrderType(enum.IntEnum): - LEX_MAX: ClassVar[RowOrderType] = ... - LEX_MIN: ClassVar[RowOrderType] = ... - MAX_CUTOFF: ClassVar[RowOrderType] = ... - MAX_INDEX: ClassVar[RowOrderType] = ... - MIN_CUTOFF: ClassVar[RowOrderType] = ... - MIN_INDEX: ClassVar[RowOrderType] = ... - MIX_CUTOFF: ClassVar[RowOrderType] = ... - RANDOM_ROW: ClassVar[RowOrderType] = ... +class RowOrder(enum.IntEnum): + LEX_MAX: ClassVar[RowOrder] = ... + LEX_MIN: ClassVar[RowOrder] = ... + MAX_CUTOFF: ClassVar[RowOrder] = ... + MAX_INDEX: ClassVar[RowOrder] = ... + MIN_CUTOFF: ClassVar[RowOrder] = ... + MIN_INDEX: ClassVar[RowOrder] = ... + MIX_CUTOFF: ClassVar[RowOrder] = ... + RANDOM_ROW: ClassVar[RowOrder] = ... def block_elimination(mat: Matrix, col_set: Container[int]) -> Matrix: ... def copy_adjacency(poly: Polyhedron) -> Sequence[Set[int]]: ... @@ -92,22 +92,22 @@ def copy_input_incidence(poly: Polyhedron) -> Sequence[Set[int]]: ... def copy_output(poly: Polyhedron) -> Matrix: ... def fourier_elimination(mat: Matrix) -> Matrix: ... def linprog_from_array( - array: Sequence[Sequence[SupportsNumberType]], obj_type: LPObjType + array: Sequence[Sequence[SupportsNumber]], obj: LPObj ) -> LinProg: ... def linprog_from_matrix(mat: Matrix) -> LinProg: ... def linprog_solve( - lp: LinProg, solver: LPSolverType = LPSolverType.DUAL_SIMPLEX + lp: LinProg, solver: LPSolver = LPSolver.DUAL_SIMPLEX ) -> None: ... def matrix_append_to(mat1: Matrix, mat2: Matrix) -> None: ... def matrix_canonicalize(mat: Matrix) -> tuple[Set[int], Set[int]]: ... def matrix_copy(mat: Matrix) -> Matrix: ... def matrix_from_array( - array: Sequence[Sequence[SupportsNumberType]], + array: Sequence[Sequence[SupportsNumber]], lin_set: Container[int] = (), - rep_type: RepType = RepType.UNSPECIFIED, - obj_type: LPObjType = LPObjType.NONE, - obj_func: Optional[Sequence[SupportsNumberType]] = None, + rep: Rep = Rep.UNSPECIFIED, + obj: LPObj = LPObj.NONE, + obj_func: Optional[Sequence[SupportsNumber]] = None, ) -> Matrix: ... def polyhedron_from_matrix( - mat: Matrix, row_order_type: Optional[RowOrderType] = None + mat: Matrix, row_order_type: Optional[RowOrder] = None ) -> Polyhedron: ... diff --git a/src/cdd/gmp.pyi b/src/cdd/gmp.pyi index 8400968..f79ad10 100644 --- a/src/cdd/gmp.pyi +++ b/src/cdd/gmp.pyi @@ -2,52 +2,52 @@ from collections.abc import Container, Sequence, Set from fractions import Fraction from typing import Optional, Union -from cdd import LPObjType, LPSolverType, LPStatusType, RepType, RowOrderType +from cdd import LPObj, LPSolver, LPStatus, Rep, RowOrder -NumberType = Fraction -SupportsNumberType = Union[Fraction, int] +Number = Fraction +SupportsNumber = Union[Fraction, int] class LinProg: @property - def array(self) -> Sequence[Sequence[NumberType]]: ... + def array(self) -> Sequence[Sequence[Number]]: ... @property - def dual_solution(self) -> Sequence[tuple[int, NumberType]]: ... + def dual_solution(self) -> Sequence[tuple[int, Number]]: ... @property - def obj_type(self) -> LPObjType: ... - @obj_type.setter - def obj_type(self, value: LPObjType) -> None: ... + def obj(self) -> LPObj: ... + @obj.setter + def obj(self, value: LPObj) -> None: ... @property - def obj_value(self) -> NumberType: ... + def obj_value(self) -> Number: ... @property - def primal_solution(self) -> Sequence[NumberType]: ... + def primal_solution(self) -> Sequence[Number]: ... @property - def status(self) -> LPStatusType: ... + def status(self) -> LPStatus: ... @property - def solver(self) -> LPSolverType: ... + def solver(self) -> LPSolver: ... class Matrix: @property - def array(self) -> Sequence[Sequence[NumberType]]: ... + def array(self) -> Sequence[Sequence[Number]]: ... @property def lin_set(self) -> Set[int]: ... @lin_set.setter def lin_set(self, value: Container[int]) -> None: ... @property - def obj_func(self) -> Sequence[NumberType]: ... + def obj_func(self) -> Sequence[Number]: ... @obj_func.setter - def obj_func(self, value: Sequence[NumberType]) -> None: ... + def obj_func(self, value: Sequence[Number]) -> None: ... @property - def obj_type(self) -> LPObjType: ... - @obj_type.setter - def obj_type(self, value: LPObjType) -> None: ... + def obj(self) -> LPObj: ... + @obj.setter + def obj(self, value: LPObj) -> None: ... @property - def rep_type(self) -> RepType: ... - @rep_type.setter - def rep_type(self, value: RepType) -> None: ... + def rep(self) -> Rep: ... + @rep.setter + def rep(self, value: Rep) -> None: ... class Polyhedron: @property - def rep_type(self) -> RepType: ... + def rep(self) -> Rep: ... def block_elimination(mat: Matrix, col_set: Container[int]) -> Matrix: ... def copy_adjacency(poly: Polyhedron) -> Sequence[Set[int]]: ... @@ -60,22 +60,22 @@ def copy_input_incidence(poly: Polyhedron) -> Sequence[Set[int]]: ... def copy_output(poly: Polyhedron) -> Matrix: ... def fourier_elimination(mat: Matrix) -> Matrix: ... def linprog_from_array( - array: Sequence[Sequence[SupportsNumberType]], obj_type: LPObjType + array: Sequence[Sequence[SupportsNumber]], obj: LPObj ) -> LinProg: ... def linprog_from_matrix(mat: Matrix) -> LinProg: ... def linprog_solve( - lp: LinProg, solver: LPSolverType = LPSolverType.DUAL_SIMPLEX + lp: LinProg, solver: LPSolver = LPSolver.DUAL_SIMPLEX ) -> None: ... def matrix_append_to(mat1: Matrix, mat2: Matrix) -> None: ... def matrix_canonicalize(mat: Matrix) -> tuple[Set[int], Set[int]]: ... def matrix_copy(mat: Matrix) -> Matrix: ... def matrix_from_array( - array: Sequence[Sequence[SupportsNumberType]], + array: Sequence[Sequence[SupportsNumber]], lin_set: Container[int] = (), - rep_type: RepType = RepType.UNSPECIFIED, - obj_type: LPObjType = LPObjType.NONE, - obj_func: Optional[Sequence[SupportsNumberType]] = None, + rep: Rep = Rep.UNSPECIFIED, + obj: LPObj = LPObj.NONE, + obj_func: Optional[Sequence[SupportsNumber]] = None, ) -> Matrix: ... def polyhedron_from_matrix( - mat: Matrix, row_order_type: Optional[RowOrderType] = None + mat: Matrix, row_order_type: Optional[RowOrder] = None ) -> Polyhedron: ... diff --git a/test/gmp/test_enums.py b/test/gmp/test_enums.py index fb70536..f171bf3 100644 --- a/test/gmp/test_enums.py +++ b/test/gmp/test_enums.py @@ -7,8 +7,8 @@ @pytest.mark.parametrize( - "name", ["RepType", "LPObjType", "LPStatusType", "LPSolverType"] + "name", ["Rep", "LPObj", "LPStatus", "LPSolver"] ) -def test_gmp_rep_type(name: str) -> None: +def test_gmp_rep(name: str) -> None: assert issubclass(getattr(cdd, name), IntEnum) assert getattr(cdd, name) is getattr(cdd.gmp, name) diff --git a/test/test_adjacency_list.py b/test/test_adjacency_list.py index ae4a7eb..e2dcec9 100644 --- a/test/test_adjacency_list.py +++ b/test/test_adjacency_list.py @@ -15,11 +15,11 @@ def test_make_vertex_adjacency_list() -> None: [1, 0, -1, 0], [1, 0, 0, -1], ], - rep_type=cdd.RepType.INEQUALITY, + rep=cdd.Rep.INEQUALITY, ) - assert mat.rep_type == cdd.RepType.INEQUALITY + assert mat.rep == cdd.Rep.INEQUALITY poly = cdd.polyhedron_from_matrix(mat) - assert poly.rep_type == cdd.RepType.INEQUALITY + assert poly.rep == cdd.Rep.INEQUALITY adjacency = cdd.copy_adjacency(poly) # Family size should equal the number of vertices of the cube (8) @@ -55,7 +55,7 @@ def test_make_facet_adjacency_list() -> None: [16, 0, -8, 1], [32, -8, -8, 1], ], - rep_type=cdd.RepType.INEQUALITY, + rep=cdd.Rep.INEQUALITY, ) poly = cdd.polyhedron_from_matrix(mat) diff --git a/test/test_block_elimination.py b/test/test_block_elimination.py index b446425..a6e6245 100644 --- a/test/test_block_elimination.py +++ b/test/test_block_elimination.py @@ -6,7 +6,7 @@ def test_block_elimination_1() -> None: # 0 <= 1 + a + b + c + d, 0 <= 1 + 2a - b - c - d array = [[1, 1, 1, 1, 1], [1, 2, -1, -1, -1]] - mat1 = cdd.matrix_from_array(array, rep_type=cdd.RepType.INEQUALITY) + mat1 = cdd.matrix_from_array(array, rep=cdd.Rep.INEQUALITY) mat2 = cdd.block_elimination(mat1, {2, 3, 4}) # 0 <= 2 + 3a assert_matrix_almost_equal(mat2.array, [[2, 3]]) @@ -21,7 +21,7 @@ def test_block_elimination_2() -> None: [-7, 1, -5, 2], # -x+5y-2z<=-7 [12, 3, -2, -6], # -3x+2y+6z<=12 ] - mat1 = cdd.matrix_from_array(array, rep_type=cdd.RepType.INEQUALITY) + mat1 = cdd.matrix_from_array(array, rep=cdd.Rep.INEQUALITY) # eliminate last variable, same as fourier mat2 = cdd.block_elimination(mat1, {3}) assert_matrix_almost_equal( @@ -38,7 +38,7 @@ def test_block_elimination_2() -> None: def test_block_elimination_3() -> None: # 0 = -2 + x + y, 0 <= y array = [[-2, 1, 1], [0, 0, 1]] - mat1 = cdd.matrix_from_array(array, rep_type=cdd.RepType.INEQUALITY, lin_set=[0]) + mat1 = cdd.matrix_from_array(array, rep=cdd.Rep.INEQUALITY, lin_set=[0]) mat2 = cdd.block_elimination(mat1, {2}) # 0 <= 2 - x assert_matrix_almost_equal(mat2.array, [[2, -1]]) diff --git a/test/test_enums.py b/test/test_enums.py index 8d17e6c..63410e4 100644 --- a/test/test_enums.py +++ b/test/test_enums.py @@ -3,17 +3,17 @@ import cdd -def test_rep_type() -> None: - assert cdd.RepType.INEQUALITY == 1 - assert cdd.RepType.INEQUALITY.name == "INEQUALITY" - assert cdd.RepType.INEQUALITY.value == 1 - assert [val for val in cdd.RepType] == [0, 1, 2] - assert [val.name for val in cdd.RepType] == [ +def test_rep() -> None: + assert cdd.Rep.INEQUALITY == 1 + assert cdd.Rep.INEQUALITY.name == "INEQUALITY" + assert cdd.Rep.INEQUALITY.value == 1 + assert [val for val in cdd.Rep] == [0, 1, 2] + assert [val.name for val in cdd.Rep] == [ "UNSPECIFIED", "INEQUALITY", "GENERATOR", ] - assert [val.value for val in cdd.RepType] == [0, 1, 2] - assert isinstance(cdd.RepType.INEQUALITY, cdd.RepType) - assert isinstance(cdd.RepType.INEQUALITY, int) - assert issubclass(cdd.RepType, IntEnum) + assert [val.value for val in cdd.Rep] == [0, 1, 2] + assert isinstance(cdd.Rep.INEQUALITY, cdd.Rep) + assert isinstance(cdd.Rep.INEQUALITY, int) + assert issubclass(cdd.Rep, IntEnum) diff --git a/test/test_fourier_elimination.py b/test/test_fourier_elimination.py index 80e9018..5ecce10 100644 --- a/test/test_fourier_elimination.py +++ b/test/test_fourier_elimination.py @@ -8,7 +8,7 @@ def test_fourier_elimination_1() -> None: # 0 <= 1 + x + y, 0 <= 1 + 3x - y array = [[1, 1, 1], [1, 3, -1]] - mat1 = cdd.matrix_from_array(array, rep_type=cdd.RepType.INEQUALITY) + mat1 = cdd.matrix_from_array(array, rep=cdd.Rep.INEQUALITY) mat2 = cdd.fourier_elimination(mat1) # 0 <= 1 + 2x assert_matrix_almost_equal(mat2.array, [[1, 2]]) @@ -23,7 +23,7 @@ def test_fourier_elimination_2() -> None: [-7, 1, -5, 2], # -x+5y-2z<=-7 [12, 3, -2, -6], # -3x+2y+6z<=12 ] - mat1 = cdd.matrix_from_array(array, rep_type=cdd.RepType.INEQUALITY) + mat1 = cdd.matrix_from_array(array, rep=cdd.Rep.INEQUALITY) mat2 = cdd.fourier_elimination(mat1) assert_matrix_almost_equal( mat2.array, @@ -37,6 +37,6 @@ def test_fourier_elimination_2() -> None: def test_fourier_elimination_3() -> None: array = [[1, 1, 1]] - mat = cdd.matrix_from_array(array, rep_type=cdd.RepType.INEQUALITY, lin_set=[0]) + mat = cdd.matrix_from_array(array, rep=cdd.Rep.INEQUALITY, lin_set=[0]) with pytest.raises(RuntimeError, match="cannot handle linearity"): cdd.fourier_elimination(mat) diff --git a/test/test_incidence.py b/test/test_incidence.py index e02da7a..a1282d2 100644 --- a/test/test_incidence.py +++ b/test/test_incidence.py @@ -16,7 +16,7 @@ def test_vertex_incidence_cube() -> None: [1, 0, 0, -1], ] ) - mat.rep_type = cdd.RepType.INEQUALITY + mat.rep = cdd.Rep.INEQUALITY poly = cdd.polyhedron_from_matrix(mat) incidence = cdd.copy_incidence(poly) @@ -55,7 +55,7 @@ def test_vertex_incidence_vtest_vo() -> None: ] ) - mat.rep_type = cdd.RepType.INEQUALITY + mat.rep = cdd.Rep.INEQUALITY poly = cdd.polyhedron_from_matrix(mat) incidence_list = [ @@ -87,7 +87,7 @@ def test_facet_incidence_cube() -> None: [1, 0, 0, -1], ] ) - mat.rep_type = cdd.RepType.INEQUALITY + mat.rep = cdd.Rep.INEQUALITY poly = cdd.polyhedron_from_matrix(mat) incidence = cdd.copy_input_incidence(poly) @@ -127,7 +127,7 @@ def test_facet_incidence_vtest_vo() -> None: ] ) - mat.rep_type = cdd.RepType.INEQUALITY + mat.rep = cdd.Rep.INEQUALITY poly = cdd.polyhedron_from_matrix(mat) incidence_list = [ diff --git a/test/test_issue20.py b/test/test_issue20.py index 9e8e4df..d8f48ec 100644 --- a/test/test_issue20.py +++ b/test/test_issue20.py @@ -12,7 +12,7 @@ def test_issue20() -> None: [[1, -1, -1], [0, 1, 0], [0, 0, 1]], dtype=np.float16 ) mat = cdd.matrix_from_array(arr) # type: ignore - mat.rep_type = cdd.RepType.GENERATOR + mat.rep = cdd.Rep.GENERATOR cdd_poly = cdd.polyhedron_from_matrix(mat) ineq = np.array(cdd.copy_inequalities(cdd_poly).array) assert ((ref_ineq - ineq) == 0).all() diff --git a/test/test_issue25.py b/test/test_issue25.py index a6ba1ef..780754d 100644 --- a/test/test_issue25.py +++ b/test/test_issue25.py @@ -3,5 +3,5 @@ # check that empty polyhedron does not cause segfault def test_issue25() -> None: - mat = cdd.matrix_from_array([], rep_type=cdd.RepType.INEQUALITY) + mat = cdd.matrix_from_array([], rep=cdd.Rep.INEQUALITY) cdd.polyhedron_from_matrix(mat) diff --git a/test/test_issue7.py b/test/test_issue7.py index a5c9ea3..d8a914c 100644 --- a/test/test_issue7.py +++ b/test/test_issue7.py @@ -17,6 +17,6 @@ def test_issue7() -> None: [1.0, -4.0, 40.0, 4.0, -31.21985375, -4.91296, 17.90974622], [1.0, 4.0, 40.0, -4.0, -28.86014625, 4.91296, 20.26945371], ] - mat = cdd.matrix_from_array(array, rep_type=cdd.RepType.GENERATOR) + mat = cdd.matrix_from_array(array, rep=cdd.Rep.GENERATOR) with pytest.raises(RuntimeError, match="inconsistency"): cdd.polyhedron_from_matrix(mat) diff --git a/test/test_linprog.py b/test/test_linprog.py index c8c9f13..b6d88b4 100644 --- a/test/test_linprog.py +++ b/test/test_linprog.py @@ -4,10 +4,10 @@ import pytest from cdd import ( - LPObjType, - LPSolverType, - LPStatusType, - RepType, + LPObj, + LPSolver, + LPStatus, + Rep, linprog_from_array, linprog_from_matrix, linprog_solve, @@ -24,12 +24,12 @@ def test_lin_prog_type() -> None: # max 2 - x subject to -0.5 + x >= 0, 2 - x >= 0 array: Sequence[Sequence[float]] = [[-0.5, 1], [2, -1], [2, -1]] - lp = linprog_from_array(array, obj_type=LPObjType.MAX) + lp = linprog_from_array(array, obj=LPObj.MAX) assert_matrix_almost_equal(lp.array, array) - assert isinstance(lp.status, LPStatusType) - assert lp.status == LPStatusType.UNDECIDED - assert isinstance(lp.solver, LPSolverType) - assert lp.solver == LPSolverType.DUAL_SIMPLEX + assert isinstance(lp.status, LPStatus) + assert lp.status == LPStatus.UNDECIDED + assert isinstance(lp.solver, LPSolver) + assert lp.solver == LPSolver.DUAL_SIMPLEX assert isinstance(lp.obj_value, float) assert lp.obj_value == 0.0 assert isinstance(lp.primal_solution, Sequence) @@ -38,8 +38,8 @@ def test_lin_prog_type() -> None: assert x == 0.0 assert isinstance(lp.dual_solution, Sequence) assert not lp.dual_solution # no variables in basis... - linprog_solve(lp, solver=LPSolverType.CRISS_CROSS) - assert lp.solver == LPSolverType.CRISS_CROSS + linprog_solve(lp, solver=LPSolver.CRISS_CROSS) + assert lp.solver == LPSolver.CRISS_CROSS assert_almost_equal(lp.obj_value, 1.5) assert_vector_almost_equal(lp.primal_solution, [0.5]) assert_matrix_almost_equal(lp.dual_solution, [(0, 1.0)]) @@ -53,9 +53,9 @@ def test_lp2() -> None: [0, 0, 1], [0, 3, 4], # objective function ] - lp = linprog_from_array(array, obj_type=LPObjType.MAX) + lp = linprog_from_array(array, obj=LPObj.MAX) linprog_solve(lp) - assert lp.status == LPStatusType.OPTIMAL + assert lp.status == LPStatus.OPTIMAL assert_almost_equal(lp.obj_value, 11 / 3) assert_vector_almost_equal(lp.primal_solution, [1 / 3, 2 / 3]) assert_matrix_almost_equal(lp.dual_solution, [(0, 3 / 2), (1, 5 / 2)]) @@ -69,9 +69,9 @@ def test_linprog_from_matrix() -> None: mat = matrix_from_array( array=array, lin_set=lin_set, - obj_type=LPObjType.MIN, + obj=LPObj.MIN, obj_func=obj_func, - rep_type=RepType.INEQUALITY, + rep=Rep.INEQUALITY, ) lp = linprog_from_matrix(mat) assert_matrix_almost_equal( @@ -91,48 +91,48 @@ def test_linprog_from_matrix() -> None: assert_matrix_almost_equal(lp.dual_solution, [(3, -0.18), (4, -1.12), (2, -0.08)]) -def test_linprog_bad_obj_type() -> None: - with pytest.raises(ValueError, match="obj_type must be MIN or MAX"): - linprog_from_array([[1, 1], [1, 1]], obj_type=LPObjType.NONE) +def test_linprog_bad_obj() -> None: + with pytest.raises(ValueError, match="obj must be MIN or MAX"): + linprog_from_array([[1, 1], [1, 1]], obj=LPObj.NONE) @pytest.mark.parametrize( - "array,obj_type,status,primal_solution", + "array,obj,status,primal_solution", [ # 0 <= -2 + x, 0 <= 3 - x, obj func 0 + x - ([[-2, 1], [3, -1], [0, 1]], LPObjType.MIN, LPStatusType.OPTIMAL, (2,)), - ([[-2, 1], [3, -1], [0, 1]], LPObjType.MAX, LPStatusType.OPTIMAL, (3,)), + ([[-2, 1], [3, -1], [0, 1]], LPObj.MIN, LPStatus.OPTIMAL, (2,)), + ([[-2, 1], [3, -1], [0, 1]], LPObj.MAX, LPStatus.OPTIMAL, (3,)), # 0 <= 5 + x, obj func 0 + x - ([[5, 1], [0, 1]], LPObjType.MIN, LPStatusType.OPTIMAL, (-5,)), - ([[5, 1], [0, 1]], LPObjType.MAX, LPStatusType.DUAL_INCONSISTENT, None), + ([[5, 1], [0, 1]], LPObj.MIN, LPStatus.OPTIMAL, (-5,)), + ([[5, 1], [0, 1]], LPObj.MAX, LPStatus.DUAL_INCONSISTENT, None), # 0 <= x, 0 <= -1 - x, obj func 0 + x - ([[0, 1], [-1, -1], [0, 1]], LPObjType.MIN, LPStatusType.INCONSISTENT, None), - ([[0, 1], [-1, -1], [0, 1]], LPObjType.MAX, LPStatusType.INCONSISTENT, None), + ([[0, 1], [-1, -1], [0, 1]], LPObj.MIN, LPStatus.INCONSISTENT, None), + ([[0, 1], [-1, -1], [0, 1]], LPObj.MAX, LPStatus.INCONSISTENT, None), # corner case where constraints contain no variables # primal: max x s.t. 0 <= 1 -> unbounded # dual: min y s.t. 0 >= 1 -> inconsistent - ([[1, 0], [0, 1]], LPObjType.MIN, LPStatusType.STRUC_DUAL_INCONSISTENT, None), - ([[1, 0], [0, 1]], LPObjType.MAX, LPStatusType.STRUC_DUAL_INCONSISTENT, None), + ([[1, 0], [0, 1]], LPObj.MIN, LPStatus.STRUC_DUAL_INCONSISTENT, None), + ([[1, 0], [0, 1]], LPObj.MAX, LPStatus.STRUC_DUAL_INCONSISTENT, None), # https://math.stackexchange.com/a/4864771 # corner case where both primal and dual are inconsistent # primal: max x s.t. 0 <= -1 -> inconsistent # dual: min -y s.t. 0 >= 1 -> inconsistent - ([[-1, 0], [0, 1]], LPObjType.MAX, LPStatusType.STRUC_DUAL_INCONSISTENT, None), - ([[-1, 0], [0, -1]], LPObjType.MIN, LPStatusType.STRUC_DUAL_INCONSISTENT, None), + ([[-1, 0], [0, 1]], LPObj.MAX, LPStatus.STRUC_DUAL_INCONSISTENT, None), + ([[-1, 0], [0, -1]], LPObj.MIN, LPStatus.STRUC_DUAL_INCONSISTENT, None), # corner case where everything is zero # primal: max 0x s.t. 0 <= 0 -> optimal # dual: min 0y s.t. 0 >= 0 -> optimal - ([[0, 0], [0, 0]], LPObjType.MAX, LPStatusType.OPTIMAL, None), - ([[0, 0], [0, 0]], LPObjType.MIN, LPStatusType.OPTIMAL, None), + ([[0, 0], [0, 0]], LPObj.MAX, LPStatus.OPTIMAL, None), + ([[0, 0], [0, 0]], LPObj.MIN, LPStatus.OPTIMAL, None), ], ) def test_linprog_1( array: Sequence[Sequence[float]], - obj_type: LPObjType, - status: LPStatusType, + obj: LPObj, + status: LPStatus, primal_solution: Optional[Sequence[float]], ) -> None: - lp = linprog_from_array(array, obj_type=obj_type) + lp = linprog_from_array(array, obj=obj) linprog_solve(lp) assert lp.status == status if primal_solution is not None: diff --git a/test/test_matrix.py b/test/test_matrix.py index 21a176b..03c58ff 100644 --- a/test/test_matrix.py +++ b/test/test_matrix.py @@ -19,10 +19,10 @@ def test_matrix_init_1() -> None: assert_matrix_almost_equal(mat.array, rows) assert isinstance(mat.lin_set, Set) assert not mat.lin_set - assert isinstance(mat.rep_type, cdd.RepType) - assert mat.rep_type == cdd.RepType.UNSPECIFIED - assert isinstance(mat.obj_type, cdd.LPObjType) - assert mat.obj_type == cdd.LPObjType.NONE + assert isinstance(mat.rep, cdd.Rep) + assert mat.rep == cdd.Rep.UNSPECIFIED + assert isinstance(mat.obj, cdd.LPObj) + assert mat.obj == cdd.LPObj.NONE assert isinstance(mat.obj_func, Sequence) assert_vector_almost_equal(mat.obj_func, [0.0, 0.0, 0.0]) @@ -59,16 +59,16 @@ def test_matrix_copy_1() -> None: mat1 = cdd.matrix_from_array( [[1, 1], [0, 2]], lin_set={1}, - rep_type=cdd.RepType.GENERATOR, - obj_type=cdd.LPObjType.MIN, + rep=cdd.Rep.GENERATOR, + obj=cdd.LPObj.MIN, obj_func=[3, 4], ) mat2 = cdd.matrix_copy(mat1) assert_matrix_almost_equal(mat2.array, [[1, 1], [0, 2]]) assert_vector_almost_equal(mat2.obj_func, [3, 4]) assert mat2.lin_set == {1} - assert mat2.rep_type == cdd.RepType.GENERATOR - assert mat2.obj_type == cdd.LPObjType.MIN + assert mat2.rep == cdd.Rep.GENERATOR + assert mat2.obj == cdd.LPObj.MIN def test_matrix_append_to_1() -> None: diff --git a/test/test_matrix_canonicalize.py b/test/test_matrix_canonicalize.py index 68c2ffe..dc11254 100644 --- a/test/test_matrix_canonicalize.py +++ b/test/test_matrix_canonicalize.py @@ -7,7 +7,7 @@ def test_matrix_canonicalize_1() -> None: array = [[1, 1], [2, 1]] # 0 <= 1 + x, 0 <= 2 + x - mat = cdd.matrix_from_array(array, rep_type=cdd.RepType.INEQUALITY) + mat = cdd.matrix_from_array(array, rep=cdd.Rep.INEQUALITY) cdd.matrix_canonicalize(mat) assert_matrix_almost_equal(mat.array, [[1, 1]]) assert not mat.lin_set @@ -16,9 +16,9 @@ def test_matrix_canonicalize_1() -> None: def test_matrix_canonicalize_2() -> None: array = [[2, 1, 2, 3], [0, 1, 2, 3], [3, 0, 1, 2], [0, -2, -4, -6]] mat = cdd.matrix_from_array(array) - with pytest.raises(ValueError, match="rep_type unspecified"): + with pytest.raises(ValueError, match="rep unspecified"): cdd.matrix_canonicalize(mat) - mat.rep_type = cdd.RepType.INEQUALITY + mat.rep = cdd.Rep.INEQUALITY assert cdd.matrix_canonicalize(mat) == ({1, 3}, {0}) assert_matrix_almost_equal(mat.array, [[0, 1, 2, 3], [3, 0, 1, 2]]) @@ -26,7 +26,7 @@ def test_matrix_canonicalize_2() -> None: def test_matrix_canonicalize_3() -> None: # test on an inconsistent system array = [[1, 1], [1, -1]] # 0 = 1 + x, 0 = 1 - x - mat = cdd.matrix_from_array(array, rep_type=cdd.RepType.INEQUALITY, lin_set={0, 1}) + mat = cdd.matrix_from_array(array, rep=cdd.Rep.INEQUALITY, lin_set={0, 1}) assert cdd.matrix_canonicalize(mat) == (set(), set()) assert_matrix_almost_equal(mat.array, [[1, 1], [1, -1]]) assert mat.lin_set == {0, 1} diff --git a/test/test_pickle.py b/test/test_pickle.py index c16a85b..78d4291 100644 --- a/test/test_pickle.py +++ b/test/test_pickle.py @@ -13,18 +13,18 @@ def test_pickle_matrix() -> None: cdd.matrix_from_array( array=array, lin_set=lin_set, - rep_type=cdd.RepType.GENERATOR, + rep=cdd.Rep.GENERATOR, obj_func=obj_func, - obj_type=cdd.LPObjType.MIN, + obj=cdd.LPObj.MIN, ) ) mat = loads(data) assert isinstance(mat, cdd.Matrix) assert_matrix_almost_equal(mat.array, array) assert mat.lin_set == lin_set - assert mat.rep_type == cdd.RepType.GENERATOR + assert mat.rep == cdd.Rep.GENERATOR assert mat.obj_func == obj_func - assert mat.obj_type == cdd.LPObjType.MIN + assert mat.obj == cdd.LPObj.MIN def test_pickle_linprog() -> None: @@ -32,10 +32,10 @@ def test_pickle_linprog() -> None: data = dumps( cdd.linprog_from_array( array=array, - obj_type=cdd.LPObjType.MIN, + obj=cdd.LPObj.MIN, ) ) lp = loads(data) assert isinstance(lp, cdd.LinProg) assert_matrix_almost_equal(lp.array, array) - assert lp.obj_type == cdd.LPObjType.MIN + assert lp.obj == cdd.LPObj.MIN diff --git a/test/test_polyhedron.py b/test/test_polyhedron.py index cacb557..553af5e 100644 --- a/test/test_polyhedron.py +++ b/test/test_polyhedron.py @@ -11,7 +11,7 @@ def test_polyhedron_type() -> None: mat = cdd.matrix_from_array([[1, 1], [1, -1]]) - mat.rep_type = cdd.RepType.INEQUALITY + mat.rep = cdd.Rep.INEQUALITY poly = cdd.polyhedron_from_matrix(mat) assert isinstance(cdd.copy_generators(poly), cdd.Matrix) assert isinstance(cdd.copy_inequalities(poly), cdd.Matrix) @@ -30,10 +30,10 @@ def test_polyhedron_type() -> None: def test_sampleh1() -> None: array = [[2, -1, -1, 0], [0, 1, 0, 0], [0, 0, 1, 0]] - mat = cdd.matrix_from_array(array, rep_type=cdd.RepType.INEQUALITY) + mat = cdd.matrix_from_array(array, rep=cdd.Rep.INEQUALITY) poly = cdd.polyhedron_from_matrix(mat) ext = cdd.copy_generators(poly) - assert ext.rep_type == cdd.RepType.GENERATOR + assert ext.rep == cdd.Rep.GENERATOR assert_matrix_almost_equal( ext.array, [[1, 0, 0, 0], [1, 2, 0, 0], [1, 0, 2, 0], [0, 0, 0, 1]] ) @@ -42,10 +42,10 @@ def test_sampleh1() -> None: def test_testcdd2() -> None: array = [[7, -3, -0], [7, 0, -3], [1, 1, 0], [1, 0, 1]] - mat = cdd.matrix_from_array(array, rep_type=cdd.RepType.INEQUALITY) + mat = cdd.matrix_from_array(array, rep=cdd.Rep.INEQUALITY) assert_matrix_almost_equal(mat.array, array) gen = cdd.copy_generators(cdd.polyhedron_from_matrix(mat)) - assert gen.rep_type == cdd.RepType.GENERATOR + assert gen.rep == cdd.Rep.GENERATOR assert_matrix_almost_equal( gen.array, [ @@ -61,14 +61,14 @@ def test_testcdd2() -> None: assert_matrix_almost_equal(mat.array, array + [[7, 1, -3], [7, -3, 1]]) assert mat.lin_set == {4} gen2 = cdd.copy_generators(cdd.polyhedron_from_matrix(mat)) - assert gen2.rep_type == cdd.RepType.GENERATOR + assert gen2.rep == cdd.Rep.GENERATOR assert_matrix_almost_equal(gen2.array, [(1, -1, 2), (1, 0, Fraction(7, 3))]) def test_polyhedron_cube_1() -> None: generators = [[1, 0, 1], [1, 1, 0], [1, 1, 1], [1, 0, 0]] inequalities = [[0, 0, 1], [0, 1, 0], [1, 0, -1], [1, -1, 0]] - mat = cdd.matrix_from_array(generators, rep_type=cdd.RepType.GENERATOR) + mat = cdd.matrix_from_array(generators, rep=cdd.Rep.GENERATOR) poly = cdd.polyhedron_from_matrix(mat) assert_matrix_almost_equal(cdd.copy_generators(poly).array, generators) assert_matrix_almost_equal(cdd.copy_inequalities(poly).array, inequalities) @@ -77,7 +77,7 @@ def test_polyhedron_cube_1() -> None: def test_polyhedron_cube_2() -> None: generators = [[1, 1, 0], [1, 0, 0], [1, 0, 1], [1, 1, 1]] # same up to ordering inequalities = [[0, 0, 1], [0, 1, 0], [1, 0, -1], [1, -1, 0]] - mat = cdd.matrix_from_array(inequalities, rep_type=cdd.RepType.INEQUALITY) + mat = cdd.matrix_from_array(inequalities, rep=cdd.Rep.INEQUALITY) poly = cdd.polyhedron_from_matrix(mat) assert_matrix_almost_equal(cdd.copy_generators(poly).array, generators) assert_matrix_almost_equal(cdd.copy_inequalities(poly).array, inequalities) @@ -86,21 +86,21 @@ def test_polyhedron_cube_2() -> None: @pytest.mark.parametrize( "row_order_type,order", [ - (cdd.RowOrderType.MAX_INDEX, [2, 3, 0, 1]), - (cdd.RowOrderType.MIN_INDEX, [2, 1, 0, 3]), - (cdd.RowOrderType.MIN_CUTOFF, [1, 0, 2, 3]), - (cdd.RowOrderType.MAX_CUTOFF, [1, 0, 2, 3]), - (cdd.RowOrderType.MIX_CUTOFF, [1, 0, 2, 3]), - (cdd.RowOrderType.LEX_MIN, [0, 1, 2, 3]), - (cdd.RowOrderType.LEX_MAX, [2, 3, 0, 1]), + (cdd.RowOrder.MAX_INDEX, [2, 3, 0, 1]), + (cdd.RowOrder.MIN_INDEX, [2, 1, 0, 3]), + (cdd.RowOrder.MIN_CUTOFF, [1, 0, 2, 3]), + (cdd.RowOrder.MAX_CUTOFF, [1, 0, 2, 3]), + (cdd.RowOrder.MIX_CUTOFF, [1, 0, 2, 3]), + (cdd.RowOrder.LEX_MIN, [0, 1, 2, 3]), + (cdd.RowOrder.LEX_MAX, [2, 3, 0, 1]), ], ) def test_polyhedron_row_order_type( - row_order_type: Optional[cdd.RowOrderType], order: Sequence[int] + row_order_type: Optional[cdd.RowOrder], order: Sequence[int] ) -> None: generators = [[1, 1, 0], [1, 0, 0], [1, 0, 1], [1, 1, 1]] inequalities = [[0, 0, 1], [0, 1, 0], [1, 0, -1], [1, -1, 0]] - mat = cdd.matrix_from_array(inequalities, rep_type=cdd.RepType.INEQUALITY) + mat = cdd.matrix_from_array(inequalities, rep=cdd.Rep.INEQUALITY) poly = cdd.polyhedron_from_matrix(mat, row_order_type=row_order_type) print(cdd.copy_generators(poly).array) assert_matrix_almost_equal(