1

How can I create a condensation of a directed graph in Tikz?

Goal 1 The left is a directed graph, digraph, while the right is its condensation, source is page 183 of Handbook of Graph Theory. Aspiring discussion on this in chat.

enter image description here

Goal 2 The same as above but with simpler example.

enter image description here

Trial 2

enter image description here

MWE 2

\begin{tikzpicture}[x=2cm, y=2cm]
\tikzstyle{every node}=[draw, circle, fill=white, inner sep=3pt,minimum size=18pt] 
%1
\draw (0,0) node(1111){1};
\draw (1,0) node(2222){2};
%2 
\draw (3,0) node(1){1};
\draw (4,0) node(111){1};
\draw (5,0) node(2){2};
\draw (6,0) node(222){2};
\draw (7,0) node(3){3};

\draw[->](1)--(111);
\draw[<->](111)--(2);
\draw[->](2)--(222);
\draw[<->](222)--(3);

\node[left] at (0.8,-0.5) {(a)};
\node[left] at (5.2,-0.5) {(b)};
%-----------

%1
\draw (0,-1) node(1111){1};
\draw (1,-1) node(2222){2};
%2 
\draw (3,-1) node(1){1};
\draw (4,-1) node(111){1};
\draw (5,-1) node(2){2};
\draw (6,-1) node(222){2};
\draw (7,-1) node(3){3};

\draw[->](1)--(111);
\draw[<->](111)--(2);
\draw[->](2)--(222);
\draw[<->](222)--(3);

\node[left] at (0.8,-1.5) {(a)$^*$};
\node[left] at (5.2,-1.5) {(b)$^*$};
\end{tikzpicture}

Perhaps relevant thread

  1. Creating a digraph with formulas instead of nodes
hhh
  • 8,743
  • Please make your code compilable. Are you trying to draw D* or part of D? I don't really understand the question right now. – cfr May 20 '16 at 21:11
  • What are you trying to put a circle around exactly? I don't understand how the image at the top relates to the image you posted for your incomplete code. – cfr May 20 '16 at 21:17
  • @cfr I am trying to put that kind of hover circle-squares around $1<->2$ and $2<->3$. I want to stress that $S_1={1,2}$ and $S_2={2,3}$ as shown here. It is a mistake to have circles around (a) and (b). – hhh May 20 '16 at 21:20
  • Maybe you could draw what you mean in some GUI application? And please complete your code. – cfr May 20 '16 at 22:06
  • @cfr updated: more accessible with Goal 1 and Goal 2 where Goal 2 was tried to be simpler, the hover square-circle drawn here. – hhh May 20 '16 at 22:23

2 Answers2

3

I don't know why you refuse to post compilable code, but whatever.

Anyway, for something like that, I'd use fit to draw the boundaries around 2+ nodes. And I'd use a chain or the TikZ graphs stuff for the graph itself.

For example, with a simple chain (no real need for a graph here):

\documentclass[tikz,border=10pt,multi]{standalone}
\usetikzlibrary{chains, fit}
\begin{document}
\begin{tikzpicture}[start chain=main going right, every on chain/.append style={circle, draw}]
  \node [on chain] {1};
  \node [on chain, join={by ->}] {1};
  \node [on chain, join={by <->}] {2};
  \node [on chain, join={by ->}] {2};
  \node [on chain, join={by <->}] {3};
  \foreach \i/\j in {2/3,4/5}
  \node [fit=(main-\i) (main-\j), draw, rounded corners] {};
\end{tikzpicture}
\end{document}

chain + fit

Or as a graph:

\documentclass[tikz,border=10pt,multi]{standalone}
\usetikzlibrary{fit, graphs}
\begin{document}
\begin{tikzpicture}
  \graph [grow right, nodes={draw, circle}, /tikz/every label/.append style={label distance=10pt}] {
    a/"1" -> 1 <-> 2[label=below:(b)*] -> b/"2" <-> 3
  };
  \foreach \i/\j in {1/2,b/3}
  \node [fit=(\i) (\j), draw, rounded corners] {};
\end{tikzpicture}
\end{document}

graph + fit

cfr
  • 198,882
  • I like the first approach +1, no need to get LuaLatex working as in second. On the first: how can you add the two captions below two graphs with b) and b)*? Code and picture: the left is the digraph while the right is the condensed graph. – hhh May 23 '16 at 21:53
  • 1
    @hhh The second doesn't require LuaTeX either. I used pdfTeX for both. – cfr May 23 '16 at 21:56
  • For the b or b*, you can use the label=below: for one of the nodes just as in the second case. This bit is no different which is why I only demonstrated it in one of the two. – cfr May 23 '16 at 21:57
  • For the second, how can I specify the position of (b)* to be on the right of (b)? Picture. I.e. two graphs side-by-side. – hhh May 23 '16 at 22:11
  • On the second, got the captions and graphs placed to correct positions with scope: picture and originating from our discussion with Alan. Thank you for helping! – hhh May 23 '16 at 23:10
  • Was about to look at this @hhh. Glad you sorted it! – cfr May 23 '16 at 23:18
2

The rework of cfr's graphs solution with scope to place the two graphs side-by-side, originating from our discussion with Alan.

enter image description here

\begin{tikzpicture}
\graph [grow right, nodes={draw, circle}, /tikz/every label/.append style={label distance=5pt}] {
a/"1" -> 1[label=above:$S_1$] <-> 2[label=below:(b) $x_1+x_1x_2+x_2x_3$] -> b/"2"[label=above:$S_2$] <-> 3
};
\foreach \i/\j in {1/2,b/3}
\node [fit=(\i) (\j), draw, rounded corners] {};

\begin{scope}[xshift=.5\linewidth]
\graph [grow right, nodes={draw, circle}, /tikz/every label/.append style={label distance=5pt}] {
1 -> b/$S_1$[label=below:(b)* ] -> c/$S_2$
};
\end{scope}
\end{tikzpicture}

P.s. \usetikzlibrary{fit, graphs} needed to be in your preamble, see the solution by cfr.

hhh
  • 8,743