diff options
author | Karl Berry <karl@freefriends.org> | 2018-03-09 22:45:46 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2018-03-09 22:45:46 +0000 |
commit | 8f6a85906eed05ad9e0bf213a1232b24ab5f5d71 (patch) | |
tree | 54e373b9f324ec9b17f869da6f46b2781cab3be7 /Master | |
parent | 956eb721c60bbe9fa5a9c79bbfbf7f59ebaa549c (diff) |
adigraph (9mar18)
git-svn-id: svn://tug.org/texlive/trunk@46901 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master')
13 files changed, 1168 insertions, 516 deletions
diff --git a/Master/texmf-dist/doc/latex/adigraph/README.md b/Master/texmf-dist/doc/latex/adigraph/README.md index b2e269014de..f7d9e127783 100644 --- a/Master/texmf-dist/doc/latex/adigraph/README.md +++ b/Master/texmf-dist/doc/latex/adigraph/README.md @@ -1,145 +1,113 @@ -# Smart Augmenting Graphs +# Adigraph +[Adigraph](https://ctan.org/pkg/adigraph) is a pure latex library for drawing directed graphs and augmenting directed graphs, and to draw cuts over them. It DOES NOT require external libraries such as Graphviz or DOT. -Copyright 2018 Luca Cappelletti +It handles automatically the positioning of labels, with the exception of the horizontal position, and the inclinations of cuts. -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, sublicense, 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: +**This library is released under MIT license (Copyright 2018 Luca Cappelletti)**. -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -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. - -A tex package to draw **augmenting graphs** easily and to draw **cuts** on them too. - -This package requires the packages **fp**, **xparse**, **xstring** and **tikz** (in particular tikz/calc). If you don't have them you can proceed by installing them by running: +## Documentation +For more information, you can read the documentation available [here](https://github.com/LucaCappelletti94/adigraph/blob/master/documentation.pdf) +## Basic setup +### Installing the package +If you are on Linux or macOs you can run the following. ```bash -sudo tlmgr instal fp xparse xstring tikz +sudo tlmgr install fp etoolbox adigraph ``` -I'm currently looking into publishing this package on ctan, until then you'll have to download it and include in locally with the usual: +Otherwise install the packages with the package manager of your choice. + +### Requiring the package in the document +Remember to require the package in the document. ```latex \usepackage{adigraph} ``` -Then, suppose you want to create a graph as the following: +## Basic example +More examples and step by step explanation is available in the [documentation](https://github.com/LucaCappelletti94/adigraph/blob/master/documentation.pdf). + +Suppose you want to create a graph as the following, with an augmenting path highlighted and a couple of cuts: -![alt text][graph] +<p align="center"> + <img src="https://github.com/LucaCappelletti94/adigraph/blob/master/img_examples/example_3.jpg?raw=true" width="600px"> +</p> -We start by defining a new graph: +We start by defining a new graph, called *myAdigraph*: ```latex - \NewAdigraph{myAdigraph}{ - s,0,0,b,red; - 1,2,2; - 3,2,-2; - 2,6,2; - 4,6,-2; - t,8,0,e,blue; - }{ - s,3,25; - s,1,25; - 3,1,5; - 3,4,20; - 4,2,5; - 2,3,15,0,near start; - 4,1,5,0,near start; - 1,2,35; - 2,t,20; - 4,t,30; - } +\NewAdigraph{myAdigraph}{ + s:0,0; + 1:2,2; + 3:2,-2; + 2:6,2; + 4:6,-2; + t:8,0; +}{ + s,1:25; + s,3:25; + 3,4:25; + 1,2:35; + 2,t:20; + 4,t:30; + 3,1:10; + 4,2:10; + 2,3:15::near start; + 4,1:5::near start; +} ``` -In the first argument we are defining the *nodes*, while in the second one we are defining the *edges*. The name of this particular graph will be *myAdigraph*. - -We now want to draw this graph. We proceed as follows: +At this point the output is the following: ```latex -\begin{figure} - \center - \myAdigraph{} - \caption{My Personal Graph} -\end{figure} +\myAdigraph{} ``` -Suppose now we want to show the steps for calculating the maximum flow of the graph. We just add the edited edges inside the now empty argument of the *\myAdigraph*: +<p align="center"> + <img src="https://github.com/LucaCappelletti94/adigraph/blob/master/img_examples/example_0.jpg?raw=true" width="600px"> +</p> +Then we can add the augmenting path as follows: ```latex -\begin{figure} - \center - \myAdigraph{ - s,3,5,20,1; - 3,4,0,20,1; - 4,t,20,10,1; - } - \caption{Sending 10 units over $s,3,4,t$} -\end{figure} - -\begin{figure} - \center - \myAdigraph{ - s,3,5,20; - 3,4,0,20; - s,1,20,5,1; - 4,1,5,0,red,blue,near start; - 4,t,15,15,1; - } - \caption{Sending 5 units over $s,1,4,t$} -\end{figure} - -\begin{figure} - \center - \myAdigraph{ - s,3,5,20; - 3,4,0,20; - s,1,15,10,1; - 1,2,25,10,1; - 4,2,5,0,1; - 4,t,10,20,1; - } - \caption{Sending 5 units over $s,1,2,4,t$} -\end{figure} - -\begin{figure} - \center - \myAdigraph{ - s,3,5,20; - 3,4,0,20; - s,1,5,20,1; - 1,2,15,20,1; - 4,2,5,0; - 2,t,0,20,1; - 4,t,10,20; - } - \caption{Sending 10 units over $s,1,2,t$} -\end{figure} - -\begin{figure} - \center - \myAdigraph[ - 3,4; - 2,t; - ]{ - s,3,5,20; - 3,4,0,20; - s,1,5,20,1; - 1,2,15,20,1; - 4,2,5,0; - 2,t,0,20,1; - 4,t,10,20; - } - \caption{Showing minimum cut} -\end{figure} +\myAdigraph{ + s,3,4,2,t:5; +} ``` -The working example in latex is found in the file *adigraph_library_example.tex*. +<p align="center"> + <img src="https://github.com/LucaCappelletti94/adigraph/blob/master/img_examples/example_1.jpg?raw=true" width="600px"> +</p> + +And the cuts (remember that the paths from previous steps are memorized by the library) are added as follows: + +```latex +\myAdigraph{}{ + 2,t,red; + 3,4,blue; +} +``` The result with the cuts is the following: -![alt text][cuts] +<p align="center"> + <img src="https://github.com/LucaCappelletti94/adigraph/blob/master/img_examples/example_2.jpg?raw=true" width="600px"> +</p> + +You can add both cuts and paths at the same time to keep the latest path highlighted: + +```latex +\myAdigraph{ + s,3,4,2,t:5; +}{ + 2,t,red; + 3,4,blue; +} +``` + +<p align="center"> + <img src="https://github.com/LucaCappelletti94/adigraph/blob/master/img_examples/example_3.jpg?raw=true" width="600px"> +</p> Have a nice day! -**Luca Cappelletti** -[graph]: https://github.com/LucaCappelletti94/smart_augmenting_graphs/blob/master/img_examples/example_1.jpg?raw=true "Graph example" -[cuts]: https://github.com/LucaCappelletti94/smart_augmenting_graphs/blob/master/img_examples/example_cut.jpg?raw=true "Example with cuts"
\ No newline at end of file +**Luca Cappelletti** diff --git a/Master/texmf-dist/doc/latex/adigraph/adigraph_library_example.pdf b/Master/texmf-dist/doc/latex/adigraph/adigraph_library_example.pdf Binary files differdeleted file mode 100644 index 9ed04629655..00000000000 --- a/Master/texmf-dist/doc/latex/adigraph/adigraph_library_example.pdf +++ /dev/null diff --git a/Master/texmf-dist/doc/latex/adigraph/adigraph_library_example.tex b/Master/texmf-dist/doc/latex/adigraph/adigraph_library_example.tex deleted file mode 100644 index 021d66cc4a7..00000000000 --- a/Master/texmf-dist/doc/latex/adigraph/adigraph_library_example.tex +++ /dev/null @@ -1,99 +0,0 @@ -\documentclass{report} - -\usepackage{adigraph} - -\begin{document} - -\NewAdigraph{myAdigraph}{ - s,0,0,b,red; - 1,2,2; - 3,2,-2; - 2,6,2; - 4,6,-2; - t,8,0,e,blue; -}{ - s,3,15,10; - s,1,25; - 3,1,5; - 3,4,10,10; - 4,2,0,5; - 2,3,15,0,black,black,near start; - 4,1,0,5,black,black,near start; - 1,2,30,5; - 2,t,10,10; - 4,t,30; -} - -\begin{figure} - \center - \myAdigraph{} - \caption{My Personal Graph} -\end{figure} - -\begin{figure} - \center - \myAdigraph{ - s,3,5,20,1; - 3,4,0,20,1; - 4,t,20,10,1; - } - \caption{Sending 10 units over $s,3,4,t$} -\end{figure} - -\begin{figure} - \center - \myAdigraph{ - s,3,5,20; - 3,4,0,20; - s,1,20,5,1; - 4,1,5,0,red,blue,near start; - 4,t,15,15,1; - } - \caption{Sending 5 units over $s,1,4,t$} -\end{figure} - -\begin{figure} - \center - \myAdigraph{ - s,3,5,20; - 3,4,0,20; - s,1,15,10,1; - 1,2,25,10,1; - 4,2,5,0,1; - 4,t,10,20,1; - } - \caption{Sending 5 units over $s,1,2,4,t$} -\end{figure} - -\begin{figure} - \center - \myAdigraph{ - s,3,5,20; - 3,4,0,20; - s,1,5,20,1; - 1,2,15,20,1; - 4,2,5,0; - 2,t,0,20,1; - 4,t,10,20; - } - \caption{Sending 10 units over $s,1,2,t$} -\end{figure} - -\begin{figure} - \center - \myAdigraph[ - 3,4; - 2,t; - ]{ - s,3,5,20; - 3,4,0,20; - s,1,5,20,1; - 1,2,15,20,1; - 4,2,5,0; - 2,t,0,20,1; - 4,t,10,20; - } - \caption{Showing minimum cut} -\end{figure} - -\end{document}
\ No newline at end of file diff --git a/Master/texmf-dist/doc/latex/adigraph/documentation.pdf b/Master/texmf-dist/doc/latex/adigraph/documentation.pdf Binary files differnew file mode 100644 index 00000000000..911e38550ad --- /dev/null +++ b/Master/texmf-dist/doc/latex/adigraph/documentation.pdf diff --git a/Master/texmf-dist/doc/latex/adigraph/documentation.tex b/Master/texmf-dist/doc/latex/adigraph/documentation.tex new file mode 100644 index 00000000000..d572758fe75 --- /dev/null +++ b/Master/texmf-dist/doc/latex/adigraph/documentation.tex @@ -0,0 +1,670 @@ +\documentclass{report} + +\title{Adigraph, V1.2} +\author{Luca Cappelletti} +\date{March 2018} + +\usepackage{adigraph} +\usepackage{xcolor} +\usepackage[colorlinks=true,urlcolor=blue,pdfpagelabels,hyperindex=false]{hyperref} +\usepackage{minted} +\usepackage{multicol} +\usepackage{graphicx} % for images and generally graphics +\usepackage{caption} % enabling of nice captions +\usepackage{subcaption} % and subcaptions of images +\definecolor{mintedbackground}{rgb}{0.95,0.95,0.95} +\setminted{ + bgcolor=mintedbackground, + fontfamily=tt, + linenos=true, + numberblanklines=true, + numbersep=5pt, + gobble=0, + frame=leftline, + framerule=0.4pt, + framesep=2mm, + funcnamehighlighting=true, + tabsize=4, + obeytabs=false, + mathescape=false + samepage=false, %with this setting you can force the list to appear on the same page + showspaces=false, + showtabs =false, + texcl=false, +} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% THE FOLLOWING CENTERS ALL FLOATING ITEMS BY DEFAULT % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\makeatletter +\g@addto@macro\@floatboxreset\centering +\makeatother + +\makeatletter +\apptocmd\subcaption@minipage{\centering}{}{} +\makeatother + +\makeatletter +\providecommand*\setfloatlocations[2]{\@namedef{fps@#1}{#2}} +\makeatother +\setfloatlocations{figure}{H} +\setfloatlocations{table}{H} + +\begin{document} + +\maketitle + +{\hypersetup{hidelinks} + \tableofcontents % Generates the table of contents +} + +\chapter{Introduction} +\section{What is Adigraph?} +\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. + +It handles automatically the positioning of labels, with the exception of the horizontal position, and the inclinations of cuts. + +The latest version is available on \href{https://github.com/LucaCappelletti94/adigraph}{Github}. + +\section{License} +Copyright 2018 Luca Cappelletti + +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: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +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.\\ + +\chapter{Setup} +\section{Installing the dependencies} +Clearly you need to have texlive installed. Then, make sure you have the following packages: + +\begin{description} + \item[\href{https://ctan.org/pkg/fp}{fp}] Used for floating point calculations. + \item[\href{https://ctan.org/pkg/xparse}{xparse}] Used for elaborating parameters. + \item[\href{https://ctan.org/pkg/xstring}{xstring}] Used for elaborating strings. + \item[\href{https://ctan.org/pkg/etoolbox}{etoolbox}] Used for operations on lists. + \item[tikz] Used for drawing the actual graphs. + \item[tikz calc library] Used for some internal calculations in tikz. +\end{description} + +To be sure you can run the following, that will install the packages only if they are not already present: + +\begin{minted}{sh} +sudo tlmgr install etoolbox fp xstring +\end{minted} + +\section{Installing Adigraph} +You can install Adigraph, if it isn't already present in your setup, by running the following on Unix systems: + +\begin{minted}{sh} +sudo tlmgr install adigraph +\end{minted} + +On windows you should check on your package manager of choice (some latex distribution have a tlmgr implementation on windows too.) + +\chapter{Usage} +\section{Creating a new graph} +Here we create a new Adigraph object, called \textit{myAdigraph}. + +\begin{minted}{latex} +\NewAdigraph{myAdigraph}{ + <nodes here, separated by semicolon> +}{ + <edges here, separated by semicolon> +}{ + <cuts here, separated by semicolon> +} +\end{minted} + +\section{Adding nodes} +We set its nodes with the following syntax: \textit{<node name: \(x\) coordinate, \(y\) coordinate, color: label>}. + +\begin{figure} + \begin{subfigure}{0.49\textwidth} + \begin{minted}{latex} +\NewAdigraph{myAdigraph}{ + s:0,0; + t:4,0; +} +\myAdigraph{} +\end{minted} + \end{subfigure} + \begin{subfigure}{0.49\textwidth} + \NewAdigraph{myAdigraph}{ + s:0,0; + t:4,0; + } + \myAdigraph{} + \end{subfigure} +\end{figure} + + +\subsection{Custom node colors} +To color a node you can use the following syntax: \textit{<node name: \(x\) coordinate, \(y\) coordinate, textual color>}. For example, to draw s in red and t in blue we would write: + +\begin{figure} + \begin{subfigure}{0.49\textwidth} + \begin{minted}{latex} +\NewAdigraph{myAdigraph}{ + s:0,0,red; + t:4,0,blue; +} +\myAdigraph{} +\end{minted} + \end{subfigure} + \begin{subfigure}{0.49\textwidth} + \NewAdigraph{myAdigraph}{ + s:0,0,red; + t:4,0,blue; + } + \myAdigraph{} + \end{subfigure} +\end{figure} + +Tested available colors are: red, blue, black, green. You may extend the possible colors with LaTex libraries such as xcolor. + +\subsection{Custom node labels} +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: \(x\) coordinate, \(y\) coordinate, textual color: node label>} will work: + +\begin{figure} + \begin{subfigure}{0.49\textwidth} + \begin{minted}{latex} +\NewAdigraph{myAdigraph}{ + s:0,0,red:start; + t:4,0:end; +} +\myAdigraph{} +\end{minted} + \end{subfigure} + \begin{subfigure}{0.49\textwidth} + \NewAdigraph{myAdigraph}{ + s:0,0,red:start; + t:4,0:end; + } + \myAdigraph{} + \end{subfigure} +\end{figure} + +\section{Adding edges} +We set its nodes with the following syntax: \textit{<node name: \(x\) coordinate, \(y\) coordinate, color : label>}. + +\subsection{A simple edge} +\begin{figure} + \begin{subfigure}{0.49\textwidth} + \begin{minted}{latex} +\NewAdigraph{myAdigraph}{ + s:0,0; + t:4,0; +}{ + s,t; +} +\myAdigraph{} +\end{minted} + \end{subfigure} + \begin{subfigure}{0.49\textwidth} + \NewAdigraph{myAdigraph}{ + s:0,0; + t:4,0; + }{ + s,t; + } + \myAdigraph{} + \end{subfigure} +\end{figure} + +\subsection{A colored simple edge} +\begin{figure} + \begin{subfigure}{0.49\textwidth} + \begin{minted}{latex} +\NewAdigraph{myAdigraph}{ + s:0,0; + t:4,0; +}{ + s,t,red; +} +\myAdigraph{} +\end{minted} + \end{subfigure} + \begin{subfigure}{0.49\textwidth} + \NewAdigraph{myAdigraph}{ + s:0,0; + t:4,0; + }{ + s,t,red; + } + \myAdigraph{} + \end{subfigure} +\end{figure} + +\subsection{A weighted edge} +\begin{figure} + \begin{subfigure}{0.49\textwidth} + \begin{minted}{latex} +\NewAdigraph{myAdigraph}{ + s:0,0; + t:4,0; +}{ + s,t:56; +} +\myAdigraph{} +\end{minted} + \end{subfigure} + \begin{subfigure}{0.49\textwidth} + \NewAdigraph{myAdigraph}{ + s:0,0; + t:4,0; + }{ + s,t:56; + } + \myAdigraph{} + \end{subfigure} +\end{figure} + +\subsection{A weighted edge with label} +\begin{figure} + \begin{subfigure}{0.49\textwidth} + \begin{minted}{latex} +\NewAdigraph{myAdigraph}{ + s:0,0; + t:4,0; +}{ + s,t:56:myLabel; +} +\myAdigraph{} +\end{minted} + \end{subfigure} + \begin{subfigure}{0.49\textwidth} + \NewAdigraph{myAdigraph}{ + s:0,0; + t:4,0; + }{ + s,t:56:myLabel; + } + \myAdigraph{} + \end{subfigure} +\end{figure} + +\subsection{Edge in both directions} +\begin{figure} + \begin{subfigure}{0.49\textwidth} + \begin{minted}{latex} +\NewAdigraph{myAdigraph}{ + s:0,0; + t:4,0; +}{ + s,t; + t,s; +} +\myAdigraph{} +\end{minted} + \end{subfigure} + \begin{subfigure}{0.49\textwidth} + \NewAdigraph{myAdigraph}{ + s:0,0; + t:4,0; + }{ + s,t; + t,s; + } + \myAdigraph{} + \end{subfigure} +\end{figure} + +\subsection{Edge with weights in both directions} +\begin{figure} + \begin{subfigure}{0.49\textwidth} + \begin{minted}{latex} +\NewAdigraph{myAdigraph}{ + s:0,0; + t:4,0; +}{ + s,t:5; + t,s:5; +} +\myAdigraph{} +\end{minted} + \end{subfigure} + \begin{subfigure}{0.49\textwidth} + \NewAdigraph{myAdigraph}{ + s:0,0; + t:4,0; + }{ + s,t:5; + t,s:5; + } + \myAdigraph{} + \end{subfigure} +\end{figure} + +\subsection{Positioning labels} +\begin{figure} + \begin{subfigure}{0.49\textwidth} + \begin{minted}{latex} +\NewAdigraph{myAdigraph}{ + 1:0,0; + 2:0,2; + 3:4,2; + 4:4,0; +}{ + 1,3,red:1:a:near start; + 2,4,blue:1:b:near end; +} +\myAdigraph{} +\end{minted} + \end{subfigure} + \begin{subfigure}{0.49\textwidth} + \NewAdigraph{myAdigraph}{ + 1:0,0; + 2:0,2; + 3:4,2; + 4:4,0; + }{ + 1,3,red:1:a:near start; + 2,4,blue:1:b:near end; + } + \myAdigraph{} + \end{subfigure} +\end{figure} + +\subsection{Positioning weights} +\begin{figure} + \begin{subfigure}{0.49\textwidth} + \begin{minted}{latex} +\NewAdigraph{myAdigraph}{ + 1:0,0; + 2:0,2; + 3:4,2; + 4:4,0; +}{ + 1,3,red:1::near start; + 2,4,blue:1::near end; +} +\myAdigraph{} +\end{minted} + \end{subfigure} + \begin{subfigure}{0.49\textwidth} + \NewAdigraph{myAdigraph}{ + 1:0,0; + 2:0,2; + 3:4,2; + 4:4,0; + }{ + 1,3,red:1::near start; + 2,4,blue:1::near end; + } + \myAdigraph{} + \end{subfigure} +\end{figure} + + +\subsection{Multiple edges with weights} +\begin{figure} + \begin{subfigure}{0.49\textwidth} + \begin{minted}{latex} +\NewAdigraph{myAdigraph}{ + s:0,0; + t:4,0; + 1:0,3; + 2:4,3; +}{ + s,t:5; + t,s:5; + s,1:5; + 1,s:5; + 1,2:5; + 2,1:5; + 2,t:5; + t,2:5; + t,1:5; + 1,t:5; +} +\myAdigraph{} +\end{minted} + \end{subfigure} + \begin{subfigure}{0.49\textwidth} + \NewAdigraph{myAdigraph}{ + s:0,0; + t:4,0; + 1:0,3; + 2:4,3; + }{ + s,t:5; + t,s:5; + s,1:5; + 1,s:5; + 1,2:5; + 2,1:5; + 2,t:5; + t,2:5; + t,1:5; + 1,t:5; + } + \myAdigraph{} + \end{subfigure} +\end{figure} + +\section{Augmenting paths} +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. + +\NewAdigraph{myAdigraph}{ + s:0,0; + 1:2,2; + 3:2,-2; + 2:6,2; + 4:6,-2; + t:8,0; +}{ + s,1:25; + s,3:25; + 3,4:25; + 1,2:35; + 2,t:20; + 4,t:30; + 3,1:10; + 4,2:10; + 2,3:15::near start; + 4,1:5::near start; +} + +\begin{figure} + \begin{subfigure}{0.49\textwidth} + \begin{minted}{latex} +\NewAdigraph{myAdigraph}{ + s:0,0; + 1:2,2; + 3:2,-2; + 2:6,2; + 4:6,-2; + t:8,0; +}{ + s,1:25; + s,3:25; + 3,4:25; + 1,2:35; + 2,t:20; + 4,t:30; + 3,1:10; + 4,2:10; + 2,3:15::near start; + 4,1:5::near start; +} +\myAdigraph{ + s,3,4,2,t:5; +} +\end{minted} + \end{subfigure} + \begin{subfigure}{0.49\textwidth} + \myAdigraph{ + s,3,4,2,t:5; + } + \end{subfigure} +\end{figure} + +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: + +\begin{figure} + \begin{subfigure}{0.49\textwidth} + \begin{minted}{latex} +\myAdigraph{ + s,3,4,1,2,t:5; +} +\end{minted} + \end{subfigure} + \begin{subfigure}{0.49\textwidth} + \myAdigraph{ + s,3,4,1,2,t:5; + } + \end{subfigure} +\end{figure} + +\begin{figure} + \begin{subfigure}{0.49\textwidth} + \begin{minted}{latex} +\myAdigraph{ + s,3,4,t:15; +} +\end{minted} + \end{subfigure} + \begin{subfigure}{0.49\textwidth} + \myAdigraph{ + s,3,4,t:15; + } + \end{subfigure} +\end{figure} + +\begin{figure} + \begin{subfigure}{0.49\textwidth} + \begin{minted}{latex} +\myAdigraph{ + s,1,4,t:5; +} +\end{minted} + \end{subfigure} + \begin{subfigure}{0.49\textwidth} + \myAdigraph{ + s,1,4,t:5; + } + \end{subfigure} +\end{figure} + +\begin{figure} + \begin{subfigure}{0.49\textwidth} + \begin{minted}{latex} +\myAdigraph{ + s,1,2,t:10; +} +\end{minted} + \end{subfigure} + \begin{subfigure}{0.49\textwidth} + \myAdigraph{ + s,1,2,t:10; + } + \end{subfigure} +\end{figure} + +\begin{figure} + \begin{subfigure}{0.49\textwidth} + \begin{minted}{latex} +\myAdigraph{ + s,1,2,4,t:5; +} +\end{minted} + \end{subfigure} + \begin{subfigure}{0.49\textwidth} + \myAdigraph{ + s,1,2,4,t:5; + } + \end{subfigure} +\end{figure} + +\section{Cuts} + +The following is to add cuts to show minimum cuts for example, the syntax is: \textit{<first node, second node;>} + +\begin{figure} + \begin{subfigure}{0.49\textwidth} + \begin{minted}{latex} +\myAdigraph{}{ + 3,4; + 2,t; +} +\end{minted} + \end{subfigure} + \begin{subfigure}{0.49\textwidth} + \myAdigraph{}{ + 2,t; + 3,4; + } + \end{subfigure} +\end{figure} + +\subsection{Colored cuts} +If you'd like to color the cuts you just have to add the color as follows: \textit{<first node, second node, color;>} + +\begin{figure} + \begin{subfigure}{0.49\textwidth} + \begin{minted}{latex} +\myAdigraph{}{ + 3,4,red; + 2,t,blue; +} +\end{minted} + \end{subfigure} + \begin{subfigure}{0.49\textwidth} + \myAdigraph{}{ + 2,t,red; + 3,4,blue; + } + \end{subfigure} +\end{figure} + +\chapter{Warnings} +\section{Reserved words} +I reserve to use for the package the following tokens: + +\begin{multicols}{2} + \begin{enumerate} + \item Adigraph + \item AdigraphAugmentingPaths + \item AdigraphBuildEdge + \item AdigraphBuildEdgeWrapper + \item AdigraphBuildNode + \item AdigraphBuildPath + \item AdigraphCalculateOrientation + \item AdigraphCounter + \item AdigraphCountPaths + \item AdigraphCurrentPathNumber + \item AdigraphCutBuilder + \item AdigraphDrawEdge + \item AdigraphDrawNode + \item AdigraphEdgeBuilder + \item AdigraphEdgeDrawer + \item AdigraphEdgeList + \item AdigraphEdgeName + \item AdigraphElaboratePath + \item AdigraphElaboratePath + \item AdigraphExecuteCutBuilder + \item AdigraphFirstNode + \item AdigraphMemorizeEdge + \item AdigraphMemorizeNode + \item AdigraphNodeBuilder + \item AdigraphNodeList + \item AdigraphNodeName + \item AdigraphNumberOfPaths + \item AdigraphPathBuilder + \item AdigraphProcessAugmentingPaths + \item AdigraphProcessCuts + \item AdigraphProcessEdges + \item AdigraphProcessNodes + \item AdigraphProcessPaths + \item AdigraphRom + \item AdigraphSecondNode + \item AdigraphSimpleSum + \item AdigraphTwinEdgeWeight + \item NewAdigraph + \end{enumerate} +\end{multicols} + +\end{document}
\ No newline at end of file diff --git a/Master/texmf-dist/doc/latex/adigraph/img_examples/example_0.jpg b/Master/texmf-dist/doc/latex/adigraph/img_examples/example_0.jpg Binary files differnew file mode 100644 index 00000000000..9e530cad255 --- /dev/null +++ b/Master/texmf-dist/doc/latex/adigraph/img_examples/example_0.jpg diff --git a/Master/texmf-dist/doc/latex/adigraph/img_examples/example_1.jpg b/Master/texmf-dist/doc/latex/adigraph/img_examples/example_1.jpg Binary files differindex 651e4aba6f7..e1389419250 100644 --- a/Master/texmf-dist/doc/latex/adigraph/img_examples/example_1.jpg +++ b/Master/texmf-dist/doc/latex/adigraph/img_examples/example_1.jpg diff --git a/Master/texmf-dist/doc/latex/adigraph/img_examples/example_2.jpg b/Master/texmf-dist/doc/latex/adigraph/img_examples/example_2.jpg Binary files differnew file mode 100644 index 00000000000..d822f93b1d2 --- /dev/null +++ b/Master/texmf-dist/doc/latex/adigraph/img_examples/example_2.jpg diff --git a/Master/texmf-dist/doc/latex/adigraph/img_examples/example_3.jpg b/Master/texmf-dist/doc/latex/adigraph/img_examples/example_3.jpg Binary files differnew file mode 100644 index 00000000000..c2ba7c7374a --- /dev/null +++ b/Master/texmf-dist/doc/latex/adigraph/img_examples/example_3.jpg diff --git a/Master/texmf-dist/doc/latex/adigraph/img_examples/example_cut.jpg b/Master/texmf-dist/doc/latex/adigraph/img_examples/example_cut.jpg Binary files differdeleted file mode 100644 index 20f4c0d75b3..00000000000 --- a/Master/texmf-dist/doc/latex/adigraph/img_examples/example_cut.jpg +++ /dev/null diff --git a/Master/texmf-dist/doc/latex/adigraph/test.pdf b/Master/texmf-dist/doc/latex/adigraph/test.pdf Binary files differnew file mode 100644 index 00000000000..bd969940ca7 --- /dev/null +++ b/Master/texmf-dist/doc/latex/adigraph/test.pdf diff --git a/Master/texmf-dist/doc/latex/adigraph/test.tex b/Master/texmf-dist/doc/latex/adigraph/test.tex new file mode 100644 index 00000000000..ba12098a92a --- /dev/null +++ b/Master/texmf-dist/doc/latex/adigraph/test.tex @@ -0,0 +1,42 @@ +\documentclass{report} + +\usepackage{adigraph} + +\title{Adigraph, V1.2, small working test} +\author{Luca Cappelletti} +\date{March 2018} + +\begin{document} +\maketitle +\NewAdigraph{myAdigraph}{ + s:0,0; + 1:2,2; + 3:2,-2; + 2:6,2; + 4:6,-2; + t:8,0; +}{ + s,1:25; + s,3:25; + 3,4:25; + 1,2:35; + 2,t:20; + 4,t:30; + 3,1:10; + 4,2:10; + 2,3:15::near start; + 4,1:5::near start; +} + +\myAdigraph{} + + +\myAdigraph{ + s,3,4,2,t:5; +} + +\myAdigraph{}{ + 2,t,red; + 3,4,blue; +} +\end{document}
\ No newline at end of file diff --git a/Master/texmf-dist/tex/latex/adigraph/adigraph.sty b/Master/texmf-dist/tex/latex/adigraph/adigraph.sty index 1d12cc9892d..5d8ad435831 100644 --- a/Master/texmf-dist/tex/latex/adigraph/adigraph.sty +++ b/Master/texmf-dist/tex/latex/adigraph/adigraph.sty @@ -9,349 +9,420 @@ % \NeedsTeXFormat{LaTeX2e}[1994/06/01] \ProvidesPackage{adigraph} - [2018/02/16 v1.0 LaTeX package for creating augmenting directed graphs] +[2018/03/09 v1.2 LaTeX package for creating augmenting directed graphs] +\RequirePackage{etoolbox} \RequirePackage{fp} \RequirePackage{xparse} \RequirePackage{xstring} \RequirePackage{tikz} \usetikzlibrary{calc} -\def\zero{0} - \makeatletter -\newcommand*{\rom}[1]{\expandafter\@slowromancap\romannumeral #1@} +\newcommand*{\AdigraphRom}[1]{\expandafter\@slowromancap\romannumeral #1@} +\makeatother + +\newcounter{AdigraphNumberOfPaths} +\setcounter{AdigraphNumberOfPaths}{0} + +\newcounter{AdigraphCurrentPathNumber} +\setcounter{AdigraphCurrentPathNumber}{0} + +\NewDocumentCommand{\AdigraphDrawNode}{m}{% + % + % #1 is node normalized id + % + \letcs{\nodeX}{adigraphNode#1X} + \letcs{\nodeY}{adigraphNode#1Y} + \letcs{\nodeLabel}{adigraphNode#1Label} + \letcs{\nodeColor}{adigraphNode#1Color} + % + \node[vertex,\nodeColor] (#1) at (\nodeX,\nodeY) {\nodeLabel}; +} + +\NewDocumentCommand{\AdigraphDrawEdge}{m m}{% + % + % #1 is first node normalized id + % #2 is second node normalized id + % + \ifbool{adigraphEdge#1v#2Drawn}{% + % This edge was already drawn + }{% + \letcs{\firstX}{adigraphNode#1X} + \letcs{\firstY}{adigraphNode#1Y} + \letcs{\secondX}{adigraphNode#2X} + \letcs{\secondY}{adigraphNode#2Y} -\NewDocumentCommand{\storeCoordinate}{m m m}{ - \@namedef{adigraphNode#1#2}{#3}% + \ifnumgreater{\secondX-\firstX}{0}{% + \def\AdigraphLabelPosition{above} + }{% + \ifnumequal{\secondX-\firstX}{0}{% + \ifnumgreater{\secondY-\firstY}{0}{% + \def\AdigraphLabelPosition{left} + }{% + \def\AdigraphLabelPosition{right} + } + }{% + \def\AdigraphLabelPosition{below} + } + } + + \booltrue{adigraphEdge#1v#2Drawn} + \letcs{\edgeLabelPosition}{adigraphEdge#1v#2LabelPosition} + \letcs{\edgeWeight}{adigraphEdge#1v#2Weight} + \ifcsdef{adigraphEdge#2v#1Weight}{% + \letcs{\AdigraphTwinEdgeWeight}{adigraphEdge#2v#1Weight} + }{% + \def\AdigraphTwinEdgeWeight{0} + } + \letcs{\edgeColor}{adigraphEdge#1v#2Color} + \ifbool{adigraphEdge#1v#2HasLabel}{% + \letcs{\edgeLabel}{adigraphEdge#1v#2Label} + }{% + \letcs{\edgeLabel}{adigraphEdge#1v#2Weight} + } + \ifnumequal{\edgeWeight}{0}{% + % We don't draw edges with weight 0 + }{% + \ifnumequal{\AdigraphTwinEdgeWeight}{0}{% + % The twin edge won't be drawn + % This edge will be a straight line + \draw[edge,\edgeColor] (#1) to node[\edgeLabelPosition, \AdigraphLabelPosition] {\edgeLabel}(#2); + }{% + % Both edges have to be drawn, they will be curly + \draw[edge,\edgeColor] (#1) to [bend right=20] node[\edgeLabelPosition, \AdigraphLabelPosition] {\edgeLabel}(#2); + }% + }% + } } -\NewDocumentCommand{\storeParsedEdge}{m m}{ - \@namedef{parsed#1#2}{1}% + +\NewDocumentCommand{\AdigraphMemorizeNode}{m m G{black}}{} + +\NewDocumentCommand{\AdigraphBuildNode}{m > { \SplitArgument{ 2 } {,} } m G{#1}}{% + % + % #1 -> given node name, not normalized + % #2 -> list of coordinates and color + % #3 -> optional label + % + \ifblank{#1}{% + %Do nothing, this is the tail of the list + }{% + \IfInteger{#1}{% + \def\AdigraphNodeName{\AdigraphRom{#1}}% + \listgadd{\AdigraphNodeList}{\AdigraphRom{#1}} + }{% + \def\AdigraphNodeName{#1}% + \listgadd{\AdigraphNodeList}{#1} + }% + \RenewDocumentCommand{\AdigraphMemorizeNode}{m m G{black}}{% + \csdef{adigraphNode\AdigraphNodeName Label}{#3}% + \csdef{adigraphNode\AdigraphNodeName X}{##1}% + \csdef{adigraphNode\AdigraphNodeName Y}{##2}% + \csdef{adigraphNode\AdigraphNodeName Color}{##3}% + }% + \AdigraphMemorizeNode#2 + } } -\makeatother -\newcommand{\markEdgeAsParsed}[2]{% - % - % #1 -> First node of edge - % #2 -> Second node of edge - % - \IfInteger{#1}{% - \def\nodeA{\rom{#1}}% - }{% - \def\nodeA{#1}% - }% - \IfInteger{#2}{% - \def\nodeB{\rom{#2}}% - }{% - \def\nodeB{#2}% - }% - \storeParsedEdge{\nodeA}{\nodeB} + +\NewDocumentCommand{\AdigraphMemorizeEdge}{m m G{black}}{} + +\NewDocumentCommand{\AdigraphBuildEdge}{> {\SplitArgument{2}{,}} m m m m}{% + % + % #1 -> List of edge nodes and its color, validated + % #2 -> Weight + % #3 -> Label, defaults to weight + % #4 -> Label position, defaults to midway + % + \RenewDocumentCommand{\AdigraphMemorizeEdge}{m m G{black}}{% + \IfInteger{##1}{% + \IfInteger{##2}{% + \def\AdigraphEdgeName{\AdigraphRom{##1}v\AdigraphRom{##2}}% + \listgadd{\AdigraphEdgeList}{\AdigraphRom{##1},\AdigraphRom{##2}} + }{% + \def\AdigraphEdgeName{\AdigraphRom{##1}v##2}% + \listgadd{\AdigraphEdgeList}{\AdigraphRom{##1},##2} + }% + }{% + \IfInteger{##2}{% + \def\AdigraphEdgeName{##1v\AdigraphRom{##2}}% + \listgadd{\AdigraphEdgeList}{##1,\AdigraphRom{##2}} + }{% + \def\AdigraphEdgeName{##1v##2}% + \listgadd{\AdigraphEdgeList}{##1,##2} + }% + }% + \newbool{adigraphEdge\AdigraphEdgeName HasLabel} + \newbool{adigraphEdge\AdigraphEdgeName Drawn} + \ifblank{#3}{% + \boolfalse{adigraphEdge\AdigraphEdgeName HasLabel} + }{% + \booltrue{adigraphEdge\AdigraphEdgeName HasLabel} + }% + \ifblank{#2}{% + \booltrue{adigraphEdge\AdigraphEdgeName HasLabel} + \csdef{adigraphEdge\AdigraphEdgeName Weight}{1}% + }{% + \csdef{adigraphEdge\AdigraphEdgeName Weight}{#2}% + }% + \csdef{adigraphEdge\AdigraphEdgeName Label}{#3}% + \csdef{adigraphEdge\AdigraphEdgeName Color}{##3}% + \csdef{adigraphEdge\AdigraphEdgeName LabelPosition}{#4}% + } + \AdigraphMemorizeEdge#1 +} + +\NewDocumentCommand{\AdigraphBuildEdgeWrapper}{m G{} G{} G{midway}}{% + % + % #1 -> List of edge nodes and its color + % #2 -> Weight + % #3 -> Label + % #4 -> Label position + % + \ifblank{#1}{% + %Do nothing, this is the tail of the list + }{% + \AdigraphBuildEdge{#1}{#2}{#3}{#4} + } +} + +\NewDocumentCommand{\AdigraphElaboratePath}{m m G{black}}{} + +\newcount\AdigraphCounter +\NewDocumentCommand{\AdigraphSimpleSum}{m m m}{% + % + % #1 -> First addendum + % #2 -> Second addendum + % #3 -> Variable to store sum + % + \AdigraphCounter #1\relax + \advance\AdigraphCounter +#2\relax + \FPset{#3}{\the\AdigraphCounter} +} + +\NewDocumentCommand{\AdigraphPathBuilder}{m m m}{% + % + % #1 -> first node + % #2 -> second node + % #3 -> units + % + \ifcsdef{adigraphEdge#1v#2Weight}{% + \letcs{\AdigraphWeightA}{adigraphEdge#1v#2Weight} + }{% + \def\AdigraphWeightA{0} + \newbool{adigraphEdge#1v#2HasLabel} + \ifcsdef{adigraphEdge#2v#1LabelPosition}{% + \csdef{adigraphEdge#1v#2LabelPosition}{\csuse{adigraphEdge#2v#1LabelPosition}} + }{% + \csdef{adigraphEdge#1v#2LabelPosition}{midway} + } + \csdef{adigraphEdge#1v#2LabelPosition}{midway} + \newbool{adigraphEdge#1v#2Drawn} + \csdef{adigraphEdge#1v#2Color}{black}% + \listgadd{\AdigraphEdgeList}{#1,#2} + } + \ifcsdef{adigraphEdge#2v#1Weight}{% + \letcs{\AdigraphWeightB}{adigraphEdge#2v#1Weight} + }{% + \def\AdigraphWeightB{0} + \newbool{adigraphEdge#2v#1HasLabel} + \ifcsdef{adigraphEdge#1v#2LabelPosition}{% + \csdef{adigraphEdge#2v#1LabelPosition}{\csuse{adigraphEdge#1v#2LabelPosition}} + }{% + \csdef{adigraphEdge#2v#1LabelPosition}{midway} + } + \newbool{adigraphEdge#2v#1Drawn} + \csdef{adigraphEdge#2v#1Color}{black}% + \listgadd{\AdigraphEdgeList}{#2,#1} + } + + \ifnum\value{AdigraphCurrentPathNumber}=\value{AdigraphNumberOfPaths} + \csdef{adigraphEdge#1v#2Color}{blue}% + \csdef{adigraphEdge#2v#1Color}{red}% + \else + % Leaves the default colors + \fi + \expandafter\AdigraphSimpleSum\expandafter{\AdigraphWeightA}{-#3}{\resultA} + \expandafter\AdigraphSimpleSum\expandafter{\AdigraphWeightB}{#3}{\resultB} + \cslet{adigraphEdge#1v#2Weight}{\resultA}% + \cslet{adigraphEdge#2v#1Weight}{\resultB}% } -\newcommand{\edgeWasParsed}[3]{% - % - % #1 -> Variable to store boolean result - % #2 -> First node of edge - % #3 -> Second node of edge - % - \IfInteger{#2}{% - \def\nodeA{\rom{#2}}% - }{% - \def\nodeA{#2}% - }% - \IfInteger{#3}{% - \def\nodeB{\rom{#3}}% - }{% - \def\nodeB{#3}% - }% - \ifcsname parsed\nodeA\nodeB\endcsname - \FPset{#1}{1} - \else% - \FPset{#1}{0} - \fi% +\NewDocumentCommand{\AdigraphBuildPath}{> { \SplitList{,} } m m}{% + % + % #1 -> List of nodes + % #2 -> Units to send over path + % + \RenewDocumentCommand{\AdigraphElaboratePath}{m}{% + \IfInteger{##1}{% + \def\AdigraphCurrentNode{\AdigraphRom{##1}}% + }{% + \def\AdigraphCurrentNode{##1}% + }% + \ifdef{\AdigraphLastParsedNode}{% + \expandafter\expandafter\expandafter\AdigraphPathBuilder\expandafter\expandafter\expandafter{\expandafter\AdigraphLastParsedNode\expandafter}\expandafter{\AdigraphCurrentNode}{#2} + }{% + % This is the first iteration + } + \IfInteger{##1}{% + \def\AdigraphLastParsedNode{\AdigraphRom{##1}}% + }{% + \def\AdigraphLastParsedNode{##1}% + }% + } + \ProcessList{#1}{\AdigraphElaboratePath} + \undef{\AdigraphLastParsedNode} } -\newcommand{\saveNodeCoordinate}[3]{ - % - % #1 -> Node name - % #2 -> Coordinate, either X or Y - % #3 -> Numeric value - % - \IfInteger{#1}{% - \def\nodeName{\rom{#1}}% - }{% - \def\nodeName{#1}% - }% - \storeCoordinate{#2}{\nodeName}{#3} +\NewDocumentCommand{\AdigraphNodeBuilder}{ > { \SplitArgument{ 2 } {:} } m }{% + \AdigraphBuildNode#1 } -\newcommand{\retrieveNodeCoordinate}[3]{ - % - % #1 -> Variable to store coordinate into - % #2 -> Node name - % #3 -> Coordinate, either X or Y - % - \IfInteger{#2}{% - \def\nodeName{\rom{#2}}% - }{% - \def\nodeName{#2}% - }% - - \FPset{#1}{\csname adigraphNode#3\nodeName\endcsname} +\NewDocumentCommand{\AdigraphEdgeBuilder}{ > { \SplitArgument{ 3 } {:} } m }{% + \AdigraphBuildEdgeWrapper#1 } -\newcommand{\saveNodeCoordinates}[3]{ - % - % #1 -> Node name - % #2 -> X value - % #3 -> Y value - % - \saveNodeCoordinate{#1}{X}{#2}% - \saveNodeCoordinate{#1}{Y}{#3}% +\NewDocumentCommand{\AdigraphEdgeDrawer}{ > { \SplitArgument{ 1 } {,} } m }{% + \AdigraphDrawEdge#1 } -\newcommand{\swp}[3]{ - % - % #1 -> variable to assign - % #2 -> First node name - % #3 -> Second node name - % - \retrieveNodeCoordinate{\firstX}{#2}{X} - \retrieveNodeCoordinate{\firstY}{#2}{Y} - \retrieveNodeCoordinate{\secondX}{#3}{X} - \retrieveNodeCoordinate{\secondY}{#3}{Y} - % - \FPsub{\xSub}{\secondX}{\firstX} - \FPsub{\ySub}{\secondY}{\firstY} - \FPset{#1}{1} - \FPifgt{\xSub}{0} - \FPset{#1}{3} - \else% - \FPset{#1}{4} - \fi% - % - \FPifeq{\xSub}{0} - \FPset{\xiszero}{1} - \else% - \FPset{\xiszero}{0} - \fi% - % - \FPifgt{\ySub}{0} - \FPset{\yispos}{1} - \else% - \FPset{\yispos}{4} - \fi% - % - \FPadd{\xzeroypos}{\xiszero}{\yispos} - % - \FPifeq{\xzeroypos}{2} - \FPset{#1}{1} - \fi% - \FPifeq{\xzeroypos}{5} - \FPset{#1}{2} - \fi% +\NewDocumentCommand{\AdigraphProcessNodes}{> { \SplitList{;} } m}{% + \ProcessList{#1}{\AdigraphNodeBuilder} + \forlistloop{\AdigraphDrawNode}{\AdigraphNodeList} } -\newcommand{\executeNodeBuilder}[5]{ - % - % #1 is node name - % #2 is x coordinate - % #3 is y coordinate - % #4 is label, that defaults to #1 when absent - % #5 is color, that defaults to black when absent - % - \IfValueT{#2}{ - \IfValueTF{#4}{ - \def\nodeLabel{#4} - }{ - \def\nodeLabel{#1} - } - \IfValueTF{#5}{ - \def\nodeColor{#5} - }{ - \def\nodeColor{black} - } - \saveNodeCoordinates{#1}{#2}{#3} - \node[vertex,\nodeColor] (#1) at (#2,#3) {$\nodeLabel$}; - } +\NewDocumentCommand{\AdigraphProcessEdges}{> { \SplitList{;} } m}{% + \ProcessList{#1}{\AdigraphEdgeBuilder} } -\NewDocumentCommand{\nodeBuilder}{ > { \SplitArgument { 4 } { , } } m }{ - \executeNodeBuilder #1 +\NewDocumentCommand{\AdigraphProcessPaths}{> { \SplitArgument{ 1 } {:} } m}{% + \stepcounter{AdigraphCurrentPathNumber} + \AdigraphBuildPath#1 } -\newcommand{\executeEdgeBuilder}[7]{ - % - % #1 is first node - % #2 is second node - % #3 is weight of first edge, which defaults to 0 - % #4 is weight of second edge, which defaults to 0 - % #5 Should we color edge? Or first optional color - % #6 Second optional color - % #7 Label position on axis - % - \edgeWasParsed{\isParsed}{#1}{#2} - \FPifeq{\isParsed}{0} - \markEdgeAsParsed{#1}{#2} - \markEdgeAsParsed{#2}{#1} - \fi% - \IfValueT{#2}{ - \def\firstNode{#1} - \def\secondNode{#2} - \IfValueTF{#3}{ - \def\firstEdgeWeight{#3} - }{ - \def\firstEdgeWeight{0} - } - \IfValueTF{#4}{ - \def\secondEdgeWeight{#4} - }{ - \def\secondEdgeWeight{0} - } - \IfValueTF{#7}{ - \def\labelPosition{#7} - }{ - \def\labelPosition{midway} - } - \IfValueTF{#6}{ - \IfValueTF{#5}{ - \def\firstEdgeColor{#5} - \def\secondEdgeColor{#6} - }{ - \def\firstEdgeColor{black} - \def\secondEdgeColor{black} - } - }{ - \IfValueTF{#5}{ - \def\firstEdgeColor{red} - \def\secondEdgeColor{blue} - }{ - \def\firstEdgeColor{black} - \def\secondEdgeColor{black} - } - } - - \FPadd{\weightSum}{\firstEdgeWeight}{\secondEdgeWeight} - \FPmul{\weightMul}{\firstEdgeWeight}{\secondEdgeWeight} - \FPadd{\firstZero}{\weightMul}{\firstEdgeWeight} - \FPadd{\secondZero}{\weightMul}{\secondEdgeWeight} - - \swp{\firstWeightPositionFlag}{#1}{#2} - \swp{\secondWeightPositionFlag}{#2}{#1} - - \FPifeq{\firstWeightPositionFlag}{1} - \def\firstWeightPosition{left} - \fi - \FPifeq{\firstWeightPositionFlag}{2} - \def\firstWeightPosition{right} - \fi - \FPifeq{\firstWeightPositionFlag}{3} - \def\firstWeightPosition{above} - \fi - \FPifeq{\firstWeightPositionFlag}{4} - \def\firstWeightPosition{below} - \fi - - \FPifeq{\secondWeightPositionFlag}{1} - \def\secondWeightPosition{left} - \fi - \FPifeq{\secondWeightPositionFlag}{2} - \def\secondWeightPosition{right} - \fi - \FPifeq{\secondWeightPositionFlag}{3} - \def\secondWeightPosition{above} - \fi - \FPifeq{\secondWeightPositionFlag}{4} - \def\secondWeightPosition{below} - \fi - \FPifeq{\isParsed}{1} - \else - \FPifeq{\weightSum}{0} - % No edge has weights, so we draw both with no labels. - \draw[edge,\firstEdgeColor] (\firstNode) to [bend right=20] (\secondNode); - \draw[edge,\secondEdgeColor] (\secondNode) to [bend right=20] (\firstNode); - \else - \FPifeq{\weightSum}{0} - \draw[edge,\firstEdgeColor] (\firstNode) to node[\labelPosition, \secondWeightPosition] {$\firstEdgeWeight$}(\secondNode); - \else - \FPifeq{\firstZero}{0} - \draw[edge,\secondEdgeColor] (\secondNode) to node[\labelPosition, \firstWeightPosition] {$\secondEdgeWeight$}(\firstNode); - \FPifeq{\weightMul}{0} - \else - \draw[edge,\firstEdgeColor] (\firstNode) to [bend right=20] node[\labelPosition, \firstWeightPosition] {$\firstEdgeWeight$}(\secondNode); - \draw[edge,\secondEdgeColor] (\secondNode) to [bend right=20] node[\labelPosition, \secondWeightPosition] {$\secondEdgeWeight$}(\firstNode); - \fi - } +\NewDocumentCommand{\AdigraphCountPaths}{m}{% + \stepcounter{AdigraphNumberOfPaths} } -\NewDocumentCommand{\edgeBuilder}{> { \SplitArgument { 6 } { , } } m}{ - \executeEdgeBuilder #1 +\NewDocumentCommand{\AdigraphCalculateOrientation}{m m m}{% + \letcs{\firstX}{adigraphNode#2X} + \letcs{\firstY}{adigraphNode#2Y} + \letcs{\secondX}{adigraphNode#3X} + \letcs{\secondY}{adigraphNode#3Y} + + \ifnumequal{\secondX-\firstX}{0}{% + \FPset{#1}{90} + }{% + \FPsub{\deltaY}{\secondY}{\firstY} + \FPsub{\deltaX}{\secondX}{\firstX} + \FPdiv{\deltaDiv}{\deltaY}{\deltaX} + \FParctan{\arcResult}{\deltaDiv} + \FPmul{#1}{\arcResult}{57.2958} + } } -\NewDocumentCommand{\calculateOrientation}{m m m}{ - \retrieveNodeCoordinate{\firstX}{#2}{X} - \retrieveNodeCoordinate{\firstY}{#2}{Y} - \retrieveNodeCoordinate{\secondX}{#3}{X} - \retrieveNodeCoordinate{\secondY}{#3}{Y} - \FPsub{\deltaY}{\secondY}{\firstY} - \FPsub{\deltaX}{\secondX}{\firstX} - \FPifeq{\deltaX}{0} - \Fpset{#1}{90} - \else - \FPdiv{\deltaDiv}{\deltaY}{\deltaX} - \FParctan{\arcResult}{\deltaDiv} - \FPmul{#1}{\arcResult}{57.2958} - \fi +\NewDocumentCommand{\AdigraphExecuteCutBuilder}{m m G{black}}{% +\ifblank{#1}{% +% Reached end of list +}{% +\IfInteger{#1}{% + \def\AdigraphFirstNode{\AdigraphRom{#1}}% +}{% + \def\AdigraphFirstNode{#1}% +}% +\IfInteger{#2}{% + \def\AdigraphSecondNode{\AdigraphRom{#2}}% +}{% + \def\AdigraphSecondNode{#2}% +}% +\AdigraphCalculateOrientation{\orientation}{\AdigraphFirstNode}{\AdigraphSecondNode} +\draw[dashed,#3,rotate=\orientation] ([yshift=10pt]$(\AdigraphFirstNode)!0.7!(\AdigraphSecondNode)$) -- ([yshift=-10pt]$(\AdigraphFirstNode)!0.7!(\AdigraphSecondNode)$); +} } -\NewDocumentCommand{\executeCutBuilder}{m m}{ - \IfValueT{#2}{ - \calculateOrientation{\orientation}{#1}{#2} - \draw[dashed,red,rotate=\orientation] ([yshift=10pt]$(#1)!0.7!(#2)$) -- ([yshift=-10pt]$(#1)!0.7!(#2)$); - % %\node[vertex] (d) at (-3,-3) {$ARIAN$}; - } +\NewDocumentCommand{\AdigraphCutBuilder}{> { \SplitArgument { 2 } { , } } m}{% + \AdigraphExecuteCutBuilder #1 } -\NewDocumentCommand{\cutBuilder}{> { \SplitArgument { 1 } { , } } m}{ - \executeCutBuilder #1 +\NewDocumentCommand{\AdigraphProcessCuts}{> { \SplitList{;} } m}{% + \ProcessList{#1}{\AdigraphCutBuilder} } -\NewDocumentCommand{\smartGraph}{> { \SplitList { ; } } m > { \SplitList { ; } } m > { \SplitList { ; } } m > { \SplitList { ; } } m}{ - % - % #1 -> Vertices - % #2 -> Edges - % #3 -> Modified edges - % #4 -> Cuts - % - \begin{tikzpicture} - \tikzset{ - vertex/.style={circle,draw,minimum size=2em}, - edge/.style={->,> = latex} - } - - % vertices - \ProcessList {#1} {\nodeBuilder} - - %edges - \ProcessList {#3} {\edgeBuilder} - \ProcessList {#2} {\edgeBuilder} - - %cuts - \ProcessList {#4} {\cutBuilder} - \end{tikzpicture} +\NewDocumentCommand{\Adigraph}{m m m m m}{% + % + % #1 -> Vertices + % #2 -> Edges + % #3 -> Augmenting paths + % #4 -> Cuts + % #5 -> Current augmenting paths + % + \def\AdigraphNodeList{} + \def\AdigraphEdgeList{} + \letcs{\AdigraphAugmentingPaths}{#3} + \begin{tikzpicture} + \tikzset{% + vertex/.style={circle,draw,minimum size=2em}, + edge/.style={->,> = latex} + } + + % vertices + \ifblank{#1}{% + % List is empty + }{% + \AdigraphProcessNodes{#1} + } + + \ifblank{#2}{% + % List is empty + }{% + \AdigraphProcessEdges{#2} + } + + \ifblank{\AdigraphAugmentingPaths}{% + % List is empty + }{% + \ifblank{#5}{% + \defcounter{AdigraphNumberOfPaths}{100000} + }{% + } + \forlistloop{\AdigraphCountPaths}{\AdigraphAugmentingPaths} + \forlistloop{\AdigraphProcessPaths}{\AdigraphAugmentingPaths} + } + + \ifblank{#2}{% + % List is empty + }{% + \forlistloop{\AdigraphEdgeDrawer}{\AdigraphEdgeList} + } + + %cuts + \ifblank{#4}{% + % List is empty + }{% + \AdigraphProcessCuts{#4} + } + \end{tikzpicture} } -\NewDocumentCommand{\NewAdigraph}{m m m}{ - % - % #1 -> Variable to assign to as command - % #2 -> Nodes - % #3 -> Edges - % - \expandafter\newcommand\csname #1\endcsname[2][]{ - % - % ##1 -> Modified edges - % - \smartGraph{#2}{#3}{##2}{##1} - }% +\NewDocumentCommand{\NewAdigraph}{m m G{}}{% + % + % #1 -> Variable to assign to as command + % #2 -> Nodes + % #3 -> Edges + % + \csdef{Adigraph#1AugmentingPaths}{}% + \expandafter\NewDocumentCommand{\AdigraphProcessAugmentingPaths}{m}{% + \listcsgadd{Adigraph#1AugmentingPaths}{##1} + } + \expandafter\NewDocumentCommand{\AdigraphProcessAugmentingPathsList}{> { \SplitList{;} } m}{% + \AdigraphProcessAugmentingPaths##1 + } + \expandafter\NewDocumentCommand\expandafter{\csname #1\endcsname}{m G{}}{% + % + % ##1 -> Augmenting path + % + \AdigraphProcessAugmentingPathsList{##1} + \Adigraph{#2}{#3}{Adigraph#1AugmentingPaths}{##2}{##1} + }% } \endinput |