8000 Rewrite article on Strongly Connected Components, and add graph pictures by el-sambal · Pull Request #1307 · cp-algorithms/cp-algorithms · GitHub
[go: up one dir, main page]

Skip to content

Rewrite article on Strongly Connected Components, and add graph pictures #1307

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 37 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
630fad7
rewrite definition of SCC and condensation graph
el-sambal Jul 6, 2024
9badcf5
rewrite proof that G^SCC is DAG
el-sambal Jul 6, 2024
7c38cc4
rewrite up to theorem
el-sambal Jul 6, 2024
998d66d
rewrite theorm
el-sambal Jul 6, 2024
d0397ff
define t_in
el-sambal Jul 6, 2024
925a84d
rewrite some things and fix mistake in def. SCC
el-sambal Jul 6, 2024
2653c39
rewrite 2 cases of proof
el-sambal Jul 7, 2024
8f4c9e4
rewrite up to **algorithm**
el-sambal Jul 7, 2024
9a2419e
rewrite up to runtime complexity
el-sambal Jul 7, 2024
330ffb6
rewrite all the way until Implementation section
el-sambal Jul 7, 2024
e7d3520
rename used to visited
el-sambal Jul 7, 2024
4a1226f
finish rewriting article
el-sambal Jul 7, 2024
bbb4ffb
make something not boldface
el-sambal Jul 7, 2024
cd7bd2f
remove "nonempty"
el-sambal Jul 7, 2024
028e313
subtle (but necessary) rewrite
el-sambal Jul 7, 2024
43872c5
make .tex file for graph
el-sambal Jul 7, 2024
dea2c18
trying out tikz things
el-sambal Jul 7, 2024
9884016
graph looks good
el-sambal Jul 7, 2024
ea7215f
graph looks even better
el-sambal Jul 7, 2024
b28b549
embed svg into webpage
el-sambal Jul 7, 2024
248b677
write SCC(G_example)
el-sambal Jul 7, 2024
469c6f4
include condensation graph picture
el-sambal Jul 7, 2024
b46830c
change title
el-sambal Jul 7, 2024
c144189
final commit (probably) before PR
el-sambal Jul 7, 2024
f5a4c9f
change # into ##
el-sambal Jul 7, 2024
f4b3019
(add sentence about multigraph)
el-sambal Jul 8, 2024
0e22d2b
make code more concise (and fix small mistake)
el-sambal Jul 8, 2024
57a5017
center images
el-sambal Jul 8, 2024
6a8c14f
intersect -> intersect with (adamant-pwn\'s suggestion)
el-sambal Jul 13, 2024
5ef1199
change code to use single dfs function (adamant-pwn's suggestion) and…
el-sambal Jul 15, 2024
3ac4ae6
adjust explanation to the fact that we now have only 1 dfs function
el-sambal Jul 15, 2024
f4a76d0
node -> vertex
el-sambal Jul 15, 2024
88eabab
write about multiple edges (adamant-pwn's suggestion)
el-sambal Jul 15, 2024
9c1a8d8
write about toposort in step 1 (adamant-pwn's suggestion)
el-sambal Jul 15, 2024
9054c35
some rewrites
el-sambal Jul 15, 2024
d45b892
Update README.md
adamant-pwn Jul 16, 2024
15b6f5b
Fix formatting in practice list + use const& in impl
adamant-pwn Jul 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Compiled pages are published at [https://cp-algorithms.com/](https://cp-algorith

## Changelog

- July 16, 2024: Major overhaul of the [Finding strongly connected components / Building condensation graph](https://cp-algorithms.com/graph/strongly-connected-components.html) article.
- June 26, 2023: Added automatic RSS feeds for [new articles](https://cp-algorithms.com/feed_rss_created.xml) and [updates in articles](https://cp-algorithms.com/feed_rss_updated.xml).
- December 20, 2022: The repository name and the owning organizations were renamed! Now the repo is located at [https://github.com/cp-algorithms/cp-algorithms](https://github.com/cp-algorithms/cp-algorithms). It is recommended to update the upstream link in your local repositories, if you have any.
- October 31, 2022: It is now possible to select and copy $\LaTeX$ source code of formulas within the articles.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.log
*.aux
*.pdf
138 changes: 138 additions & 0 deletions src/graph/strongly-connected-components-tikzpicture/cond_graph.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions src/graph/strongly-connected-components-tikzpicture/cond_graph.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
\documentclass[tikz]{standalone}
\usepackage{xcolor}
\usetikzlibrary{arrows,positioning,quotes,backgrounds,arrows.meta,bending,positioning,shapes,shapes.geometric}
\begin{document}
\begin{tikzpicture}
[scale=2.5,very thick,every node/.style={draw,inner sep=0.18cm,outer sep=1.5mm}, every path/.style={->}]

%\draw[help lines] (-1,-2) grid (7,2);
\node[rectangle,green,fill=green!20] (0) at (0,0) {\color{black}\textbf{\{0,7\}}};
\node[rectangle,red,fill=red!20] (1) at (1,0.5) {\color{black}\textbf{\{1,2,3,5,6\}}};
\node[rectangle,blue,fill=blue!20] (4) at (2,0) {\color{black}\textbf{\{4,9\}}};
\node[rectangle,yellow,fill=yellow!20] (8) at (1,-0.3) {\color{black}\textbf{\{8\}}};

\path (0) edge (1);
\path (0) edge (8);
\path (1) edge (4);
\path (8) edge (1);
\path (8) edge (4);

\end{tikzpicture}

\end{document}
166 changes: 166 additions & 0 deletions src/graph/strongly-connected-components-tikzpicture/graph.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 50 additions & 0 deletions src/graph/strongly-connected-components-tikzpicture/graph.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
\documentclass[tikz]{standalone}
\usepackage{xcolor}
\usetikzlibrary{arrows,positioning,quotes,backgrounds,arrows.meta,bending,positioning,shapes,shapes.geometric}
\begin{document}
\pgfdeclarelayer{background}
\pgfsetlayers{background,main}
\begin{tikzpicture}
[scale=1.3,very thick,every circle node/.style={draw,inner sep=0.18cm,outer sep=1.1mm,fill=brown!30}, every path/.style={->}]

%\draw[help lines] (-1,-2) grid (7,2);
\node[circle] (0) at (0,0) {\textbf0};
\node[circle] (1) at (1,1) {\textbf1};
\node[circle] (2) at (3,1) {\textbf2};
\node[circle] (3) at (5,1) {\textbf3};
\node[circle] (4) at (6,0) {\textbf4};
\node[circle] (5) at (4,0) {\textbf5};
\node[circle] (6) at (2,0) {\textbf6};
\node[circle] (7) at (1,-1) {\textbf7};
\node[circle] (8) at (3,-1) {\textbf8};
\node[circle] (9) at (5,-1) {\textbf9};

\path (0) edge (1);
\path (0) edge[bend left=20] (7);
\path (1) edge[loop below] (1);
\path (1) edge[bend left=20] (2);
\path (2) edge[bend left=20] (1);
\path (2) edge (5);
\path (3) edge (2);
\path (3) edge (4);
\path (4) edge[bend left=20] (9);
\path (5) edge (3);
\path (5) edge (6);
\path (5) edge (9);
\path (6) edge (2);
\path (7) edge[bend left=20] (0);
\path (7) edge (6);
\path (7) edge (8);
\path (8) edge (6);
\path (8) edge (9);
\path (9) edge[bend left=20] (4);

\begin{pgfonlayer}{background}
\draw[thick, red, fill=red!20!white] plot [smooth cycle,tension=0.65] coordinates{(0.65,1.3)(4.7,1.52)(5.4,0.7)(4.25,-.4)(3,-.33)(1.5,-.4)};
\draw[thick, green, fill=green!20!white] plot [smooth cycle,tension=0.7] coordinates{(0.2,0.4)(1.5,-0.9)(.9,-1.5)(-.45,-.1)};
\draw[thick, blue, fill=blue!20!white] plot [smooth cycle,tension=0.7] coordinates{(5.8,0.5)(4.45,-0.8)(5.1,-1.5)(6.6,-.1)};
\draw[thick, yellow, fill=yellow!20!white] plot [smooth cycle,tension=0.9] coordinates{(3,-0.5)(3.6,-1)(3,-1.5)(2.4,-1)};
\end{pgfonlayer}
\end{tikzpicture}

\end{document}
5 changes: 5 additions & 0 deletions src/graph/strongly-connected-components-tikzpicture/info.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
These are the pictures (graphs) used in the article about Strongly Connected Components and the Condensation graph.

Compile the .tex file with pdflatex, and then use a command line tool like pdf2svg to convert the compiled pdf into an svg file. We want svg because it is scalable, i.e. still looks good when the user zooms in far.

This svg can than be directly included in the markdown.
195 changes: 94 additions & 101 deletions src/graph/strongly-connected-components.md

Large diffs are not rendered by default.

50 changes: 50 additions & 0 deletions test/test_strongly_connected_components.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include <bits/stdc++.h>
using namespace std;

#include "strongly_connected_components.h"

int main() {
// we only have a single test case for now
int n = 10;
vector<vector<int>> adj(n);
adj[0].push_back(1);
adj[0].push_back(7);
adj[1].push_back(1);
adj[1].push_back(2);
adj[2].push_back(1);
adj[2].push_back(5);
adj[3].push_back(2);
adj[3].push_back(4);
adj[4].push_back(9);
adj[5].push_back(3);
adj[5].push_back(6);
adj[5].push_back(9);
adj[6].push_back(2);
adj[7].push_back(0);
adj[7].push_back(6);
adj[7].push_back(8);
adj[8].push_back(6);
adj[8].push_back(9);
adj[9].push_back(4);

vector<vector<int>> components, adj_scc;
strongy_connected_components(adj, components, adj_scc);

// sort things to make it easier to verify
sort(components.begin(), components.end(),
[](auto &l, auto &r) { return l[0] < r[0]; });
for (vector<int> a : adj_scc)
sort(a.begin(), a.end());

assert(components.size() == 4);
assert(components[0] == std::vector<int>({0, 7}));
assert(components[1] == std::vector<int>({1, 2, 3, 5, 6}));
assert(components[2] == std::vector<int>({4, 9}));
assert(components[3] == std::vector<int>({8}));

assert(adj_scc[0] == std::vector<int>({1, 1, 8}));
assert(adj_scc[1] == std::vector<int>({4, 4}));
assert(adj_scc[8] == std::vector<int>({1, 4}));

return 0;
}
Loading
0