Ejemplo n.º 1
0
    def create_graph(self, file_name):
        lines = self.read_file(file_name)
        start_node_cords = coordinates(lines[1])
        target_node_cords = coordinates(lines[2])

        nodes_dict: Dict[Tuple[int, int], Node] = {}

        for i in range(3, len(lines)):
            line = lines[i]
            if len(line.split(" ")) > 1:
                from_node_cords, to_node_cords = line.split(" ", 1)
                from_node_cords = coordinates(from_node_cords)
                to_node_cords = coordinates(to_node_cords)
                if from_node_cords in nodes_dict:
                    from_node = nodes_dict[from_node_cords]
                else:
                    from_node = Node.Node(*from_node_cords)

                if to_node_cords in nodes_dict:
                    to_node = nodes_dict[to_node_cords]
                else:
                    to_node = Node.Node(*to_node_cords)
                nodes_dict[from_node_cords] = from_node
                nodes_dict[to_node_cords] = to_node
                self.graph.add_edge(from_node, to_node)
            else:
                raise ValueError("Die Zeile ist falsch lol!")

        start_node = nodes_dict[start_node_cords]
        target_node = nodes_dict[target_node_cords]
        return start_node, target_node
Ejemplo n.º 2
0
    def test_edge_constructs(self):

        a = Node(1)
        b = Node(2)
        w = 0.98
        edge = Edge(b, a, w)
        self.assertEqual(edge.get_a(), a)
        self.assertEqual(edge.get_b(), b)
Ejemplo n.º 3
0
    def test_partition_generator_generates(self):
        nodes = {Node(i) for i in range(0, 5)}
        size_space = DiscreteProbabilitySpace({1: 0.5, 2: 0.5})
        generator = PartitionGenerator(nodes)
        self.assertTrue(isinstance(generator, PartitionGenerator))

        graph = generator.generate(size_space, 0.5)
        self.assertTrue(isinstance(graph, Graph))
        self.assertEqual(graph.get_nodes(), nodes)
Ejemplo n.º 4
0
def graph():
    node_1 = Node(5)
    node_2 = Node(3)
    node_3 = Node(7)
    node_4 = Node(2)
    node_5 = Node(5)
    node_6 = Node(1)
    node_7 = Node(0)
    node_8 = Node(2)
    node_9 = Node(8)
    node_10 = Node(5)

    node_1.add_neighbours([node_2, node_3])
    node_2.add_neighbours([node_4, node_5])
    node_3.add_neighbours([node_6, node_7])
    node_7.add_neighbours([node_8, node_9])
    node_9.add_neighbours([node_10])

    return [
        node_1, node_2, node_3, node_4, node_5, node_6, node_7, node_8, node_9,
        node_10
    ]
Ejemplo n.º 5
0
    def test_node_constructs(self):

        node = Node("abc")
        self.assertEqual(node.get_id(), "abc")