[Tex/LaTex] How to label TikZ-graphs on four vertices with a loop

loopstikz-pgf

I need to draw all these simple labelled graphs on four vertices. Anyway, can I do this in a quick manner with a loop? And put them in an array? I have already drawn all unlabelled simple graphs on four vertices. Therefore I am hoping that I can just run a loop that labels the edges six different ways for each graph except the complete one and the empty one. Any ideas would be very helpful.


These are the graphs that I have drawn so far. I want to make a loop that permutes the labeling of the edges.

Code

\documentclass[tikz,convert=false]{standalone}
\begin{document}
    \begin{tikzpicture}[scale=.5,auto=left,every node/.style={circle,fill=black!20}]  
      \node (n1) at (0,0) {1};
      \node (n2) at (0,2)  {2};
      \node (n3) at (2,2)  {3};
      \node (n4) at (2,0) {4};
    \foreach \from/\to in {n2/n3}
    \draw (\from) -- (\to);
    \end{tikzpicture}
\end{document}

Output

enter image description here

I want to make a loop draw the same picture relabeling the vertices, six times.

Best Answer

You can do that with two loops: one running from 1 to n-1, the other from the current value of the first to n. Here an example for six:

Code

\documentclass[tikz,convert=false]{standalone}

\begin{document}

\begin{tikzpicture}[scale=.5,auto=left,every node/.style={circle,fill=black!20}]  
        \foreach \x in {1,...,6}
        {   \node (n\x) at (\x*60:3) {\x};
        }
    \foreach \x in {1,...,5}
    {   \pgfmathtruncatemacro{\lowerbound}{\x+1}
        \foreach \y in {\lowerbound,...,6}
        {   \draw (n\x) -- (n\y);
            % for labelled edges
            %\draw (n\x) -- (n\y) node[sloped,pos=0.39,fill=white,fill opacity=0.3,above=0.1mm,rectangle, inner sep=0.1mm] {\tiny \x-\y};
        }
    }

\end{tikzpicture}

\end{document}

Output

enter image description here

Output with labels

enter image description here

Bonus homework: adapted for 36 nodes

enter image description here