Beispiel #1
0
def construct(n, k):
    assert n % 2 == 0
    g = Graph(n + 4)

    # make complete graph on n vertices
    for i in range(n):
        for j in range(i + 1, n):
            g[i, j] = 0

    edges = []

    # add the 1 vertex
    g[0, n] = 0
    edges.append((0, n))

    # add the n+1 and n+2 vertices
    for i in range(n):
        g[i, n + 1] = 0
        g[i, n + 2] = 0
        edges.extend([
            (i, n+1),
            (i, n+2),
        ])

    # add the n+3 vertex
    g[n + 1, n + 3] = 0
    g[n + 2, n + 3] = 0
    edges.extend([
        (n+1, n+3),
        (n+2, n+3),
    ])
    for i in range(1, n):
        g[i, n + 3] = 0
        edges.append((i, n+3))

    for to_delete in chain.from_iterable(combinations(edges, i) for i in range(1, k+1)):
        for u, v in to_delete:
            del g[u, v]

        deg = g.degrees()
        delta = max(deg.values())
        valid = True
        for node, d in deg.items():
            valid = (d == delta if 0 <= node < n else
                     d < delta)
            if not valid:
                break
        if valid:
            yield g

        for u, v in to_delete:
            g[u, v] = 0

    return g
Beispiel #2
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('file', type=str)
    parser.add_argument('-d', '--dir', type=str, default='.', required=False)
    parser.add_argument('-p',
                        '--prefix',
                        type=str,
                        default=None,
                        required=False)
    parser.add_argument('--node-label',
                        dest='node_label',
                        type=str,
                        default="node_num",
                        required=False)
    parser.add_argument('--no-core-same-rank',
                        dest='core_same_rank',
                        action='store_false')
    parser.add_argument('--nice-core', dest='nice_core', action='store_true')
    parser.set_defaults(core_same_rank=True)

    args = parser.parse_args()
    args.prefix = args.file if args.prefix is None else args.prefix

    for i, line in enumerate(open(args.file)):
        z = json.loads(line)
        g = Graph(len(z["edge_data"]))

        # if g.n != 8:
        #     continue

        g.edge_data = [[(x if x != -1 else False) for x in row]
                       for row in z["edge_data"]]
        seq = list(g.degrees().values())
        seq.sort()

        # if seq != [g.n - 1] * g.n:
        #     continue

        plot_graph(
            g,
            with_labels=False,
            node_label=args.node_label,
            core_same_rank=args.core_same_rank,
            nice_core=args.nice_core,
        ).render(
            filename=f"{args.dir}/{args.prefix}.{g.n}.{i}",
            cleanup=True,
        )
Beispiel #3
0
def construct(m):
    assert m % 2 == 1 and m >= 7
    g = Graph(m + 5)

    # Complete graph on m
    for u in range(m):
        for v in range(u + 1, m):
            g[u, v] = 0

    # initialize extension
    # deg( m   ) = 1
    # deg( m+1 ) = m
    # deg( m+2 ) = m
    # deg( m+3 ) = m+1
    # deg( m+4 ) = m+1
    g[m, m - 1] = 0
    g[m + 1, m + 3] = 0
    g[m + 1, m + 4] = 0
    g[m + 2, m + 3] = 0
    g[m + 2, m + 4] = 0
    g[m + 3, m + 4] = 0

    for u in range(0, m - 2):
        g[m + 1, u] = 0

    return g
Beispiel #4
0
def adj_mat_to_graph(lines,
                     n,
                     delta=None,
                     underfull=None,
                     delta_core=None,
                     is_semicore=False):
    while True:
        line = next(lines, "")
        if not line:
            break

        if line.startswith("Graph"):
            mat = []
            for _, line in zip(range(n), lines):
                mat.append(line.strip())
            g = Graph(n)
            g.edge_data = [[False if x == '0' else 0 for x in row]
                           for row in mat]
            if (delta is None or max_degree(g) == delta) and \
                    (underfull is None or is_overfull(g) == (not underfull)) and \
                    (delta_core is None or deg_core(g) == delta_core) and \
                    (not is_semicore or graph_is_semicore(g)):
                yield g
Beispiel #5
0
def construct(n):
    assert n % 2 == 0
    g = Graph(n + 4)

    # Make complete graph on n vertices
    for i in range(n):
        for j in range(i + 1, n):
            g[i, j] = 0

    # Add the 1 vertex
    g[0, n] = 0

    # Add the n+1 and n+2 vertices
    for i in range(n):
        g[i, n + 1] = 0
        g[i, n + 2] = 0

    # Add the n+3 vertex
    g[n + 1, n + 3] = 0
    g[n + 2, n + 3] = 0
    for i in range(1, n):
        g[i, n + 3] = 0

    return g
Beispiel #6
0
def nx2graph(G: nx.Graph):
    g = Graph(len(G.nodes))
    for u, v in G.edges:
        g[u, v] = 0
    return g
Beispiel #7
0
def golang_graph_to_graph(edge_data):
    g = PyecolGraph(len(edge_data))
    g.edge_data = [[(False if x == -1 else 0) for x in row]
                   for row in edge_data]
    return g
Beispiel #8
0
def is_valid_semicore(g: Graph, neighbours, core) -> bool:
    # Check that all nodes have a core-neighbour
    return all(neighbours[u] & core for u in g.nodes())
Beispiel #9
0
    # Check that core is a disjoint union of cycles
    return all(len(neighbours[u] & core) <= 2 for u in core)


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('--relax-core',
                        dest='relax_core',
                        default=False,
                        action='store_true')

    args = parser.parse_args()

    for line in sys.stdin:
        u = json.loads(line)
        edge_data = u["edge_data"]
        g = Graph(len(edge_data))
        g.edge_data = [[(False if x == -1 else 0) for x in row]
                       for row in edge_data]

        deg = g.degrees()
        delta = max(deg.values())
        neighbours = {u: set(g.neighbours(u)) for u in g.nodes()}
        core = {u for u in g.nodes() if deg[u] == delta}
        if core \
                and min(deg.values()) == delta - 1 \
                and is_valid_semicore(g, neighbours, core) \
                and (args.relax_core or is_valid_core(g, neighbours, core)):
            sys.stdout.write(line)
            sys.stdout.flush()