-
Notifications
You must be signed in to change notification settings - Fork 2
/
l_flowedge.h
42 lines (36 loc) · 915 Bytes
/
l_flowedge.h
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
#ifndef _L_FLOWEDGE_H
#define _L_FLOWEDGE_H
#include "l.h"
class FlowEdge {
int v;
int w;
double flow;
double capacity;
public:
FlowEdge(int v, int w, double c) : v(v), w(w), capacity(c), flow(0.0){}
int from() { return v; }
int to() { return w; }
int other(int i) {
if (i == v) return w;
else return v;
}
double residualCapacityTo(int i) {
// from
if (i == v) return flow;
// to
else if (i == w) return capacity - flow;
else throw(runtime_error("wrong vertice"));
}
void addResidualFlowTo(int i, double delta) {
// from
if (i == v) flow -= delta;
// to
else if (i == w) flow += delta;
else throw(runtime_error("wrong vertice"));
}
friend ostream& operator<<(ostream& out, FlowEdge &e) {
out << e.v << "->" << e.w << " " << fixed << setprecision(2) << e.capacity << " " << e.flow;
return out;
}
};
#endif // !_L_FLOWEDGE_H