Ticket #12108 (closed defect: fixed)

Opened 18 months ago

Last modified 18 months ago

is_eulerian doesn't handle disconnected graphs properly

Reported by: brunellus Owned by: jason, ncohen, rlm
Priority: major Milestone: sage-4.8
Component: graph theory Keywords:
Cc: ncohen Work issues:
Report Upstream: N/A Reviewers: Nathann Cohen
Authors: Lukáš Lánský Merged in: sage-4.8.alpha5
Dependencies: Stopgaps:

Description (last modified by ncohen) (diff)

Consider following:

sage: g = DiGraph({0:[1], 1:[0], 2:[]}); g.is_eulerian()
False

is_eulerian sees two components and refuses to label graph as an eulerian one. But the common definition (and the docstring) says that eulerian graph has all its edges coverable by one tour -- that permits disconnected graphs as long as every component but one don't contains any edges.

Apply:

Attachments

trac_12108_is_eulerian_fix.patch Download (1.8 KB) - added by brunellus 18 months ago.
trac_12108_is_eulerian_fix2.patch Download (1.9 KB) - added by brunellus 18 months ago.

Change History

comment:1 Changed 18 months ago by ncohen

  • Cc ncohen added

Changed 18 months ago by brunellus

comment:2 follow-up: ↓ 3 Changed 18 months ago by brunellus

  • Status changed from new to needs_review

My first patch. :-)

comment:3 in reply to: ↑ 2 Changed 18 months ago by ncohen

Replying to brunellus:

My first patch. :-)

And a good one ! :-)

Just one remark : the connected_components_number actually calls connected components. So instead of computing the number of CC and *then* go over all vertices, what would you think of something like that :

ok = True
for cc in self.connected_components():
    if len(cc) > 1:
        if ok:
           ok = False
        else:
           return False

I feel like it could be faster, but that's really about milliseconds :-)

Nathann

comment:4 Changed 18 months ago by brunellus

Thanks for pointing this out. I will send another patch (with a few more tests cases, also) -- is it prefered to create it on top of the first one, or is it better to be replacement?

comment:5 Changed 18 months ago by ncohen

Oh, it is better to replace the patch (on bigger patches you can have a lot of modifications to make, soo...). It actually is not hard if you use mercurial queue

 http://wiki.sagemath.org/MercurialQueues

And it will not be a waste if you intend to write other patches ;-)

Nathann

Changed 18 months ago by brunellus

comment:6 Changed 18 months ago by brunellus

Thanks very much for the advices.

Graph.eulerian_circuit() suffers from a similar error (it tries to take first vertex at hand and if it is an isolated one, it immidiately fails) -- but I am already rewriting it for #10135, keeping this in mind.

comment:7 Changed 18 months ago by ncohen

  • Status changed from needs_review to positive_review
  • Reviewers set to Nathann Cohen
  • Description modified (diff)
  • Authors set to Lukáš Lánský

Oh ! I did not noticed you updated the patch...... It's good to go ! :-)

Nathann

comment:8 Changed 18 months ago by brunellus

Thanks!

comment:9 Changed 18 months ago by jdemeyer

  • Status changed from positive_review to closed
  • Resolution set to fixed
  • Merged in set to sage-4.8.alpha5
Note: See TracTickets for help on using tickets.