Exemplo n.º 1
0
    def test_get_vertexes(self):
        lg = LabeledGraph()
        expected_vertexes = ('vertex1', 'vertex2')

        for vertex in expected_vertexes:
            lg.add_vertex(vertex)

        result_vertexes = lg.vertexes()
        self.assertEqual(2, len(result_vertexes))
        self.assertEqual(set(expected_vertexes), set(result_vertexes))
    def test_get_vertexes(self):
        lg = LabeledGraph()
        expected_vertexes = ('vertex1', 'vertex2')

        for vertex in expected_vertexes:
            lg.add_vertex(vertex)

        result_vertexes = lg.vertexes()
        self.assertEqual(2, len(result_vertexes))
        self.assertEqual(set(expected_vertexes), set(result_vertexes))
    def test_set_label(self):
        lg = LabeledGraph()
        lg.set_edge('v1', 'v2', 5)
        lg.set_edge('v2', 'v3', 10)

        self.assertEqual(5, lg.get_edge('v1', 'v2'))
        self.assertEqual(10, lg.get_edge('v2', 'v3'))
    def test_get_successors(self):
        lg = LabeledGraph()
        lg.set_edge('s1', 't1', 10)
        lg.set_edge('s1', 't2', 10)
        lg.set_edge('s1', 't3', 10)

        lg.set_edge('s2', 't1', 10)
        lg.set_edge('s2', 't2', 10)

        self.assertEqual(set(lg.get_successors('s1')), set(['t1', 't2', 't3']))
        self.assertEqual(set(lg.get_successors('s2')), set(['t1', 't2']))
Exemplo n.º 5
0
    def test_set_label(self):
        lg = LabeledGraph()
        lg.set_edge('v1', 'v2', 5)
        lg.set_edge('v2', 'v3', 10)

        self.assertEqual(5, lg.get_edge('v1', 'v2'))
        self.assertEqual(10, lg.get_edge('v2', 'v3'))
Exemplo n.º 6
0
    def test_get_successors(self):
        lg = LabeledGraph()
        lg.set_edge('s1', 't1', 10)
        lg.set_edge('s1', 't2', 10)
        lg.set_edge('s1', 't3', 10)

        lg.set_edge('s2', 't1', 10)
        lg.set_edge('s2', 't2', 10)

        self.assertEqual(set(lg.get_successors('s1')), set(['t1', 't2', 't3']))
        self.assertEqual(set(lg.get_successors('s2')), set(['t1', 't2']))
    def test_remove_vertex(self):
        lg = LabeledGraph()
        lg.set_edge('t1', 's1', 2)
        lg.set_edge('t1', 's2', 3)

        lg.remove_vertex('t1')

        exp_vertexes = ['s1', 's2']
        self.assertEqual(set(lg.vertexes()), set(exp_vertexes))

        self.assertEqual(None, lg.get_edge('t1', 's1'))
        self.assertEqual(None, lg.get_edge('t1', 's2'))
Exemplo n.º 8
0
    def test_remove_vertex(self):
        lg = LabeledGraph()
        lg.set_edge('t1', 's1', 2)
        lg.set_edge('t1', 's2', 3)

        lg.remove_vertex('t1')

        exp_vertexes = ['s1', 's2']
        self.assertEqual(set(lg.vertexes()), set(exp_vertexes))

        self.assertEqual(None, lg.get_edge('t1', 's1'))
        self.assertEqual(None, lg.get_edge('t1', 's2'))
Exemplo n.º 9
0
 def clear(self):
     self.links = LabeledGraph()
     self.location_positions = {}
Exemplo n.º 10
0
class ExtendableMap:
    """
        Map to save information about locations, their coordinates and lengths of paths between them.
    """

    def __init__(self):
        self.clear()

    def clear(self):
        self.links = LabeledGraph()
        self.location_positions = {}

    def add_location(self, location):
        self.links.add_vertex(location)

    def get_locations(self):
        return self.links.vertexes()

    def is_location(self, location):
        return location in self.links.vertexes()

    def get_locations_linked_to(self, location):
        return self.links.get_successors(location)

    def get_distance(self, from_location, to_location):
        return self.links.get_edge(from_location, to_location)

    def add_unidirectional_link(self, from_location, to_location, distance):
        self.links.set_edge(from_location, to_location, distance)

    def add_bidirectional_link(self, from_location, to_location, distance):
        self.links.set_edge(from_location, to_location, distance)
        self.links.set_edge(to_location, from_location, distance)

    def remove_unidirectional_link(self, from_location, to_location):
        self.links.remove_edge(from_location, to_location)

    def remove_bidirectional_link(self, from_location, to_location):
        self.links.remove_edge(from_location, to_location)
        self.links.remove_edge(to_location, from_location)

    def set_position(self, location, pos):
        self.location_positions[location] = pos

    def get_position(self, location):
        return self.location_positions[location]

    def set_dist_and_dir_to_ref_location(self, location, dist, dir):
        coordinates = Point2D(-sin(dir * math.pi / 180) * dist, cos(dir * math.pi / 180) * dist)
        self.links.add_vertex(location)
        self.location_positions[location] = coordinates
Exemplo n.º 11
0
 def clear(self):
     self.links = LabeledGraph()
     self.location_positions = {}
Exemplo n.º 12
0
class ExtendableMap:
    """
        Map to save information about locations, their coordinates and lengths of paths between them.
    """
    def __init__(self):
        self.clear()

    def clear(self):
        self.links = LabeledGraph()
        self.location_positions = {}

    def add_location(self, location):
        self.links.add_vertex(location)

    def get_locations(self):
        return self.links.vertexes()

    def is_location(self, location):
        return location in self.links.vertexes()

    def get_locations_linked_to(self, location):
        return self.links.get_successors(location)

    def get_distance(self, from_location, to_location):
        return self.links.get_edge(from_location, to_location)

    def add_unidirectional_link(self, from_location, to_location, distance):
        self.links.set_edge(from_location, to_location, distance)

    def add_bidirectional_link(self, from_location, to_location, distance):
        self.links.set_edge(from_location, to_location, distance)
        self.links.set_edge(to_location, from_location, distance)

    def remove_unidirectional_link(self, from_location, to_location):
        self.links.remove_edge(from_location, to_location)

    def remove_bidirectional_link(self, from_location, to_location):
        self.links.remove_edge(from_location, to_location)
        self.links.remove_edge(to_location, from_location)

    def set_position(self, location, pos):
        self.location_positions[location] = pos

    def get_position(self, location):
        return self.location_positions[location]

    def set_dist_and_dir_to_ref_location(self, location, dist, dir):
        coordinates = Point2D(-sin(dir * math.pi / 180) * dist,
                              cos(dir * math.pi / 180) * dist)
        self.links.add_vertex(location)
        self.location_positions[location] = coordinates