Ask Your Question

jlv's profile - activity

2022-04-03 04:27:54 +0100 received badge  Famous Question (source)
2020-08-24 00:01:31 +0100 received badge  Notable Question (source)
2018-01-23 15:47:26 +0100 received badge  Famous Question (source)
2016-11-22 13:55:31 +0100 received badge  Notable Question (source)
2016-06-28 01:43:39 +0100 received badge  Popular Question (source)
2016-06-28 01:43:12 +0100 received badge  Popular Question (source)
2012-10-11 13:21:52 +0100 received badge  Teacher (source)
2012-10-11 13:21:52 +0100 received badge  Self-Learner (source)
2012-10-11 11:53:29 +0100 answered a question Adding a loop to graph

Figured it out myself.

My iteration starts with a graph of just one edge, then adds different types of edges to it. Initially, I had

G=Graph({0:[1],1:[]})

I checked in detail through the Sage manual pages on graphs, and found that there are options multiedges and loops that can be set for a given graph. So now I have

G=Graph(multiedges=True,loops=True)
G.add_edge(0,1)

This gives me exactly what I want. Now G.add_edge(0,0) adds a loop to the graph, and G.add_edge(0,1) makes it have a pair of multiple edges.

My problem was that Sage assumes False values by default for these options, meaning that a graph by default is simple.

2012-10-11 10:30:53 +0100 asked a question Adding a loop to graph

I have a for loop that adds edges to a graph g, but I also want the graph to add loops. How can I do this, for a general graph whose structure I do not know (that is, I want to add the loop to a graph, rather than make a new graph)?

I've tried using the g.add_edge(1,1) function, but that doesn't work, i.e. no loop is added. I also tried using g.add_edge three times, then g.merge_vertices to contract the cycle to a loop, but also to no avail. Sage justs simplifies the graph.

Any approach to this would be appreciated, direct or indirect.

2012-10-09 21:25:39 +0100 commented answer Where is the default directory for outputting?

Indeed, DATA was key. I can even see plots as .png files there! Super.

2012-10-09 21:24:39 +0100 received badge  Scholar (source)
2012-10-09 21:24:39 +0100 marked best answer Where is the default directory for outputting?

From the notebook, evaluate the variable DATA; you'll get something like

'/Users/jlv/.sage/sage_notebook.sagenb/home/admin/42/data/'

(although probably with a different number than "42"). It looks to me as though the output directory for write_to_eps is obtained by replacing data with cells, or actually a subdirectory of

'/Users/jlv/.sage/sage_notebook.sagenb/home/admin/42/cells/'

Because of this, from the notebook, I often specify a full path when outputting: g.write_to_eps('/Users/jlv/Desktop/sage.eps'), for example.

2012-10-09 21:24:23 +0100 received badge  Supporter (source)
2012-10-08 22:07:12 +0100 received badge  Student (source)
2012-10-08 20:35:42 +0100 received badge  Editor (source)
2012-10-08 20:09:38 +0100 asked a question Where is the default directory for outputting?

So I'm running Sage on OSX, and I'm using the function g.write_to_eps(), where g is a graph. One from the sage help pages is

 g = Graph({0:[6,7],1:[7,8],2:[8,9],3:[9,10],4:[10,11],5:[11,6],6:[0,5,7],7:[0,1,6],8:[1,2,9],9:[2,3,8],10:[3,4,11],11:[4,5,10]})

So I run that, then g.write_to_eps('sage.eps'), but I have no idea where it is supposed to show up. Could anybody help me with this? Probably a very easy answer, but I couldn't find a solid reply through Google. Sage is located in '/Applications/sage' and I'm in '/Users/jlv/'

Thanks!

P.S. To be more precise, where is the output executing the above commands from the browser notebook, not Terminal. Through Terminal things work as they should, as in g.write_to_eps('/Users/jlv/Desktop/sage.eps') appears on my Desktop.