예제 #1
0
    def test_with_parameter(self):
        net1, edgeList = create_mock_graph_tool(num_nodes=100, num_edges=300)
        GLS = GtLayoutService()
        params = {
            'layout-name': 'default',
            'only-layout': True,
            'root': 0,
            'vweight': 'vweight',
            'eweight': 'eweight',
            'pin': 'pin',
            'groups': 'groups',
            'pos': 'pos',
            'weight': 'weight',
            'rel_order': 'rel_order',
            'node_weight': 'node_weight'
        }

        params["vweight"] = "vw"
        params["eweight"] = "ew"
        net1.vp.vw = net1.new_vp("int")
        net1.ep.ew = net1.new_ep("int")
        for v in net1.vertices():
            net1.vp.vw[v] = random.randint(0, 100)
        for edge in net1.edges():
            net1.ep.ew[edge] = random.randint(0, 100)
        gs, poss = GLS.process_graphs(params, [net1])
        cx = GraphToolAdapter.from_graph_tool(gs, poss)
        b, dp = has_unique_position(cx)
        assert b, "There are same position nodes.  %s" % (dp)
        b, ns, ls = has_corresponding_layout(cx)
        assert b, "Set of Node id and Set of Layout are different. <node %s> != <layout %s>" % (
            ns, ls)
예제 #2
0
    def process(self, params, input_stream):
        logging.debug(params)

        # Convert to graph-tool objects
        gs = GraphToolAdapter.to_graph_tool(input_stream)
        ts, tposs = self.process_graphs(params, gs)
        return GraphToolAdapter.from_graph_tool(ts, tposs, False)
예제 #3
0
    def test_all_algorithms(self):
        net1, edgeList = create_mock_planar(dim=[10, 15])
        GLS = GtLayoutService()
        params = {
            'layout-name': 'default',
            'only-layout': True,
            'root': 10,
            'vweight': 'vweight',
            'eweight': 'eweight',
            'pin': 'pin',
            'groups': 'groups',
            'pos': 'pos',
            'weight': 'weight',
            'rel_order': 'rel_order',
            'node_weight': 'node_weight'
        }

        layout_names = [
            "sfdp_layout", "fruchterman_reingold_layout", "arf_layout",
            "radial_tree_layout", "planar_layout", "random_layout"
        ]
        # layout_names = ["sfdp_layout", "fruchterman_reingold_layout", "arf_layout", "radial_tree_layout", "random_layout"]
        for l in layout_names:
            params['layout-name'] = l
            gs, poss = GLS.process_graphs(params, [net1])
            cx = GraphToolAdapter.from_graph_tool(gs, poss)
            b, ns, ls = has_corresponding_layout(cx)
            assert b, "Set of Node id and Set of Layout are different. Algorithm: %s <node %s> != <layout %s>" % (
                l, ns, ls)
예제 #4
0
    def test_clabel(self):
        net1, edgeList = create_mock_graph_tool(num_nodes=30, num_edges=100)
        GDHS = GtDrawHierarchyService()
        params = {'layout': 'radial', 'pos': 'pos', 'beta': 8, 'deg_order': True, 'deg_size': True, 'vsize_scale': 1.0, 'hsize_scale': 1.0, 'hshortcuts': 0, 'hide': 0, 'bip_aspect': 1.0, 'empty_branches': False, 'only-layout': True}

        gs, poss = GDHS.process_graphs(params, [net1])
        cx = GraphToolAdapter.from_graph_tool(gs,  poss)
        check_clabel(cx)
예제 #5
0
    def test_all_nodes_have_layout(self):
        net1, edgeList = create_mock_graph_tool(num_nodes=30, num_edges=100)
        GDHS = GtDrawHierarchyService()
        params = {'layout': 'radial', 'pos': 'pos', 'beta': 8, 'deg_order': True, 'deg_size': True, 'vsize_scale': 1.0, 'hsize_scale': 1.0, 'hshortcuts': 0, 'hide': 0, 'bip_aspect': 1.0, 'empty_branches': False, 'only-layout': True}

        gs, poss = GDHS.process_graphs(params, [net1])
        cx = GraphToolAdapter.from_graph_tool(gs,  poss)
        b, ns, ls = has_corresponding_layout(cx)
        assert b, "Set of Node id and Set of Layout are different. <node %s> != <layout %s>" % (ns, ls)
예제 #6
0
    def test_nodes_have_unique_position(self):
        net1, edgeList = create_mock_graph_tool(num_nodes=30, num_edges=100)
        GDHS = GtDrawHierarchyService()
        params = {'layout': 'radial', 'pos': 'pos', 'beta': 8, 'deg_order': True, 'deg_size': True, 'vsize_scale': 1.0, 'hsize_scale': 1.0, 'hshortcuts': 0, 'hide': 0, 'bip_aspect': 1.0, 'empty_branches': False, 'only-layout': True}

        gs, poss = GDHS.process_graphs(params, [net1])
        cx = GraphToolAdapter.from_graph_tool(gs,  poss)
        b, dp = has_unique_position(cx)
        assert b, "There are same position nodes.  %s" % (dp)
예제 #7
0
 def testMultipleNetworks(self):
     nets = [
         create_mock_graph_tool('net1')[0],
         create_mock_graph_tool('net2')[0]
     ]
     streams = GraphToolAdapter.from_graph_tool(nets)
     res_nets = GraphToolAdapter.to_graph_tool(streams)
     compare_graph_tool(nets[0], res_nets[0])
     compare_graph_tool(nets[1], res_nets[1])
