Beispiel #1
0
    def test_K2(self):
        G = nx.complete_graph(2)

        self.assertTrue(dnx.is_hamiltonian_path(G, [0, 1]))
        self.assertTrue(dnx.is_hamiltonian_path(G, [1, 0]))
        self.assertFalse(dnx.is_hamiltonian_path(G, [0]))
        self.assertFalse(dnx.is_hamiltonian_path(G, [1]))
        self.assertFalse(dnx.is_hamiltonian_path(G, []))
Beispiel #2
0
    def test_TSP_basic(self):
        """Runs the function on some small and simple graphs, just to make
        sure it works in basic functionality.
        """
        G = nx.complete_graph(4)
        for u, v in G.edges():
            G[u][v]['weight'] = 1
        route = dnx.traveling_salesperson(G, dimod.ExactSolver())
        self.assertTrue(dnx.is_hamiltonian_path(G, route))

        G = nx.complete_graph(4)
        for u, v in G.edges():
            G[u][v]['weight'] = u + v
        route = dnx.traveling_salesperson(G,
                                          dimod.ExactSolver(),
                                          lagrange=10.0)
        self.assertTrue(dnx.is_hamiltonian_path(G, route))
Beispiel #3
0
    def test_empty(self):
        G = nx.Graph()

        self.assertTrue(dnx.is_hamiltonian_path(G, []))