INFO:
This module implements classes (GraphDatabase, GraphQuery, GenericGraphQuery) for interfacing with the sqlite database graphs.db.
The GraphDatabase class interfaces with the sqlite database graphs.db. It is an immutable database that inherits from SQLDatabase (see sage.databases.database.py).
The database contains all unlabeled graphs with 7 or fewer nodes. This class will also interface with the optional database package containing all unlabeled graphs with 8 or fewer nodes. The database(s) consists of five tables, and has the structure given by the function graph_info. (For a full description including column data types, create a GraphDatabase instance and call the method get_skeleton).
AUTHORS:
REFERENCES:
Bases: sage.databases.database.GenericSQLDatabase
TODO: This function could use improvement. Add full options of typical GraphQuery (i.e.: have it accept list input); and update options in interact to make it less annoying to put in operators.
Generates an interact shell (in the notebook only) that allows the user to manipulate query parameters and see the updated results.
EXAMPLE:
sage: D = GraphDatabase()
sage: D.interactive_query(display_cols=['graph6','num_vertices','degree_sequence'],num_edges=5,max_degree=3)
<html>...</html>
Creates a GraphQuery on this database. For full class details, type GraphQuery? and press shift+enter.
EXAMPLE:
sage: D = GraphDatabase()
sage: q = D.query(display_cols=['graph6','num_vertices','degree_sequence'],num_edges=['<=',5])
sage: q.show()
Graph6 Num Vertices Degree Sequence
------------------------------------------------------------
@ 1 [0]
A? 2 [0, 0]
A_ 2 [1, 1]
B? 3 [0, 0, 0]
BG 3 [0, 1, 1]
BW 3 [1, 1, 2]
Bw 3 [2, 2, 2]
C? 4 [0, 0, 0, 0]
C@ 4 [0, 0, 1, 1]
CB 4 [0, 1, 1, 2]
CK 4 [1, 1, 1, 1]
CF 4 [1, 1, 1, 3]
CJ 4 [0, 2, 2, 2]
CL 4 [1, 1, 2, 2]
CN 4 [1, 2, 2, 3]
C] 4 [2, 2, 2, 2]
C^ 4 [2, 2, 3, 3]
D?? 5 [0, 0, 0, 0, 0]
D?C 5 [0, 0, 0, 1, 1]
D?K 5 [0, 0, 1, 1, 2]
D@O 5 [0, 1, 1, 1, 1]
D?[ 5 [0, 1, 1, 1, 3]
D@K 5 [0, 0, 2, 2, 2]
D_K 5 [1, 1, 1, 1, 2]
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_?Hg 7 [1, 1, 1, 1, 1, 2, 3]
F?CqO 7 [0, 1, 1, 2, 2, 2, 2]
F?CaW 7 [0, 1, 1, 1, 2, 2, 3]
F?LCG 7 [1, 1, 1, 1, 2, 2, 2]
F?C_w 7 [0, 0, 1, 2, 2, 2, 3]
FG?Gw 7 [0, 1, 1, 1, 2, 2, 3]
F?Ch_ 7 [0, 0, 2, 2, 2, 2, 2]
FG?Wo 7 [0, 1, 1, 2, 2, 2, 2]
F_?XO 7 [1, 1, 1, 1, 2, 2, 2]
FK?GW 7 [1, 1, 1, 1, 2, 2, 2]
Bases: sage.databases.database.SQLQuery, sage.graphs.graph_database.GenericGraphQuery
Returns a list of Sage Graph objects that satisfy the query.
EXAMPLES:
sage: Q = GraphQuery(display_cols=['graph6','num_vertices','degree_sequence'],num_edges=['<=',5],min_degree=1)
sage: L = Q.get_graphs_list()
sage: L[0]
Graph on 2 vertices
sage: len(L)
35
Returns the number of graphs in the database that satisfy the query.
EXAMPLES:
sage: Q = GraphQuery(display_cols=['graph6','num_vertices','degree_sequence'],num_edges=['<=',5],min_degree=1)
sage: Q.number_of()
35
Returns an iterator over the results list of the GraphQuery.
EXAMPLE:
sage: Q = GraphQuery(display_cols=['graph6'],num_vertices=7, diameter=5)
sage: for g in Q:
... print g.graph6_string()
F@?]O
F@OKg
F?`po
F?gqg
FIAHo
F@R@o
FA_pW
FGC{o
FEOhW
sage: Q = GraphQuery(display_cols=['graph6'],num_vertices=7, diameter=5)
sage: it = iter(Q)
sage: while True:
... try: print it.next().graph6_string()
... except StopIteration: break
F@?]O
F@OKg
F?`po
F?gqg
FIAHo
F@R@o
FA_pW
FGC{o
FEOhW
Displays the results of a query in table format.
INPUT:
EXAMPLES:
sage: G = GraphDatabase()
sage: Q = GraphQuery(G, display_cols=['graph6','num_vertices','aut_grp_size'], num_vertices=4, aut_grp_size=4)
sage: Q.show()
Graph6 Num Vertices Aut Grp Size
------------------------------------------------------------
C@ 4 4
C^ 4 4
sage: R = GraphQuery(G, display_cols=['graph6','num_vertices','degree_sequence'], num_vertices=4)
sage: R.show()
Graph6 Num Vertices Degree Sequence
------------------------------------------------------------
C? 4 [0, 0, 0, 0]
C@ 4 [0, 0, 1, 1]
CB 4 [0, 1, 1, 2]
CK 4 [1, 1, 1, 1]
CF 4 [1, 1, 1, 3]
CJ 4 [0, 2, 2, 2]
CL 4 [1, 1, 2, 2]
CN 4 [1, 2, 2, 3]
C] 4 [2, 2, 2, 2]
C^ 4 [2, 2, 3, 3]
C~ 4 [3, 3, 3, 3]
Show the pictures (in notebook mode only):
sage: S = GraphQuery(G, display_cols=['graph6','aut_grp_size'], num_vertices=4)
sage: S.show(with_picture=True)
...
NotImplementedError: Cannot display plot on command line.
Note that pictures can be turned off:
sage: S.show(with_picture=False)
Graph6 Aut Grp Size
----------------------------------------
C? 24
C@ 4
CB 2
CK 8
CF 6
CJ 6
CL 2
CN 2
C] 8
C^ 4
C~ 24
Show your own query (note that the output is not reformatted for generic queries):
sage: (GenericGraphQuery('select degree_sequence from degrees where max_degree=2 and min_degree >= 1',G)).show()
degree_sequence
--------------------
211
222
2211
2222
21111
22211
22211
22222
221111
221111
222211
222211
222211
222222
222222
2111111
2221111
2221111
2221111
2222211
2222211
2222211
2222211
2222222
2222222
Takes the database integer data type (one digit per vertex representing its degree, sorted high to low) and converts it to degree sequence list. The graph6 identifier is required for all graphs with no edges, so that the correct number of zeros will be returned.
EXAMPLE:
sage: from sage.graphs.graph_database import data_to_degseq
sage: data_to_degseq(3221)
[1, 2, 2, 3]
sage: data_to_degseq(0,'D??')
[0, 0, 0, 0, 0]
Takes a degree sequence list (of Integers) and converts to a sorted (max-min) integer data type, as used for faster access in the underlying database.
EXAMPLE:
sage: from sage.graphs.graph_database import degseq_to_data
sage: degseq_to_data([2,2,3,1])
3221
Constructs a graph from a graph6 string and returns a Graphics object with arguments preset for show function.
EXAMPLE:
sage: from sage.graphs.graph_database import graph6_to_plot
sage: type(graph6_to_plot('D??'))
<class 'sage.plot.plot.Graphics'>
Returns a dictionary of allowed table and column names.
INPUT:
EXAMPLE:
sage: graph_db_info().keys()
['graph_data', 'degrees', 'spectrum', 'misc', 'aut_grp']
sage: graph_db_info(tablename='graph_data')
['complement_graph6',
'eulerian',
'graph6',
'lovasz_number',
'num_cycles',
'num_edges',
'num_hamiltonian_cycles',
'num_vertices',
'perfect',
'planar']
Constructs and returns a GraphQuery object respecting the special input required for the induced_subgraphs parameter. This input can be an individual graph6 string (in which case it is evaluated without the use of this method) or a list of strings. In the latter case, the list should be of one of the following two formats: 1. [‘one_of’,String,...,String] Will search for graphs containing a subgraph isomorphic to any of the graph6 strings in the list. 2. [‘all_of’,String,...,String] Will search for graphs containing a subgraph isomorphic to each of the graph6 strings in the list.
This is a helper method called by the GraphQuery constructor to handle this special format. This method should not be used on its own because it doesn’t set any display columns in the query string, causing a failure to fetch the data when run.
EXAMPLE:
sage: from sage.graphs.graph_database import subgraphs_to_query
sage: gd = GraphDatabase()
sage: q = subgraphs_to_query(['all_of','A?','B?','C?'],gd)
sage: q.get_query_string()
'SELECT , ,, ,, FROM misc WHERE ( ( misc.induced_subgraphs regexp ? ) AND ( misc.induced_subgraphs regexp ? ) ) AND ( misc.induced_subgraphs regexp ? )'