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

Adding Method for testing avoidance in posets #14099

Closed
sagetrac-chrisjamesberg mannequin opened this issue Feb 12, 2013 · 43 comments
Closed

Adding Method for testing avoidance in posets #14099

sagetrac-chrisjamesberg mannequin opened this issue Feb 12, 2013 · 43 comments

Comments

@sagetrac-chrisjamesberg
Copy link
Mannequin

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

@nathanncohen
Copy link
Mannequin

nathanncohen mannequin commented Feb 13, 2013

comment:1

Could you be interested in running this method on the transitive closure of your poset ?

http://www.sagemath.org/doc/reference/sage/graphs/generic_graph.html#sage.graphs.generic_graph.GenericGraph.subgraph_search

Nathann

@sagetrac-chrisjamesberg
Copy link
Mannequin Author

comment:3

apply: poset_functionality_14099_er.patch

@sagetrac-rowland
Copy link
Mannequin

sagetrac-rowland mannequin commented Feb 13, 2013

comment:4

Is the transitive closure + subgraph_search fast enough to make it worthwhile?

@nathanncohen
Copy link
Mannequin

nathanncohen mannequin commented Feb 13, 2013

comment:5

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

@sagetrac-rowland
Copy link
Mannequin

sagetrac-rowland mannequin commented Feb 13, 2013

comment:6

apply: poset_functionality_14099_er.patch

@sagetrac-rowland
Copy link
Mannequin

sagetrac-rowland mannequin commented Feb 14, 2013

comment:7

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

@nathanncohen
Copy link
Mannequin

nathanncohen mannequin commented Feb 14, 2013

comment:8

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

@sagetrac-rowland
Copy link
Mannequin

sagetrac-rowland mannequin commented Feb 14, 2013

comment:9

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

@sagetrac-rowland
Copy link
Mannequin

sagetrac-rowland mannequin commented Feb 14, 2013

comment:10

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

@sagetrac-rowland
Copy link
Mannequin

sagetrac-rowland mannequin commented Feb 14, 2013

Changed keywords from posets to posets, days45

@sagetrac-chrisjamesberg
Copy link
Mannequin Author

Changed author from chrisjamesberg, rowland, ahmorales to Eric rowland, Alejandro Morales

@sagetrac-chrisjamesberg
Copy link
Mannequin Author

Changed reviewer from saliola to Chris Berg

@nathanncohen
Copy link
Mannequin

nathanncohen mannequin commented Feb 14, 2013

comment:13

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

@sagetrac-rowland
Copy link
Mannequin

sagetrac-rowland mannequin commented Feb 14, 2013

comment:14

Attachment: poset_functionality_14099_er.patch.gz

@sagetrac-rowland
Copy link
Mannequin

sagetrac-rowland mannequin commented Feb 14, 2013

Changed author from Eric rowland, Alejandro Morales to Eric Rowland, Alejandro Morales

@nathanncohen
Copy link
Mannequin

nathanncohen mannequin commented Feb 15, 2013

comment:15

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

@sagetrac-rowland
Copy link
Mannequin

sagetrac-rowland mannequin commented Feb 15, 2013

comment:16

What is the advantage of merging them into one? The disadvantage is a decrease in clarity.

@nathanncohen
Copy link
Mannequin

nathanncohen mannequin commented Feb 15, 2013

comment:17

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

@nathanncohen
Copy link
Mannequin

nathanncohen mannequin commented Feb 24, 2013

comment:18

#14122 has been merged into beta1.

Nathann

@fchapoton
Copy link
Contributor

comment:20

instruction for the bot:

Apply poset_functionality_14099-er.patch

@nathanncohen
Copy link
Mannequin

nathanncohen mannequin commented Jun 19, 2013

comment:33

O_O

@nathanncohen
Copy link
Mannequin

nathanncohen mannequin commented Jun 19, 2013

comment:34

Okayyyyyyyyyyyyyyyyyyyyyyyy I see ......

@nathanncohen
Copy link
Mannequin

nathanncohen mannequin commented Jun 19, 2013

comment:36

No way.

@nathanncohen
Copy link
Mannequin

nathanncohen mannequin commented Jun 19, 2013

comment:37

I am currently writing an additional patch for this bibliographical reference.

I will upload it shortly.

Nathann

@nathanncohen
Copy link
Mannequin

nathanncohen mannequin commented Jun 19, 2013

comment:39

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

@nathanncohen

This comment has been minimized.

@sagetrac-rowland
Copy link
Mannequin

sagetrac-rowland mannequin commented Jun 19, 2013

comment:40

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.

@jdemeyer
Copy link

comment:42

The patches need proper commit messages (use hg qrefresh -e for that).

@sagetrac-rowland
Copy link
Mannequin

sagetrac-rowland mannequin commented Jun 20, 2013

Attachment: poset_functionality_14099-er.patch.gz

@jdemeyer
Copy link

comment:43

The reviewer patch needs a proper commit message, use hg qrefresh -e for this.

@nathanncohen
Copy link
Mannequin

nathanncohen mannequin commented Jul 24, 2013

comment:44

Attachment: trac_14099-rev.patch.gz

@jdemeyer
Copy link

Merged: sage-5.11.rc0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants