#12165: Unexpected behavior with weighted graph
------------------------+---------------------------------------------------
   Reporter:  akm       |          Owner:  jason, was
       Type:  defect    |         Status:  new       
   Priority:  major     |      Milestone:  sage-4.8  
  Component:  graphics  |       Keywords:            
Work_issues:            |       Upstream:  N/A       
   Reviewer:            |         Author:            
     Merged:            |   Dependencies:            
------------------------+---------------------------------------------------
 This bug is about a non-obvious, wierd behavior when plotting a certain
 type of weighted graph.

 I posted this on Google groups here:  http://groups.google.com/group/sage-
 support/browse_thread/thread/fc6d0a7e2911984c/22914ce6373dd5c0

 This code results in a graph plotted with the  (single) edges labeled with
 the weight between each pair of vertices:

 M = Matrix([[0,1,-1,5],[1,0,-1/2,-1],[-1,-1/2,0,2],[5,-1,2,0]])  G =
 Graph(M,sparse=True)  G.plot(edge_labels=True)

 Whereas this code does not and instead has multi-edges labeled "None":

 M = Matrix([[0, 1, 0, 0], [1, 0, 1, 2], [0, 1, 0, 0], [0, 2, 0, 0]])  G =
 Graph(M,sparse=True)  G.plot(edge_labels=True)

 Here was the answer I got for reference:

 I think it's something like this (take with grain of salt, I'm bad at
 multitasking):  Briefly, it's not interpreting the second matrix as a
 weighted  adjacency matrix.  If you specifically tell it that it is, say
 by  M = Matrix([[0, 1, 0, 0], [1, 0, 1, 2], [0, 1, 0, 0], [0, 2, 0, 0]])
 G = Graph(M,weighted=True)  it should behave.  Less briefly: the code in
 graph.py uses the following logic to decide  whether these two are
 weighted or not:

   if format == 'adjacency_matrix':
     entries = uniq(data.list())  for e in entries:
       try:
         e = int(e)  assert e >= 0
       except:
         if weighted is False:
           raise ValueError("Non-weighted graph's"+  " adjacency matrix
 must have only nonnegative"+  " integer entries")
         weighted = True  if multiedges is None: multiedges = False  break

 IOW, to decide if it should set weighted to True, it loops over each
 entry and (1) tries to convert it to an integer, and (2) asserts that
 it's non-negative.  If either of those fail, then it decides that
 weighted should be True (in this case weighted starts as None).  So the
 first graph works because the nonnegative check fails (or the  integral
 check fails, I'm too lazy to confirm what direction the  matrix entries
 are iterated in..)  The second graph's matrix is  integral and
 nonnegative, so it sneaks through, and things get silly  after that.
 Would you like to open a bug report on trac?  This should be easy to fix.
 Doug

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/12165>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sage-trac?hl=en.

Reply via email to