cycle_ratio

Contents

cycle_ratio#

graph_tool.structure.cycle_ratio(g, weight, time=None, maximum=True, cycle=False)[git][source]#

Return the maximum (or minimum) ratio of the total weight to the total time of the directed cycles.

Parameters:
gGraph

Directed graph to be used.

weightEdgePropertyMap

Edge weights.

timeEdgePropertyMap (optional, default: None)

Edge times. If not given, every edge has unit time, and the cycle mean is obtained.

maximumbool (optional, default: True)

If True, the maximum ratio is returned, otherwise the minimum.

cyclebool (optional, default: False)

If True, the edge indices of an optimal cycle are also returned.

Returns:
ratiofloat

The optimal ratio, or \(\mp\infty\) if there are no cycles.

cyclenumpy.ndarray

The edge indices of an optimal cycle. Only returned if cycle == True.

See also

find_negative_cycle

Cycle of negative total weight

all_circuits

All cycles of a directed graph

Notes

The value returned is the maximum (or minimum) cycle ratio

\[\rho = \max_{C}\frac{\sum_{e\in C}w_e}{\sum_{e\in C}t_e},\]

where \(C\) runs over the directed cycles of the graph, \(w_e\) is the weight and \(t_e\) the time of edge \(e\) (\(t_e = 1\) if no times are given, so that \(\rho\) is the maximum mean weight of a cycle), which requires the total time of every cycle to be positive. It is optimized with Howard’s policy iteration algorithm [dasdan-experimental-2004], which is typically fast, although its worst-case complexity is not known to be polynomial.

References

[dasdan-experimental-2004]

Ali Dasdan, “Experimental analysis of the fastest optimum cycle ratio and mean algorithms”, ACM Transactions on Design Automation of Electronic Systems 9, 385-418 (2004), DOI: 10.1145/1027084.1027085 [sci-hub, @tor]

Examples

>>> g = gt.Graph([(0, 1), (1, 2), (2, 0), (1, 0)])
>>> w = g.new_ep("double", vals=[1, 2, 3, 5])
>>> print(gt.cycle_ratio(g, w, cycle=True))
(3.0, array([0, 3], dtype=uint64))