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

edge_connectivity and vertex labels #19348

Closed
jm58660 mannequin opened this issue Oct 5, 2015 · 34 comments
Closed

edge_connectivity and vertex labels #19348

jm58660 mannequin opened this issue Oct 5, 2015 · 34 comments

Comments

@jm58660
Copy link
Mannequin

jm58660 mannequin commented Oct 5, 2015

g1 = Graph({0: [1]})
g2 = Graph({'a': ['b']})
g1.edge_connectivity(value_only=False), g2.edge_connectivity(value_only=False)

should output ([1, [(0, 1)]], [1, [('a', 'b')]]), but it does not look vertex labels at all.

CC: @nathanncohen @sagetrac-borassi @dcoudert

Component: graph theory

Author: Michele Borassi

Branch/Commit: 7f3c0b9

Reviewer: Vincent Delecroix, Jori Mäntysalo, Nathann Cohen, David Coudert

Issue created by migration from https://trac.sagemath.org/ticket/19348

@jm58660 jm58660 mannequin added this to the sage-6.9 milestone Oct 5, 2015
@jm58660 jm58660 mannequin added c: graph theory labels Oct 5, 2015
@jm58660
Copy link
Mannequin Author

jm58660 mannequin commented Oct 5, 2015

@jm58660
Copy link
Mannequin Author

jm58660 mannequin commented Oct 5, 2015

Author: Jori Mäntysalo

@jm58660
Copy link
Mannequin Author

jm58660 mannequin commented Oct 5, 2015

Commit: b788ce7

@jm58660
Copy link
Mannequin Author

jm58660 mannequin commented Oct 5, 2015

comment:3

This at least seems to work. May not be best way to write the code.

