def add_connection(self, block_1: Block, index_1, block_2: Block, index_2): """ Add an edge between index_1 of block_1 and index_2 of block_2 :param block_1: Block :param index_1: int :param block_2: Block :param index_2: int :return: None """ # Since Value Blocks only allow one connection, get_block() always returns a new block for that variable block_1 = block_1.get_block() if block_1 not in self.block: self.block.append(block_1) block_2 = block_2.get_block() if block_2 not in self.block: self.block.append(block_2) if block_2 in block_1.adjacent.keys(): block_1.adjacent[block_2].append((index_1, index_2)) else: block_1.adjacent[block_2] = [(index_1, index_2)] if block_1 in block_2.adjacent.keys(): block_2.adjacent[block_1].append((index_2, index_1)) else: block_2.adjacent[block_1] = [(index_2, index_1)]
def add_block(self, block: Block): """ Adds a new block to the network :param block: Block to be added :return: None """ if isinstance(block, ValueBlock): self.value_block.append(block) self.block.append(block.get_block())