Skip to content

Commit 148a088

Browse files
committed
Graphviz dump for maxflow, shortestpath
1 parent d134230 commit 148a088

File tree

4 files changed

+30
-36
lines changed

4 files changed

+30
-36
lines changed

combinatorial_opt/maxflow.hpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
#include <algorithm>
44
#include <cassert>
5+
#include <fstream>
56
#include <limits>
7+
#include <string>
68
#include <vector>
79

810
// CUT begin
@@ -145,6 +147,19 @@ template <class Cap> struct mf_graph {
145147
return visited;
146148
}
147149

150+
void dump_graphviz(std::string filename = "maxflow") const {
151+
std::ofstream ss(filename + ".DOT");
152+
ss << "digraph{\n";
153+
for (int i = 0; i < _n; i++) {
154+
for (const auto &e : g[i]) {
155+
if (e.cap > 0) ss << i << "->" << e.to << "[label=" << e.cap << "];\n";
156+
}
157+
}
158+
ss << "}\n";
159+
ss.close();
160+
return;
161+
}
162+
148163
int _n;
149164
struct _edge {
150165
int to, rev;

graph/bellman_ford.hpp

Lines changed: 0 additions & 27 deletions
This file was deleted.

graph/shortest_path.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#pragma once
22
#include <cassert>
33
#include <deque>
4+
#include <fstream>
45
#include <functional>
56
#include <limits>
67
#include <queue>
8+
#include <string>
79
#include <utility>
810
#include <vector>
911

@@ -160,4 +162,15 @@ template <typename T, T INF = std::numeric_limits<T>::max() / 2, int INVALID = -
160162
}
161163
}
162164
}
165+
166+
void dump_graphviz(std::string filename = "shortest_path") const {
167+
std::ofstream ss(filename + ".DOT");
168+
ss << "digraph{\n";
169+
for (int i = 0; i < V; i++) {
170+
for (const auto &e : to[i]) ss << i << "->" << e.first << "[label=" << e.second << "];\n";
171+
}
172+
ss << "}\n";
173+
ss.close();
174+
return;
175+
}
163176
};

graph/test/bellman_ford.test.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,28 @@
1-
#include "../bellman_ford.hpp"
21
#include "../shortest_path.hpp"
32
#include <iostream>
43
#include <vector>
54
#define PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_B"
6-
7-
wedges e;
5+
using namespace std;
86

97
int main() {
108
int V, E, r;
119
cin >> V >> E >> r;
1210
ShortestPath<long long> graph(V);
13-
e.resize(V);
1411
for (int i = 0; i < E; i++) {
1512
int s, t, d;
1613
cin >> s >> t >> d;
17-
e[s].emplace_back(t, d);
1814
graph.add_edge(s, t, d);
1915
}
20-
vector<long long> ret = bellman_ford(r, e, V);
2116

2217
if (!graph.BellmanFord(r, V + 1)) {
2318
puts("NEGATIVE CYCLE");
2419
return 0;
2520
}
2621

2722
for (int i = 0; i < V; i++) {
28-
if (graph.dist[i] >= INF) {
29-
assert(ret[i] == INF);
23+
if (graph.dist[i] >= 1LL << 50) {
3024
puts("INF");
3125
} else {
32-
assert(ret[i] == graph.dist[i]);
3326
printf("%lld\n", graph.dist[i]);
3427
}
3528
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy