Esempio n. 1
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
Esempio n. 2
0
 def test_add_missing_edges(self):
     input = networkx.generators.cycle_graph(10)
     self.assertEqual(graph.add_missing_edges(input).number_of_edges(), 45)