Skip to content

Commit

Permalink
Chordal graph
Browse files Browse the repository at this point in the history
  • Loading branch information
Nisiyama-Suzune committed Sep 10, 2018
1 parent d73b148 commit 010edcb
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 7 deletions.
16 changes: 9 additions & 7 deletions main.fdb_latexmk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Fdb version 3
["pdflatex"] 1536545731 "main.tex" "main.pdf" "main" 1536545770
["pdflatex"] 1536620993 "main.tex" "main.pdf" "main" 1536620996
"LICENSE" 1535737342 1093 46a8cebcf97629527ceec69eb0f2c696 ""
"c:/texlive/2018/texmf-dist/fonts/enc/dvips/base/8r.enc" 1535734939 4850 80dc9bab7f31fb78a000ccfed0e27cab ""
"c:/texlive/2018/texmf-dist/fonts/map/fontname/texfonts.map" 1535735424 3332 103109f5612ad95229751940c61aada0 ""
Expand Down Expand Up @@ -152,9 +152,9 @@
"c:/texlive/2018/texmf-var/fonts/map/pdftex/updmap/pdftex.map" 1535740063 2913278 8705261e42bce24cf31f0900b633b274 ""
"c:/texlive/2018/texmf-var/web2c/pdftex/pdflatex.fmt" 1535740124 4217499 fda4c91ad5410734bea2fc174ab14733 ""
"c:/texlive/2018/texmf.cnf" 1535740047 673 4ae7b2f49cee444c5343a45b5d0f169c ""
"main.aux" 1536545734 19821 ba53718ed6c307709cc63eba6a842457 ""
"main.tex" 1536545769 10048 b42dd5236deb77e3efb75b83e29ac85a ""
"main.toc" 1536545734 10047 aa6dbac7fb77d4782005788ffc9af5d3 ""
"main.aux" 1536620996 20009 d37bb2c159c7d88fd967b872d79ef5b6 ""
"main.tex" 1536620953 10140 de6aaeb7a9c0683f81d96471bc1e24b1 ""
"main.toc" 1536620996 10114 f5180499bb2856a3413c01db969e1abb ""
"nul" 0 0 d41d8cd98f00b204e9800998ecf8427e ""
"src/appendix/table-of-formulae.tex" 1535737342 5839 7839ab32d586f68592a577f7564c9827 ""
"src/appendix/table-of-integrals.tex" 1535737342 17141 fc845aa61fe185e4ef964492355424de ""
Expand Down Expand Up @@ -198,6 +198,8 @@
"src/geometry/point/point.tex" 1535737342 95 c8a4eef7a38d65bcafea26410f073969 ""
"src/geometry/point/triangle-center.cpp" 1535737342 443 d51461b0c21aabe451fda424b467d5f7 ""
"src/geometry/point/triangle-center.tex" 1535737342 346 51278ba10ecc1d64dba95844ab375293 ""
"src/graph/characteristic/chordal-graph.cpp" 1536620000 1669 2c2c793689e8b3eecc5f8ab71fbb44a0 ""
"src/graph/characteristic/chordal-graph.tex" 1536620976 2049 8eebc70e91f960d2b971e2b58bf5e052 ""
"src/graph/characteristic/euler-characteristic.tex" 1535737342 1552 577cd4ba8f8c385297374cf5717f27cb ""
"src/graph/clique/dn-maximum-clique.cpp" 1535737342 2932 95945391e2cacf397007b6bb7d3f0ee1 ""
"src/graph/clique/dn-maximum-clique.tex" 1535737342 333 45309cbd2e03e1e503201db95acaaa34 ""
Expand Down Expand Up @@ -228,7 +230,7 @@
"src/mathematics/computation/adaptive-simpsons-method.cpp" 1535737342 632 48c5f40feaa6b2632faebdd8830dd421 ""
"src/mathematics/computation/adaptive-simpsons-method.tex" 1535737342 137 4a071e7251e1bad98c50ed98c9790552 ""
"src/mathematics/computation/dirichlet-convolution.cpp" 1536545073 884 d5b9b09399b0fa865915dfc1b3b1202a ""
"src/mathematics/computation/dirichlet-convolution.tex" 1536545724 2722 a90ffff4c236fd9e83181f2c58390138 ""
"src/mathematics/computation/dirichlet-convolution.tex" 1536570756 2722 a90ffff4c236fd9e83181f2c58390138 ""
"src/mathematics/computation/euclidean-like-algorithm.cpp" 1535737342 297 fa1cfdd72ecc357a0c009e18864e28e4 ""
"src/mathematics/computation/euclidean-like-algorithm.tex" 1535737342 123 8cd5ba01e57a452648d88655b21d3b1c ""
"src/mathematics/computation/extended-eratosthenes-sieve.cpp" 1535737342 2202 6e66fc7fd0302569dd556ab38d4b82c8 ""
Expand Down Expand Up @@ -292,7 +294,7 @@
"src/system/stack-hack.tex" 1535737342 290 0f567aa592efd9e03cff3b46d7e75f06 ""
"src/system/time-hack.tex" 1535737342 172 7d6463e09f3b066153cc15d1a3f1ca74 ""
(generated)
"main.log"
"main.aux"
"main.pdf"
"main.toc"
"main.log"
"main.aux"
5 changes: 5 additions & 0 deletions main.fls
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,11 @@ INPUT src/graph/graph.tex
INPUT src/graph/graph.cpp
INPUT src/graph/graph.cpp
INPUT src/graph/graph.cpp
INPUT src/graph/characteristic/chordal-graph.tex
INPUT src/graph/characteristic/chordal-graph.tex
INPUT src/graph/characteristic/chordal-graph.cpp
INPUT src/graph/characteristic/chordal-graph.cpp
INPUT src/graph/characteristic/chordal-graph.cpp
INPUT src/graph/characteristic/euler-characteristic.tex
INPUT src/graph/characteristic/euler-characteristic.tex
INPUT src/graph/clique/dn-maximum-clique.tex
Expand Down
Binary file modified main.pdf
Binary file not shown.
Binary file modified main.synctex.gz
Binary file not shown.
2 changes: 2 additions & 0 deletions main.tex
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@
\section{Graph}
\input{src/graph/graph.tex}
\subsection{Characteristic}
\subsubsection{Chordal graph}
\input{src/graph/characteristic/chordal-graph.tex}
\subsubsection{Euler characteristic}
\input{src/graph/characteristic/euler-characteristic.tex}
\subsection{Clique}
Expand Down
43 changes: 43 additions & 0 deletions src/graph/characteristic/chordal-graph.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
template <int MAXN = 100000, int MAXM = 100000>
struct chordal_graph {
int n; edge_list <MAXN, MAXM> e;
int id[MAXN], seq[MAXN];
void init () {
struct point {
int lab, u;
point (int lab = 0, int u = 0) : lab (lab), u (u) {}
bool operator < (const point &a) const { return lab < a.lab; } };
std::fill (id, id + n, -1);
static int label[MAXN]; std::fill (label, label + n, 0);
std::priority_queue <point> q;
for (int i = 0; i < n; ++i) q.push (point (0, i));
for (int i = n - 1; i >= 0; --i) {
for (; ~id[q.top ().u]; ) q.pop ();
int u = q.top (); q.pop (); id[u] = i;
for (int j = e.begin[u]; ~j; j = e.next[j])
if (v = e.dest[j], !~id[v]) ++label[v], q.push (point (label[v], v)); }
for (int i = 0; i < n; ++i) seq[id[i]] = i; }
bool is_chordal () {
static int vis[MAXN], q[MAXN]; std::fill (vis, vis + n, 0);
for (int i = n - 1; i >= 0; --i) {
int u = seq[i], t = 0, v;
for (int j = e.begin[u]; ~j; j = e.next[j])
if (v = e.dest[j], id[v] > id[u]) q[t++] = v;
if (!t) continue; w = q[0];
for (int j = 0; j < t; ++j) if (id[q[j]] < id[w]) w = q[j];
for (int j = e.begin[w]; ~j; j = e.next[j]) vis[e.dest[j]] = i;
for (int j = 0; j < t; ++j) if (q[j] != w && vis[q[j]] != i) return 0;
}
return 1; }
int min_color () {
int res = 0;
static int vis[MAXN], c[MAXN];
std::fill (vis, vis + n, 0);
std::fill (c, c + n, n);
for (int i = n - 1; i >= 0; --i) {
int u = seq[i];
for (int j = e.begin[u]; ~j; j = e.next[j]) vis[c[e.dest[j]]] = i;
int k; for (k = 0; vis[k] == i; ++k);
c[u] = k; res = std::max (res, k + 1);
}
return res; } };
17 changes: 17 additions & 0 deletions src/graph/characteristic/chordal-graph.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
A chordal graph is one in which all cycles of four or more vertices have a chord, which is an edge that is not part of the cycle but connects two vertices of the cycle.

