示例#1
0
 def test_dominating_set(self):
     input = networkx.generators.cycle_graph(10)
     output = graph.dominating_set(input, 4)
     self.assertEqual(len(output), 4)
     self.assertTrue(networkx.is_dominating_set(input, output))
     output = graph.dominating_set(input, 3)
     self.assertIsNone(output)
示例#2
0
def brute_force(k, graph):
    """This function solves the k-center problem on graphs by exhaustive calculations.

    :param k: int
    :param graph: Graph
    :return: list
    """
    graph = add_missing_edges(graph)
    test_graph = networkx.Graph()
    test_graph.add_nodes_from(graph.nodes())
    for edge in sorted(graph.edges(data=True), key=lambda e: e[2]['weight']):
        test_graph.add_edge(*edge)
        result = dominating_set(test_graph, k)  # Das ist langsam
        if result:
            return result