-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEdge.cpp
More file actions
48 lines (40 loc) · 1.01 KB
/
Copy pathEdge.cpp
File metadata and controls
48 lines (40 loc) · 1.01 KB
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
#include "Edge.h"
//edges are initialized with a flow of zero
//isResidual has default value false
Edge::Edge (size_t _node0, size_t _node1, intmax_t _cost, intmax_t _capacity, bool _isResidual) :
node0(_node0), node1(_node1), cost(_cost), capacity(_capacity), flow(0), isResidual(_isResidual) {}
//overflow (huehuehe) is handled
bool Edge::changeFlowPossible(intmax_t f) {
intmax_t temp = flow + f;
if (temp < 0 or temp > capacity) {
return false;
}
return true;
}
bool Edge::changeFlow (intmax_t f) {
if (changeFlowPossible(f)) {
flow += f;
return true;
}
return false;
}
//change to residuality
void Edge::invert () {
size_t temp = node0;
node0 = node1;
node1 = temp;
cost = -cost;
flow = capacity - flow;
isResidual = not isResidual;
}
void Edge::toggleCost() {
if (isToggled) {
cost = toggledCost;
toggledCost = 0;
}
else {
toggledCost = cost;
cost = 0;
}
isToggled = not isToggled;
}