diff --git a/cython/pycddlib.pxi b/cython/pycddlib.pxi index 94ce110..c014234 100644 --- a/cython/pycddlib.pxi +++ b/cython/pycddlib.pxi @@ -89,14 +89,15 @@ cdef _get_set(set_type set_): elem for elem in range(set_[0]) if set_member(elem + 1, set_) } -cdef _set_set(set_type set_, elems): +cdef _set_set(set_type set_, elems, bool is_var_ind=False): # set elements of set_type by elements from a Python Container cdef unsigned long elem + offset = 2 if is_var_ind else 1 for elem in range(set_[0]): if elem in elems: - set_addelem(set_, elem + 1) + set_addelem(set_, elem + offset) else: - set_delelem(set_, elem + 1) + set_delelem(set_, elem + offset) cdef setfam_from_ptr(dd_SetFamilyPtr dd_setfam): # create Python Sequence[Set] from dd_SetFamilyPtr, and @@ -1171,8 +1172,8 @@ def fourier_elimination(mat: Matrix) -> Matrix: return matrix_from_ptr_with_error(dd_mat, error) -def block_elimination(mat: Matrix, col_set: Container[int]) -> Matrix: - """Eliminate the variables *col_set* from the system of linear inequalities *mat*. +def block_elimination(mat: Matrix, var_set: Container[int]) -> Matrix: + """Eliminate the variables *var_set* from the system of linear inequalities *mat*. It does this by using the generators of the dual linear system, where the generators are calculated using the double description algorithm. @@ -1191,7 +1192,7 @@ def block_elimination(mat: Matrix, col_set: Container[int]) -> Matrix: cdef dd_ErrorType error = dd_NoError set_initialize(&dd_colset, mat.dd_mat.colsize) try: - _set_set(dd_colset, col_set) + _set_set(dd_colset, var_set, True) dd_mat = dd_BlockElimination(mat.dd_mat, dd_colset, &error) return matrix_from_ptr_with_error(dd_mat, error) finally: diff --git a/test/test_block_elimination.py b/test/test_block_elimination.py index b446425..32d583d 100644 --- a/test/test_block_elimination.py +++ b/test/test_block_elimination.py @@ -7,7 +7,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) - mat2 = cdd.block_elimination(mat1, {2, 3, 4}) + mat2 = cdd.block_elimination(mat1, {1, 2, 3}) # 0 <= 2 + 3a assert_matrix_almost_equal(mat2.array, [[2, 3]]) assert mat2.lin_set == set() @@ -23,7 +23,7 @@ def test_block_elimination_2() -> None: ] mat1 = cdd.matrix_from_array(array, rep_type=cdd.RepType.INEQUALITY) # eliminate last variable, same as fourier - mat2 = cdd.block_elimination(mat1, {3}) + mat2 = cdd.block_elimination(mat1, {2}) assert_matrix_almost_equal( mat2.array, [ @@ -39,7 +39,7 @@ 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]) - mat2 = cdd.block_elimination(mat1, {2}) + mat2 = cdd.block_elimination(mat1, {1}) # 0 <= 2 - x assert_matrix_almost_equal(mat2.array, [[2, -1]]) assert mat2.lin_set == set()