ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 28 Jan 2012 06:11:55 -0600Path after deletion of vertexhttp://ask.sagemath.org/question/8676/path-after-deletion-of-vertex/The following code
g = graphs.PathGraph(15)
g.delete_vertex(6)
g
prints
> Path Graph: Graph on 14 vertices
but it's not a path after I delete vertex 6. It's the disjoint union of 2 paths. Same thing occurs with cycle (except it says Cycle Graph), same thing occurs if you delete an edge from either. Happens with complete graph if you delete an edge and make it no longer complete... so probably happens with any such named graph under edge or vertex deletions. Or, if you end with "Print g" instead of just "g", it says just "Complete Graph".Sat, 28 Jan 2012 03:57:02 -0600http://ask.sagemath.org/question/8676/path-after-deletion-of-vertex/Answer by DSM for <p>The following code</p>
<pre><code>g = graphs.PathGraph(15)
g.delete_vertex(6)
g
</code></pre>
<p>prints</p>
<blockquote>
<p>Path Graph: Graph on 14 vertices</p>
</blockquote>
<p>but it's not a path after I delete vertex 6. It's the disjoint union of 2 paths. Same thing occurs with cycle (except it says Cycle Graph), same thing occurs if you delete an edge from either. Happens with complete graph if you delete an edge and make it no longer complete... so probably happens with any such named graph under edge or vertex deletions. Or, if you end with "Print g" instead of just "g", it says just "Complete Graph".</p>
http://ask.sagemath.org/question/8676/path-after-deletion-of-vertex/?answer=13205#post-id-13205Yeah, that's a side effect of the way the classes work. I'm not sure what the best way to handle this is:
(1) Give up on clever naming entirely.
(2) Check whether the name still makes sense whenever the graph is changed and update accordingly. This would be very silly and very expensive.
(3) Check whether the name still makes sense whenever the *name* is printed, and update accordingly. This makes a lot more sense but could still be pretty expensive, although it could have a modification-invalidating cache.
(4) Whenever a graph has nodes or vertices changed, in-place or otherwise, set a "modified" flag. If the modified flag is set, print the generic string instead, without testing whether the name would still apply. This would add one extra operation to every graph change, but it should be pretty fast.
ISTR this came up on one of the mailing lists within the last six months or so.Sat, 28 Jan 2012 06:11:55 -0600http://ask.sagemath.org/question/8676/path-after-deletion-of-vertex/?answer=13205#post-id-13205