Source code for mqt.ionshuttler.multi_shuttler.inside.graph_utils
# Copyright (c) 2023 - 2026 Chair for Design Automation, TUM
# All rights reserved.
#
# SPDX-License-Identifier: MIT
#
# Licensed under the MIT License
from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from .graph import Graph
from .ion_types import Edge
[docs]
def create_idc_dictionary(graph: Graph) -> dict[int, Edge]:
edge_dict = {}
for edge_idx, edge_idc in enumerate(graph.edges()):
edge_dict[edge_idx] = tuple(sorted(edge_idc, key=lambda e: sum(list(e))))
return edge_dict
[docs]
def get_idx_from_idc(edge_dictionary: dict[int, Edge], idc: Edge) -> int:
node1, node2 = tuple(sorted(idc, key=lambda e: sum(list(e))))
return list(edge_dictionary.values()).index((node1, node2))
[docs]
def get_idc_from_idx(edge_dictionary: dict[int, Edge], idx: int) -> Edge:
return edge_dictionary[idx]