예제 #8
0
 def testUnusualAttributeType(self):
     net, edgeList = create_mock_graph_tool(num_nodes=100,
                                            num_edges=50,
                                            data={'keyDict': {
                                                1: 2
                                            }})
     stream = GraphToolAdapter.from_graph_tool([net])
     net_res_list = GraphToolAdapter.to_graph_tool(stream)
     compare_graph_tool(net, net_res_list[0])
     # autoconvert to string for unrecognized value types
     self.assertEqual(str(net.gp['keyDict']), net_res_list[0].gp['keyDict'])
예제 #9
0
    def test_all_algorithms(self):
        net1, edgeList = create_mock_planar(dim=[5, 5])
        GDHS = GtDrawHierarchyService()
        params = {'layout': 'radial', 'pos': 'pos', 'beta': 8, 'deg_order': True, 'deg_size': True, 'vsize_scale': 1.0, 'hsize_scale': 1.0, 'hshortcuts': 0, 'hide': 0, 'bip_aspect': 1.0, 'empty_branches': False, 'only-layout': True}

        layout_names = ["sfdp", "radial", "bipartite"]
        for l in layout_names:
            params['layout'] = l
            gs, poss = GDHS.process_graphs(params, [net1])
            cx = GraphToolAdapter.from_graph_tool(gs,  poss)
            b, ns, ls = has_corresponding_layout(cx)
            assert b, "Set of Node id and Set of Layout are different. Algorithm: %s <node %s> != <layout %s>" % (l, ns, ls)
예제 #10
0
    def test_to_graph_tool(self):
        net, edgeList = create_mock_graph_tool(num_nodes=100,
                                               num_edges=50,
                                               data={
                                                   'keyStr': 'value',
                                                   'keyInt': 1,
                                                   'keyFloat': 1.2,
                                                   'keyBool': True
                                               })

        stream = GraphToolAdapter.from_graph_tool([net])
        net_res_list = GraphToolAdapter.to_graph_tool(stream)
        compare_graph_tool(net, net_res_list[0])
        self.assertEqual(net.gp.keys(), net_res_list[0].gp.keys())
        for k in net.gp.keys():
            self.assertEqual(net.gp[k], net_res_list[0].gp[k])
예제 #11
0
    def test_nodes_have_unique_position(self):
        net1, edgeList = create_mock_graph_tool(num_nodes=100, num_edges=300)
        GLS = GtLayoutService()
        params = {
            'layout-name': 'default',
            'only-layout': True,
            'root': 0,
            'vweight': 'vweight',
            'eweight': 'eweight',
            'pin': 'pin',
            'groups': 'groups',
            'pos': 'pos',
            'weight': 'weight',
            'rel_order': 'rel_order',
            'node_weight': 'node_weight'
        }

        gs, poss = GLS.process_graphs(params, [net1])
        cx = GraphToolAdapter.from_graph_tool(gs, poss)
        b, dp = has_unique_position(cx)
        assert b, "There are same position nodes.  %s" % (dp)
예제 #12
0
    def test_large_graph(self):
        net1, edgeList = create_mock_graph_tool(num_nodes=1000, num_edges=3000)
        GLS = GtLayoutService()
        params = {
            'layout-name': 'default',
            'only-layout': True,
            'root': 0,
            'vweight': 'vweight',
            'eweight': 'eweight',
            'pin': 'pin',
            'groups': 'groups',
            'pos': 'pos',
            'weight': 'weight',
            'rel_order': 'rel_order',
            'node_weight': 'node_weight'
        }

        gs, poss = GLS.process_graphs(params, [net1])
        cx = GraphToolAdapter.from_graph_tool(gs, poss)
        b, ns, ls = has_corresponding_layout(cx)
        assert b, "Set of Node id and Set of Layout are different. <node %s> != <layout %s>" % (
            ns, ls)
예제 #13
0
    def test_from_graph_tool(self):
        net, edgeList = create_mock_graph_tool(num_nodes=100, num_edges=50)
        net.gp.desc = net.new_gp("string")
        net.gp.desc = 'example'
        nodeCount = 0
        edgeCount = 0

        for aspect in GraphToolAdapter.from_graph_tool([net]):
            which = aspect.WhichOneof('element')
            if which == 'node':
                nodeCount += 1
                node = aspect.node
                self.assertEqual(net.vp['name'][net.vertex(node.id)],
                                 node.name)
            elif which == 'edge':
                edgeCount += 1
                edge = aspect.edge
                self.assertEqual(
                    edge.id, net.ep.id[net.edge(edge.sourceId, edge.targetId)])
            elif which == 'nodeAttribute':
                attr = aspect.nodeAttribute
                self.assertEqual(net.vp[attr.name][net.vertex(node.id)],
                                 attr.value)
            elif which == 'edgeAttribute':
                attr = aspect.edgeAttribute
                a, b = edgeList[attr.edgeId]
                self.assertEqual(
                    str(net.ep.value[net.edge(edge.sourceId, edge.targetId)]),
                    attr.value)
            elif which == 'networkAttribute':
                attr = aspect.networkAttribute
                self.assertEqual(net.gp[attr.name], attr.value)
            else:
                print("UNTESTED %s" % aspect)
        self.assertEqual(nodeCount, len(net.get_vertices()))
        self.assertEqual(edgeCount, len(net.get_edges()))
예제 #14
0
 def testLargeNetwork(self):
     net, edgeList = create_mock_graph_tool(num_nodes=10000, num_edges=5000)
     stream = GraphToolAdapter.from_graph_tool([net])
     net_res_list = GraphToolAdapter.to_graph_tool(stream)
     compare_graph_tool(net, net_res_list[0])
예제 #15
0
 def process(self, params, input_stream):
     logging.debug(params)
     ol = params.pop("only-layout")
     gs = GraphToolAdapter.to_graph_tool(input_stream)
     gs, poss = self.process_graphs(params, gs)
     return GraphToolAdapter.from_graph_tool(gs, poss, ol)