Debian Codegraph @

texmf-dist/doc/latex/adigraph/adigraph_documentation.tex

raw
1 \documentclass{report}
2
3 \title{Adigraph, \AdigraphVersionNumber}
4 \author{Luca Cappelletti}
5 \date{March 2024}
6
7 \usepackage{adigraph}
8 \usepackage{xcolor}
9 \usepackage[colorlinks=true,urlcolor=blue,pdfpagelabels,hyperindex=false]{hyperref}
10 \usepackage{minted}
11 \usepackage{graphicx} % for images and generally graphics
12 \usepackage{caption} % enabling of nice captions
13 \usepackage{subcaption} % and subcaptions of images
14 \usepackage{multicol}
15 \definecolor{mintedbackground}{rgb}{0.95,0.95,0.95}
16 \setminted{
17 bgcolor=mintedbackground,
18 fontfamily=tt,
19 linenos=true,
20 numberblanklines=true,
21 numbersep=5pt,
22 gobble=0,
23 frame=leftline,
24 framerule=0.4pt,
25 framesep=2mm,
26 funcnamehighlighting=true,
27 tabsize=4,
28 obeytabs=false,
29 mathescape=false
30 samepage=false, %with this setting you can force the list to appear on the same page
31 showspaces=false,
32 showtabs =false,
33 texcl=false,
34 }
35
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37 % THE FOLLOWING CENTERS ALL FLOATING ITEMS BY DEFAULT %
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39
40
41 \makeatletter
42 \providecommand*\setfloatlocations[2]{\@namedef{fps@#1}{#2}}
43 \makeatother
44 \setfloatlocations{figure}{H}
45 \setfloatlocations{table}{H}
46
47 \begin{document}
48
49 \maketitle
50
51 {\hypersetup{hidelinks}
52 \tableofcontents % Generates the table of contents
53 }
54
55 \chapter{Introduction}
56 \section{What is Adigraph?}
57 \textbf{\href{https://ctan.org/pkg/adigraph}{Adigraph}} is a latex library for drawing directed graphs and augmenting directed graphs, and to draw cuts over them.
58
59 It handles automatically the positioning of labels, with the exception of the horizontal position, and the inclinations of cuts.
60
61 The latest version is available on \href{https://github.com/LucaCappelletti94/adigraph}{Github}.
62
63 \section{License}
64 Copyright 2018 Luca Cappelletti
65
66 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sub-license, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
67
68 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
69
70 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\\
71
72 \chapter{Setup}
73 \section{Installing the dependencies}
74 Clearly you need to have texlive installed. Then, make sure you have the following packages:
75
76 \begin{description}
77 \item[\href{https://ctan.org/pkg/fp}{fp}] Used for floating point calculations.
78 \item[\href{https://ctan.org/pkg/xparse}{xparse}] Used for elaborating parameters.
79 \item[\href{https://ctan.org/pkg/xstring}{xstring}] Used for elaborating strings.
80 \item[\href{https://ctan.org/pkg/etoolbox}{etoolbox}] Used for operations on lists.
81 \item[tikz] Used for drawing the actual graphs.
82 \item[tikz calc library] Used for some internal calculations in tikz.
83 \end{description}
84
85 To be sure you can run the following, that will install the packages only if they are not already present:
86
87 \begin{minted}{sh}
88 sudo tlmgr install etoolbox fp xstring
89 \end{minted}
90
91 \section{Installing Adigraph}
92 You can install Adigraph, if it isn't already present in your setup, by running the following on Unix systems:
93
94 \begin{minted}{sh}
95 sudo tlmgr install adigraph
96 \end{minted}
97
98 On windows you should check on your package manager of choice (some latex distribution have a tlmgr implementation on windows too.)
99
100 \chapter{Usage}
101 \section{Creating a new graph}
102 Here we create a new Adigraph object, called \textit{myAdigraph}.
103
104 \begin{minted}{latex}
105 \NewAdigraph{myAdigraph}{
106 <nodes here, separated by semicolon>
107 }{
108 <edges here, separated by semicolon>
109 }{
110 <cuts here, separated by semicolon>
111 }[
112 <edge style here>
113 ]
114 \end{minted}
115
116 \section{Changing an existing graph}
117 You can renovate an older graph by calling \textbackslash RenewAdigraph
118
119 \begin{minted}{latex}
120 \RenewAdigraph{myAdigraph}{
121 <nodes here, separated by semicolon>
122 }{
123 <edges here, separated by semicolon>
124 }{
125 <cuts here, separated by semicolon>
126 }[
127 <edge style here>
128 ]
129 \end{minted}
130
131 \section{Adding nodes}
132 We set its nodes with the following syntax: \textit{<node name[, textual color, border width]: \(x\) coordinate[, \(y\) coordinate][: label]>}.
133
134 \begin{figure}
135 \begin{subfigure}{0.49\textwidth}
136 \begin{minted}{latex}
137 \NewAdigraph{myAdigraph}{
138 s:0,0;
139 t:4,0;
140 }
141 \myAdigraph{}
142 \end{minted}
143 \end{subfigure}
144 \begin{subfigure}{0.49\textwidth}
145 \NewAdigraph{myAdigraph}{
146 s:0,0;
147 t:4,0;
148 }
149 \myAdigraph{}
150 \end{subfigure}
151 \end{figure}
152
153 \subsection{Custom node colors}
154 To color a node you can use the following syntax: \textit{<node name[, textual color]: \(x\) coordinate[, \(y\) coordinate]>}. For example, to draw s in red and t in blue we would write:
155
156 \begin{figure}
157 \begin{subfigure}{0.49\textwidth}
158 \begin{minted}{latex}
159 \NewAdigraph{myAdigraph}{
160 s,red:0,0;
161 t,blue:4,0;
162 }
163 \myAdigraph{}
164 \end{minted}
165 \end{subfigure}
166 \begin{subfigure}{0.49\textwidth}
167 \NewAdigraph{myAdigraph}{
168 s,red:0,0;
169 t,blue:4,0;
170 }
171 \myAdigraph{}
172 \end{subfigure}
173 \end{figure}
174
175 Tested available colors are: red, blue, black, green. You may extend the possible colors with LaTex libraries such as xcolor.
176
177 \subsection{Custom node width}
178 To color a node you can use the following syntax: \textit{<node name[, textual color[, border width]]: \(x\) coordinate[, \(y\) coordinate]>}. For example:
179
180 \begin{figure}
181 \begin{subfigure}{0.49\textwidth}
182 \begin{minted}{latex}
183 \NewAdigraph{myAdigraph}{
184 s,red,5:0,0;
185 t,blue,3:4,0;
186 }
187 \myAdigraph{}
188 \end{minted}
189 \end{subfigure}
190 \begin{subfigure}{0.49\textwidth}
191 \NewAdigraph{myAdigraph}{
192 s,red,5:0,0;
193 t,blue,3:4,0;
194 }
195 \myAdigraph{}
196 \end{subfigure}
197 \end{figure}
198
199 \subsection{Custom node labels}
200 To add a custom label you can use the following syntax: either \textit{<node name: \(x\) coordinate[, \(y\) coordinate][: node label]>} or \textit{<node name[, textual color]: \(x\) coordinate[, \(y\) coordinate][: node label]>} will work:
201
202 \begin{figure}
203 \begin{subfigure}{0.49\textwidth}
204 \begin{minted}{latex}
205 \NewAdigraph{myAdigraph}{
206 s,red:0,0:start;
207 t:4,0:end;
208 }
209 \myAdigraph{}
210 \end{minted}
211 \end{subfigure}
212 \begin{subfigure}{0.49\textwidth}
213 \NewAdigraph{myAdigraph}{
214 s,red:0,0:start;
215 t:4,0:end;
216 }
217 \myAdigraph{}
218 \end{subfigure}
219 \end{figure}
220
221 \section{Automatically position nodes}
222 When no coordinates are given or you just don't have time to think about where to put those nodes, just choose a radius and Adigraph will position them on the circle of that radius.
223
224 \begin{figure}
225 \begin{subfigure}{0.49\textwidth}
226 \begin{minted}{latex}
227 \NewAdigraph{myAdigraph}{
228 1:0,0;
229 2:2;
230 3:2;
231 4:2;
232 5:2;
233 6:2;
234 7:2;
235 8:2;
236 }
237 \myAdigraph{}
238 \end{minted}
239 \end{subfigure}
240 \begin{subfigure}{0.49\textwidth}
241 \NewAdigraph{myAdigraph}{
242 1:0,0;
243 2:2;
244 3:2;
245 4:2;
246 5:2;
247 6:2;
248 7:2;
249 8:2;
250 }
251 \myAdigraph{}
252 \end{subfigure}
253 \end{figure}
254
255 \subsection{Colored automatically positioned nodes}
256
257 \begin{figure}
258 \begin{subfigure}{0.49\textwidth}
259 \begin{minted}{latex}
260 \NewAdigraph{myAdigraph}{
261 1:0,0;
262 2,purple:2;
263 3,brown:2;
264 4,gray:2;
265 5,blue:2;
266 6,red:2;
267 7,green:2;
268 8,pink:2;
269 }
270 \myAdigraph{}
271 \end{minted}
272 \end{subfigure}
273 \begin{subfigure}{0.49\textwidth}
274 \NewAdigraph{myAdigraph}{
275 1:0,0;
276 2,purple:2;
277 3,brown:2;
278 4,gray:2;
279 5,blue:2;
280 6,red:2;
281 7,green:2;
282 8,pink:2;
283 }
284 \myAdigraph{}
285 \end{subfigure}
286 \end{figure}
287
288
289 \section{Adding edges}
290 We set its edges with the following syntax: \textit{<first node, second node,[color,[edge width]][:weight[:label:[label position]]]>}.
291
292 \subsection{A simple edge}
293 \begin{figure}
294 \begin{subfigure}{0.49\textwidth}
295 \begin{minted}{latex}
296 \NewAdigraph{myAdigraph}{
297 s:0,0;
298 t:4,0;
299 }{
300 s,t;
301 }
302 \myAdigraph{}
303 \end{minted}
304 \end{subfigure}
305 \begin{subfigure}{0.49\textwidth}
306 \NewAdigraph{myAdigraph}{
307 s:0,0;
308 t:4,0;
309 }{
310 s,t;
311 }
312 \myAdigraph{}
313 \end{subfigure}
314 \end{figure}
315
316 \subsection{A looped edge}
317 Looped edges position automatically by themselves to minimize overlapping.
318 \begin{figure}
319 \begin{subfigure}{0.49\textwidth}
320 \begin{minted}{latex}
321 \NewAdigraph{myAdigraph}{
322 s:0,0;
323 t:4,0;
324 }{
325 s,s;
326 t,t;
327 s,t;
328 }
329 \myAdigraph{}
330 \end{minted}
331 \end{subfigure}
332 \begin{subfigure}{0.49\textwidth}
333 \NewAdigraph{myAdigraph}{
334 s:0,0;
335 t:4,0;
336 }{
337 s,s;
338 t,t;
339 s,t;
340 }
341 \myAdigraph{}
342 \end{subfigure}
343 \end{figure}
344
345 \subsection{A colored simple edge}
346 \begin{figure}
347 \begin{subfigure}{0.49\textwidth}
348 \begin{minted}{latex}
349 \NewAdigraph{myAdigraph}{
350 s:0,0;
351 t:4,0;
352 }{
353 s,t,red;
354 }
355 \myAdigraph{}
356 \end{minted}
357 \end{subfigure}
358 \begin{subfigure}{0.49\textwidth}
359 \NewAdigraph{myAdigraph}{
360 s:0,0;
361 t:4,0;
362 }{
363 s,t,red;
364 }
365 \myAdigraph{}
366 \end{subfigure}
367 \end{figure}
368
369 \subsection{A wider simple edge}
370 \begin{figure}
371 \begin{subfigure}{0.49\textwidth}
372 \begin{minted}{latex}
373 \NewAdigraph{myAdigraph}{
374 s:0,0;
375 t:4,0;
376 }{
377 s,t,red,5;
378 }
379 \myAdigraph{}
380 \end{minted}
381 \end{subfigure}
382 \begin{subfigure}{0.49\textwidth}
383 \NewAdigraph{myAdigraph}{
384 s:0,0;
385 t:4,0;
386 }{
387 s,t,red,5;
388 }
389 \myAdigraph{}
390 \end{subfigure}
391 \end{figure}
392
393 \subsection{A weighted edge}
394 \begin{figure}
395 \begin{subfigure}{0.49\textwidth}
396 \begin{minted}{latex}
397 \NewAdigraph{myAdigraph}{
398 s:0,0;
399 t:4,0;
400 }{
401 s,t:56;
402 }
403 \myAdigraph{}
404 \end{minted}
405 \end{subfigure}
406 \begin{subfigure}{0.49\textwidth}
407 \NewAdigraph{myAdigraph}{
408 s:0,0;
409 t:4,0;
410 }{
411 s,t:56;
412 }
413 \myAdigraph{}
414 \end{subfigure}
415 \end{figure}
416
417 \subsection{A weighted edge with label}
418 \begin{figure}
419 \begin{subfigure}{0.49\textwidth}
420 \begin{minted}{latex}
421 \NewAdigraph{myAdigraph}{
422 s:0,0;
423 t:4,0;
424 }{
425 s,t:56:myLabel;
426 }
427 \myAdigraph{}
428 \end{minted}
429 \end{subfigure}
430 \begin{subfigure}{0.49\textwidth}
431 \NewAdigraph{myAdigraph}{
432 s:0,0;
433 t:4,0;
434 }{
435 s,t:56:myLabel;
436 }
437 \myAdigraph{}
438 \end{subfigure}
439 \end{figure}
440
441 \subsection{Edge in both directions}
442 \begin{figure}
443 \begin{subfigure}{0.49\textwidth}
444 \begin{minted}{latex}
445 \NewAdigraph{myAdigraph}{
446 s:0,0;
447 t:4,0;
448 }{
449 s,t;
450 t,s;
451 }
452 \myAdigraph{}
453 \end{minted}
454 \end{subfigure}
455 \begin{subfigure}{0.49\textwidth}
456 \NewAdigraph{myAdigraph}{
457 s:0,0;
458 t:4,0;
459 }{
460 s,t;
461 t,s;
462 }
463 \myAdigraph{}
464 \end{subfigure}
465 \end{figure}
466
467 \subsection{Edge with weights in both directions}
468 \begin{figure}
469 \begin{subfigure}{0.49\textwidth}
470 \begin{minted}{latex}
471 \NewAdigraph{myAdigraph}{
472 s:0,0;
473 t:4,0;
474 }{
475 s,t:5;
476 t,s:5;
477 }
478 \myAdigraph{}
479 \end{minted}
480 \end{subfigure}
481 \begin{subfigure}{0.49\textwidth}
482 \NewAdigraph{myAdigraph}{
483 s:0,0;
484 t:4,0;
485 }{
486 s,t:5;
487 t,s:5;
488 }
489 \myAdigraph{}
490 \end{subfigure}
491 \end{figure}
492
493 \subsection{Positioning labels}
494 \begin{figure}
495 \begin{subfigure}{0.49\textwidth}
496 \begin{minted}{latex}
497 \NewAdigraph{myAdigraph}{
498 1:0,0;
499 2:0,2;
500 3:4,2;
501 4:4,0;
502 }{
503 1,3,red:1:a:near start;
504 2,4,blue:1:b:near end;
505 }
506 \myAdigraph{}
507 \end{minted}
508 \end{subfigure}
509 \begin{subfigure}{0.49\textwidth}
510 \NewAdigraph{myAdigraph}{
511 1:0,0;
512 2:0,2;
513 3:4,2;
514 4:4,0;
515 }{
516 1,3,red:1:a:near start;
517 2,4,blue:1:b:near end;
518 }
519 \myAdigraph{}
520 \end{subfigure}
521 \end{figure}
522
523 \subsection{Positioning weights}
524 \begin{figure}
525 \begin{subfigure}{0.49\textwidth}
526 \begin{minted}{latex}
527 \NewAdigraph{myAdigraph}{
528 1:0,0;
529 2:0,2;
530 3:4,2;
531 4:4,0;
532 }{
533 1,3,red:1::near start;
534 2,4,blue:1::near end;
535 }
536 \myAdigraph{}
537 \end{minted}
538 \end{subfigure}
539 \begin{subfigure}{0.49\textwidth}
540 \NewAdigraph{myAdigraph}{
541 1:0,0;
542 2:0,2;
543 3:4,2;
544 4:4,0;
545 }{
546 1,3,red:1::near start;
547 2,4,blue:1::near end;
548 }
549 \myAdigraph{}
550 \end{subfigure}
551 \end{figure}
552
553
554 \subsection{Multiple edges with weights}
555 \begin{figure}
556 \begin{subfigure}{0.49\textwidth}
557 \begin{minted}{latex}
558 \NewAdigraph{myAdigraph}{
559 s:0,0;
560 t:4,0;
561 1:0,3;
562 2:4,3;
563 }{
564 s,t:5;
565 t,s:5;
566 s,1:5;
567 1,s:5;
568 1,2:5;
569 2,1:5;
570 2,t:5;
571 t,2:5;
572 t,1:5;
573 1,t:5;
574 }
575 \myAdigraph{}
576 \end{minted}
577 \end{subfigure}
578 \begin{subfigure}{0.49\textwidth}
579 \NewAdigraph{myAdigraph}{
580 s:0,0;
581 t:4,0;
582 1:0,3;
583 2:4,3;
584 }{
585 s,t:5;
586 t,s:5;
587 s,1:5;
588 1,s:5;
589 1,2:5;
590 2,1:5;
591 2,t:5;
592 t,2:5;
593 t,1:5;
594 1,t:5;
595 }
596 \myAdigraph{}
597 \end{subfigure}
598 \end{figure}
599
600 \section{Kleene star operators}
601 \subsection{Kleene star on an element}
602 This works only when you don't have a node called \textit{<*>}. When this happens, the behaviour of a tuple \textit{<a,*>} becomes the normal one.
603 \begin{figure}
604 \begin{subfigure}{0.49\textwidth}
605 \begin{minted}{latex}
606 \NewAdigraph{myAdigraph}{
607 1:3;
608 2:3;
609 3:3;
610 4:3;
611 5:3;
612 6:3;
613 7:3;
614 8:3;
615 }{
616 1,*,blue;
617 *,4,red;
618 }
619 \myAdigraph{}
620 \end{minted}
621 \end{subfigure}
622 \begin{subfigure}{0.49\textwidth}
623 \NewAdigraph{myAdigraph}{
624 1:3;
625 2:3;
626 3:3;
627 4:3;
628 5:3;
629 6:3;
630 7:3;
631 8:3;
632 }{
633 1,*,blue;
634 *,4,red;
635 }
636 \myAdigraph{}
637 \end{subfigure}
638 \end{figure}
639
640 \subsection{Kleene star minus the element}
641 This works only when you don't have a node called \textit{<+>}. When this happens, the behaviour of a tuple \textit{<a,+>} becomes the normal one.
642 \begin{figure}
643 \begin{subfigure}{0.49\textwidth}
644 \begin{minted}{latex}
645 \NewAdigraph{myAdigraph}{
646 1:3;
647 2:3;
648 3:3;
649 4:3;
650 5:3;
651 6:3;
652 7:3;
653 8:3;
654 }{
655 1,+,blue;
656 +,4;
657 }
658 \myAdigraph{}
659 \end{minted}
660 \end{subfigure}
661 \begin{subfigure}{0.49\textwidth}
662 \NewAdigraph{myAdigraph}{
663 1:3;
664 2:3;
665 3:3;
666 4:3;
667 5:3;
668 6:3;
669 7:3;
670 8:3;
671 }{
672 1,+,blue;
673 +,4;
674 }
675 \myAdigraph{}
676 \end{subfigure}
677 \end{figure}
678
679
680 \subsection{Combining Kleene operations}
681 Sadly, operations such as \textit{<*,+>} or \textit{<+,+>} are not currently supported and not for lack of trying. I'll try implementing them again in the future when I'll have more time.
682
683 \section{Paths}
684 A path is specified by the following syntax: \textit{<comma separated list of nodes>}.
685
686 \NewAdigraph{myPathsTestAdigraph}{
687 s:0,0;
688 1:2,2;
689 3:2,-2;
690 2:6,2;
691 4:6,-2;
692 t:8,0;
693 }{
694 s,1:25;
695 s,3:25;
696 3,4:25;
697 1,2:35;
698 2,t:20;
699 4,t:30;
700 3,1:10;
701 4,2:10;
702 2,3:15::near start;
703 4,1:5::near start;
704 }
705
706 \begin{figure}
707 \begin{subfigure}{0.49\textwidth}
708 \begin{minted}{latex}
709 \NewAdigraph{myAdigraph}{
710 s:0,0;
711 1:2,2;
712 3:2,-2;
713 2:6,2;
714 4:6,-2;
715 t:8,0;
716 }{
717 s,1:25;
718 s,3:25;
719 3,4:25;
720 1,2:35;
721 2,t:20;
722 4,t:30;
723 3,1:10;
724 4,2:10;
725 2,3:15::near start;
726 4,1:5::near start;
727 }
728 \myAdigraph{
729 s,3,4,2,t;
730 }
731 \end{minted}
732 \end{subfigure}
733 \begin{subfigure}{0.49\textwidth}
734 \myPathsTestAdigraph{
735 s,3,4,2,t;
736 }
737 \end{subfigure}
738 \end{figure}
739
740 \subsection{Augmenting paths}
741 An augmenting path is specified by the following syntax: \textit{<comma separated list of nodes:units>}. It is \textbf{very important} to note that incremental paths called upon the same object are memorized by default.
742
743 \NewAdigraph{myAdigraph}{
744 s:0,0;
745 1:2,2;
746 3:2,-2;
747 2:6,2;
748 4:6,-2;
749 t:8,0;
750 }{
751 s,1:25;
752 s,3:25;
753 3,4:25;
754 1,2:35;
755 2,t:20;
756 4,t:30;
757 3,1:10;
758 4,2:10;
759 2,3:15::near start;
760 4,1:5::near start;
761 }
762
763 \begin{figure}
764 \begin{subfigure}{0.49\textwidth}
765 \begin{minted}{latex}
766 \NewAdigraph{myAdigraph}{
767 s:0,0;
768 1:2,2;
769 3:2,-2;
770 2:6,2;
771 4:6,-2;
772 t:8,0;
773 }{
774 s,1:25;
775 s,3:25;
776 3,4:25;
777 1,2:35;
778 2,t:20;
779 4,t:30;
780 3,1:10;
781 4,2:10;
782 2,3:15::near start;
783 4,1:5::near start;
784 }
785 \myAdigraph{
786 s,3,4,2,t:5;
787 }
788 \end{minted}
789 \end{subfigure}
790 \begin{subfigure}{0.49\textwidth}
791 \myAdigraph{
792 s,3,4,2,t:5;
793 }
794 \end{subfigure}
795 \end{figure}
796
797 For example, suppose now we'd like to send another 5 units on the graph edited by the previous incremental path, we'll have just to write the following:
798
799 \begin{figure}
800 \begin{subfigure}{0.49\textwidth}
801 \begin{minted}{latex}
802 \myAdigraph{
803 s,3,4,1,2,t:5;
804 }
805 \end{minted}
806 \end{subfigure}
807 \begin{subfigure}{0.49\textwidth}
808 \myAdigraph{
809 s,3,4,1,2,t:5;
810 }
811 \end{subfigure}
812 \end{figure}
813
814 \begin{figure}
815 \begin{subfigure}{0.49\textwidth}
816 \begin{minted}{latex}
817 \myAdigraph{
818 s,3,4,t:15;
819 }
820 \end{minted}
821 \end{subfigure}
822 \begin{subfigure}{0.49\textwidth}
823 \myAdigraph{
824 s,3,4,t:15;
825 }
826 \end{subfigure}
827 \end{figure}
828
829 \begin{figure}
830 \begin{subfigure}{0.49\textwidth}
831 \begin{minted}{latex}
832 \myAdigraph{
833 s,1,4,t:5;
834 }
835 \end{minted}
836 \end{subfigure}
837 \begin{subfigure}{0.49\textwidth}
838 \myAdigraph{
839 s,1,4,t:5;
840 }
841 \end{subfigure}
842 \end{figure}
843
844 \begin{figure}
845 \begin{subfigure}{0.49\textwidth}
846 \begin{minted}{latex}
847 \myAdigraph{
848 s,1,2,t:10;
849 }
850 \end{minted}
851 \end{subfigure}
852 \begin{subfigure}{0.49\textwidth}
853 \myAdigraph{
854 s,1,2,t:10;
855 }
856 \end{subfigure}
857 \end{figure}
858
859 \begin{figure}
860 \begin{subfigure}{0.49\textwidth}
861 \begin{minted}{latex}
862 \myAdigraph{
863 s,1,2,4,t:5;
864 }
865 \end{minted}
866 \end{subfigure}
867 \begin{subfigure}{0.49\textwidth}
868 \myAdigraph{
869 s,1,2,4,t:5;
870 }
871 \end{subfigure}
872 \end{figure}
873
874 \subsection{Custom colored augmenting Paths}
875 A path is specified by the following syntax: \textit{<comma separated list of nodes>:<units>:<forward path color, backward path color>}.
876
877 \NewAdigraph{myCustomAugmentingPathAdigraph}{
878 s:0,0;
879 1:2,2;
880 3:2,-2;
881 2:6,2;
882 4:6,-2;
883 t:8,0;
884 }{
885 s,1:25;
886 s,3:25;
887 3,4:25;
888 1,2:35;
889 2,t:20;
890 4,t:30;
891 3,1:10;
892 4,2:10;
893 2,3:15::near start;
894 4,1:5::near start;
895 }
896
897 \begin{figure}
898 \begin{subfigure}{0.49\textwidth}
899 \begin{minted}{latex}
900 \NewAdigraph{myAdigraph}{
901 s:0,0;
902 1:2,2;
903 3:2,-2;
904 2:6,2;
905 4:6,-2;
906 t:8,0;
907 }{
908 s,1:25;
909 s,3:25;
910 3,4:25;
911 1,2:35;
912 2,t:20;
913 4,t:30;
914 3,1:10;
915 4,2:10;
916 2,3:15::near start;
917 4,1:5::near start;
918 }
919 \myAdigraph{
920 s,3,4,2,t:5:green,blue;
921 }
922 \end{minted}
923 \end{subfigure}
924 \begin{subfigure}{0.49\textwidth}
925 \myCustomAugmentingPathAdigraph{
926 s,3,4,2,t:5:green,blue;
927 }
928 \end{subfigure}
929 \end{figure}
930
931 \subsection{Custom colored Paths}
932 A path is specified by the following syntax: \textit{<comma separated list of nodes>::<forward path color, backward path color>}. \textbf{Note the double colons!}.
933
934 \NewAdigraph{myCustomPathAdigraph}{
935 s:0,0;
936 1:2,2;
937 3:2,-2;
938 2:6,2;
939 4:6,-2;
940 t:8,0;
941 }{
942 s,1:25;
943 s,3:25;
944 3,4:25;
945 1,2:35;
946 2,t:20;
947 4,t:30;
948 3,1:10;
949 4,2:10;
950 2,3:15::near start;
951 4,1:5::near start;
952 }
953
954 \begin{figure}
955 \begin{subfigure}{0.49\textwidth}
956 \begin{minted}{latex}
957 \NewAdigraph{myAdigraph}{
958 s:0,0;
959 1:2,2;
960 3:2,-2;
961 2:6,2;
962 4:6,-2;
963 t:8,0;
964 }{
965 s,1:25;
966 s,3:25;
967 3,4:25;
968 1,2:35;
969 2,t:20;
970 4,t:30;
971 3,1:10;
972 4,2:10;
973 2,3:15::near start;
974 4,1:5::near start;
975 }
976 \myAdigraph{
977 s,3,4,2,t::green;
978 s,1,2::red;
979 }
980 \end{minted}
981 \end{subfigure}
982 \begin{subfigure}{0.49\textwidth}
983 \myCustomPathAdigraph{
984 s,1,2::red;
985 s,3,4,2,t::green;
986 }
987 \end{subfigure}
988 \end{figure}
989
990 \section{Cuts}
991 The following is to add cuts to show minimum cuts for example, the syntax is: \textit{<first node, second node;>}
992
993 \begin{figure}
994 \begin{subfigure}{0.49\textwidth}
995 \begin{minted}{latex}
996 \myAdigraph{}{
997 3,4;
998 2,t;
999 }
1000 \end{minted}
1001 \end{subfigure}
1002 \begin{subfigure}{0.49\textwidth}
1003 \myAdigraph{}{
1004 2,t;
1005 3,4;
1006 }
1007 \end{subfigure}
1008 \end{figure}
1009
1010 \subsection{Colored cuts}
1011 If you'd like to color the cuts you just have to add the color as follows: \textit{<first node, second node, color;>}. \textbf{Note that if you want to only add a cut and not an augmenting path and a cut, you still need to add the empty curly braces \{\}.}
1012
1013 \begin{figure}
1014 \begin{subfigure}{0.49\textwidth}
1015 \begin{minted}{latex}
1016 \myAdigraph{}{
1017 3,4,red;
1018 2,t,blue;
1019 2,4,green;
1020 }
1021 \end{minted}
1022 \end{subfigure}
1023 \begin{subfigure}{0.49\textwidth}
1024 \myAdigraph{}{
1025 2,t,red;
1026 3,4,blue;
1027 2,4,green;
1028 }
1029 \end{subfigure}
1030 \end{figure}
1031
1032 \section{Non oriented (undirected) edges and custom edge stiles}
1033 If you need non oriented edges or in general to ad a custom style to your edges you can proceed as follows:
1034 \subsection{Non oriented (undirected)}
1035 \begin{figure}
1036 \begin{subfigure}{0.49\textwidth}
1037 \begin{minted}{latex}
1038 \NewAdigraph{myCustomEdgesAdigraph}{
1039 s:0,0;
1040 1:2,2;
1041 3:2,-2;
1042 2:6,2;
1043 4:6,-2;
1044 t:8,0;
1045 }{
1046 s,1:25;
1047 s,3:25;
1048 3,4:25;
1049 1,2:35;
1050 2,t:20;
1051 4,t:30;
1052 3,1:10;
1053 4,2:10;
1054 2,3:15::near start;
1055 4,1:5::near start;
1056 }[-]
1057 \myCustomEdgesAdigraph{}
1058 \end{minted}
1059 \end{subfigure}
1060 \begin{subfigure}{0.49\textwidth}
1061 \NewAdigraph{myCustomEdgesAdigraph}{
1062 s:0,0;
1063 1:2,2;
1064 3:2,-2;
1065 2:6,2;
1066 4:6,-2;
1067 t:8,0;
1068 }{
1069 s,1:25;
1070 s,3:25;
1071 3,4:25;
1072 1,2:35;
1073 2,t:20;
1074 4,t:30;
1075 3,1:10;
1076 4,2:10;
1077 2,3:15::near start;
1078 4,1:5::near start;
1079 }[-]
1080 \myCustomEdgesAdigraph{}
1081 \end{subfigure}
1082 \end{figure}
1083
1084 \subsection{Dashed}
1085 \begin{figure}
1086 \begin{subfigure}{0.49\textwidth}
1087 \begin{minted}{latex}
1088 \NewAdigraph{myCustomEdgesAdigraph}{
1089 s:0,0;
1090 1:2,2;
1091 3:2,-2;
1092 2:6,2;
1093 4:6,-2;
1094 t:8,0;
1095 }{
1096 s,1:25;
1097 s,3:25;
1098 3,4:25;
1099 1,2:35;
1100 2,t:20;
1101 4,t:30;
1102 3,1:10;
1103 4,2:10;
1104 2,3:15::near start;
1105 4,1:5::near start;
1106 }[dashed]
1107 \myCustomEdgesAdigraph{}
1108 \end{minted}
1109 \end{subfigure}
1110 \begin{subfigure}{0.49\textwidth}
1111 \NewAdigraph{myCustomEdgesAdigraph}{
1112 s:0,0;
1113 1:2,2;
1114 3:2,-2;
1115 2:6,2;
1116 4:6,-2;
1117 t:8,0;
1118 }{
1119 s,1:25;
1120 s,3:25;
1121 3,4:25;
1122 1,2:35;
1123 2,t:20;
1124 4,t:30;
1125 3,1:10;
1126 4,2:10;
1127 2,3:15::near start;
1128 4,1:5::near start;
1129 }[dashed]
1130 \myCustomEdgesAdigraph{}
1131 \end{subfigure}
1132 \end{figure}
1133
1134 \chapter{PyAdigraph}
1135 \href{https://github.com/LucaCappelletti94/pyadigraph}{Pyadigraph} turns your networkx into Adigraph latex package. It requires Adigraph (1.7.0+) to work.
1136
1137 \section{Installation}
1138 The package can be installed by simply running:
1139 \begin{minted}{bash}
1140 pip installed pyadigraph
1141 \end{minted}
1142 \clearpage
1143 \section{Example}
1144 \subsection{Python code}
1145 For example by running the following python code:
1146 \begin{minted}{python}
1147 from pyadigraph import Adigraph
1148 import networkx as nx
1149
1150 A = Adigraph(
1151 vertices_color_fallback="gray!90",
1152 edges_color_fallback="gray!90",
1153 sub_caption="My adigraph number {i} of {n}",
1154 sub_label="adigraph_{i}_{n}",
1155 row_size=1,
1156 caption="A graph generated with python and latex.",
1157 label="pyadigraph_example"
1158 )
1159
1160 A.add_graph(
1161 nx.bipartite.random_graph(4, 4, 1),
1162 vertices_color={
1163 0: 'red!90',
1164 1: 'red!90',
1165 4: 'cyan!90',
1166 7: 'cyan!90'
1167 })
1168
1169 A.save("test/result.tex", document=True)
1170 \end{minted}
1171 \clearpage
1172 \subsection{Latex result}
1173 You automatically obtain the following latex:
1174
1175 \begin{minted}{latex}
1176 \documentclass{report}
1177 \usepackage{adigraph}
1178 \usepackage{subcaption}
1179
1180 \begin{document}
1181 \begin{figure}
1182 \begin{subfigure}{1.0\textwidth}
1183 \NewAdigraph{myAdigraph}{
1184 0,red!90,:-0.4386601404141742\textwidth,0.2091077552922947\textwidth:;
1185 1,red!90,:-0.15708496776680972\textwidth,0.09630690244229406\textwidth:;
1186 2,gray!90,:0.43887677279554366\textwidth,-0.2079924280020609\textwidth:;
1187 3,gray!90,:0.15678823839504888\textwidth,-0.09746320565948384\textwidth:;
1188 4,cyan!90,:-0.3736460590634439\textwidth,-0.327631363498189\textwidth:;
1189 5,gray!90,:0.3735687548614322\textwidth,0.3275275669374224\textwidth:;
1190 6,gray!90,:-0.042735184609099336\textwidth,-0.4998552275122768\textwidth:;
1191 7,cyan!90,:0.0428925858015027\textwidth,0.5\textwidth:;
1192 }{
1193 0,4,gray!90,::;
1194 0,5,gray!90,::;
1195 0,6,gray!90,::;
1196 0,7,gray!90,::;
1197 1,4,gray!90,::;
1198 1,5,gray!90,::;
1199 1,6,gray!90,::;
1200 1,7,gray!90,::;
1201 2,4,gray!90,::;
1202 2,5,gray!90,::;
1203 2,6,gray!90,::;
1204 2,7,gray!90,::;
1205 3,4,gray!90,::;
1206 3,5,gray!90,::;
1207 3,6,gray!90,::;
1208 3,7,gray!90,::;
1209 }[]
1210 \myAdigraph{}
1211 \caption{My adigraph number 1 of 1}\label{adigraph_1_1}
1212 \end{subfigure}
1213 \caption{A graph generated with python and latex.}\label{pyadigraph_example}
1214 \end{figure}
1215 \end{document}
1216 \end{minted}
1217
1218 And once you compile that you receive a graph like the following:
1219 \begin{figure}
1220 \includegraphics[width=0.5\textwidth]{img_examples/pyadigraph.png}
1221 \end{figure}
1222
1223 \chapter{Utilities}
1224 If for some reason you need to disable all the adigraphs in your latex code, for example using an online editor such as Overleaf that allows only a given maximum compile time, you can use the following command:
1225
1226 \begin{minted}{latex}
1227 \DisableAdigraphs
1228 \end{minted}
1229
1230 You can then re-enable adigraphs with:
1231
1232 \begin{minted}{latex}
1233 \EnableAdigraphs
1234 \end{minted}
1235
1236 \chapter{Warnings}
1237 \section{Reserved words}
1238 I reserve to use for the package the following tokens:
1239
1240 \begin{multicols}{2}
1241 \begin{enumerate}
1242 \item \textbackslash Adigraph
1243 \item \textbackslash AdigraphBuildEdge
1244 \item \textbackslash AdigraphBuildEdgeWrapper
1245 \item \textbackslash AdigraphBuildNode
1246 \item \textbackslash AdigraphBuildNodeWrapper
1247 \item \textbackslash AdigraphBuildPath
1248 \item \textbackslash AdigraphCalculateOrientation
1249 \item \textbackslash AdigraphCountPaths
1250 \item \textbackslash AdigraphCutBuilder
1251 \item \textbackslash AdigraphDrawEdge
1252 \item \textbackslash AdigraphDrawNode
1253 \item \textbackslash AdigraphEdgeBuilder
1254 \item \textbackslash AdigraphEdgeDrawer
1255 \item \textbackslash AdigraphElaboratePath
1256 \item \textbackslash AdigraphExecuteCutBuilder
1257 \item \textbackslash AdigraphGenerateNodeName
1258 \item \textbackslash AdigraphMemorizeEdge
1259 \item \textbackslash AdigraphMemorizeNode
1260 \item \textbackslash AdigraphNodeBuilder
1261 \item \textbackslash AdigraphNodeCounter
1262 \item \textbackslash AdigraphNodeCounterSecondWrapper
1263 \item \textbackslash AdigraphNodeCounterWrapper
1264 \item \textbackslash AdigraphNodesCounter
1265 \item \textbackslash AdigraphPathBuilder
1266 \item \textbackslash AdigraphProcessAugmentingPaths
1267 \item \textbackslash AdigraphProcessAugmentingPathsList
1268 \item \textbackslash AdigraphProcessCuts
1269 \item \textbackslash AdigraphProcessEdges
1270 \item \textbackslash AdigraphProcessNodes
1271 \item \textbackslash AdigraphProcessPaths
1272 \item \textbackslash AdigraphSimpleSum
1273 \item \textbackslash NewAdigraph
1274 \item \textbackslash RenewAdigraph
1275 \item \textbackslash DisableAdigraphs
1276 \end{enumerate}
1277 \end{multicols}
1278
1279 \end{document}