Ejemplo n.º 1
0
    def test_pickling_sgraph_types(self):

        sg_test_1 = tc.SGraph().add_vertices([
            tc.Vertex(0, {'fluffy': 1}),
            tc.Vertex(1, {
                'fluffy': 1,
                'woof': 1
            }),
            tc.Vertex(2, {})
        ])

        sg_test_2 = tc.SGraph()
        sg_test_2 = sg_test_2.add_vertices([tc.Vertex(x) for x in [0, 1, 2]])
        sg_test_2 = sg_test_2.add_edges([
            tc.Edge(0, 1, attr={'relationship': 'dislikes'}),
            tc.Edge(1, 2, attr={'relationship': 'likes'}),
            tc.Edge(1, 0, attr={'relationship': 'likes'})
        ])

        sarray_list = [sg_test_1, sg_test_2]
        for obj in sarray_list:
            pickler = gl_pickle.GLPickler(self.filename)
            pickler.dump(obj)
            pickler.close()
            unpickler = gl_pickle.GLUnpickler(self.filename)
            obj_ret = unpickler.load()
            unpickler.close()
            assert_sframe_equal(obj.get_vertices(), obj_ret.get_vertices())
            assert_sframe_equal(obj.get_edges(), obj_ret.get_edges())
Ejemplo n.º 2
0
    def test_shortest_path(self):
        if "sssp" in get_unity().list_toolkit_functions():
            m = tc.shortest_path.create(self.graph, source_vid=0)
            print(m)
            m.summary()
            self.__test_model_save_load_helper__(m)

            m2 = tc.shortest_path.create(self.graph, source_vid=0)
            print(m2)
            self.__test_model_save_load_helper__(m2)

            # Test get_path function on a simple chain graph and star graph
            chain_graph = tc.SGraph().add_edges([tc.Edge(i, i + 1) for i in range(10)])
            m3 = tc.shortest_path.create(chain_graph, source_vid=0)
            for i in range(10):
                self.assertSequenceEqual(m3.get_path(i), [(j, float(j)) for j in range(i + 1)])

            star_graph = tc.SGraph().add_edges([tc.Edge(0, i + 1) for i in range(10)])
            m4 = tc.shortest_path.create(star_graph, source_vid=0)
            for i in range(1, 11):
                self.assertSequenceEqual(m4.get_path(i), [(0, 0.0), (i, 1.0)])

            # Test that get_path with the 'show' parameter set to True doesn't
            # break.
            #
            # Showing is problematic when there is actually a browser.
            # This will pause scripts.
            # m4.get_path(i, show=True)

            # Test sssp ignoring the existing distance field
            star_graph.vertices['distance'] = 0
            m5 = tc.shortest_path.create(star_graph, source_vid=0)
            for i in range(1, 11):
                self.assertSequenceEqual(m5.get_path(i), [(0, 0.0), (i, 1.0)])