-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflow.html
95 lines (88 loc) · 2.56 KB
/
flow.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Max flow - Minnebar graph algorithms</title>
<script src="src/Graph.js"></script>
<script src="src/Node.js"></script>
<script src="src/Edge.js"></script>
<script src="src/GraphBuilder.js"></script>
<script src="src/EdmondsKarp.js"></script>
<script src="src/GraphRenderer.js"></script>
<style>
.node {
fill: lightskyblue;
stroke-width: 2px;
stroke: darkblue;
}
.line {
stroke: darkblue;
stroke-width: 4px;
}
.u {
fill: forestgreen;
}
.v {
fill: orange;
}
.nodeDist {
fill: darkmagenta;
}
.distConsider {
font-weight: bold;
}
.visited {
fill: dimgray;
}
.path {
stroke-width: 6px;
stroke: orangered;
}
.filled {
stroke-width: 1px;
stroke: #333;
}
</style>
</head>
<body>
<div id="consoleOutput" style="float: right; width: 300px; font-family: monospace;"></div>
<div id="graphViz">
<svg height="500" width="1000" id="graphSvg"><g id="graphSvgG"></g></svg>
</div>
<button id="nextStep">Next step</button>
<script>
const graph = (new GraphBuilder()).buildFlowGraph();
const edmondsKarp = new EdmondsKarp(graph);
const minneapolis = graph.getNodes().get('Minneapolis');
const chicago = graph.getNodes().get('Chicago');
/*
edmondsKarp.run(minneapolis, chicago);
console.log(edmondsKarp.summarizeResults());
*/
const graphRenderer = new GraphRenderer(graph);
const width = window.innerWidth - 100;
const height = window.innerHeight - 100;
const svg = document.getElementById('graphSvg');
svg.setAttribute('width', String(width));
svg.setAttribute('height', String(height));
graphRenderer.render(graph, {
'Minneapolis': [0.1 * width, 0.1 * height],
'Rochester': [0.2 * width, 0.5 * height],
'Madison': [0.5 * width, 0.6 * height],
'Des Moines': [0.1 * width, 0.9 * height],
'Chicago': [0.8 * width, 0.9 * height],
'Milwaukee': [0.8 * width, 0.6 * height],
});
document.getElementById('nextStep').onclick = function() {
if (!graphRenderer.runNextStep) {
return;
}
graphRenderer.runNextStep();
}
async function run() {
await edmondsKarp.runVisualize(minneapolis, chicago, graphRenderer);
}
run();
</script>
</body>
</html>