This repository has been archived by the owner on Oct 22, 2021. It is now read-only.
/
kishimoto.jl
70 lines (61 loc) · 2.91 KB
/
kishimoto.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# Method when using Boykov-Kolmogorov as a subroutine
# Kishimoto algorithm
@traitfn function kishimoto(
flow_graph::::lg.IsDirected, # the input graph
source::Integer, # the source vertex
target::Integer, # the target vertex
capacity_matrix::AbstractMatrix, # edge flow capacities
flow_algorithm::BoykovKolmogorovAlgorithm, # keyword argument for algorithm
routes::Int # keyword argument for routes
)
# Initialisation
flow, F, labels = maximum_flow(flow_graph, source, target,
capacity_matrix, algorithm = flow_algorithm)
restriction = flow / routes
flow, F, labels = maximum_flow(flow_graph, source, target, capacity_matrix,
algorithm = flow_algorithm, restriction = restriction)
# Loop condition : approximatively not equal is enforced by floating precision
i = 1
while flow < routes * restriction && flow ≉ routes * restriction
restriction = (flow - i * restriction) / (routes - i)
i += 1
flow, F, labels = maximum_flow(flow_graph, source, target, capacity_matrix,
algorithm = flow_algorithm, restriction = restriction)
end
# End
return flow, F, labels
end
"""
kishimoto(flow_graph, source, target, capacity_matrix, flow_algorithm, routes)
Compute the maximum multiroute flow (for an integer number of `route`s)
between `source` and `target` in `flow_graph` with capacities in `capacity_matrix`
using the [Kishimoto algorithm](http://dx.doi.org/10.1109/ICCS.1992.255031).
Return the value of the multiroute flow as well as the final flow matrix,
along with a multiroute cut if Boykov-Kolmogorov is used as a subroutine.
"""
function kishimoto end
@traitfn function kishimoto(
flow_graph::::lg.IsDirected, # the input graph
source::Integer, # the source vertex
target::Integer, # the target vertex
capacity_matrix::AbstractMatrix, # edge flow capacities
flow_algorithm::AbstractFlowAlgorithm, # keyword argument for algorithm
routes::Int # keyword argument for routes
)
# Initialisation
flow, F = maximum_flow(flow_graph, source, target,
capacity_matrix, algorithm = flow_algorithm)
restriction = flow / routes
flow, F = maximum_flow(flow_graph, source, target, capacity_matrix,
algorithm = flow_algorithm, restriction = restriction)
# Loop condition : approximatively not equal is enforced by floating precision
i = 1
while flow < routes * restriction && flow ≉ routes * restriction
restriction = (flow - i * restriction) / (routes - i)
i += 1
flow, F = maximum_flow(flow_graph, source, target, capacity_matrix,
algorithm = flow_algorithm, restriction = restriction)
end
# End
return flow, F
end