Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
""" Iterators for linear subclasses
The classes below are iterators returned by the functions :func:`M.linear_subclasses() <sage.matroids.matroid.Matroid.linear_subclasses>` and :func:`M.extensions() <sage.matroids.matroid.Matroid.extensions>`. See the documentation of these methods for more detail. For direct access to these classes, run::
sage: from sage.matroids.advanced import *
See also :mod:`sage.matroids.advanced`.
AUTHORS:
- Rudi Pendavingh, Stefan van Zwam (2013-04-01): initial version
Methods ======= """ #***************************************************************************** # Copyright (C) 2013 Rudi Pendavingh <rudi.pendavingh@gmail.com> # Copyright (C) 2013 Stefan van Zwam <stefanvanzwam@gmail.com> # # # Distributed under the terms of the GNU General Public License (GPL) # as published by the Free Software Foundation; either version 2 of # the License, or (at your option) any later version. # http://www.gnu.org/licenses/ #***************************************************************************** from __future__ import print_function
include 'sage/data_structures/bitset.pxi' from .basis_matroid cimport BasisMatroid
cdef class CutNode: """ An internal class used for creating linear subclasses of a matroids in a depth-first manner.
A linear subclass is a set of hyperplanes `mc` with the property that certain sets of hyperplanes must either be fully contained in `mc` or intersect `mc` in at most 1 element. The way we generate them is by a depth-first seach. This class represents a node in the search tree.
It contains the set of hyperplanes selected so far, as well as a collection of hyperplanes whose insertion has been explored elsewhere in the seach tree.
The class has methods for selecting a hyperplane to insert, for inserting hyperplanes and closing the set to become a linear subclass again, and for adding a hyperplane to the set of *forbidden* hyperplanes, and similarly closing that set.
""" def __cinit__(self, MC, N=None): """ Internal data structure init
EXAMPLES::
sage: len(list(matroids.named_matroids.Fano().linear_subclasses())) # indirect doctest 16 """ cdef CutNode node else:
def __dealloc__(self):
cdef CutNode copy(self):
cdef bint insert_plane(self, long p0): """ Add a hyperplane to the linear subclass. """ cdef long l, p cdef list p_stack, l_stack return False else: else:
cdef bint remove_plane(self, long p0): """ Remove a hyperplane from the linear subclass. """ cdef long p, l cdef list p_stack, l_stack else:
cdef select_plane(self): """ Choose a hyperplane from the linear subclass. """ cdef long l, p
cdef list planes(self): """ Return all hyperplanes from the linear subclass. """
cdef class LinearSubclassesIter: """ An iterator for a set of linear subclass. """ def __init__(self, MC): """ Create a linear subclass iterator.
Auxiliary to class LinearSubclasses.
INPUT:
- ``MC`` -- a member of class LinearSubclasses.
EXAMPLES::
sage: from sage.matroids.extension import LinearSubclasses sage: M = matroids.Uniform(3, 6) sage: type(LinearSubclasses(M).__iter__()) <... 'sage.matroids.extension.LinearSubclassesIter'> """
return
return
def __next__(self): """ Return the next linear subclass.
EXAMPLES::
sage: from sage.matroids.advanced import * sage: from sage.matroids.extension import LinearSubclasses sage: M = BasisMatroid(matroids.Uniform(3, 6)) sage: I = LinearSubclasses(M).__iter__() sage: M.extension('x', I.__next__()) Matroid of rank 3 on 7 elements with 35 bases sage: M.extension('x', I.__next__()) Matroid of rank 3 on 7 elements with 34 bases """ cdef CutNode node, node2
cdef class LinearSubclasses: """ An iterable set of linear subclasses of a matroid.
Enumerate linear subclasses of a given matroid. A *linear subclass* is a collection of hyperplanes (flats of rank `r - 1` where `r` is the rank of the matroid) with the property that no modular triple of hyperplanes has exactly two members in the linear subclass. A triple of hyperplanes in a matroid of rank `r` is *modular* if its intersection has rank `r - 2`.
INPUT:
- ``M`` -- a matroid. - ``line_length`` -- (default: ``None``) an integer. - ``subsets`` -- (default: ``None``) a set of subsets of the groundset of ``M``. - ``splice`` -- (default: ``None``) a matroid `N` such that for some `e \in E(N)` and some `f \in E(M)`, we have `N\setminus e= M\setminus f`.
OUTPUT:
An enumerator for the linear subclasses of M.
If ``line_length`` is not ``None``, the enumeration is restricted to linear subclasses ``mc`` so containing at least one of each set of ``line_length`` hyperplanes which have a common intersection of rank `r - 2`.
If ``subsets`` is not ``None``, the enumeration is restricted to linear subclasses ``mc`` containing all hyperplanes which fully contain some set from ``subsets``.
If ``splice`` is not ``None``, then the enumeration is restricted to linear subclasses `mc` such that if `M'` is the extension of `M` by `e` that arises from `mc`, then `M'\setminus f = N`.
EXAMPLES::
sage: from sage.matroids.extension import LinearSubclasses sage: M = matroids.Uniform(3, 6) sage: len([mc for mc in LinearSubclasses(M)]) 83 sage: len([mc for mc in LinearSubclasses(M, line_length=5)]) 22 sage: for mc in LinearSubclasses(M, subsets=[[0, 1], [2, 3], [4, 5]]): ....: print(len(mc)) 3 15
Note that this class is intended for runtime, internal use, so no loads/dumps mechanism was implemented. """ def __init__(self, M, line_length=None, subsets=None, splice=None): """ See class docstring for full documentation.
EXAMPLES::
sage: from sage.matroids.advanced import * # LinearSubclasses, BasisMatroid sage: M = matroids.Uniform(3, 6) sage: len([mc for mc in LinearSubclasses(M)]) 83 sage: len([mc for mc in LinearSubclasses(M, line_length=5)]) 22 sage: for mc in LinearSubclasses(M, ....: subsets=[[0, 1], [2, 3], [4, 5]]): ....: print(len(mc)) 3 15 sage: M = BasisMatroid(matroids.named_matroids.BetsyRoss()); M Matroid of rank 3 on 11 elements with 140 bases sage: e = 'k'; f = 'h'; Me = M.delete(e); Mf=M.delete(f) sage: for mc in LinearSubclasses(Mf, splice=Me): ....: print(Mf.extension(f, mc)) Matroid of rank 3 on 11 elements with 141 bases Matroid of rank 3 on 11 elements with 140 bases sage: for mc in LinearSubclasses(Me, splice=Mf): ....: print(Me.extension(e, mc)) Matroid of rank 3 on 11 elements with 141 bases Matroid of rank 3 on 11 elements with 140 bases """ # set up hyperplanes/ hyperlines
raise ValueError("LinearSubclasses: the ground set of the splice matroid is not of the form E + e-f")
else:
def __iter__(self): """ Return an iterator for the linear subclasses.
EXAMPLES::
sage: from sage.matroids.extension import LinearSubclasses sage: M = matroids.Uniform(3, 6) sage: for mc in LinearSubclasses(M, subsets=[[0, 1], [2, 3], [4, 5]]): ....: print(len(mc)) 3 15 """
def __getitem__(self, CutNode node): """ Return a linear subclass stored in a given CutNode.
Internal function.
EXAMPLES::
sage: from sage.matroids.extension import LinearSubclasses sage: M = matroids.Uniform(3, 6) sage: len([mc for mc in LinearSubclasses(M)]) 83 """ cdef long p
cdef class MatroidExtensions(LinearSubclasses): """ An iterable set of single-element extensions of a given matroid.
INPUT:
- ``M`` -- a matroid - ``e`` -- an element - ``line_length`` (default: ``None``) -- an integer - ``subsets`` (default: ``None``) -- a set of subsets of the groundset of ``M`` - ``splice`` -- a matroid `N` such that for some `f \in E(M)`, we have `N\setminus e= M\setminus f`.
OUTPUT:
An enumerator for the extensions of ``M`` to a matroid ``N`` so that `N\setminus e = M`. If ``line_length`` is not ``None``, the enumeration is restricted to extensions `N` without `U(2, k)`-minors, where ``k > line_length``.
If ``subsets`` is not ``None``, the enumeration is restricted to extensions `N` of `M` by element `e` so that all hyperplanes of `M` which fully contain some set from ``subsets``, will also span `e`.
If ``splice`` is not ``None``, then the enumeration is restricted to extensions `M'` such that `M'\setminus f = N`, where `E(M)\setminus E(N)=\{f\}`.
EXAMPLES::
sage: from sage.matroids.advanced import * sage: M = matroids.Uniform(3, 6) sage: len([N for N in MatroidExtensions(M, 'x')]) 83 sage: len([N for N in MatroidExtensions(M, 'x', line_length=5)]) 22 sage: for N in MatroidExtensions(M, 'x', subsets=[[0, 1], [2, 3], ....: [4, 5]]): print(N) Matroid of rank 3 on 7 elements with 32 bases Matroid of rank 3 on 7 elements with 20 bases sage: M = BasisMatroid(matroids.named_matroids.BetsyRoss()); M Matroid of rank 3 on 11 elements with 140 bases sage: e = 'k'; f = 'h'; Me = M.delete(e); Mf=M.delete(f) sage: for N in MatroidExtensions(Mf, f, splice=Me): print(N) Matroid of rank 3 on 11 elements with 141 bases Matroid of rank 3 on 11 elements with 140 bases sage: for N in MatroidExtensions(Me, e, splice=Mf): print(N) Matroid of rank 3 on 11 elements with 141 bases Matroid of rank 3 on 11 elements with 140 bases
Note that this class is intended for runtime, internal use, so no loads/dumps mechanism was implemented. """ def __init__(self, M, e, line_length=None, subsets=None, splice=None, orderly=False): """ See class docstring for full documentation.
EXAMPLES::
sage: from sage.matroids.advanced import * sage: M = matroids.Uniform(3, 6) sage: len([N for N in MatroidExtensions(M, 'x')]) 83 sage: len([N for N in MatroidExtensions(M, 'x', line_length=5)]) 22 sage: for N in MatroidExtensions(M, 'x', subsets=[[0, 1], [2, 3], ....: [4, 5]]): print(N) Matroid of rank 3 on 7 elements with 32 bases Matroid of rank 3 on 7 elements with 20 bases
""" pass else: self._orderly = True
def __getitem__(self, CutNode node): """ Return a single-element extension determined by a given CutNode.
Internal function.
EXAMPLES::
sage: from sage.matroids.advanced import * sage: M = matroids.Uniform(3, 6) sage: len([N for N in MatroidExtensions(M, 'x')]) 83 """ cdef long i return None |