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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/* Implementation of network algorithms: shortests path, minimum cost flow, etc.
*/
/* Search any path from source to destination using Breadth First Search.
*
* input:
* @ctx: tal allocator,
* @graph: graph of the network,
* @source: source node,
* @destination: destination node,
* @capacity: arcs capacity
* @cap_threshold: an arc i is traversable if capacity[i]>=cap_threshold
*
* output:
* @prev: prev[i] is the arc that leads to node i for an optimal solution, it
* @return: true if the destination node was reached.
*
* precondition:
* |capacity|=graph_max_num_arcs
* |prev|=graph_max_num_nodes
*
* The destination is only used as a stopping condition, if destination is
* passed with an invalid idx then the algorithm will produce a discovery tree
* of all reacheable nodes from the source.
* */
bool ;
/* Computes the distance from the source to every other node in the network
* using Dijkstra's algorithm.
*
* input:
* @ctx: tal context for internal allocation
* @graph: topological information of the graph
* @source: source node
* @destination: destination node
* @prune: if prune is true the algorithm stops when the optimal path is found
* for the destination node
* @capacity: arcs capacity
* @cap_threshold: an arc i is traversable if capacity[i]>=cap_threshold
* @cost: arc's cost
* @potential: nodes' potential, ie. reduced cost for an arc
* c_ij = cost_ij - potential[i] + potential[j]
*
* output:
* @prev: for each node, this is the arc that was used to arrive to it, this can
* be used to reconstruct the path from the destination to the source,
* @distance: node's best distance
* returns true if an optimal path is found for the destination, false otherwise
*
* precondition:
* |capacity|=|cost|=graph_max_num_arcs
* |prev|=|distance|=graph_max_num_nodes
* cost[i]>=0
* if prune is true the destination must be valid
* */
bool ;
/* Finds any flow that satisfy the capacity constraints:
* flow[i] <= capacity[i]
* and supply/demand constraints:
* supply[source] = demand[destination] = amount
* supply/demand[node] = 0 for every other node
*
* It uses simple augmenting paths algorithm.
*
* input:
* @ctx: tal context for internal allocation
* @graph: topological information of the graph
* @source: source node
* @destination: destination node
* @capacity: arcs capacity
* @amount: supply/demand
*
* output:
* @capacity: residual capacity
* returns true if the balance constraint can be satisfied
*
* precondition:
* |capacity|=graph_max_num_arcs
* amount>=0
* */
bool ;
/* Computes the balance of a node, ie. the incoming flows minus the outgoing.
*
* @graph: topology
* @node: node
* @capacity: capacity in the residual sense, not the constrain capacity
*
* This works because in the adjacency list an arc wich is dual is associated
* with an inconming arc i, then we add this flow, while an arc which is not
* dual corresponds to and outgoing flow that we need to substract.
* The flow on the arc i (not dual) is computed as:
* flow[i] = residual_capacity[i_dual],
* while the constrain capacity is
* capacity[i] = residual_capacity[i] + residual_capacity[i_dual] */
s64 ;
/* Finds the minimum cost flow that satisfy the capacity constraints:
* flow[i] <= capacity[i]
* and supply/demand constraints:
* supply[source] = demand[destination] = amount
* supply/demand[node] = 0 for every other node
*
* It uses successive shortest path algorithm.
*
* input:
* @ctx: tal context for internal allocation
* @graph: topological information of the graph
* @source: source node
* @destination: destination node
* @capacity: arcs capacity
* @amount: desired balance at the destination
* @cost: cost per unit of flow
*
* output:
* @capacity: residual capacity
* returns true if the balance constraint can be satisfied
*
* precondition:
* |capacity|=graph_max_num_arcs
* |cost|=graph_max_num_arcs
* amount>=0
* */
bool ;
/* Compute the cost of a flow in the network.
*
* @graph: network topology
* @capacity: residual capacity (encodes the flow)
* @cost: cost per unit of flow */
s64 ;
/* Take an existent flow and find an optimal redistribution:
*
* inputs:
* @ctx: tal context for internal allocation,
* @graph: topological information of the graph,
* @excess: supply/demand of nodes,
* @capacity: residual capacity in the arcs,
* @cost: cost per unit of flow for every arc,
* @potential: node potential,
*
* outputs:
* @excess: all values become zero if there exist a feasible solution,
* @capacity: encodes the resulting flow,
* @potential: the potential that proves the solution using the complementary
* slackness optimality condition.
* */
bool ;
/* LIGHTNING_PLUGINS_ASKRENE_CHILD_ALGORITHM_H */