Skip to content

Commit 86a3ee8

Browse files
authored
Deep refactoring (#46)
* refactoring of the lower-level library
1 parent 0dd2a25 commit 86a3ee8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+5363
-3639
lines changed

README.md

Lines changed: 150 additions & 298 deletions
Large diffs are not rendered by default.

ngraph/lib/algorithms/base.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
from __future__ import annotations
2+
3+
from enum import IntEnum
4+
from typing import Union, Tuple
5+
from ngraph.lib.graph import NodeID, EdgeID
6+
7+
#: Represents numeric cost in the network (e.g. distance, latency, etc.).
8+
Cost = Union[int, float]
9+
10+
#: A single path element is a tuple of:
11+
#: - The current node ID.
12+
#: - A tuple of one or more parallel edge IDs from this node to the next node.
13+
#: In a complete path, intermediate elements usually have a non-empty edge tuple,
14+
#: while the final element has an empty tuple to indicate termination.
15+
PathElement = Tuple[NodeID, Tuple[EdgeID]]
16+
17+
#: A path is a tuple of PathElements forming a complete route from
18+
#: a source node to a destination node.
19+
PathTuple = Tuple[PathElement, ...]
20+
21+
#: Capacity threshold below which capacity values are treated as effectively zero.
22+
MIN_CAP = 2**-12
23+
24+
#: Flow threshold below which flow values are treated as effectively zero.
25+
MIN_FLOW = 2**-12
26+
27+
28+
class PathAlg(IntEnum):
29+
"""
30+
Types of path finding algorithms
31+
"""
32+
33+
SPF = 1
34+
KSP_YENS = 2
35+
36+
37+
class EdgeSelect(IntEnum):
38+
"""
39+
Edge selection criteria determining which edges are considered
40+
for path-finding between a node and its neighbor(s).
41+
"""
42+
43+
#: Return all edges matching the minimum metric among the candidate edges.
44+
ALL_MIN_COST = 1
45+
#: Return all edges matching the minimum metric among edges with remaining capacity.
46+
ALL_MIN_COST_WITH_CAP_REMAINING = 2
47+
#: Return all edges that have remaining capacity, ignoring metric except for returning min_cost.
48+
ALL_ANY_COST_WITH_CAP_REMAINING = 3
49+
#: Return exactly one edge (the single lowest metric).
50+
SINGLE_MIN_COST = 4
51+
#: Return exactly one edge, the lowest-metric edge with remaining capacity.
52+
SINGLE_MIN_COST_WITH_CAP_REMAINING = 5
53+
#: Return exactly one edge factoring both metric and load:
54+
#: cost = (metric * 100) + round(flow / capacity * 10).
55+
SINGLE_MIN_COST_WITH_CAP_REMAINING_LOAD_FACTORED = 6
56+
#: Use a user-defined function for edge selection logic.
57+
USER_DEFINED = 99
58+
59+
60+
class FlowPlacement(IntEnum):
61+
"""Ways to distribute flow on parallel edges."""
62+
63+
PROPORTIONAL = 1 # Flow is split proportional to capacity (Dinic-like approach)
64+
EQUAL_BALANCED = 2 # Flow is equally divided among parallel edges

0 commit comments

Comments
 (0)