Closed d561a5fa-51dc-41bc-86f5-988f7f02b59b closed 11 years ago
Could you be interested in running this method on the transitive closure of your poset ?
Nathann
apply: poset_functionality_14099_er.patch
Is the transitive closure + subgraph_search fast enough to make it worthwhile?
Is the transitive closure + subgraph_search fast enough to make it worthwhile?
Well... It is sligthly smarter than what you do (it would not enumerate all chains of length 'n' beginning with an element v, if this element v is comparable with an element of the chain of length 'm' you already picked) and it is implemented in Cython.
I'd say that it's definitely worth a try.
Nathann
apply: poset_functionality_14099_er.patch
I don't think subgraph_search answers the same question....
Using induced=True results in the poset Poset({0 : [], 1 : [2], 2 : [3]}) which is 3+1 being (3+1)-free:
# g is the transitive closure
sage: g = DiGraph({0 : [], 1 : [2, 3], 2 : [3]})
sage: g.subgraph_search(DiGraph({0 : [1], 1 : [2]}) + DiGraph({0 : []}), induced=True)
Using induced=False results in the poset Poset({0 : [1, 2], 2 : [3]}) which is (3+1)-free containing (3+1):
# g is the transitive closure
sage: g = DiGraph({0 : [1, 2, 3], 2 : [3]})
sage: g.subgraph_search(DiGraph({0 : [1], 1 : [2]}) + DiGraph({0 : []}), induced=False)
Subgraph of (): Digraph on 4 vertices
you definitely need to use induced = True
, but not on the digraphs. As I said you need to work on their transitive closure :
def test(g,n,m):
n = 3
m = 1
pattern = digraphs.Circuit(n+1); pattern.delete_vertex(n)
pattern += digraphs.Circuit(m+1); pattern.delete_vertex(n+m-1)
c = g.transitive_closure().subgraph_search(pattern.transitive_closure(), induced = True)
if c:
print "Pattern found with chains", c.connected_components()
else:
print "No pattern in this graph"
g = DiGraph({0 : [], 1 : [2, 3], 2 : [3]})
test(g,3,1)
Nathann
Yes, you are right; it seems to work. It doesn't seem to be any faster for posets on 7 elements, but perhaps it's worth having both options available.
sage: def test1(poset, m, n):
....: for mchain in poset.chains().elements_of_depth_iterator(m):
....: for nchain in poset.chains().elements_of_depth_iterator(n):
....: if all(poset.compare_elements(x, y) is None for x in mchain for y in nchain):
....: return False
....: return True
....:
sage: %time len([p for p in Posets(7) if test1(p, 3, 1)])
CPU times: user 22.46 s, sys: 0.03 s, total: 22.49 s
Wall time: 22.49 s
639
sage: def test2(poset, m, n):
....: relations = poset.relations()
....: g = DiGraph([rel for rel in relations if rel[0] != rel[1]])
....: g.add_vertices([rel[0] for rel in relations if rel[0] == rel[1]])
....: mchain = digraphs.Circuit(m+1)
....: mchain.delete_vertex(m)
....: nchain = digraphs.Circuit(n+1)
....: nchain.delete_vertex(n)
....: return g.transitive_closure().subgraph_search((mchain + nchain).transitive_closure(), induced = True) is None
....:
sage: %time len([p for p in Posets(7) if test2(p, 3, 1)])
CPU times: user 23.47 s, sys: 0.01 s, total: 23.48 s
Wall time: 23.48 s
639
On the other hand, for larger posets using the graph search does much better:
sage: posets = [Posets.RandomPoset(30, .5) for x in range(10)]
sage: %time len([p for p in posets if test1(p, 3, 1)])
CPU times: user 20.69 s, sys: 0.00 s, total: 20.69 s
Wall time: 20.69 s
6
sage: %time len([p for p in posets if test2(p, 3, 1)])
CPU times: user 0.19 s, sys: 0.00 s, total: 0.19 s
Wall time: 0.19 s
6
Changed keywords from posets to posets, days45
Changed author from chrisjamesberg, rowland, ahmorales to Eric rowland, Alejandro Morales
Changed reviewer from saliola to Chris Berg
I just created ticket #14122 because of this ticket.
With that ticket, the following code
mchain = digraphs.Circuit(m+1)
mchain.delete_vertex(m)
nchain = digraphs.Circuit(n+1)
nchain.delete_vertex(n)
return g.transitive_closure().subgraph_search((mchain + nchain).transitive_closure(), induced = True) is None
can be replaced by
twochains = digraphs.Tournament(n) + digraphs.Tournament(m)
return g.transitive_closure().subgraph_search(twochains, induced = True) is None
Nathann
Attachment: poset_functionality_14099_er.patch.gz
Changed author from Eric rowland, Alejandro Morales to Eric Rowland, Alejandro Morales
As #14122 just got reviewed, could you rebase your patch on top of it and use the Tournament cnstructor ? :-)
By the way, could your merge your two functions into only one ? It would accept a list as a parameter and run the "real code" if the list has length one, and call itself on each pair of the list when it has a larger length.
Nathann
What is the advantage of merging them into one? The disadvantage is a decrease in clarity.
What is the advantage of merging them into one? The disadvantage is a decrease in clarity.
One advantage is that you only have to write documentation and doctests for only one function instead of two, and documentation and doctests are actually the largest part of this patch. Then 50% of the actual code is only there to deal with the input and not actual computations. If you want to improve clarity, you can also dramatically decrease the tests you do at the beginning. Something like that :
def i_take_lists_of_pairs_or_just_a_pair_as_input(u,v=None):
if v is None:
return all(i_take_lists_of_pairs_or_just_a_pair_as_input(*x) for x in u)
u,v = Integer(u), Integer(v)
if u<0 or v<0:
raise ValueError("Both elements of a pair must be positive integers")
# No I can do some actual computations
print u,v
return True
But honestly I think that only one method (taking a pair as input) should exist in Sage. To me the rest is "personal code".
Nathann
Nathann
instruction for the bot:
Apply poset_functionality_14099-er.patch
Description changed:
---
+++
@@ -1 +1,4 @@
-This is a test for finite posets to check if the do not have induced posets each of which isomorphic to two disjoint chains. Example 3+1 free, 2+2 free.
+This is a test for finite posets to check if they do not have induced posets isomorphic to the union of two disjoint chains. Example 3+1 free, 2+2 free.
+
+Apply:
+* [attachment: poset_functionality_14099-er.patch](https://github.com/sagemath/sage-prod/files/10657108/poset_functionality_14099-er.patch.gz)
I also think that only the method taking a pair of numbers should go into sage.
You can now use the TransitiveTournament method, it works for n=1.
Dependencies: #14536
This is now rebased on #14536.
Awaiting review.
Changed keywords from posets, days45 to posets, days45, days49
Helloooooooooooooooooooooo !!
Could you rewrite your reference so that Sphinx understands it ? You have an example there :
sage: Graph.average_distance??
O_o
Nathann
I have no idea what Sphinx is.
It is the piece of code that generates the html documentation of Sage.
sage -b && sage -docbuild reference/combinat html
Nathann
O_o
Nathann
Could you please rewrite the reference to [Stanley, Enumerative Combinatorics Volume 1, 2nd edition]
in the usual Sphinx format, or explain why you think that it is a bad idea ?
Nathann
Anything else?
O_O
Okayyyyyyyyyyyyyyyyyyyyyyyy I see ......
No way.
I am currently writing an additional patch for this bibliographical reference.
I will upload it shortly.
Nathann
Here is a patch that rewrites the reference to Stanley's book as we usually do in Sphinx, and as it is done in Graph.average_distance??
and other functions.
I don't know why you set the ticket to positive_review
twice even though the guy who was doing the review (=me) never said that he agreed with it. I don't get why Chris set it to positive review while there was a comment which had not been fixed either. Anyway, I think that this small attachment: trac_14099-rev.patch patch has to be added to this ticket too, unless you can explain why you prefer it to be left out.
Nathann
Description changed:
---
+++
@@ -2,3 +2,4 @@
Apply:
* [attachment: poset_functionality_14099-er.patch](https://github.com/sagemath/sage-prod/files/10657108/poset_functionality_14099-er.patch.gz)
+* [attachment: trac_14099-rev.patch](https://github.com/sagemath/sage-prod/files/10657109/trac_14099-rev.patch.gz)
I set the ticket to positive review, once, after I asked if there was anything else and you said "Okayyyyyyyyyyyyyyyyyyyyyyyy I see ......" which I took to mean that everything was okay.
Chris set it to positive review after I addressed your latest comment, which was not specific at all. I improved the typesetting of the variables. Apparently this was not what you had in mind, but you hadn't said that.
You need to be more clear in your communication with people who are learning how to contribute. At this point I am tired of making point modifications every time you think something should be changed, so please just finish the patch up yourself as you want it.
The patches need proper commit messages (use hg qrefresh -e
for that).
Attachment: poset_functionality_14099-er.patch.gz
The reviewer patch needs a proper commit message, use hg qrefresh -e
for this.
Attachment: trac_14099-rev.patch.gz
Merged: sage-5.11.rc0
This is a test for finite posets to check if they do not have induced posets isomorphic to the union of two disjoint chains. Example 3+1 free, 2+2 free.
Apply:
Depends on #14536
CC: @sagetrac-chrisjamesberg @sagetrac-ahmorales @saliola @nathanncohen @nthiery @hivert
Component: combinatorics
Keywords: posets, days45, days49
Author: Eric Rowland, Alejandro Morales
Reviewer: Chris Berg
Merged: sage-5.11.rc0
Issue created by migration from https://trac.sagemath.org/ticket/14099