예제 #1
0
def test_mst_prim():
    graph = RandomGraph()
    mst = mst_prim(graph, graph.nodes()[0])

    nx_graph = networkx.Graph()
    for node in graph.nodes():
        for neighbor in graph.get(node):
            if nx_graph.has_edge(node,
                                 neighbor) is False and nx_graph.has_edge(
                                     neighbor, node) is False:
                nx_graph.add_edge(node,
                                  neighbor,
                                  weight=graph.get(node, neighbor))

    tree = []
    for node in mst:
        if mst[node] is not None:
            tree.append((node, mst[node]))
    print(tree)

    T = networkx.minimum_spanning_tree(nx_graph)
    edges = T.edges(data=False)

    # Begin the test
    test = True

    # I need to check if (x,y) or (y,x) is in networkx generated mst
    for node in tree:
        x, y = node
        print(x, y)
        test = test and ((x, y) in edges or (y, x) in edges)

    assert test
예제 #2
0
def test_connected_components():
    graph = RandomGraph()
    number_cc = len(connected_components(graph))
    graph_data = networkx.Graph(graph.graph_dict)
    test = networkx.is_connected(graph_data)
    test = number_cc == 1 if test else number_cc != 1
    assert test
예제 #3
0
    def __init__(self, node_num, p, in_channels, out_channels, graph_mode,
                 is_train, name):
        super(RandWire, self).__init__()
        self.node_num = node_num
        self.p = p
        self.in_channels = in_channels
        self.out_channels = out_channels
        self.graph_mode = graph_mode
        self.is_train = is_train
        self.name = name

        # get graph nodes and in edges
        graph_node = RandomGraph(self.node_num, self.p, graph_mode=graph_mode)
        if self.is_train is True:
            print("is_train: True")
            graph = graph_node.make_graph()
            self.nodes, self.in_edges = graph_node.get_graph_info(graph)
            graph_node.save_random_graph(graph, name)
        else:
            graph = graph_node.load_random_graph(name)
            self.nodes, self.in_edges = graph_node.get_graph_info(graph)

        # define input Node
        self.module_list = nn.ModuleList([
            Node(self.in_edges[0],
                 self.in_channels,
                 self.out_channels,
                 stride=2)
        ])
        # define the rest Node
        self.module_list.extend([
            Node(self.in_edges[node], self.out_channels, self.out_channels)
            for node in self.nodes if node > 0
        ])
예제 #4
0
steps = 200

full_graph = FullGraph(5)
todo = [{
    "msg": "Running IL",
    "name": "IL",
    "partners": 0,
    "n_samples": args.n_samples,
    "fun": lambda: LJALPart1(graph=Graph(5)).n_steps(steps)
}, {
    "msg": "Running LJAL-2",
    "name": "LJAL-2",
    "partners": 2,
    "n_samples": args.n_samples,
    "fun": lambda: LJALPart1(graph=RandomGraph(5, 2)).n_steps(steps)
}, {
    "msg": "Running LJAL-3",
    "name": "LJAL-3",
    "partners": 3,
    "n_samples": args.n_samples,
    "fun": lambda: LJALPart1(graph=RandomGraph(5, 3)).n_steps(steps)
}, {
    "msg": "Running JAL",
    "name": "JAL",
    "partners": 4,
    "n_samples": args.n_samples,
    "fun": lambda: LJALPart1(graph=full_graph).n_steps(steps)
}]

tasks.run(todo, args.save_name)
예제 #5
0
def test_cc():
    graph = RandomGraph()
    number_cc = len(connected_components(graph))
    graph_data = networkx.Graph(graph.graph_dict)
    assert networkx.number_connected_components(graph_data) == number_cc
예제 #6
0
def build_graph(filename, p):
    for i in range(start, end, offset):
        RandomGraph(list(range(i)),
                    p).save_graph(filename + format_p(p) + str(i))