1 | initial version |
The graphs with a given property (provided by the lambda function) are constructed by recurrence (see the augment
parameter in the doc). The problem you are facing is that having maximal degree at least two is not preserved by removing an edge. In particular, the graph on 5 vertices with no edges does not have this property, hence no larger graph can be constructed from this one, which explains why you do not get any graph in your first construction.
A possible workaround is to actually filter among all graphs of size 5:
sage: L = [G for G in graphs(5) if max(G.degree()) >= 2]
sage: len(L)
31
Of course, it is not speed-efficient since you have to look at all graphs.
2 | No.2 Revision |
The graphs with a given property (provided by the lambda function) are constructed by recurrence (see the augment
parameter in the doc). The problem you are facing is that having maximal degree at least two is not preserved by removing an edge. In particular, the graph on 5 vertices with no edges does not have this property, hence no larger graph can be constructed from this one, which explains why you do not get any graph in your first construction.
A possible workaround is to actually filter among all graphs of size 5:
sage: L = [G for G in graphs(5) if max(G.degree()) >= 2]
sage: len(L)
31
Of course, it is not speed-efficient in general since you have to look at all graphs.
Another workaround is to notice that the condition max(G.degree()) >= 2]
on G
is equivalent to the condition min(G.degree()) <= 2]
on G.complement()
, and this latter condition is hereditary:
sage: M = [G.complement() for G in graphs(5, lambda G: min(G.degree()) <= 2)]
sage: len(M)
31
Of course, you will not see much speed difference in this case, but it can matter for classes of graphs with smaller density among all graphs:
sage: %timeit L = [G for G in graphs(7) if max(G.degree()) >= 5]
1 loops, best of 3: 11.7 s per loop
sage: %timeit M = [G.complement() for G in graphs(7, lambda G: min(G.degree()) <= 1)]
1 loops, best of 3: 5.84 s per loop
3 | No.3 Revision |
The graphs with a given property (provided by the lambda function) are constructed by recurrence (see the augment
parameter in the doc). The problem you are facing is that having maximal degree at least two is not preserved by removing an edge. In particular, the graph on 5 vertices with no edges does not have this property, hence no larger graph can be constructed from this one, which explains why you do not get any graph in your first construction.
A possible workaround is to actually filter among all graphs of size 5:
sage: L = [G for G in graphs(5) if max(G.degree()) >= 2]
sage: len(L)
31
Of course, it is not speed-efficient in general since you have to look at all graphs. In your case it is not a problem since almost all graphs have your property.
Another workaround is to notice that the condition max(G.degree()) >=
on 2]2G
is equivalent to the condition min(G.degree()) <=
on 2]2G.complement()
, and this latter condition is hereditary:
sage: M = [G.complement() for G in graphs(5, lambda G: min(G.degree()) <= 2)]
sage: len(M)
31
Of course, you will not see much speed difference in this case, but it can matter for classes of graphs with smaller density among all graphs:
sage: %timeit L = [G for G in graphs(7) if max(G.degree()) >= 5]
1 loops, best of 3: 11.7 s per loop
sage: %timeit M = [G.complement() for G in graphs(7, lambda G: min(G.degree()) <= 1)]
1 loops, best of 3: 5.84 s per loop
4 | No.4 Revision |
The graphs with a given property (provided by the lambda function) are constructed by recurrence (see the augment
parameter in the doc). The problem you are facing is that having maximal degree at least two is not preserved by removing an edge. In particular, the graph on 5 vertices with no edges does not have this property, hence no larger graph can be constructed from this one, which explains why you do not get any graph in your first construction.
A possible workaround is to actually filter among all graphs of size 5:
sage: L = [G for G in graphs(5) if max(G.degree()) >= 2]
sage: len(L)
31
Of course, it is not speed-efficient in general since you have to look at all graphs. In your case it is not a problem since almost all graphs have your property.
Another workaround is to notice that the condition max(G.degree()) max(H.degree()) >= 2on for G
H=G
is equivalent to the condition min(G.degree()) min(H.degree()) <= 2on for G.complement()
H=G.complement()
, and this latter condition is hereditary:
sage: M = [G.complement() for G in graphs(5, lambda G: min(G.degree()) <= 2)]
sage: len(M)
31
Of course, you will not see much speed difference in this case, but it can matter for classes of graphs with smaller density among all graphs:
sage: %timeit L = [G for G in graphs(7) if max(G.degree()) >= 5]
1 loops, best of 3: 11.7 s per loop
sage: %timeit M = [G.complement() for G in graphs(7, lambda G: min(G.degree()) <= 1)]
1 loops, best of 3: 5.84 s per loop