pyroutelib3.nx¶
Adaptors¶
- class pyroutelib3.nx.GraphAdaptor(g: GraphLike, edge_cost_getter: Callable[[Mapping[str, Any]], float] = operator.itemgetter('weight'), node_position_getter: Callable[[Mapping[str, Any]], Tuple[float, float]] = operator.itemgetter('lat', 'lon'))¶
Bases:
GraphLike[NodeAdaptor]GraphAdaptor adapts a networkx graph into the
pyroutelib3.GraphLikeprotocol, with plain nodes without external ids.- get_edges(id: int) Iterable[Tuple[int, float]]¶
get_edges must return all edges outgoing from a node with the provided ID. The edges are a pair of (node_id, cost). All returned neighbor nodes must exist in the graph.
If there are no outgoing edges from the provided node, must return an empty iterable. If a node with the given ID, may return an empty iterable, or raise KeyError.
- get_node(id: int) NodeAdaptor¶
get_node must return a
NodeLikeof a node by the provided ID. If such a node doesn’t exist, must raise KeyError.
- edge_cost_getter: Callable[[Mapping[str, Any]], float] = operator.itemgetter('weight')¶
node_position_getter is used to extract the cost/weight of an edge from its networkx data dictionary. Defaults to returning
data["weight"].Usage of operator.itemgetter is highly recommended.
- node_position_getter: Callable[[Mapping[str, Any]], Tuple[float, float]] = operator.itemgetter('lat', 'lon')¶
node_position_getter is used to extract the
Positionof a node from its networkx data dictionary. Defaults to returning(data["lat"], data["lon"]).Usage of operator.itemgetter is highly recommended.
- class pyroutelib3.nx.ExternalGraphAdaptor(g: GraphLike, edge_cost_getter: Callable[[Mapping[str, Any]], float] = operator.itemgetter('weight'), node_position_getter: Callable[[Mapping[str, Any]], Tuple[float, float]] = operator.itemgetter('lat', 'lon'), node_external_id_getter: Callable[[Mapping[str, Any]], int] = operator.itemgetter('external_id'))¶
Bases:
GraphAdaptor,GraphLike[ExternalNodeAdaptor]ExternalGraphAdaptor adapts a networkx graph into the
pyroutelib3.GraphLikeprotocol, with nodes containing external IDs.- get_node(id: int) ExternalNodeAdaptor¶
get_node must return a
NodeLikeof a node by the provided ID. If such a node doesn’t exist, must raise KeyError.
- node_external_id_getter: Callable[[Mapping[str, Any]], int] = operator.itemgetter('external_id')¶
node_external_id_getter is used to extract the external ID of a node from its networkx data dictionary. Defaults to returning
data["external_id"].Usage of operator.itemgetter is highly recommended.
- class pyroutelib3.nx.NodeAdaptor(id: int, data: Mapping[str, Any], position_getter: Callable[[Mapping[str, Any]], Tuple[float, float]] = operator.itemgetter('lat', 'lon'))¶
Bases:
objectNodeAdaptor adapts a networkx node into the
pyroutelib3.NodeLikeprotocol.- data: Mapping[str, Any]¶
- id: int¶
- property position: Tuple[float, float]¶
- position_getter: Callable[[Mapping[str, Any]], Tuple[float, float]] = operator.itemgetter('lat', 'lon')¶
position_getter is used to extract the
Positionof a node from its networkx data dictionary. Defaults to returning(data["lat"], data["lon"]).Usage of operator.itemgetter is highly recommended.
- class pyroutelib3.nx.ExternalNodeAdaptor(id: int, data: Mapping[str, Any], position_getter: Callable[[Mapping[str, Any]], Tuple[float, float]] = operator.itemgetter('lat', 'lon'), external_id_getter: Callable[[Mapping[str, Any]], int] = operator.itemgetter('external_id'))¶
Bases:
NodeAdaptorNodeAdaptor adapts a networkx node into the
pyroutelib3.ExternalNodeLikeprotocol.- property external_id: int¶
- external_id_getter: Callable[[Mapping[str, Any]], int] = operator.itemgetter('external_id')¶
external_id_getter is used to extract the external ID of a node from its networkx data dictionary. Defaults to returning
data["external_id"].Usage of operator.itemgetter is highly recommended.
Protocols¶
- class pyroutelib3.nx.GraphLike(*args, **kwargs)¶
Bases:
ProtocolGraphLike describes the minimal set of features required from a nx.Graph to adapt it into the
pyroutelib3.GraphLikeprotocol.- property adj: AdjacencyViewLike¶
- property nodes: NodeViewLike¶
- class pyroutelib3.nx.AdjacencyViewLike(*args, **kwargs)¶
Bases:
ProtocolAdjacencyViewLike describes the minimal set of features required from nx.Graph.adj to adapt the edges of a networkx graph.
- get(_AdjacencyViewLike__o: int) AtlasViewLike | None¶
- class pyroutelib3.nx.AtlasViewLike(*args, **kwargs)¶
Bases:
ProtocolAtlasViewLike describes the minimal set of features required from the return value of calling
geton nx.Graph.adj to adapt the edges of a networkx graph.- items() Iterable[Tuple[int, Mapping[str, Any]]]¶
- class pyroutelib3.nx.NodeViewLike(*args, **kwargs)¶
Bases:
ProtocolNodeViewLike describes the minimal set of features required from nx.Graph.nodes to adapt the nodes of a networkx graph.
- pyroutelib3.nx.Data¶
Data represents arbitrary networkx data held in a dictionary.
alias of
Mapping[str,Any]