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))
Ejemplo n.º 2
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))
Ejemplo n.º 3
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
Ejemplo n.º 4
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