Skip to content

Commit 9df7a19

Browse files
jsantillan3J SJ S
authored
Add examples to OneSumNode in seymour_decomposition.pyx, add methods block_matrix_form, summand_matrices (sagemath#8)
* wip onesum * wip onesum2 * wip onesum test * onesum node example * fixed names of .summand_matrices() and .block_matrix_form, ....: and added examples to ._children() * style fixes --------- Co-authored-by: J S <[email protected]> Co-authored-by: J S <[email protected]>
1 parent 6bcdbeb commit 9df7a19

File tree

1 file changed

+82
-2
lines changed

1 file changed

+82
-2
lines changed

src/sage/matrix/seymour_decomposition.pyx

+82-2
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,35 @@ cdef class DecompositionNode(SageObject):
157157

158158
@cached_method
159159
def _children(self):
160+
r"""
161+
Returns tuple of summands, () in the case of graphic or leaf nodes.
162+
EXAMPLES::
163+
164+
sage: from sage.matrix.matrix_cmr_sparse import Matrix_cmr_chr_sparse
165+
sage: M = Matrix_cmr_chr_sparse.one_sum([[1, 0], [-1, 1]],
166+
....: [[1, 1], [-1, 0]], [[1, 0], [0,1]]); M
167+
[ 1 0| 0 0| 0 0]
168+
[-1 1| 0 0| 0 0]
169+
[-----+-----+-----]
170+
[ 0 0| 1 1| 0 0]
171+
[ 0 0|-1 0| 0 0]
172+
[-----+-----+-----]
173+
[ 0 0| 0 0| 1 0]
174+
[ 0 0| 0 0| 0 1]
175+
sage: result, certificate = M3.is_totally_unimodular(certificate=True); certificate
176+
OneSumNode with 4 children
177+
sage: certificate._children()
178+
(GraphicNode, GraphicNode, GraphicNode, GraphicNode)
179+
180+
sage: M2 = Matrix_cmr_chr_sparse(MatrixSpace(ZZ, 2, 2, sparse=True),
181+
...: [[1, 1], [-1, 0]]); M2
182+
[ 1 1]
183+
[-1 0]
184+
sage: result, certificate = M.is_totally_unimodular(certificate=True); certificate
185+
GraphicNode
186+
certificate._children()
187+
()
188+
"""
160189
return tuple(create_DecompositionNode(CMRdecChild(self._dec, index),
161190
self._root or self)
162191
for index in range(CMRdecNumChildren(self._dec)))
@@ -194,14 +223,65 @@ cdef class SumNode(DecompositionNode):
194223

195224
summands = DecompositionNode._children
196225

226+
def summand_matrices(self):
227+
return tuple(s.matrix() for s in self._children())
228+
197229

198230
cdef class OneSumNode(SumNode):
199231

200-
pass
232+
def block_matrix_form(self):
233+
r"""
234+
EXAMPLES::
235+
236+
sage: from sage.matrix.matrix_cmr_sparse import Matrix_cmr_chr_sparse
237+
sage: M = Matrix_cmr_chr_sparse.one_sum([[1, 0], [-1, 1]], [[1, 1], [-1, 0]])
238+
sage: result, certificate = M.is_totally_unimodular(certificate=True); certificate
239+
OneSumNode with 2 children
240+
sage: certificate.summand_matrices()
241+
(
242+
[ 1 0] [ 1 1]
243+
[-1 1], [-1 0]
244+
)
245+
sage: certificate.block_matrix_form()
246+
[ 1 0| 0 0]
247+
[-1 1| 0 0]
248+
[-----+-----]
249+
[ 0 0| 1 1]
250+
[ 0 0|-1 0]
251+
252+
sage: M3 = Matrix_cmr_chr_sparse.one_sum([[1, 0], [-1, 1]], [[1, 1], [-1, 0]], [[1, 0], [0,1]]
253+
....: [[1, 1], [-1, 0]], [[1, 0], [0,1]]); M3
254+
[ 1 0| 0 0| 0 0]
255+
[-1 1| 0 0| 0 0]
256+
[-----+-----+-----]
257+
[ 0 0| 1 1| 0 0]
258+
[ 0 0|-1 0| 0 0]
259+
[-----+-----+-----]
260+
[ 0 0| 0 0| 1 0]
261+
[ 0 0| 0 0| 0 1]
262+
sage: result, certificate = M3.is_totally_unimodular(certificate=True); certificate
263+
OneSumNode with 4 children
264+
sage: certificate.summand_matrices()
265+
(
266+
[ 1 0] [ 1 1]
267+
[-1 1], [-1 0], [1], [1]
268+
)
269+
sage: certificate.block_matrix_form()
270+
[ 1 0| 0 0| 0| 0]
271+
[-1 1| 0 0| 0| 0]
272+
[-----+-----+--+--]
273+
[ 0 0| 1 1| 0| 0]
274+
[ 0 0|-1 0| 0| 0]
275+
[-----+-----+--+--]
276+
[ 0 0| 0 0| 1| 0]
277+
[-----+-----+--+--]
278+
[ 0 0| 0 0| 0| 1]
279+
"""
280+
return Matrix_cmr_chr_sparse.one_sum(*self.summand_matrices())
201281

202282

203283
cdef class TwoSumNode(SumNode):
204-
284+
205285
pass
206286

207287

0 commit comments

Comments
 (0)