-
Notifications
You must be signed in to change notification settings - Fork 0
/
FlowEdge.cpp
89 lines (73 loc) · 2.17 KB
/
FlowEdge.cpp
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
/*************************************************************************
> File Name: FlowEdge.cpp
> Author: Louis1992
> Mail: [email protected]
> Blog: http://gzc.github.io
> Created Time: Fri Nov 13 08:19:03 2015
************************************************************************/
#ifndef FLOW_EDGE_H
#define FLOW_EDGE_H
#include<iostream>
using namespace std;
class FlowEdge {
int v; // from
int w; // to
double capacity; // capacity
double flow; // flow
public:
FlowEdge() {
this->v = -1;
this->w = -1;
this->capacity = 0;
this->flow = 0.0;
}
FlowEdge(int v, int w, double capacity) {
this->v = v;
this->w = w;
this->capacity = capacity;
this->flow = 0.0;
}
FlowEdge(int v, int w, double capacity, double flow) {
this->v = v;
this->w = w;
this->capacity = capacity;
this->flow = flow;
}
FlowEdge(const FlowEdge &e) {
this->v = e.v;
this->w = e.w;
this->capacity = e.capacity;
this->flow = e.flow;
}
int from() {
return this->v;
}
int to() {
return this->w;
}
double getCapacity() {
return this->capacity;
}
double getFlow() {
return this->flow;
}
int other(int vertex) {
if (vertex == v) return this->w;
else return this->v;
}
double residualCapacityTo(int vertex) {
if (vertex == this->v) return this->flow; // backward edge
else return this->capacity - this->flow; // forward edge
}
void addResidualFlowTo(int vertex, double delta) {
if (vertex == v) this->flow -= delta; // backward edge
else this->flow += delta; // forward edge
}
friend ostream& operator << (ostream& out, FlowEdge& fe)
{
out << to_string(fe.v) << "->" << to_string(fe.w) << "\t"
<< to_string(fe.flow) << "\t" << to_string(fe.capacity) << endl;
return out;
}
};
#endif