Ask Your Question
1

Resuming a running process in Sage

asked 2012-05-01 06:21:10 +0100

Naji gravatar image

updated 2015-01-13 21:32:54 +0100

FrédéricC gravatar image

Dear all,

I am running the Sage on Ubuntu and I am using the vertex_coloring() to calculate the k-colorablity of a specific graph. As you might know the process is long enough and the electricity may gone through the process. Is there any way that I could make a sage process resumable or in way moderate the vertex_coloring() to resume the things from the last point it left?

Thanks.

edit retag flag offensive close merge delete

Comments

3

I suspect (but don't know) that you will need to write your own vertex_coloring function. Copy the source of the built-in function and modify it so that it saves whatever it has calculated every now and then.

chaesloc2 gravatar imagechaesloc2 ( 2012-05-01 07:39:23 +0100 )edit

Thanks. It seems the only possible way.

Naji gravatar imageNaji ( 2012-05-01 14:03:07 +0100 )edit

1 Answer

Sort by » oldest newest most voted
2

answered 2012-05-01 13:51:29 +0100

niles gravatar image

Using the double question mark to see the source code (vertex_coloring??) I see that it loops over increasingly large values of k, testing whether the graph is k-colorable:

    while True:
        # tries to color the graph, increasing k each time it fails.
        tmp = vertex_coloring(g, k=k, value_only=value_only,
                              hex_colors=hex_colors, verbose=verbose)
        if tmp is not False:
            if value_only:
                return k
            else:
                return tmp
        k += 1

So one simple idea is to do this loop manually. If the process quits, at least you'll know what values of k have already been checked:

sage: from sage.graphs.graph_coloring import vertex_coloring
sage: from sys import stdout
sage: g = graphs.CompleteGraph(9)
sage: for k in range(15):
    print '%s-colorable: %s'%(k,vertex_coloring(g, k=k, value_only=True))
    stdout.flush()
....:     
0-colorable: False
1-colorable: False
2-colorable: False
3-colorable: False
4-colorable: False
5-colorable: False
6-colorable: False
7-colorable: False
8-colorable: False
9-colorable: True
10-colorable: True
11-colorable: True
12-colorable: True
13-colorable: True
14-colorable: True
edit flag offensive delete link more

Comments

Thank you very much but as I mentioned I am only calculating vertex_coloring(G,k=12,value_only=False) in my code... So as I believe this doesn't help(?) About vertex_coloring?? I don't know why but I get : "No object vertex_coloring" in a box! Thanks again.

Naji gravatar imageNaji ( 2012-05-01 14:06:15 +0100 )edit

Oh, I didn't notice that you were only working on a specific value for k -- sorry! Did you first type "from sage.graphs.graph_coloring import vertex_coloring" ?

niles gravatar imageniles ( 2012-05-01 22:12:46 +0100 )edit

No problem. Thanks for helping.Yes this is the code I tried: from sage.graphs.graph_coloring import vertex_coloring; vertex_coloring??; And this is what I get: "No object vertex_coloring" in a box!

Naji gravatar imageNaji ( 2012-05-02 06:44:44 +0100 )edit

Strange -- in notebook I also get "No object vertex_coloring" (is this a bug?). It works well in the command-line interface to sage though. Also one can look directly at the file, which is (as vertex_coloring? or vertex_coloring?? on command-line tells you) at local/lib/python2.6/site-packages/sage/graphs/graph_coloring.py under your sage installation.

Robert Samal gravatar imageRobert Samal ( 2012-05-10 08:29:48 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-05-01 06:21:10 +0100

Seen: 468 times

Last updated: May 01 '12