(Btw, I don't like to have keyword implementation in one function and algorithm in another.)


New commits:

b788ce7Fix edge labels with value_only=False in edge_connectivity().

@jm58660 jm58660 mannequin added the s: needs review label Oct 5, 2015
@nathanncohen
Copy link
Mannequin

nathanncohen mannequin commented Oct 5, 2015

comment:4

Hello Jori,

Sorry but the "bug" is more in the boost function that in generic_graph.py. Otherwise we still have a function somewhere that takes a vertex-labelled graph as input and returns an integer-labelled answer.

Furthermore, it is in any case better if instead of having a doctest returning 'a' you just check that the vertex belongs to the graph: the answer 'b' would be valid too.

Nathann

@jm58660
Copy link
Mannequin Author

jm58660 mannequin commented Oct 5, 2015

Changed author from Jori Mäntysalo to none

@jm58660
Copy link
Mannequin Author

jm58660 mannequin commented Oct 5, 2015

comment:5

Replying to @nathanncohen:

Sorry but the "bug" is more in the boost function that in generic_graph.py. Otherwise we still have a function somewhere that takes a vertex-labelled graph as input and returns an integer-labelled answer.

OK. I mark this as needs_work. (And let others to do it.)

Furthermore, it is in any case better if instead of having a doctest returning 'a' you just check that the vertex belongs to the graph: the answer 'b' would be valid too.

Ah, then I misunderstood some documentation about this kind of functions.

Assuming for example that vertices are ASCII-strings, will .vertices() give them alphabetically?

@jm58660 jm58660 mannequin added s: needs work and removed s: needs review labels Oct 5, 2015
@nathanncohen
Copy link
Mannequin

nathanncohen mannequin commented Oct 5, 2015

comment:6

Ah, then I misunderstood some documentation about this kind of functions.

Assuming for example that vertices are ASCII-strings, will .vertices() give them alphabetically?

It will. But in the present case, I think that you are after a "bipartition of your vertex set", and that you could get {a},{b} as often as {b},{a}.

Nathann

@sagetrac-borassi
Copy link
Mannequin

sagetrac-borassi mannequin commented Oct 5, 2015

Author: Michele Borassi

@sagetrac-borassi
Copy link
Mannequin

sagetrac-borassi mannequin commented Oct 5, 2015

comment:7

Hello!

You are right: the edge connectivity is the first Boost algorithm I implemented, and I missed the vertex labels. Thank you very much for noting this.

Since I made the mistake, I think I should solve it: let me know if you like my solution. I replaced Jori's branch with a different one, that corrects boost_graph.pyx instead of generic_graph.pyx. I hope this is the correct procedure: if not, let me know!

Have fun!

Michele

@sagetrac-borassi
Copy link
Mannequin

sagetrac-borassi mannequin commented Oct 5, 2015

@videlec
Copy link
Contributor

videlec commented Oct 6, 2015

comment:9

Hello,

What is the point of making a dict to map 0, 1, 2, 3, ... to Python objects? Use a list!

cdef list int_to_vertex = g.vertices()

Vincent


New commits:

98e4667Solved bug with edge labels

@videlec
Copy link
Contributor

videlec commented Oct 6, 2015

Changed commit from b788ce7 to 98e4667

@videlec
Copy link
Contributor

videlec commented Oct 6, 2015

Reviewer: Vincent Delecroix

@jm58660
Copy link
Mannequin Author

jm58660 mannequin commented Oct 6, 2015

comment:10

Replying to @sagetrac-borassi:

I replaced Jori's branch with a different one, that corrects boost_graph.pyx instead of generic_graph.pyx. I hope this is the correct procedure: if not, let me know!

Yes, it is good. Actually I think that whatever makes Sage better is good.

@sagetrac-borassi
Copy link
Mannequin

sagetrac-borassi mannequin commented Oct 6, 2015

comment:11

Hello!

What is the point of making a dict to map 0, 1, 2, 3, ... to Python objects? Use a list!

I used a dict because (I think) lists are linked lists, and the random access time is O(n). Am I missing something?

@jm58660
Copy link
Mannequin Author

jm58660 mannequin commented Oct 6, 2015

comment:12

Replying to @sagetrac-borassi:

What is the point of making a dict to map 0, 1, 2, 3, ... to Python objects? Use a list!

I used a dict because (I think) lists are linked lists, and the random access time is O(n). Am I missing something?

https://wiki.python.org/moin/TimeComplexity says that it is O(1).

@sagetrac-borassi
Copy link
Mannequin

sagetrac-borassi mannequin commented Oct 6, 2015

comment:13

You are right! I modified everything!

@sagetrac-borassi sagetrac-borassi mannequin removed the s: needs work label Oct 6, 2015
@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Oct 6, 2015

Changed commit from 98e4667 to 7f3c0b9

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Oct 6, 2015

Branch pushed to git repo; I updated commit sha1. New commits:

7f3c0b9Use list instead of dict

@jm58660
Copy link
Mannequin Author

jm58660 mannequin commented Oct 6, 2015

comment:15

FYI I did some more testing and it seems that vertex_connectivity(), line_graph() etc etc. does not have same kind of bug.

I guess this could be on checklist for reviewers. This applies to all kind of containers, like graphs and sets.

@sagetrac-borassi
Copy link
Mannequin

sagetrac-borassi mannequin commented Oct 6, 2015

comment:16

Sorry, I have troubles understanding your comment. After you said that lists were better than dictionaries, I transformed all dictionaries named int_to_vertex into lists (there were several other routines where these dictionaries were used: these routines were correct, but the new version is simpler and more efficient).

Am I missing some points?

Replying to @jm58660:

FYI I did some more testing and it seems that vertex_connectivity(), line_graph() etc etc. does not have same kind of bug.

I guess this could be on checklist for reviewers. This applies to all kind of containers, like graphs and sets.

@jm58660
Copy link
Mannequin Author

jm58660 mannequin commented Oct 6, 2015

comment:17

Replying to @sagetrac-borassi:

Sorry, I have troubles understanding your comment.

Sorry for being unclear. My comment did not relate to this spefic ticket. (And maybe I should have write it to sage-devel instead of this.)

@nathanncohen
Copy link
Mannequin

nathanncohen mannequin commented Oct 6, 2015

comment:18

Sorry, I have troubles understanding your comment. After you said that lists were better than dictionaries, I transformed all dictionaries named int_to_vertex into lists (there were several other routines where these dictionaries were used: these routines were correct, but the new version is simpler and more efficient).

Am I missing some points?

To me at least you did right. Is there any reason why you added those <int> cast though? Given that result is a typed vector that should not be necessary ?... O_o

Nathann

@sagetrac-borassi
Copy link
Mannequin

sagetrac-borassi mannequin commented Oct 6, 2015

comment:19

I inserted them in order to avoid a compilation error, saying that there was a wrong conversion from long to int.

Replying to @nathanncohen:

Sorry, I have troubles understanding your comment. After you said that lists were better than dictionaries, I transformed all dictionaries named int_to_vertex into lists (there were several other routines where these dictionaries were used: these routines were correct, but the new version is simpler and more efficient).

Am I missing some points?

To me at least you did right. Is there any reason why you added those <int> cast though? Given that result is a typed vector that should not be necessary ?... O_o

Nathann

@nathanncohen
Copy link
Mannequin

nathanncohen mannequin commented Oct 6, 2015

comment:20

I inserted them in order to avoid a compilation error, saying that there was a wrong conversion from long to int.

Okayyyyy O_o

Good to know. Thanks.

Nathann

@videlec
Copy link
Contributor

videlec commented Oct 6, 2015

comment:21

Replying to @jm58660:

Replying to @sagetrac-borassi:

What is the point of making a dict to map 0, 1, 2, 3, ... to Python objects? Use a list!

I used a dict because (I think) lists are linked lists, and the random access time is O(n). Am I missing something?

https://wiki.python.org/moin/TimeComplexity says that it is O(1).

More precisely:

  • A python object is a PyObject *
  • A list or a tuple is a PyObject **
  • A set/dict is a hash table
    So you that you can not beat a Python list.

On the other hand, if you want faster access to my_list[i] you can have a look at Cython compiler directives.

@jm58660
Copy link
Mannequin Author

jm58660 mannequin commented Oct 28, 2015

comment:22

This is still in needs_review, but the discussions seems to have end. Is there something to do, or can someone who understand the code click this to positive_review?

@videlec
Copy link
Contributor

videlec commented Oct 29, 2015

Changed reviewer from Vincent Delecroix to Vincent Delecroix, Jori Mäntysalo, Nathann Cohen

@videlec
Copy link
Contributor

videlec commented Oct 29, 2015

comment:23

I am ok for a positive review. I let to the other reviewers some possible final comment.

@videlec videlec modified the milestones: sage-6.9, sage-6.10 Oct 29, 2015
@nathanncohen
Copy link
Mannequin

nathanncohen mannequin commented Oct 29, 2015

comment:24

I have nothing against this branch.

@dcoudert
Copy link
Contributor

Changed reviewer from Vincent Delecroix, Jori Mäntysalo, Nathann Cohen to Vincent Delecroix, Jori Mäntysalo, Nathann Cohen, David Coudert

@dcoudert
Copy link
Contributor

comment:25

Passes all tests on my computer as well, so let's go.

@vbraun
Copy link
Member

vbraun commented Oct 29, 2015

Changed branch from u/borassi/edge_connectivity_and_vertex_labels to 7f3c0b9

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

3 participants