-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
63 lines (53 loc) · 1.92 KB
/
main.cpp
File metadata and controls
63 lines (53 loc) · 1.92 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "lib/graph.h"
#include "lib/graph_reader.h"
#include "lib/point.h"
#include "lib/area.h"
void PrintVector(std::vector<int> vector)
{
for (int i = 0; i < vector.size(); i++)
{
std::cout << vector[i] << " ";
}
}
int main(int argc, char *argv[])
{
std::vector<Area> areas = GraphReader::readAreas(argv[4]);
std::vector<Field> fields = GraphReader::readFieldsPosition(argv[5]);
for (int i = 0; i < fields.size(); i++)
{
for (int j = 0; j < areas.size(); j++)
{
if (areas[j].isInTheArea(fields[i].position))
{
fields[i].productivity = areas[j].areaValue;
break;
}
}
}
Graph newGraph = Graph(GraphReader::readToMatrix(argv[1]));
newGraph.UpdateMatrix(GraphReader::addSource(newGraph.GetMatrix(), argv[2], 'p', 'b'));
int source = newGraph.GetMatrix().size() - 1;
int dest = newGraph.GetMatrix().size() - 2;
std::vector<int> p(newGraph.GetMatrix().size(), 0);
for (int i = 0; i < fields.size(); i++)
{
if (fields[i].productivity != -1)
{
p[fields[i].vectorIndex] = fields[i].productivity;
}
}
newGraph.UpdateMatrixRow(p, source);
std::vector<int> browarsOutput;
std::vector<std::vector<int>> residualGraph;
int maxFlow = newGraph.MaxFlow(source, dest, browarsOutput, residualGraph);
std::cout << "Max flow from fields to breweries: " << maxFlow << std::endl;
newGraph.UpdateMatrix(GraphReader::readToMatrix(argv[3]));
newGraph.UpdateMatrix(GraphReader::addSource(newGraph.GetMatrix(), argv[2], 'b', 't'));
newGraph.UpdateMatrixRow(browarsOutput, source);
std::cout << std::endl << "Capacity matrix:";
newGraph.PrintGraph();
std::cout << std::endl;
maxFlow = newGraph.MaxFlow(source, dest, browarsOutput, residualGraph);
std::cout << "Max flow from brewieries to taverns: " << maxFlow;
return 0;
}