-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
215 lines (213 loc) · 28.3 KB
/
index.html
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.6"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>LAL: Linear Arrangement Library: Documentation of the Linear Arrangement Library</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
extensions: ["tex2jax.js"],
jax: ["input/TeX","output/HTML-CSS"],
});
</script>
<script type="text/javascript" async="async" src="https://cdn.jsdelivr.net/npm/mathjax@2/MathJax.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr id="projectrow">
<td id="projectalign">
<div id="projectname">LAL: Linear Arrangement Library<span id="projectnumber"> 23.01.00</span>
</div>
<div id="projectbrief">A library focused on algorithms on linear arrangements of graphs.</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.6 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search/",'.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
$(function() {
initMenu('',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
</div><!-- top -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">Loading...</div>
<div class="SRStatus" id="Searching">Searching...</div>
<div class="SRStatus" id="NoMatches">No Matches</div>
</div>
</div>
</div>
</div>
<div><div class="header">
<div class="headertitle"><div class="title">Documentation of the Linear Arrangement Library </div></div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p >This library offers a variety of algorithms related to linear arrangements of graphs so as to provide researchers in the field of Quantitative Linguistics with a toolset with which they can perform statistical analyses on different corpora of treebanks efficiently and effectively. Therefore, this library implements several state-of-the-art algorithms and offers a variety of functionalities. While most of the functions have been generalised to be applicable to general graphs, we also provide specialised functions for trees, which are more efficient than their more general counterparts.</p>
<p >The main goal of this library is to provide algorithms with which the library's users can use to do statistical studies. One of the most attractive features offered in this library is that of treebank collection processing. This library offers a class that automatically processes a collection and computes several metrics based on the capabilities of the library. See class <a class="el" href="classlal_1_1io_1_1treebank__collection__processor.html">lal::io::treebank_collection_processor</a> and <a class="el" href="classlal_1_1io_1_1treebank__processor.html">lal::io::treebank_processor</a> for details. We also provide classes for custom processing of treebanks (see <a class="el" href="classlal_1_1io_1_1treebank__collection__reader.html">lal::io::treebank_collection_reader</a> and <a class="el" href="classlal_1_1io_1_1treebank__reader.html">lal::io::treebank_reader</a>).</p>
<p >All the features of syntactic dependency trees that can be calculated with the algorithms in this library are gathered in the namespaces <a class="el" href="namespacelal_1_1linarr.html">lal::linarr</a> and in <a class="el" href="namespacelal_1_1properties.html">lal::properties</a>. These features include, but are not limited to,</p><ul>
<li>the sum of edge lengths \(D\) (see <a class="el" href="namespacelal_1_1linarr.html#ab70693683a8da54a2e4350c665067cf1">lal::linarr::sum_edge_lengths</a>), and the expectation and variance of the sum of edge lengths (see <a class="el" href="namespacelal_1_1properties.html#a80c20fa410c8b9b216afe7f5241209a6">lal::properties::exp_sum_edge_lengths</a> and <a class="el" href="namespacelal_1_1properties.html#ade6a3f20263e2a982cfc5dc59facaf40" title="Computes the variance of the sum of the length of edges of a graph, .">lal::properties::var_sum_edge_lengths</a>),</li>
<li>the computation of optimal arrangements:<ul>
<li>minimum unconstrained arrangements with respect to the sum of edge lengths (see <a class="el" href="namespacelal_1_1linarr.html#a450d0dd41fec42a39bb1204ecedaaa91">lal::linarr::min_sum_edge_lengths</a>), with free choice on the algorithm to be used (see <a class="el" href="namespacelal_1_1linarr.html#a1c6a617eb12e032ee641fd390776ff3f">lal::linarr::algorithms_Dmin</a>),</li>
<li>minimum planar arrangements (see <a class="el" href="namespacelal_1_1linarr.html#a8ee049d439a7e8dd41ac0145679a84bb">lal::linarr::min_sum_edge_lengths_planar</a>), with free choice on the algorithm to be used (see <a class="el" href="namespacelal_1_1linarr.html#a4a49efcc64c3b63502ad8cc18d508ce3">lal::linarr::algorithms_Dmin_planar</a>),</li>
<li>minimum projective arrangements (see <a class="el" href="namespacelal_1_1linarr.html#aff8ac86ade398306f32ee39692ebfe4a">lal::linarr::min_sum_edge_lengths_projective</a>), with free choice on the algorithm to be used (see <a class="el" href="namespacelal_1_1linarr.html#a30bc00af5439a56f037ed84875f1911f">lal::linarr::algorithms_Dmin_projective</a>),</li>
<li>maximum planar arrangements (see <a class="el" href="namespacelal_1_1linarr.html#aadd6d6ed9cadb57228200d32c3a99191">lal::linarr::max_sum_edge_lengths_planar</a>),</li>
<li>maximum projective arrangements (see <a class="el" href="namespacelal_1_1linarr.html#a0886a4326be3b40cf34ee526514d60ab">lal::linarr::max_sum_edge_lengths_projective</a>),</li>
</ul>
</li>
<li>the number of crossings (see <a class="el" href="namespacelal_1_1linarr.html#a3806eb869914f45cf79c15e8aa7d2a51">lal::linarr::num_crossings</a>), and the expectation and variance of the number of crossings (see <a class="el" href="namespacelal_1_1properties.html#ab8ff16428584d88aba05a4b677444a4b">lal::properties::exp_num_crossings</a> and <a class="el" href="namespacelal_1_1properties.html#ad59eec82bbd716aefedc4453d82becd4" title="Computes the variance of the number of crossings of a graph in unconstrained arrangements,...">lal::properties::var_num_crossings</a>),</li>
<li>any moment of the degree of the vertices of a graph (see <a class="el" href="namespacelal_1_1properties.html#a389874693cfac1b4043e61a8f93792d1">lal::properties::moment_degree</a> and its variants),</li>
<li>the mean dependency distance (see <a class="el" href="namespacelal_1_1linarr.html#a2030c0f279ced9571405cebe5675e241">lal::linarr::mean_dependency_distance</a>),</li>
<li>the mean dependency distance over ensembles of graphs (see <a class="el" href="namespacelal_1_1linarr.html#a1f8c78736426eea6282258b26534c7e5">lal::linarr::mean_dependency_distance_1level</a> and <a class="el" href="namespacelal_1_1linarr.html#ac837af66d13aa3e2865a6737aec34e7a">lal::linarr::mean_dependency_distance_2level</a>),</li>
<li>the mean hierarchical distance (see <a class="el" href="namespacelal_1_1properties.html#a0c70ec4072e1df27592aa7a51876c1a9">lal::properties::mean_hierarchical_distance</a>),</li>
<li>the headedness of a tree (see <a class="el" href="namespacelal_1_1linarr.html#acc15417e84e2d272ca8d49a266929e12">lal::linarr::head_initial</a>),</li>
<li>the type of syntactic dependency trees according to their projectivity (see <a class="el" href="namespacelal_1_1linarr.html#a6c33c7725ebeca22b2489b29ebc78071">lal::linarr::syntactic_dependency_structure_class</a>).</li>
<li>calculation of the centre of a tree (see <a class="el" href="namespacelal_1_1properties.html#ada5517f223bcb1369b625a840dc9c8fa">lal::properties::tree_centre</a>), the centroid of a tree (see <a class="el" href="namespacelal_1_1properties.html#adda281d4c9e024ea87844756ffbd945e">lal::properties::tree_centroid</a>), a tree's diameter (see <a class="el" href="namespacelal_1_1properties.html#a3b40731d0c6eb1115f4ca7c655841078">lal::properties::tree_diameter</a>).</li>
</ul>
<p >As extra features, useful for experimentation, are the generation of different types of trees, all of which are available in the <a class="el" href="namespacelal_1_1generate.html">lal::generate</a> namespace. We have implemented existing techniques (cited accordingly) or made or own to enumerate</p><ul>
<li>all labelled/unlabelled free trees,</li>
<li>all labelled/unlabelled rooted trees,</li>
<li>all projective arrangements of rooted trees,</li>
<li>all planar arrangements of free trees,</li>
</ul>
<p >and to generate uniformly at random</p><ul>
<li>labelled/unlabelled free/rooted trees,</li>
<li>projective arrangements of rooted trees.</li>
<li>planar arrangements of free trees.</li>
</ul>
<p >The documentation of each class includes usage examples.</p>
<p >This library implements several types of graphs that can be found in the <a class="el" href="namespacelal_1_1graphs.html">lal::graphs</a> namespace.</p>
<h1><a class="anchor" id="MP_basic_DS"></a>
The basic data structures in this library</h1>
<p >In order to be able to use the library comfortably, its users must take good note of the different data structures that are the library's core.</p>
<p >With LAL, most metrics can be calculated as exact rational numbers (see <a class="el" href="classlal_1_1numeric_1_1rational.html">lal::numeric::rational</a>), but also as floating point values of double precision. For the former, add the suffix '_rational' at the end of the function name. For example, the function <a class="el" href="namespacelal_1_1properties.html#ad59eec82bbd716aefedc4453d82becd4">lal::properties::var_num_crossings</a> returns the variance of the number of crossings 'C' as a floating point value. By adding the suffix, i.e., <a class="el" href="namespacelal_1_1properties.html#a726f70a34d6950773beea9cdadf7e5c5">lal::properties::var_num_crossings_rational</a>, we obtain said variance as an exact rational value. To see what a rational value is in the context of this library, see the documentation of the namespace <a class="el" href="namespacelal_1_1numeric.html">lal::numeric</a>.</p>
<h2><a class="anchor" id="MP_basic_DS_integer_rational"></a>
Exact integer and rational arithmetic</h2>
<p >Most operations in this library are done using exact integer and rational arithmetic. Such arithmetic is powered by the GMP library (see <a class="el" href="citelist.html#CITEREF_GMP_library">[20]</a>). We have wrapped their C structures into the classes <a class="el" href="classlal_1_1numeric_1_1integer.html">lal::numeric::integer</a> and <a class="el" href="classlal_1_1numeric_1_1rational.html">lal::numeric::rational</a>.</p>
<h2><a class="anchor" id="MP_basic_DS_graphs"></a>
The different types of graphs</h2>
<p >As it should be expected, this library offers a number of different graph abstractions: undirected graphs (see <a class="el" href="classlal_1_1graphs_1_1undirected__graph.html">lal::graphs::undirected_graph</a>), directed graphs (see <a class="el" href="classlal_1_1graphs_1_1directed__graph.html">lal::graphs::directed_graph</a>), free trees (see <a class="el" href="classlal_1_1graphs_1_1free__tree.html">lal::graphs::free_tree</a>) and roted trees (see <a class="el" href="classlal_1_1graphs_1_1rooted__tree.html">lal::graphs::rooted_tree</a>), all of which can be found within the <a class="el" href="namespacelal_1_1graphs.html">lal::graphs</a> namespace.</p>
<h3><a class="anchor" id="MP_basic_DS_graphs_internal"></a>
The internal structure of graphs</h3>
<p >Although all graphs should be regarded as unlabelled, each node carries an implicit labelling. Such labelling has a most trivial nature since each node is labelled with a number between 0 and the total number of vertices minus one.</p>
<p >Due to most graphs being sparse, the data structure of choice are adjacency lists where each vertex has a list of neighbouring nodes, or simply neighbours, associated to it. The user can affect the order of appearance of neighbours in multiple ways. One of them is, evidently, the order in which edges are added. Another way is via the <a class="el" href="classlal_1_1graphs_1_1graph.html#a32fef69d99615a885bb8a0f421108c76">lal::graphs::graph::normalise</a> function, which sorts every list of neighbours increasingly by index. By default, the addition of edges is normalising, namely the following code</p>
<div class="fragment"><div class="line"><a class="code hl_class" href="classlal_1_1graphs_1_1free__tree.html">lal::graphs::free_tree</a> t(4);</div>
<div class="line">t.add_edge(0,1,<span class="keyword">false</span>,<span class="keyword">false</span>).add_edge(0,3,<span class="keyword">false</span>,<span class="keyword">false</span>).add_edge(0,2,<span class="keyword">false</span>,<span class="keyword">false</span>);</div>
<div class="line">t.normalise();</div>
<div class="line">cout << t << endl;</div>
<div class="ttc" id="aclasslal_1_1graphs_1_1free__tree_html"><div class="ttname"><a href="classlal_1_1graphs_1_1free__tree.html">lal::graphs::free_tree</a></div><div class="ttdoc">Free tree graph class.</div><div class="ttdef"><b>Definition:</b> free_tree.hpp:60</div></div>
</div><!-- fragment --><p >produces the same output as</p>
<div class="fragment"><div class="line"><a class="code hl_class" href="classlal_1_1graphs_1_1free__tree.html">lal::graphs::free_tree</a> t(4);</div>
<div class="line">t.add_edge(0,1).add_edge(0,3).add_edge(0,2);</div>
<div class="line">cout << t << endl;</div>
</div><!-- fragment --><p >which is</p>
<pre class="fragment">0: 1 2 3
1: 0
2: 0
3: 0
</pre><p >The output is easy to interpret: the first line indicates the nodes are incident to vertex 0, the second line indicates the nodes incident to vertex 1, and so on. Without normalisation (neither the call to <a class="el" href="classlal_1_1graphs_1_1graph.html#a32fef69d99615a885bb8a0f421108c76">lal::graphs::free_tree::normalise</a>, and using 'false' in the optional parameters), the output is</p>
<pre class="fragment">0: 1 3 2
1: 0
2: 0
3: 0
</pre><p >where only the first line changes.</p>
<p >Such normalisation is required by some of the algorithms in this library. Without proper normalisation, the algorithms are not likely to compute correct values. The parameter that governs the graphs' normalisation is called the normalisation parameter.</p>
<p >The adjacency list structure has been extended to directed graphs in a way that the user can query them for in-degree (see <a class="el" href="classlal_1_1graphs_1_1directed__graph.html#ad330c752a499f32d049308599000389b">lal::graphs::directed_graph::get_in_degree</a>) and in-neighbours (see <a class="el" href="classlal_1_1graphs_1_1directed__graph.html#a318d53241c954129917c7fd939407d6d">lal::graphs::directed_graph::get_in_neighbours</a>).</p>
<h1><a class="anchor" id="MP_terminology"></a>
Basic terminology and notation</h1>
<p ><b>NOTE</b> Pages <a class="el" href="LAL_notation.html">Notation in the library's documentation</a> and <a class="el" href="LAL_concepts.html">Important concepts in LAL</a> further explain everything there is to know about notation and concepts.</p>
<p >Users will note, after browsing through the library's documentation, that several concepts are quite ubiquitous. The <a class="el" href="namespacelal.html#ae5688e9acca02d5865dfc724e480ce25">lal::node</a> type is simply a typedef of an unsigned integer type, and the <a class="el" href="namespacelal.html#a5969ec7ecc85697ebb9ec0ace78fbcab">lal::edge</a> type is simply a STL's pair of nodes. Moreover, users need to have a deep understanding of what a head vector is (see <a class="el" href="namespacelal.html#a2eb5b7f5b50ff908a7a67889a9ea744d">lal::head_vector</a>), which is what allows users to easily read trees from files and process a file containing a large collection of trees (see <a class="el" href="namespacelal_1_1io.html">lal::io</a> namespace).</p>
<p >A more advanced concept is that of linear arrangement (see <a class="el" href="classlal_1_1linear__arrangement.html">lal::linear_arrangement</a>). In this library, a linear arrangement is viewed as a function that relates each node to a position in a linear sequence. Due to the properties of such functions, a linear arrangement is implemented with the STL's vector. Note that the concept of linear arrangement has been detached from that of trees, and the pair of a linear arrangement and a tree forms, in the context of the library, a syntactic dependency tree (this is why this class is not implemented). The symbol of choice for representing a linear arrangement in the library is the greek letter for the number pi \(\pi\).</p>
<p >Now, many functions (see those fuctions within the <a class="el" href="namespacelal_1_1linarr.html">lal::linarr</a> namespace) admit a linear arrangement which can be empty. Whenever it is empty, i.e., the value of the parameter is an empty vector, the positions of the nodes of the graphs in question are given by their implicit label. Such empty arrangement is called, in the context of the library, the identity arrangement symbolised with \(\pi_I\). Therefore, the following measurement of the sum of the lengths of the edges are equivalent</p>
<div class="fragment"><div class="line"><a class="code hl_class" href="classlal_1_1graphs_1_1free__tree.html">lal::graphs::free_tree</a> t(4);</div>
<div class="line">t.add_edges({<a class="code hl_typedef" href="namespacelal.html#a5969ec7ecc85697ebb9ec0ace78fbcab">lal::edge</a>(0,1), <a class="code hl_typedef" href="namespacelal.html#a5969ec7ecc85697ebb9ec0ace78fbcab">lal::edge</a>(1,2), <a class="code hl_typedef" href="namespacelal.html#a5969ec7ecc85697ebb9ec0ace78fbcab">lal::edge</a>(2,3)});</div>
<div class="line">uint64_t D1 = <a class="code hl_function" href="namespacelal_1_1linarr.html#ab70693683a8da54a2e4350c665067cf1">lal::linarr::sum_edge_lengths</a>(t);</div>
<div class="line">uint64_t D2 = <a class="code hl_function" href="namespacelal_1_1linarr.html#ab70693683a8da54a2e4350c665067cf1">lal::linarr::sum_edge_lengths</a>(t, {0,1,2,3});</div>
<div class="ttc" id="anamespacelal_1_1linarr_html_ab70693683a8da54a2e4350c665067cf1"><div class="ttname"><a href="namespacelal_1_1linarr.html#ab70693683a8da54a2e4350c665067cf1">lal::linarr::sum_edge_lengths</a></div><div class="ttdeci">uint64_t sum_edge_lengths(const graphs::directed_graph &g, const linear_arrangement &pi={}) noexcept</div><div class="ttdoc">Computes the sum of the length of the edges in a linear arrangement.</div></div>
<div class="ttc" id="anamespacelal_html_a5969ec7ecc85697ebb9ec0ace78fbcab"><div class="ttname"><a href="namespacelal.html#a5969ec7ecc85697ebb9ec0ace78fbcab">lal::edge</a></div><div class="ttdeci">std::pair< node, node > edge</div><div class="ttdoc">See Edge page for further details.</div><div class="ttdef"><b>Definition:</b> basic_types.hpp:58</div></div>
</div><!-- fragment --><p >The possibility of expliciting a linear arrangement increases the flexibility of the library. For example, for the purposes of illustration, one can calculate the expected sum of the length of the edges as follows</p>
<div class="fragment"><div class="line"><a class="code hl_class" href="classlal_1_1graphs_1_1free__tree.html">lal::graphs::free_tree</a> t(4);</div>
<div class="line">t.add_edges({<a class="code hl_typedef" href="namespacelal.html#a5969ec7ecc85697ebb9ec0ace78fbcab">lal::edge</a>(0,1), <a class="code hl_typedef" href="namespacelal.html#a5969ec7ecc85697ebb9ec0ace78fbcab">lal::edge</a>(1,2), <a class="code hl_typedef" href="namespacelal.html#a5969ec7ecc85697ebb9ec0ace78fbcab">lal::edge</a>(2,3)});</div>
<div class="line"><a class="code hl_class" href="classlal_1_1numeric_1_1rational.html">lal::numeric::rational</a> Dt = 0;</div>
<div class="line"><a class="code hl_class" href="classlal_1_1linear__arrangement.html">lal::linear_arrangement</a> arr({0,1,2,3});</div>
<div class="line"><span class="keywordflow">do</span> {</div>
<div class="line"> arr.<a class="code hl_function" href="classlal_1_1linear__arrangement.html#a71f927053906157a4bc62811bc51855a">update_inverse</a>();</div>
<div class="line"> Dt += <a class="code hl_function" href="namespacelal_1_1linarr.html#ab70693683a8da54a2e4350c665067cf1">lal::linarr::sum_edge_lengths</a>(t, arr);</div>
<div class="line">}</div>
<div class="line"><span class="keywordflow">while</span> (std::next_permutation(arr.begin_direct(), arr.end_direct()));</div>
<div class="line">Dt /= 24;</div>
<div class="ttc" id="aclasslal_1_1linear__arrangement_html"><div class="ttname"><a href="classlal_1_1linear__arrangement.html">lal::linear_arrangement</a></div><div class="ttdoc">Linear arrangement of vertices.</div><div class="ttdef"><b>Definition:</b> linear_arrangement.hpp:103</div></div>
<div class="ttc" id="aclasslal_1_1linear__arrangement_html_a71f927053906157a4bc62811bc51855a"><div class="ttname"><a href="classlal_1_1linear__arrangement.html#a71f927053906157a4bc62811bc51855a">lal::linear_arrangement::update_inverse</a></div><div class="ttdeci">void update_inverse() noexcept</div><div class="ttdoc">Updates the inverse arrangement using the direct arrangement.</div><div class="ttdef"><b>Definition:</b> linear_arrangement.hpp:474</div></div>
<div class="ttc" id="aclasslal_1_1numeric_1_1rational_html"><div class="ttname"><a href="classlal_1_1numeric_1_1rational.html">lal::numeric::rational</a></div><div class="ttdoc">Exact rational number.</div><div class="ttdef"><b>Definition:</b> rational.hpp:63</div></div>
</div><!-- fragment --><h1><a class="anchor" id="MP_effective_usage"></a>
Using the library effectively</h1>
<p >As a rule of the thumb, the user is encouraged not to change the default value of the parameters whenever they are given. However, certain operations can be less efficient than others, and sometimes it is even desirable to use values different from the default ones.</p>
<p >One the one hand, the wrong choice of operation can affect the library's performance gravely. For example, the addition/deletion of edges to/from graphs is slower when it is done edge by edge than when it is done in bulk. Users are highly encouraged to add/delete them in bulk using the appropriate functions (see, for example, <a class="el" href="classlal_1_1graphs_1_1undirected__graph.html#ad8255183f59620fe545c1e9a40cc02ca">lal::graphs::undirected_graph::add_edges</a> and <a class="el" href="classlal_1_1graphs_1_1undirected__graph.html#a34a2d08fad8a4ce2498e2101bafcc50b">lal::graphs::undirected_graph::remove_edges</a>). Although correct, the following code is discouraged</p>
<div class="fragment"><div class="line"><a class="code hl_class" href="classlal_1_1graphs_1_1free__tree.html">lal::graphs::free_tree</a> t(10);</div>
<div class="line"><a class="code hl_typedef" href="namespacelal.html#ae5688e9acca02d5865dfc724e480ce25">lal::node</a> u, v;</div>
<div class="line"><span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < 9; ++i) {</div>
<div class="line"> cin >> u >> v;</div>
<div class="line"> t.add_edge(u,v);</div>
<div class="line">}</div>
<div class="ttc" id="anamespacelal_html_ae5688e9acca02d5865dfc724e480ce25"><div class="ttname"><a href="namespacelal.html#ae5688e9acca02d5865dfc724e480ce25">lal::node</a></div><div class="ttdeci">uint64_t node</div><div class="ttdoc">Node type. See Node / Vertex page for further details.</div><div class="ttdef"><b>Definition:</b> basic_types.hpp:53</div></div>
</div><!-- fragment --><p >while the next piece of code is strongly encouraged whenever possible</p>
<div class="fragment"><div class="line"><a class="code hl_class" href="classlal_1_1graphs_1_1free__tree.html">lal::graphs::free_tree</a> t(10);</div>
<div class="line">vector<lal::edge> e(9);</div>
<div class="line"><span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < 9; ++i) {</div>
<div class="line"> cin >> e[i].first >> e[i].second;</div>
<div class="line">}</div>
<div class="line">t.set_edges(e);</div>
</div><!-- fragment --><p >A similar reasoning should be applied to the deletion of edges.</p>
<p >Furthermore, graphs are seldom required to be normalised. For example, when calculating the variance of \(C\) (see <a class="el" href="namespacelal_1_1properties.html#ad59eec82bbd716aefedc4453d82becd4">lal::properties::var_num_crossings</a>), it is mandatory that the graph be normalised, namely, the function has a precondition that requires the graph to be normalised. If such a function is to be called eventually then add all edges in bulk and with normalisation, or read the graph from disk also with normalisation. However, if such functions will never be called then the users are encouraged to set the normalisation parameter to false. For example, if the variance of \(C\) is to be calculated,</p>
<div class="fragment"><div class="line"><span class="keyword">const</span> <span class="keywordtype">string</span> filename = <span class="stringliteral">"..."</span>; <span class="comment">// a valid name of a file</span></div>
<div class="line"><span class="keyword">const</span> <a class="code hl_class" href="classlal_1_1graphs_1_1free__tree.html">lal::graphs::free_tree</a> t = *<a class="code hl_function" href="namespacelal_1_1io.html#a96f4f6a65fa430f95a84b60d01169178">lal::io::read_edge_list</a>(filename);</div>
<div class="line"><span class="keywordtype">double</span> var_C = <a class="code hl_function" href="namespacelal_1_1properties.html#ad59eec82bbd716aefedc4453d82becd4">lal::properties::var_num_crossings</a>(t);</div>
<div class="ttc" id="anamespacelal_1_1io_html_a96f4f6a65fa430f95a84b60d01169178"><div class="ttname"><a href="namespacelal_1_1io.html#a96f4f6a65fa430f95a84b60d01169178">lal::io::read_edge_list</a></div><div class="ttdeci">std::optional< graph_t > read_edge_list(const std::string &filename, bool norm=true, bool check_norm=true) noexcept</div><div class="ttdoc">Reads a graph in edge list format.</div><div class="ttdef"><b>Definition:</b> edge_list.hpp:159</div></div>
<div class="ttc" id="anamespacelal_1_1properties_html_ad59eec82bbd716aefedc4453d82becd4"><div class="ttname"><a href="namespacelal_1_1properties.html#ad59eec82bbd716aefedc4453d82becd4">lal::properties::var_num_crossings</a></div><div class="ttdeci">double var_num_crossings(const graphs::undirected_graph &g, bool reuse=true) noexcept</div><div class="ttdoc">Computes the variance of the number of crossings of a graph in unconstrained arrangements,...</div><div class="ttdef"><b>Definition:</b> C_rla.hpp:115</div></div>
</div><!-- fragment --><p >but if not</p>
<div class="fragment"><div class="line"><span class="keyword">const</span> <span class="keywordtype">string</span> filename = <span class="stringliteral">"..."</span>; <span class="comment">// a valid name of a file</span></div>
<div class="line"><span class="keyword">const</span> <a class="code hl_class" href="classlal_1_1graphs_1_1free__tree.html">lal::graphs::free_tree</a> t = *<a class="code hl_function" href="namespacelal_1_1io.html#a96f4f6a65fa430f95a84b60d01169178">lal::io::read_edge_list</a>(filename, <span class="keyword">false</span>);</div>
<div class="line"><span class="comment">// ...</span></div>
</div><!-- fragment --> </div></div><!-- PageDoc -->
</div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.6
</small></address>
</body>
</html>