Exemplo n.º 1
0
 def test_algo2(self):
     fLOG (__file__, self._testMethodName, OutputPrint = __name__ == "__main__")
     folder = os.path.join(os.path.abspath(os.path.dirname(__file__)),"temp_rues2")
     if not os.path.exists(folder) : os.mkdir(folder)
     edges = get_data(whereTo=folder)
     edges = edges[:1000]
     added = eulerien_extension(edges, fLOG = fLOG, alpha = 1/8)
     assert len(added)>0
     fLOG ("nb added",len(added))
Exemplo n.º 2
0
 def test_algo_euler4(self):
     fLOG (__file__, self._testMethodName, OutputPrint = __name__ == "__main__")
     folder = os.path.join(os.path.abspath(os.path.dirname(__file__)),"temp_rues5")
     if not os.path.exists(folder) : os.mkdir(folder)
     edges = get_data(whereTo=folder)
     edges = edges[:3]
     
     vertices = { }
     for e in edges :
         for i in range(0,2):
             _ = e[i]
             p = e[i+3]
             vertices[_] = p
     
     connex = connected_components(edges)
     v = [ v for k,v in connex.items() ]
     mi,ma = min(v), max(v)
     
     while mi != ma :
         edges.append( (mi, ma, 2, vertices[mi], vertices[ma], 
                 distance_haversine( * (vertices[mi] + vertices[ma]) ) ) )
         
         connex = connected_components(edges)
         v = [ v for k,v in connex.items() ]
         mi,ma = min(v), max(v)
         
     if __name__ == "__main__":
         import matplotlib.pyplot as plt
         import networkx as nx
         fig = plt.figure()
         G = nx.Graph()
         for e in edges :
             a,b = e[:2]
             G.add_edge(a,b)
         pos = nx.spring_layout(G)
         nx.draw(G,pos,node_color='#A0CBE2')
         plt.savefig(os.path.join(folder, "graph1.png"))
         
     added = eulerien_extension( edges, fLOG=lambda *l : None, 
                                 distance = distance_paris)
                                 
     if __name__ == "__main__":
         for e in added :
             a,b = e[:2]
             G.add_edge(a,b)
         fig = plt.figure()
         pos = nx.spring_layout(G)
         deg = graph_degree(edges + added)
         #labels={ v:"{0}".format(deg[v]) for v in G.nodes() }
         nx.draw(G,pos,node_color='#A0CBE2'#,labels=labels
                         )
         plt.savefig(os.path.join(folder, "graph2.png"))
                                 
     path = euler_path(edges, added)
     all = edges + added
     fLOG(len(all),len(path))
Exemplo n.º 3
0
 def test_algo3(self):
     fLOG (__file__, self._testMethodName, OutputPrint = __name__ == "__main__")
     return
     folder = os.path.join(os.path.abspath(os.path.dirname(__file__)),"temp_rues2")
     if not os.path.exists(folder) : os.mkdir(folder)
     edges = get_data(whereTo=folder)
     fLOG("start")
     added = eulerien_extension(edges, fLOG=fLOG, distance = distance_paris)
     assert len(added)>0
     fLOG ("nb added",len(added))
     with open(os.path.join(folder,"added.txt"),"w") as f : 
         f.write(str(added))
 def test_algo3(self):
     fLOG(__file__,
          self._testMethodName,
          OutputPrint=__name__ == "__main__")
     folder = get_temp_folder(__file__, "temp_algo3")
     edges = get_data(whereTo=folder, fLOG=fLOG)
     fLOG("start")
     added = eulerien_extension(edges, fLOG=fLOG, distance=distance_paris)
     assert len(added) > 0
     fLOG("nb added", len(added))
     with open(os.path.join(folder, "added.txt"), "w") as f:
         f.write(str(added))
Exemplo n.º 5
0
 def test_algo2(self):
     fLOG(__file__,
          self._testMethodName,
          OutputPrint=__name__ == "__main__")
     folder = os.path.join(os.path.abspath(os.path.dirname(__file__)),
                           "temp_algo2")
     if not os.path.exists(folder):
         os.mkdir(folder)
     edges = get_data(whereTo=folder, fLOG=fLOG)
     edges = edges[:1000]
     added = eulerien_extension(edges, fLOG=fLOG, alpha=1 / 8)
     assert len(added) > 0
     fLOG("nb added", len(added))
Exemplo n.º 6
0
 def test_algo3(self):
     fLOG(__file__,
          self._testMethodName,
          OutputPrint=__name__ == "__main__")
     return
     folder = os.path.join(os.path.abspath(os.path.dirname(__file__)),
                           "temp_rues2")
     if not os.path.exists(folder):
         os.mkdir(folder)
     edges = get_data(whereTo=folder, fLOG=fLOG)
     fLOG("start")
     added = eulerien_extension(edges, fLOG=fLOG, distance=distance_paris)
     assert len(added) > 0
     fLOG("nb added", len(added))
     with open(os.path.join(folder, "added.txt"), "w") as f:
         f.write(str(added))
Exemplo n.º 7
0
    def test_algo_euler4(self):
        fLOG(__file__,
             self._testMethodName,
             OutputPrint=__name__ == "__main__")
        folder = os.path.join(os.path.abspath(os.path.dirname(__file__)),
                              "temp_algo_euler4")
        if not os.path.exists(folder):
            os.mkdir(folder)
        edges = get_data(whereTo=folder, fLOG=fLOG)
        edges = edges[:3]

        vertices = {}
        for e in edges:
            for i in range(0, 2):
                _ = e[i]
                p = e[i + 3]
                vertices[_] = p

        connex = connected_components(edges)
        v = [v for k, v in connex.items()]
        mi, ma = min(v), max(v)

        while mi != ma:
            edges.append((mi, ma, 2, vertices[mi], vertices[ma],
                          distance_haversine(*(vertices[mi] + vertices[ma]))))

            connex = connected_components(edges)
            v = [v for k, v in connex.items()]
            mi, ma = min(v), max(v)

        fix_tkinter_issues_virtualenv()
        import matplotlib.pyplot as plt
        import networkx as nx
        plt.figure()
        G = nx.Graph()
        for e in edges:
            a, b = e[:2]
            G.add_edge(a, b)
        pos = nx.spring_layout(G)
        nx.draw(G, pos, node_color='#A0CBE2')
        plt.savefig(os.path.join(folder, "graph1.png"))
        plt.close('all')

        added = eulerien_extension(edges,
                                   fLOG=lambda *l: None,
                                   distance=distance_paris)

        for e in added:
            a, b = e[:2]
            G.add_edge(a, b)
        plt.figure()
        pos = nx.spring_layout(G)
        graph_degree(edges + added)
        #labels={ v:"{0}".format(deg[v]) for v in G.nodes() }
        nx.draw(
            G,
            pos,
            node_color='#A0CBE2'  # ,labels=labels
        )
        plt.savefig(os.path.join(folder, "graph2.png"))
        plt.close('all')

        path = euler_path(edges, added)
        alls = edges + added
        fLOG(len(alls), len(path))