A perfect elimination ordering in a graph is an ordering of the vertices of the graph such that, for each vertex $v$, $v$ and the neighbors of $v$ that occur after $v$ in the order form a clique. A graph is chordal if and only if it has a perfect elimination ordering. One application of perfect elimination orderings is finding a maximum clique of a chordal graph in polynomial-time, while the same problem for general graphs is NP-complete. More generally, a chordal graph can have only linearly many maximal cliques, while non-chordal graphs may have exponentially many. To list all maximal cliques of a chordal graph, simply find a perfect elimination ordering, form a clique for each vertex $v$ together with the neighbors of $v$ that are later than $v$ in the perfect elimination ordering, and test whether each of the resulting cliques is maximal.

The largest maximal clique is a maximum clique, and, as chordal graphs are perfect, the size of this clique equals the chromatic number of the chordal graph. Chordal graphs are perfectly orderable: an optimal coloring may be obtained by applying a greedy coloring algorithm to the vertices in the reverse of a perfect elimination ordering.

In any graph, a vertex separator is a set of vertices the removal of which leaves the remaining graph disconnected; a separator is minimal if it has no proper subset that is also a separator. Chordal graphs are graphs in which each minimal separator is a clique.

Usage:
\begin{enumerate}
\item Set \texttt{n} and \texttt{e}.
\item Call \texttt{init} to obtain the perfect elimination ordering in \texttt{seq}.
\item Use \texttt{is\_chordal} to test whether the graph is chordal.
\item Use \texttt{min\_color} to obtain the size of the maximum clique (and the chromatic number).
\end{enumerate}

\lstinputlisting{src/graph/characteristic/chordal-graph.cpp}

0 comments on commit 010edcb

Please sign in to comment.