summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/adigraph/README.md
blob: b2e269014deabb67faf3a8da5212d1fa952c8d2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# Smart Augmenting Graphs

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, 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:

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:

```bash
sudo tlmgr instal fp xparse xstring tikz
```

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:

```latex
\usepackage{adigraph}
```

Then, suppose you want to create a graph as the following:

![alt text][graph]

We start by defining a new graph:

```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;
    }
```

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:

```latex
\begin{figure}
    \center
    \myAdigraph{}
    \caption{My Personal Graph}
\end{figure}
```

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*:

```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}
```

The working example in latex is found in the file *adigraph_library_example.tex*.

The result with the cuts is the following:

![alt text][cuts]

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"