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.º 2
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']))
Exemplo 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
Exemplo 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