def partition_metis(g, fpga, pe, ufactor=1):
    logger.debug("Dividing into {} partitions, ufactor: {}".format(fpga, ufactor))
    ug = g.to_undirected()
    for node in ug.nodes():
        ug.nodes[node]['weight'] = ug.degree(node)
    objval, fpgaparts = nxmetis.partition(ug, fpga, options=nxmetis.MetisOptions(contig=False, ufactor=ufactor))
    logger.debug("Edges crossing: {} , expected from random partition: {}".format(objval , nx.number_of_edges(ug)*(fpga-1)/fpga))
    logger.debug("Improvement: {}x".format((nx.number_of_edges(ug)*(fpga-1)/fpga)/objval))

    parts = []
    for part in fpgaparts:
        parts.extend(_partition_greedy(g, pe, part))

    return relabel_with_parts(g, parts)
    def test_partition(self):
        partition = nxmetis.partition(self.G, 4)
        # When we choose one node from one part of the partitioned Graph,
        # It must be adjacent to one or more of the nodes in the same part.
        # This is to verify the continuity of the chain of nodes.
        parts = partition[1]  # List containing partitioned node lists

        nose.tools.assert_equal(partition[0], 4)
        nose.tools.assert_equal(len(partition[1]), 4)

        for part in parts:
            nose.tools.assert_not_equal(0, len(part))  # Non-empty set
            nose.tools.assert_equal(len(part), len(set(part)))  # Duplicate-free
            nose.tools.ok_(nx.is_connected(self.G.subgraph(part)))  # Connected

        # Disjoint sets
        for part1, part2 in itertools.combinations(parts, 2):
            nose.tools.assert_equal(set(), set(part1) & set(part2))

        # These parts must be exhaustive with the node list of the Graph
        parts_combined = parts[0] + parts[1] + parts[2] + parts[3]
        nose.tools.assert_equal(set(parts_combined), set(self.G))
Beispiel #3
0
 def metis_partition(self, parts):
     edgecuts, metis_list = nxmetis.partition(self.graph, parts)
     metis_set_list = [set(l) for l in metis_list]
     return metis_set_list