Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add class FlatsMatroid #37340

Merged
merged 13 commits into from
Apr 8, 2024
1 change: 1 addition & 0 deletions src/doc/en/reference/matroids/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Concrete implementations
sage/matroids/basis_matroid
sage/matroids/circuits_matroid
sage/matroids/circuit_closures_matroid
sage/matroids/flats_matroid
sage/matroids/linear_matroid
sage/matroids/rank_matroid
sage/matroids/graphic_matroid
Expand Down
17 changes: 15 additions & 2 deletions src/sage/matroids/constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
import sage.matroids.basis_exchange_matroid
from .rank_matroid import RankMatroid
from .circuits_matroid import CircuitsMatroid
from .flats_matroid import FlatsMatroid
from .circuit_closures_matroid import CircuitClosuresMatroid
from .basis_matroid import BasisMatroid
from .linear_matroid import LinearMatroid, RegularMatroid, BinaryMatroid, TernaryMatroid, QuaternaryMatroid
Expand Down Expand Up @@ -180,6 +181,7 @@ def Matroid(groundset=None, data=None, **kwds):
- ``circuits`` -- The list of circuits of the matroid.
- ``nonspanning_circuits`` -- The list of nonspanning_circuits of the
matroid.
- ``flats`` -- The dictionary of flats indexed by their rank.
gmou3 marked this conversation as resolved.
Show resolved Hide resolved
- ``graph`` -- A graph, whose edges form the elements of the matroid.
- ``matrix`` -- A matrix representation of the matroid.
- ``reduced_matrix`` -- A reduced representation of the matroid: if
Expand Down Expand Up @@ -698,8 +700,9 @@ def Matroid(groundset=None, data=None, **kwds):
key = None
if data is None:
for k in ['bases', 'independent_sets', 'circuits',
'nonspanning_circuits', 'graph', 'matrix', 'reduced_matrix',
'rank_function', 'revlex', 'circuit_closures', 'matroid']:
'nonspanning_circuits', 'flats', 'graph', 'matrix',
'reduced_matrix', 'rank_function', 'revlex',
'circuit_closures', 'matroid']:
if k in kwds:
data = kwds.pop(k)
key = k
Expand Down Expand Up @@ -791,6 +794,16 @@ def Matroid(groundset=None, data=None, **kwds):
nsc_defined=True
)

# Flats
elif key == 'flats':
# Determine groundset
if groundset is None:
groundset = set()
for i in data:
for F in data[i]:
groundset.update(F)
M = FlatsMatroid(groundset=groundset, flats=data)

# Graphs:
elif key == 'graph':
from sage.graphs.graph import Graph
Expand Down
20 changes: 20 additions & 0 deletions src/sage/matroids/flats_matroid.pxd
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from sage.matroids.matroid cimport Matroid

cdef class FlatsMatroid(Matroid):
cdef frozenset _groundset # _E
cdef int _matroid_rank # _R
cdef dict _F # flats
cpdef groundset(self) noexcept
gmou3 marked this conversation as resolved.
Show resolved Hide resolved
cpdef _rank(self, X) noexcept
cpdef full_rank(self) noexcept
cpdef _is_independent(self, F) noexcept

# enumeration
cpdef flats(self, k) noexcept
cpdef whitney_numbers2(self) noexcept

# isomorphism
cpdef _is_isomorphic(self, other, certificate=*) noexcept

# verification
cpdef is_valid(self) noexcept
Loading
Loading