Пример #1
0
def list_bipartite_graphs(n_vertices_1, n_vertices_2, deg_range_1, deg_range_2, n_edges):
    """Create a list of bipartite graphs, vertices of the first colour have degree in the range min_deg_1:max_deg_1,
    vertices of the second colour have degree in the range min_deg_2:max_deg_2.

    :param n_vertices_1: Number of vertices of the first colour.
    :type n_vertices_1: int
    :param n_vertices_2: Number of vertices of the second colour.
    :type n_vertices_2: int
    :param deg_range_1: (min, max) degree of the vertices of the first colour.
    :type deg_range_1: tuple(int, int)
    :param deg_range_2: (min, max) degree of the vertices of the second colour.
    :type deg_range_2: tuple(int, int)
    :param n_edges: Number of edges of the bipartite graph.
    :type n_edges: int
    :return: List of generated sage graphs.
    :rtype: list(Graph)
    """
    (min_deg_1, max_deg_1) = deg_range_1
    (min_deg_2, max_deg_2) = deg_range_2
    # z switch prevents multiple hairs and multiple edges
    StoreLoad.makedirs(Parameters.temp_folder)
    with tempfile.NamedTemporaryFile(dir=Parameters.temp_folder) as f:
        nauty_command = 'genbgL -czlq -d%d:%d -D%d:%d %d %d %d:%d %s' % \
            (min_deg_1, min_deg_2, max_deg_1, max_deg_2,
             n_vertices_1, n_vertices_2, n_edges, n_edges, f.name)
        #logger.warn('call nauty to generate bipartite graphs: ' + nauty_command)
        os.system(nauty_command)
        list_g6 = f.read().splitlines()
        # if len(list_g6) == 0:
        #print('Call nauty to generate bipartite graphs: ' + nauty_command)
        #print('List of bipartite graphs generated using nauty has zero length')
        #logger.warn('Call nauty to generate bipartite graphs: ' + nauty_command)
        #logger.warn('List of bipartite graphs generated using nauty has zero length')
    return [Graph(g6) for g6 in list_g6]
Пример #2
0
def list_bipartite_graphs3(n_vertices_1, n_vertices_2, deg_range_1, deg_range_2, n_edges, n_maxneighbors):
    """
    Same as before, but with  n_maxcommon_neighbors many common neighbors ...
    Create a list of bipartite graphs, vertices of the first colour have degree in the range min_deg_1:max_deg_1,
    vertices of the second colour have degree in the range min_deg_2:max_deg_2.

    :param n_vertices_1: Number of vertices of the first colour.
    :type n_vertices_1: int
    :param n_vertices_2: Number of vertices of the second colour.
    :type n_vertices_2: int
    :param deg_range_1: (min, max) degree of the vertices of the first colour.
    :type deg_range_1: tuple(int, int)
    :param deg_range_2: (min, max) degree of the vertices of the second colour.
    :type deg_range_2: tuple(int, int)
    :param n_edges: Number of edges of the bipartite graph.
    :type n_edges: int
    :param n_maxneighbors: Maximum number of common neighbors of second color vertices
    :return: List of generated sage graphs.
    :rtype: list(Graph)
    """
    (min_deg_1, max_deg_1) = deg_range_1
    (min_deg_2, max_deg_2) = deg_range_2
    # z switch prevents multiple hairs and multiple edges

    StoreLoad.makedirs(Parameters.temp_folder)
    with tempfile.NamedTemporaryFile(dir=Parameters.temp_folder) as f:
        nauty_command = 'genbgL -clq -Z%d -d%d:%d -D%d:%d %d %d %d:%d %s' % \
            (n_maxneighbors, min_deg_1, min_deg_2, max_deg_1, max_deg_2,
             n_vertices_1, n_vertices_2, n_edges, n_edges, f.name)
        # print(nauty_command)
        #logger.warn('call nauty to generate bipartite graphs: ' + nauty_command)
        os.system(nauty_command)
        txt = f.read()
        if not type(txt) is str:
            txt = txt.decode("ascii")
        list_g6 = txt.splitlines()
        # list_g6 = f.read().decode("utf-8").splitlines()
        # print(list_g6)
        # if len(list_g6) == 0:
        #print('Call nauty to generate bipartite graphs: ' + nauty_command)
        #print('List of bipartite graphs generated using nauty has zero length')
        #logger.warn('Call nauty to generate bipartite graphs: ' + nauty_command)
        #logger.warn('List of bipartite graphs generated using nauty has zero length')
    return [Graph(g6) for g6 in list_g6]
Пример #3
0
"""Generate sample images of graphs to be used on the webpage."""

import SpecialGraphs
import Parameters
import OrdinaryGraphComplex
import HairyGraphComplex
import StoreLoad

imgdir = Parameters.web_dir + "/img/"
StoreLoad.makedirs(imgdir)

# Commutatie graph complex
G = SpecialGraphs.wheel_graph(7)
VS = OrdinaryGraphComplex.OrdinaryGVS(8, 7, False)
# p = VS.plot_graph(G)
p = G.plot(vertex_labels=False, transparent=True)
p.save(imgdir + "wheel7.png")


# hairy graph complex
G = SpecialGraphs.hedgehog_graph(5)
VS = HairyGraphComplex.HairyGraphVS(5, 1, 5, False, False)
p = G.plot(vertex_labels=False, transparent=True)
p.save(imgdir + "hedgehog5.png")