Exemplo n.º 1
0
    def test_dimod_vs_list(self):
        G = nx.complete_graph(4)
        for u, v in G.edges():
            G[u][v]['weight'] = 1

        route = tsp.traveling_salesman(G, dimod.ExactSolver())
        route = tsp.traveling_salesman(G, dimod.SimulatedAnnealingSampler())
Exemplo n.º 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 = tsp.traveling_salesman(G, dimod.ExactSolver())
        self.assertTrue(tsp.is_hamiltonian_path(G, route))

        G = nx.complete_graph(4)
        for u, v in G.edges():
            G[u][v]['weight'] = u + v
        route = tsp.traveling_salesman(G, dimod.ExactSolver(), lagrange=10.0)
        self.assertTrue(tsp.is_hamiltonian_path(G, route))