3443 lines
151 KiB
HTML
3443 lines
151 KiB
HTML
<html>
|
||
<head>
|
||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||
<title>Chapter 4. Basic data types and interface</title>
|
||
<meta name="generator" content="DocBook XSL Stylesheets Vsnapshot">
|
||
<link rel="home" href="index.html" title="igraph Reference Manual">
|
||
<link rel="up" href="index.html" title="igraph Reference Manual">
|
||
<link rel="prev" href="igraph-Tutorial.html" title="Chapter 3. Tutorial">
|
||
<link rel="next" href="igraph-Error.html" title="Chapter 5. Error handling">
|
||
<script type="text/javascript" src="toggle.js"></script><link rel="stylesheet" href="style.css" type="text/css">
|
||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" type="text/css">
|
||
<link rel="chapter" href="igraph-Introduction.html" title="Chapter 1. Introduction">
|
||
<link rel="chapter" href="igraph-Installation.html" title="Chapter 2. Installation">
|
||
<link rel="chapter" href="igraph-Tutorial.html" title="Chapter 3. Tutorial">
|
||
<link rel="chapter" href="igraph-Basic.html" title="Chapter 4. Basic data types and interface">
|
||
<link rel="chapter" href="igraph-Error.html" title="Chapter 5. Error handling">
|
||
<link rel="chapter" href="igraph-Memory.html" title="Chapter 6. Memory (de)allocation">
|
||
<link rel="chapter" href="igraph-Data-structures.html" title="Chapter 7. Data structure library: vector, matrix, other data types">
|
||
<link rel="chapter" href="igraph-Random.html" title="Chapter 8. Random numbers">
|
||
<link rel="chapter" href="igraph-Iterators.html" title="Chapter 9. Vertex and edge selectors and sequences, iterators">
|
||
<link rel="chapter" href="igraph-Attributes.html" title="Chapter 10. Graph, vertex and edge attributes">
|
||
<link rel="chapter" href="igraph-Generators.html" title="Chapter 11. Deterministic graph generators">
|
||
<link rel="chapter" href="igraph-Games.html" title='Chapter 12. Stochastic graph generators ("games")'>
|
||
<link rel="chapter" href="igraph-Bipartite.html" title="Chapter 13. Bipartite, i.e. two-mode graphs">
|
||
<link rel="chapter" href="igraph-Spatial.html" title="Chapter 14. Spatial graphs">
|
||
<link rel="chapter" href="igraph-Operators.html" title="Chapter 15. Graph operators">
|
||
<link rel="chapter" href="igraph-Visitors.html" title="Chapter 16. Graph visitors">
|
||
<link rel="chapter" href="igraph-Structural.html" title="Chapter 17. Structural properties of graphs">
|
||
<link rel="chapter" href="igraph-Cycles.html" title="Chapter 18. Graph cycles">
|
||
<link rel="chapter" href="igraph-Cliques.html" title="Chapter 19. Cliques and independent vertex sets">
|
||
<link rel="chapter" href="igraph-Motifs.html" title="Chapter 20. Graph motifs, dyad census and triad census">
|
||
<link rel="chapter" href="igraph-Isomorphism.html" title="Chapter 21. Graph isomorphism">
|
||
<link rel="chapter" href="igraph-Coloring.html" title="Chapter 22. Graph coloring">
|
||
<link rel="chapter" href="igraph-Flows.html" title="Chapter 23. Maximum flows, minimum cuts and related measures">
|
||
<link rel="chapter" href="igraph-Separators.html" title="Chapter 24. Vertex separators">
|
||
<link rel="chapter" href="igraph-Community.html" title="Chapter 25. Detecting community structure">
|
||
<link rel="chapter" href="igraph-Graphlets.html" title="Chapter 26. Graphlets">
|
||
<link rel="chapter" href="igraph-HRG.html" title="Chapter 27. Hierarchical random graphs">
|
||
<link rel="chapter" href="igraph-Embedding.html" title="Chapter 28. Embedding of graphs">
|
||
<link rel="chapter" href="igraph-Layout.html" title="Chapter 29. Generating layouts for graph drawing">
|
||
<link rel="chapter" href="igraph-Processes.html" title="Chapter 30. Processes on graphs">
|
||
<link rel="chapter" href="igraph-Foreign.html" title="Chapter 31. Reading and writing graphs from and to files">
|
||
<link rel="chapter" href="igraph-Linalg.html" title="Chapter 32. Using BLAS, LAPACK and ARPACK for igraph matrices and graphs">
|
||
<link rel="chapter" href="igraph-Nongraph.html" title="Chapter 33. Non-graph related functions">
|
||
<link rel="chapter" href="igraph-Advanced.html" title="Chapter 34. Advanced igraph programming">
|
||
<link rel="chapter" href="igraph-Glossary.html" title="Chapter 35. Glossary">
|
||
<link rel="chapter" href="igraph-Licenses.html" title="Chapter 36. Licenses for igraph and this manual">
|
||
<link rel="index" href="ix01.html" title="Index">
|
||
</head>
|
||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||
<div class="navigation-header mb-4" width="100%" summary="Navigation header"><div class="btn-group">
|
||
<a accesskey="p" class="btn btn-light" href="igraph-Tutorial.html"><i class="fa fa-chevron-left"></i>
|
||
Previous
|
||
</a><a accesskey="h" class="btn btn-light" href="index.html"><i class="fa fa-home"></i>
|
||
Home
|
||
</a><a accesskey="n" class="btn btn-light" href="igraph-Error.html"><i class="fa fa-chevron-right"></i>
|
||
Next
|
||
</a>
|
||
</div></div>
|
||
<div class="chapter">
|
||
<div class="titlepage"><div><div><h1 class="title">
|
||
<a name="igraph-Basic"></a>Chapter 4. Basic data types and interface</h1></div></div></div>
|
||
<div class="toc"><dl class="toc">
|
||
<dt><span class="section"><a href="igraph-Basic.html#igraph-data-model">1. The igraph data model</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Basic.html#igraph-functions">2. General conventions of igraph functions</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Basic.html#basic-data-types">3. Atomic data types</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Basic.html#id-1.5.5">4. Setup and initialization</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Basic.html#basic-interface">5. The basic interface</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Basic.html#misc-helper-functions">6. Miscellaneous macros and helper functions</a></span></dt>
|
||
</dl></div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||
<a name="igraph-data-model"></a>1. The igraph data model</h2></div></div></div>
|
||
<p>
|
||
The igraph library can handle directed and
|
||
undirected graphs. The igraph graphs are multisets
|
||
of ordered (if directed) or unordered (if undirected) labeled pairs.
|
||
The labels of the pairs plus the number of vertices always starts with
|
||
zero and ends with the number of edges minus one. In addition to that,
|
||
a table of metadata is also attached to every graph, its most
|
||
important entries being the number of vertices in the graph and whether
|
||
the graph is directed or undirected.
|
||
</p>
|
||
<p>
|
||
Like the edges, the igraph vertices are also
|
||
labeled by numbers between zero and the number of vertices minus one.
|
||
So, to summarize, a directed graph can be imagined like this:
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
( vertices: 6,
|
||
directed: yes,
|
||
{
|
||
(0,2),
|
||
(2,2),
|
||
(3,2),
|
||
(3,3),
|
||
(3,4),
|
||
(3,4),
|
||
(4,3),
|
||
(4,1)
|
||
}
|
||
)
|
||
</pre></div>
|
||
<p>
|
||
Here the edges are ordered pairs or vertex ids, and the graph is a multiset
|
||
of edges plus some metadata.
|
||
</p>
|
||
<p>
|
||
An undirected graph is like this:
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
( vertices: 6,
|
||
directed: no,
|
||
{
|
||
(0,2),
|
||
(2,2),
|
||
(2,3),
|
||
(3,3),
|
||
(3,4),
|
||
(3,4),
|
||
(3,4),
|
||
(1,4)
|
||
}
|
||
)
|
||
</pre></div>
|
||
<p>
|
||
Here, an edge is an unordered pair of two vertex IDs. A graph is a multiset
|
||
of edges plus metadata, just like in the directed case.
|
||
</p>
|
||
<p>It is possible to convert between directed and undirected graphs,
|
||
see the <a class="link" href="igraph-Structural.html#igraph_to_directed" title="18.1. igraph_to_directed — Convert an undirected graph to a directed one.">
|
||
<code class="function">igraph_to_directed()</code></a>
|
||
and <a class="link" href="igraph-Structural.html#igraph_to_undirected" title="18.2. igraph_to_undirected — Convert a directed graph to an undirected one.">
|
||
<code class="function">igraph_to_undirected()</code></a> functions.
|
||
</p>
|
||
<p>igraph aims to robustly support multigraphs, i.e. graphs which
|
||
have more than one edge between some pairs of vertices, as well as
|
||
graphs with self-loops. Most functions which do not support such graphs
|
||
will check their input and issue an error if it is not valid. Those
|
||
rare functions which do not perform this check clearly indicate this
|
||
in their documentation. To eliminate multiple edges from a graph, you can use
|
||
<a class="link" href="igraph-Operators.html#igraph_simplify" title="3.11. igraph_simplify — Removes loop and/or multiple edges from the graph.">
|
||
<code class="function">igraph_simplify()</code></a>.
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||
<a name="igraph-functions"></a>2. General conventions of igraph functions</h2></div></div></div>
|
||
<p>
|
||
igraph has a simple and consistent interface. Most functions check
|
||
their input for validity and display an informative error message
|
||
when something goes wrong. In order to support this, the majority of functions
|
||
return an error code. In basic usage, this code can be ignored, as the
|
||
default behaviour is to abort the program immediately upon error. See
|
||
<a class="link" href="igraph-Error.html" title="Chapter 5. Error handling">the section on error handling</a> for
|
||
more information on this topic.
|
||
</p>
|
||
<p>
|
||
Results are typically returned through <span class="emphasis"><em>output arguments</em></span>,
|
||
i.e. pointers to a data structure into which the result will be written.
|
||
In almost all cases, this data structure is expected to be pre-initialized.
|
||
A few simple functions communicate their result directly through their return
|
||
value—these functions can never encounter an error.
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||
<a name="basic-data-types"></a>3. Atomic data types</h2></div></div></div>
|
||
<a class="indexterm" name="id-1.5.4.2"></a><p>
|
||
igraph introduces a few aliases to standard C data types that are then used
|
||
throughout the library. The most important of these types is
|
||
<span class="type">igraph_int_t</span>, which is an alias to either a 32-bit or a 64-bit
|
||
<span class="emphasis"><em>signed</em></span> integer, depending on whether igraph was compiled
|
||
in 32-bit or 64-bit mode. The size of <span class="type">igraph_int_t</span> also
|
||
influences the maximum number of vertices that an igraph graph can represent
|
||
as the number of vertices is stored in a variable of type
|
||
<span class="type">igraph_int_t</span>.
|
||
</p>
|
||
<p>
|
||
Before igraph 1.0, <span class="type">igraph_int_t</span> was called <span class="type">igraph_integer_t</span>.
|
||
This is still available as an alias to <span class="type">igraph_int_t</span> and will remain
|
||
accessible until at least version 2.0 of the library.
|
||
</p>
|
||
<p>Since the size of a variable of type <span class="type">igraph_int_t</span> may
|
||
change depending on how igraph is compiled, you cannot simply use
|
||
<code class="code">%d</code> or <code class="code">%ld</code> as a placeholder for igraph integers in
|
||
<code class="code">printf</code> format strings. igraph provides the
|
||
<code class="code">IGRAPH_PRId</code> macro, which maps to <code class="code">d</code>, <code class="code">ld</code>
|
||
or <code class="code">lld</code> depending on the size of <span class="type">igraph_int_t</span>, and
|
||
you must use this macro in <code class="code">printf</code> format strings to avoid compiler
|
||
warnings.
|
||
</p>
|
||
<a class="indexterm" name="id-1.5.4.6"></a><p>Similarly to how <span class="type">igraph_int_t</span> maps to the standard size
|
||
signed integer in the library, <span class="type">igraph_uint_t</span> maps to a 32-bit or
|
||
a 64-bit <span class="emphasis"><em>unsigned</em></span> integer. It is guaranteed that the size of
|
||
<span class="type">igraph_int_t</span> is the same as the size of <span class="type">igraph_uint_t</span>.
|
||
igraph provides <code class="code">IGRAPH_PRIu</code> as a format string placeholder for
|
||
variables of type <span class="type">igraph_uint_t</span>.
|
||
</p>
|
||
<a class="indexterm" name="id-1.5.4.8"></a><p>Real numbers (i.e. quantities that can potentially be fractional or
|
||
infinite) are represented with a type named <span class="type">igraph_real_t</span>. Currently
|
||
<span class="type">igraph_real_t</span> is always aliased to <span class="type">double</span>, but it is
|
||
still good practice to use <span class="type">igraph_real_t</span> in your own code for sake
|
||
of consistency.</p>
|
||
<a class="indexterm" name="id-1.5.4.10"></a><p>Boolean values are represented with a type named <span class="type">igraph_bool_t</span>.
|
||
It tries to be as small as possible since it only needs to represent a truth
|
||
value. For printing purposes, you can treat it as an integer and use
|
||
<code class="code">%d</code> in format strings as a placeholder for an <span class="type">igraph_bool_t</span>.
|
||
</p>
|
||
<a class="indexterm" name="id-1.5.4.12"></a><a class="indexterm" name="id-1.5.4.13"></a><a class="indexterm" name="id-1.5.4.14"></a><a class="indexterm" name="id-1.5.4.15"></a><p>
|
||
Upper and lower limits of <span class="type">igraph_int_t</span> and
|
||
<span class="type">igraph_uint_t</span> are provided by the constants named
|
||
<code class="constant">IGRAPH_INTEGER_MIN</code>, <code class="constant">IGRAPH_INTEGER_MAX</code>,
|
||
<code class="constant">IGRAPH_UINT_MIN</code> and <code class="constant">IGRAPH_UINT_MAX</code>.
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||
<a name="id-1.5.5"></a>4. Setup and initialization</h2></div></div></div>
|
||
<div class="toc"><dl class="toc"><dt><span class="section"><a href="igraph-Basic.html#igraph_setup">4.1. <code class="function">igraph_setup</code> — Initializes the igraph library.</a></span></dt></dl></div>
|
||
<p>
|
||
Certain parts of igraph must be initialized before first use, which can be
|
||
accomplished using the setup functions below. As of igraph 1.0, most functions
|
||
will work correctly even if setup is not performed, as currently the only setup
|
||
action is seeding the random number generator. That said, it is strongly
|
||
recommended to call
|
||
<a class="link" href="igraph-Basic.html#igraph_setup" title="4.1. igraph_setup — Initializes the igraph library."><code class="function">igraph_setup()</code></a>
|
||
before using any other function, as future igraph versions may add critical
|
||
initialization steps.
|
||
</p>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h3 class="title">
|
||
<a name="igraph_setup"></a>4.1. <code class="function">igraph_setup</code> — Initializes the igraph library.</h3></div></div></div>
|
||
<a class="indexterm" name="id-1.5.5.3.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_setup(void);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
|
||
This function is a convenience function to call all setup functions that are
|
||
provided by the igraph library.
|
||
|
||
</p>
|
||
<p>
|
||
Most of the library functions will work even if this function is not called,
|
||
but it is recommended to call it before using any igraph functions that may
|
||
use random numbers, such as graph generators or random sampling functions.
|
||
This function initializes the random number generator with a seed based on
|
||
the current time, ensuring that the random numbers generated by igraph are
|
||
different each time the program is run.
|
||
|
||
</p>
|
||
<p><b>Returns: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
Error code; currently always <code class="constant">IGRAPH_SUCCESS</code>.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
</p>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||
<a name="basic-interface"></a>5. The basic interface</h2></div></div></div>
|
||
<div class="toc"><dl class="toc">
|
||
<dt><span class="section"><a href="igraph-Basic.html#graph-constructors-and-destructors">5.1. Graph constructors and destructors</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Basic.html#basic-query-operations">5.2. Basic query operations</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Basic.html#adding-and-deleting-vertices-and-edges">5.3. Adding and deleting vertices and edges</a></span></dt>
|
||
</dl></div>
|
||
<p>This is the very minimal API in <span class="command"><strong>igraph</strong></span>. All the other
|
||
functions use this minimal set for creating and manipulating
|
||
graphs.</p>
|
||
<p>This is a very important principle since it makes possible to
|
||
implement other data representations by implementing only this
|
||
minimal set.</p>
|
||
<p>This section lists all the functions and macros that are considered
|
||
as part of the core API from the point of view of the <span class="emphasis"><em>users</em></span>
|
||
of igraph. Some of these functions and macros have sensible default
|
||
implementations that simply call some other core function (e.g.,
|
||
<a class="link" href="igraph-Basic.html#igraph_empty" title="5.1.1. igraph_empty — Creates an empty graph with some vertices and no edges."><code class="function">igraph_empty()</code></a> calls <a class="link" href="igraph-Basic.html#igraph_empty_attrs" title="5.1.2. igraph_empty_attrs — Creates an empty graph with some vertices, no edges and some graph attributes."><code class="function">igraph_empty_attrs()</code></a> with a null attribute
|
||
table pointer). If you wish to experiment with implementing an alternative
|
||
data type, the actual number of functions that you need to replace is lower
|
||
as you can rely on the same default implementations in most cases.</p>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h3 class="title">
|
||
<a name="graph-constructors-and-destructors"></a>5.1. Graph constructors and destructors</h3></div></div></div>
|
||
<div class="toc"><dl class="toc">
|
||
<dt><span class="section"><a href="igraph-Basic.html#igraph_empty">5.1.1. <code class="function">igraph_empty</code> — Creates an empty graph with some vertices and no edges.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Basic.html#igraph_empty_attrs">5.1.2. <code class="function">igraph_empty_attrs</code> — Creates an empty graph with some vertices, no edges and some graph attributes.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Basic.html#igraph_copy">5.1.3. <code class="function">igraph_copy</code> — Creates an exact (deep) copy of a graph.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Basic.html#igraph_destroy">5.1.4. <code class="function">igraph_destroy</code> — Frees the memory allocated for a graph object.</a></span></dt>
|
||
</dl></div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="igraph_empty"></a>5.1.1. <code class="function">igraph_empty</code> — Creates an empty graph with some vertices and no edges.</h4></div></div></div>
|
||
<a class="indexterm" name="id-1.5.6.5.2.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_empty(igraph_t *graph, igraph_int_t n, igraph_bool_t directed);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
|
||
</p>
|
||
<p>
|
||
The most basic constructor, all the other constructors should call
|
||
this to create a minimal graph object. Our use of the term "empty graph"
|
||
in the above description should be distinguished from the mathematical
|
||
definition of the empty or null graph. Strictly speaking, the empty or null
|
||
graph in graph theory is the graph with no vertices and no edges. However
|
||
by "empty graph" as used in <span class="command"><strong>igraph</strong></span> we mean a graph having zero or more
|
||
vertices, but no edges.
|
||
</p>
|
||
<p><b>Arguments: </b>
|
||
</p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>graph</code></em>:</span></p></td>
|
||
<td><p>
|
||
Pointer to a not-yet initialized graph object.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>n</code></em>:</span></p></td>
|
||
<td><p>
|
||
The number of vertices in the graph, a non-negative
|
||
integer number is expected.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>directed</code></em>:</span></p></td>
|
||
<td>
|
||
<p>
|
||
Boolean; whether the graph is directed or not. Supported
|
||
values are:
|
||
</p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">IGRAPH_DIRECTED</code></span></p></td>
|
||
<td><p>
|
||
|
||
The graph will be <span class="emphasis"><em>directed.</em></span>
|
||
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">IGRAPH_UNDIRECTED</code></span></p></td>
|
||
<td><p>
|
||
|
||
The graph will be <span class="emphasis"><em>undirected.</em></span>
|
||
|
||
</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<p>
|
||
</p>
|
||
</td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<p>
|
||
</p>
|
||
<p><b>Returns: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
Error code:
|
||
<code class="constant">IGRAPH_EINVAL</code>: invalid number of vertices.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
Time complexity: O(|V|) for a graph with
|
||
|V| vertices (and no edges).
|
||
|
||
</p>
|
||
<div class="hideshow" onClick="toggle(this, event)">
|
||
<div class="example">
|
||
<a name="id-1.5.6.5.2.9.1"></a><p class="title"><b>Example 4.1. File <code class="code">examples/simple/creation.c</code></b></p>
|
||
<div class="example-contents">
|
||
<pre class="programlisting"><span class="strong"><strong>#include</strong></span> <igraph.h>
|
||
<span class="strong"><strong>#include</strong></span> <assert.h>
|
||
|
||
int <span class="strong"><strong>main</strong></span>(void) {
|
||
igraph_t graph;
|
||
igraph_vector_int_t edges;
|
||
|
||
<span class="emphasis"><em>/* Initialize the library. */</em></span>
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_setup" title="4.1. igraph_setup — Initializes the igraph library.">igraph_setup</a></strong></span>();
|
||
|
||
<span class="emphasis"><em>/* Create a directed graph with no vertices or edges. */</em></span>
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_empty" title="5.1.1. igraph_empty — Creates an empty graph with some vertices and no edges.">igraph_empty</a></strong></span>(&graph, 0, IGRAPH_DIRECTED);
|
||
|
||
<span class="emphasis"><em>/* Add 5 vertices. Vertex IDs will range from 0 to 4, inclusive. */</em></span>
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_add_vertices" title="5.3.3. igraph_add_vertices — Adds vertices to a graph.">igraph_add_vertices</a></strong></span>(&graph, 5, NULL);
|
||
|
||
<span class="emphasis"><em>/* Add 5 edges, specified as 5 consecutive pairs of vertex IDs</em></span>
|
||
<span class="emphasis"><em> * stored in an integer vector. */</em></span>
|
||
<span class="strong"><strong>igraph_vector_int_init_int</strong></span>(&edges, 10,
|
||
0,1, 0,2, 3,1, 2,1, 0,4);
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_add_edges" title="5.3.2. igraph_add_edges — Adds edges to a graph object.">igraph_add_edges</a></strong></span>(&graph, &edges, NULL);
|
||
|
||
<span class="strong"><strong>igraph_vector_int_destroy</strong></span>(&edges);
|
||
|
||
<span class="emphasis"><em>/* Now the graph has 5 vertices and 5 edges. */</em></span>
|
||
<span class="strong"><strong>assert</strong></span>(<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_vcount" title="5.2.1. igraph_vcount — The number of vertices in a graph.">igraph_vcount</a></strong></span>(&graph) == 5);
|
||
<span class="strong"><strong>assert</strong></span>(<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_ecount" title="5.2.2. igraph_ecount — The number of edges in a graph.">igraph_ecount</a></strong></span>(&graph) == 5);
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_destroy" title="5.1.4. igraph_destroy — Frees the memory allocated for a graph object.">igraph_destroy</a></strong></span>(&graph);
|
||
|
||
<span class="strong"><strong>return</strong></span> 0;
|
||
}
|
||
</pre>
|
||
<p></p>
|
||
</div>
|
||
</div>
|
||
<br class="example-break">
|
||
</div>
|
||
<p>
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="igraph_empty_attrs"></a>5.1.2. <code class="function">igraph_empty_attrs</code> — Creates an empty graph with some vertices, no edges and some graph attributes.</h4></div></div></div>
|
||
<a class="indexterm" name="id-1.5.6.5.3.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_empty_attrs(
|
||
igraph_t *graph, igraph_int_t n, igraph_bool_t directed,
|
||
const igraph_attribute_record_list_t *attr
|
||
);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
|
||
Use this instead of <a class="link" href="igraph-Basic.html#igraph_empty" title="5.1.1. igraph_empty — Creates an empty graph with some vertices and no edges."><code class="function">igraph_empty()</code></a> if you wish to add some graph
|
||
attributes right after initialization. This function is currently
|
||
not very interesting for the ordinary user. Just supply 0 here or
|
||
use <a class="link" href="igraph-Basic.html#igraph_empty" title="5.1.1. igraph_empty — Creates an empty graph with some vertices and no edges."><code class="function">igraph_empty()</code></a>.
|
||
|
||
</p>
|
||
<p>
|
||
This function does not set any vertex attributes. To create a graph which has
|
||
vertex attributes, call this function specifying 0 vertices, then use
|
||
<a class="link" href="igraph-Basic.html#igraph_add_vertices" title="5.3.3. igraph_add_vertices — Adds vertices to a graph."><code class="function">igraph_add_vertices()</code></a> to add vertices and their attributes.
|
||
|
||
</p>
|
||
<p><b>Arguments: </b>
|
||
</p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>graph</code></em>:</span></p></td>
|
||
<td><p>
|
||
Pointer to a not-yet initialized graph object.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>n</code></em>:</span></p></td>
|
||
<td><p>
|
||
The number of vertices in the graph; a non-negative
|
||
integer number is expected.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>directed</code></em>:</span></p></td>
|
||
<td>
|
||
<p>
|
||
Boolean; whether the graph is directed or not. Supported
|
||
values are:
|
||
</p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">IGRAPH_DIRECTED</code></span></p></td>
|
||
<td><p>
|
||
|
||
Create a <span class="emphasis"><em>directed</em></span> graph.
|
||
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">IGRAPH_UNDIRECTED</code></span></p></td>
|
||
<td><p>
|
||
|
||
Create an <span class="emphasis"><em>undirected</em></span> graph.
|
||
|
||
</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<p>
|
||
</p>
|
||
</td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>attr</code></em>:</span></p></td>
|
||
<td><p>
|
||
The graph attributes. Supply <code class="constant">NULL</code> if not graph attributes
|
||
are to be set.
|
||
</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<p>
|
||
</p>
|
||
<p><b>Returns: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
Error code:
|
||
<code class="constant">IGRAPH_EINVAL</code>: invalid number of vertices.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
</p>
|
||
<p><b>See also: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
<a class="link" href="igraph-Basic.html#igraph_empty" title="5.1.1. igraph_empty — Creates an empty graph with some vertices and no edges."><code class="function">igraph_empty()</code></a> to create an empty graph without attributes;
|
||
<a class="link" href="igraph-Basic.html#igraph_add_vertices" title="5.3.3. igraph_add_vertices — Adds vertices to a graph."><code class="function">igraph_add_vertices()</code></a> and <a class="link" href="igraph-Basic.html#igraph_add_edges" title="5.3.2. igraph_add_edges — Adds edges to a graph object."><code class="function">igraph_add_edges()</code></a> to add vertices
|
||
and edges, possibly with associated attributes.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
Time complexity: O(|V|) for a graph with
|
||
|V| vertices (and no edges).
|
||
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="igraph_copy"></a>5.1.3. <code class="function">igraph_copy</code> — Creates an exact (deep) copy of a graph.</h4></div></div></div>
|
||
<a class="indexterm" name="id-1.5.6.5.4.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_copy(igraph_t *to, const igraph_t *from);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
|
||
</p>
|
||
<p>
|
||
This function deeply copies a graph object to create an exact
|
||
replica of it. The new replica should be destroyed by calling
|
||
<a class="link" href="igraph-Basic.html#igraph_destroy" title="5.1.4. igraph_destroy — Frees the memory allocated for a graph object."><code class="function">igraph_destroy()</code></a> on it when not needed any more.
|
||
|
||
</p>
|
||
<p>
|
||
You can also create a shallow copy of a graph by simply using the
|
||
standard assignment operator, but be careful and do <span class="emphasis"><em>not</em></span>
|
||
destroy a shallow replica. To avoid this mistake, creating shallow
|
||
copies is not recommended.
|
||
</p>
|
||
<p><b>Arguments: </b>
|
||
</p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>to</code></em>:</span></p></td>
|
||
<td><p>
|
||
Pointer to an uninitialized graph object.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>from</code></em>:</span></p></td>
|
||
<td><p>
|
||
Pointer to the graph object to copy.
|
||
</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<p>
|
||
</p>
|
||
<p><b>Returns: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
Error code.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
Time complexity: O(|V|+|E|) for a
|
||
graph with |V| vertices and
|
||
|E| edges.
|
||
|
||
</p>
|
||
<div class="hideshow" onClick="toggle(this, event)">
|
||
<div class="example">
|
||
<a name="id-1.5.6.5.4.10.1"></a><p class="title"><b>Example 4.2. File <code class="code">examples/simple/igraph_copy.c</code></b></p>
|
||
<div class="example-contents">
|
||
<pre class="programlisting"><span class="strong"><strong>#include</strong></span> <igraph.h>
|
||
|
||
int <span class="strong"><strong>main</strong></span>(void) {
|
||
|
||
igraph_t g1, g2;
|
||
igraph_vector_int_t v1, v2;
|
||
|
||
<span class="emphasis"><em>/* Initialize the library. */</em></span>
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_setup" title="4.1. igraph_setup — Initializes the igraph library.">igraph_setup</a></strong></span>();
|
||
|
||
<span class="strong"><strong>igraph_vector_int_init</strong></span>(&v1, 8);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#VECTOR" title="2.4.1. VECTOR — Accessing an element of a vector.">VECTOR</a></strong></span>(v1)[0] = 0;
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#VECTOR" title="2.4.1. VECTOR — Accessing an element of a vector.">VECTOR</a></strong></span>(v1)[1] = 1;
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#VECTOR" title="2.4.1. VECTOR — Accessing an element of a vector.">VECTOR</a></strong></span>(v1)[2] = 1;
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#VECTOR" title="2.4.1. VECTOR — Accessing an element of a vector.">VECTOR</a></strong></span>(v1)[3] = 2;
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#VECTOR" title="2.4.1. VECTOR — Accessing an element of a vector.">VECTOR</a></strong></span>(v1)[4] = 2;
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#VECTOR" title="2.4.1. VECTOR — Accessing an element of a vector.">VECTOR</a></strong></span>(v1)[5] = 3;
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#VECTOR" title="2.4.1. VECTOR — Accessing an element of a vector.">VECTOR</a></strong></span>(v1)[6] = 2;
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#VECTOR" title="2.4.1. VECTOR — Accessing an element of a vector.">VECTOR</a></strong></span>(v1)[7] = 2;
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Generators.html#igraph_create" title="2.1. igraph_create — Creates a graph with the specified edges.">igraph_create</a></strong></span>(&g1, &v1, 0, 0);
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_copy" title="5.1.3. igraph_copy — Creates an exact (deep) copy of a graph.">igraph_copy</a></strong></span>(&g2, &g1);
|
||
|
||
<span class="strong"><strong>igraph_vector_int_init</strong></span>(&v2, 0);
|
||
<span class="strong"><strong><a class="link" href="igraph-Structural.html#igraph_get_edgelist" title="26.11. igraph_get_edgelist — The list of edges in a graph.">igraph_get_edgelist</a></strong></span>(&g2, &v2, 0);
|
||
<span class="strong"><strong>if</strong></span> (!<span class="strong"><strong>igraph_vector_int_all_e</strong></span>(&v1, &v2)) {
|
||
<span class="strong"><strong>return</strong></span> 1;
|
||
}
|
||
|
||
<span class="strong"><strong>igraph_vector_int_destroy</strong></span>(&v1);
|
||
<span class="strong"><strong>igraph_vector_int_destroy</strong></span>(&v2);
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_destroy" title="5.1.4. igraph_destroy — Frees the memory allocated for a graph object.">igraph_destroy</a></strong></span>(&g1);
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_destroy" title="5.1.4. igraph_destroy — Frees the memory allocated for a graph object.">igraph_destroy</a></strong></span>(&g2);
|
||
|
||
<span class="strong"><strong>return</strong></span> 0;
|
||
}
|
||
</pre>
|
||
<p></p>
|
||
</div>
|
||
</div>
|
||
<br class="example-break">
|
||
</div>
|
||
<p>
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="igraph_destroy"></a>5.1.4. <code class="function">igraph_destroy</code> — Frees the memory allocated for a graph object.</h4></div></div></div>
|
||
<a class="indexterm" name="id-1.5.6.5.5.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
void igraph_destroy(igraph_t *graph);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
|
||
</p>
|
||
<p>
|
||
This function should be called for every graph object exactly once.
|
||
|
||
</p>
|
||
<p>
|
||
This function invalidates all iterators (of course), but the
|
||
iterators of a graph should be destroyed before the graph itself
|
||
anyway.
|
||
</p>
|
||
<p><b>Arguments: </b>
|
||
</p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code>graph</code></em>:</span></p></td>
|
||
<td><p>
|
||
Pointer to the graph to free.</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
|
||
Time complexity: operating system specific.
|
||
|
||
</p>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h3 class="title">
|
||
<a name="basic-query-operations"></a>5.2. Basic query operations</h3></div></div></div>
|
||
<div class="toc"><dl class="toc">
|
||
<dt><span class="section"><a href="igraph-Basic.html#igraph_vcount">5.2.1. <code class="function">igraph_vcount</code> — The number of vertices in a graph.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Basic.html#igraph_ecount">5.2.2. <code class="function">igraph_ecount</code> — The number of edges in a graph.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Basic.html#igraph_is_directed">5.2.3. <code class="function">igraph_is_directed</code> — Is this a directed graph?</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Basic.html#igraph_edge">5.2.4. <code class="function">igraph_edge</code> — Returns the head and tail vertices of an edge.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Basic.html#igraph_edges">5.2.5. <code class="function">igraph_edges</code> — Gives the head and tail vertices of a series of edges.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Basic.html#IGRAPH_FROM">5.2.6. <code class="function">IGRAPH_FROM</code> — The source vertex of an edge.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Basic.html#IGRAPH_TO">5.2.7. <code class="function">IGRAPH_TO</code> — The target vertex of an edge.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Basic.html#IGRAPH_OTHER">5.2.8. <code class="function">IGRAPH_OTHER</code> — The other endpoint of an edge.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Basic.html#igraph_get_eid">5.2.9. <code class="function">igraph_get_eid</code> — Get the edge ID from the endpoints of an edge.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Basic.html#igraph_get_eids">5.2.10. <code class="function">igraph_get_eids</code> — Return edge IDs based on the adjacent vertices.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Basic.html#igraph_get_all_eids_between">5.2.11. <code class="function">igraph_get_all_eids_between</code> — Returns all edge IDs between a pair of vertices.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Basic.html#igraph_neighbors">5.2.12. <code class="function">igraph_neighbors</code> — Adjacent vertices to a vertex.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Basic.html#igraph_incident">5.2.13. <code class="function">igraph_incident</code> — Gives the incident edges of a vertex.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Basic.html#igraph_degree">5.2.14. <code class="function">igraph_degree</code> — The degree of some vertices in a graph.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Basic.html#igraph_degree_1">5.2.15. <code class="function">igraph_degree_1</code> — The degree of of a single vertex in the graph.</a></span></dt>
|
||
</dl></div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="igraph_vcount"></a>5.2.1. <code class="function">igraph_vcount</code> — The number of vertices in a graph.</h4></div></div></div>
|
||
<a class="indexterm" name="id-1.5.6.6.2.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_int_t igraph_vcount(const igraph_t *graph);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
|
||
</p>
|
||
<p><b>Arguments: </b>
|
||
</p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code>graph</code></em>:</span></p></td>
|
||
<td><p>
|
||
The graph.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
</p>
|
||
<p><b>Returns: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
Number of vertices.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
Time complexity: O(1)
|
||
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="igraph_ecount"></a>5.2.2. <code class="function">igraph_ecount</code> — The number of edges in a graph.</h4></div></div></div>
|
||
<a class="indexterm" name="id-1.5.6.6.3.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_int_t igraph_ecount(const igraph_t *graph);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
|
||
</p>
|
||
<p><b>Arguments: </b>
|
||
</p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code>graph</code></em>:</span></p></td>
|
||
<td><p>
|
||
The graph.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
</p>
|
||
<p><b>Returns: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
Number of edges.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
Time complexity: O(1)
|
||
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="igraph_is_directed"></a>5.2.3. <code class="function">igraph_is_directed</code> — Is this a directed graph?</h4></div></div></div>
|
||
<a class="indexterm" name="id-1.5.6.6.4.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_bool_t igraph_is_directed(const igraph_t *graph);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
|
||
</p>
|
||
<p><b>Arguments: </b>
|
||
</p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code>graph</code></em>:</span></p></td>
|
||
<td><p>
|
||
The graph.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
</p>
|
||
<p><b>Returns: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
Boolean value, <code class="constant">true</code> if the graph is directed,
|
||
<code class="constant">false</code> otherwise.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
Time complexity: O(1)
|
||
|
||
</p>
|
||
<div class="hideshow" onClick="toggle(this, event)">
|
||
<div class="example">
|
||
<a name="id-1.5.6.6.4.8.1"></a><p class="title"><b>Example 4.3. File <code class="code">examples/simple/igraph_is_directed.c</code></b></p>
|
||
<div class="example-contents">
|
||
<pre class="programlisting"><span class="strong"><strong>#include</strong></span> <igraph.h>
|
||
|
||
int <span class="strong"><strong>main</strong></span>(void) {
|
||
|
||
igraph_t g;
|
||
|
||
<span class="emphasis"><em>/* Initialize the library. */</em></span>
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_setup" title="4.1. igraph_setup — Initializes the igraph library.">igraph_setup</a></strong></span>();
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_empty" title="5.1.1. igraph_empty — Creates an empty graph with some vertices and no edges.">igraph_empty</a></strong></span>(&g, 0, 0);
|
||
<span class="strong"><strong>if</strong></span> (<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_is_directed" title="5.2.3. igraph_is_directed — Is this a directed graph?">igraph_is_directed</a></strong></span>(&g)) {
|
||
<span class="strong"><strong>return</strong></span> 1;
|
||
}
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_destroy" title="5.1.4. igraph_destroy — Frees the memory allocated for a graph object.">igraph_destroy</a></strong></span>(&g);
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_empty" title="5.1.1. igraph_empty — Creates an empty graph with some vertices and no edges.">igraph_empty</a></strong></span>(&g, 0, 1);
|
||
<span class="strong"><strong>if</strong></span> (!<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_is_directed" title="5.2.3. igraph_is_directed — Is this a directed graph?">igraph_is_directed</a></strong></span>(&g)) {
|
||
<span class="strong"><strong>return</strong></span> 2;
|
||
}
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_destroy" title="5.1.4. igraph_destroy — Frees the memory allocated for a graph object.">igraph_destroy</a></strong></span>(&g);
|
||
|
||
<span class="strong"><strong>return</strong></span> 0;
|
||
}
|
||
</pre>
|
||
<p></p>
|
||
</div>
|
||
</div>
|
||
<br class="example-break">
|
||
</div>
|
||
<p>
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="igraph_edge"></a>5.2.4. <code class="function">igraph_edge</code> — Returns the head and tail vertices of an edge.</h4></div></div></div>
|
||
<a class="indexterm" name="id-1.5.6.6.5.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_edge(
|
||
const igraph_t *graph, igraph_int_t eid,
|
||
igraph_int_t *from, igraph_int_t *to
|
||
);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
</p>
|
||
<p><b>Arguments: </b>
|
||
</p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>graph</code></em>:</span></p></td>
|
||
<td><p>
|
||
The graph object.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>eid</code></em>:</span></p></td>
|
||
<td><p>
|
||
The edge ID.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>from</code></em>:</span></p></td>
|
||
<td><p>
|
||
Pointer to an <span class="type">igraph_int_t</span>. The tail (source) of
|
||
the edge will be placed here.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>to</code></em>:</span></p></td>
|
||
<td><p>
|
||
Pointer to an <span class="type">igraph_int_t</span>. The head (target) of the
|
||
edge will be placed here.
|
||
</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<p>
|
||
</p>
|
||
<p><b>Returns: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
Error code.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
</p>
|
||
<p><b>See also: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
<a class="link" href="igraph-Basic.html#igraph_get_eid" title="5.2.9. igraph_get_eid — Get the edge ID from the endpoints of an edge."><code class="function">igraph_get_eid()</code></a> for the opposite operation;
|
||
<a class="link" href="igraph-Basic.html#igraph_edges" title="5.2.5. igraph_edges — Gives the head and tail vertices of a series of edges."><code class="function">igraph_edges()</code></a> to get the endpoints of several edges;
|
||
<a class="link" href="igraph-Basic.html#IGRAPH_TO" title="5.2.7. IGRAPH_TO — The target vertex of an edge."><code class="function">IGRAPH_TO()</code></a>, <a class="link" href="igraph-Basic.html#IGRAPH_FROM" title="5.2.6. IGRAPH_FROM — The source vertex of an edge."><code class="function">IGRAPH_FROM()</code></a> and <a class="link" href="igraph-Basic.html#IGRAPH_OTHER" title="5.2.8. IGRAPH_OTHER — The other endpoint of an edge."><code class="function">IGRAPH_OTHER()</code></a> for
|
||
a faster but non-error-checked version.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
Added in version 0.2.</p>
|
||
<p>
|
||
|
||
Time complexity: O(1).
|
||
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="igraph_edges"></a>5.2.5. <code class="function">igraph_edges</code> — Gives the head and tail vertices of a series of edges.</h4></div></div></div>
|
||
<a class="indexterm" name="id-1.5.6.6.6.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_edges(
|
||
const igraph_t *graph, igraph_es_t eids, igraph_vector_int_t *edges,
|
||
igraph_bool_t bycol
|
||
);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
</p>
|
||
<p><b>Arguments: </b>
|
||
</p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>graph</code></em>:</span></p></td>
|
||
<td><p>
|
||
The graph object.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>eids</code></em>:</span></p></td>
|
||
<td><p>
|
||
Edge selector, the series of edges.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>edges</code></em>:</span></p></td>
|
||
<td><p>
|
||
Pointer to an initialized vector. The start and endpoints of
|
||
each edge will be placed here.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>bycol</code></em>:</span></p></td>
|
||
<td><p>
|
||
Boolean constant. If true, the edges will be returned
|
||
columnwise, e.g. the first edge is
|
||
<code class="literal">res[0]->res[|E|]</code>, the second is
|
||
<code class="literal">res[1]->res[|E|+1]</code>, etc. Supply false to get
|
||
the edge list in a format compatible with <a class="link" href="igraph-Basic.html#igraph_add_edges" title="5.3.2. igraph_add_edges — Adds edges to a graph object."><code class="function">igraph_add_edges()</code></a>.
|
||
</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<p>
|
||
</p>
|
||
<p><b>Returns: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
Error code.
|
||
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p></p>
|
||
<p><b>See also: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
<a class="link" href="igraph-Basic.html#igraph_get_eids" title="5.2.10. igraph_get_eids — Return edge IDs based on the adjacent vertices."><code class="function">igraph_get_eids()</code></a> for the opposite operation;
|
||
<a class="link" href="igraph-Basic.html#igraph_edge" title="5.2.4. igraph_edge — Returns the head and tail vertices of an edge."><code class="function">igraph_edge()</code></a> for getting the endpoints of a single edge;
|
||
<a class="link" href="igraph-Basic.html#IGRAPH_TO" title="5.2.7. IGRAPH_TO — The target vertex of an edge."><code class="function">IGRAPH_TO()</code></a>, <a class="link" href="igraph-Basic.html#IGRAPH_FROM" title="5.2.6. IGRAPH_FROM — The source vertex of an edge."><code class="function">IGRAPH_FROM()</code></a> and <a class="link" href="igraph-Basic.html#IGRAPH_OTHER" title="5.2.8. IGRAPH_OTHER — The other endpoint of an edge."><code class="function">IGRAPH_OTHER()</code></a> for
|
||
a faster but non-error-checked method.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
Time complexity: O(k) where k is the number of edges in the selector.
|
||
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="IGRAPH_FROM"></a>5.2.6. <code class="function">IGRAPH_FROM</code> — The source vertex of an edge.</h4></div></div></div>
|
||
<a class="indexterm" name="id-1.5.6.6.7.2"></a><p>
|
||
</p>
|
||
<pre class="programlisting">
|
||
#define IGRAPH_FROM(graph,eid)
|
||
</pre>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
Faster than <a class="link" href="igraph-Basic.html#igraph_edge" title="5.2.4. igraph_edge — Returns the head and tail vertices of an edge."><code class="function">igraph_edge()</code></a>, but no error checking is done: <em class="parameter"><code>eid</code></em> is assumed to be valid.
|
||
|
||
</p>
|
||
<p><b>Arguments: </b>
|
||
</p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>graph</code></em>:</span></p></td>
|
||
<td><p>
|
||
The graph.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>eid</code></em>:</span></p></td>
|
||
<td><p>
|
||
The edge ID.
|
||
</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<p>
|
||
</p>
|
||
<p><b>Returns: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
The source vertex of the edge.
|
||
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p></p>
|
||
<p><b>See also: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
<a class="link" href="igraph-Basic.html#igraph_edge" title="5.2.4. igraph_edge — Returns the head and tail vertices of an edge."><code class="function">igraph_edge()</code></a> if error checking is desired.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="IGRAPH_TO"></a>5.2.7. <code class="function">IGRAPH_TO</code> — The target vertex of an edge.</h4></div></div></div>
|
||
<a class="indexterm" name="id-1.5.6.6.8.2"></a><p>
|
||
</p>
|
||
<pre class="programlisting">
|
||
#define IGRAPH_TO(graph,eid)
|
||
</pre>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
Faster than <a class="link" href="igraph-Basic.html#igraph_edge" title="5.2.4. igraph_edge — Returns the head and tail vertices of an edge."><code class="function">igraph_edge()</code></a>, but no error checking is done: <em class="parameter"><code>eid</code></em> is assumed to be valid.
|
||
|
||
</p>
|
||
<p><b>Arguments: </b>
|
||
</p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>graph</code></em>:</span></p></td>
|
||
<td><p>
|
||
The graph object.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>eid</code></em>:</span></p></td>
|
||
<td><p>
|
||
The edge ID.
|
||
</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<p>
|
||
</p>
|
||
<p><b>Returns: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
The target vertex of the edge.
|
||
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p></p>
|
||
<p><b>See also: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
<a class="link" href="igraph-Basic.html#igraph_edge" title="5.2.4. igraph_edge — Returns the head and tail vertices of an edge."><code class="function">igraph_edge()</code></a> if error checking is desired.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="IGRAPH_OTHER"></a>5.2.8. <code class="function">IGRAPH_OTHER</code> — The other endpoint of an edge.</h4></div></div></div>
|
||
<a class="indexterm" name="id-1.5.6.6.9.2"></a><p>
|
||
</p>
|
||
<pre class="programlisting">
|
||
#define IGRAPH_OTHER(graph,eid,vid)
|
||
</pre>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
Typically used with undirected edges when one endpoint of the edge is known,
|
||
and the other endpoint is needed. No error checking is done:
|
||
<em class="parameter"><code>eid</code></em> and <em class="parameter"><code>vid</code></em> are assumed to be valid.
|
||
|
||
</p>
|
||
<p><b>Arguments: </b>
|
||
</p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>graph</code></em>:</span></p></td>
|
||
<td><p>
|
||
The graph object.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>eid</code></em>:</span></p></td>
|
||
<td><p>
|
||
The edge ID.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>vid</code></em>:</span></p></td>
|
||
<td><p>
|
||
The vertex ID of one endpoint of an edge.
|
||
</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<p>
|
||
</p>
|
||
<p><b>Returns: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
The other endpoint of the edge.
|
||
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p></p>
|
||
<p><b>See also: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
<a class="link" href="igraph-Basic.html#IGRAPH_TO" title="5.2.7. IGRAPH_TO — The target vertex of an edge."><code class="function">IGRAPH_TO()</code></a> and <a class="link" href="igraph-Basic.html#IGRAPH_FROM" title="5.2.6. IGRAPH_FROM — The source vertex of an edge."><code class="function">IGRAPH_FROM()</code></a> to get the source and target
|
||
of directed edges.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="igraph_get_eid"></a>5.2.9. <code class="function">igraph_get_eid</code> — Get the edge ID from the endpoints of an edge.</h4></div></div></div>
|
||
<a class="indexterm" name="id-1.5.6.6.10.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_get_eid(const igraph_t *graph, igraph_int_t *eid,
|
||
igraph_int_t from, igraph_int_t to,
|
||
igraph_bool_t directed, igraph_bool_t error);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
For undirected graphs <code class="constant">from</code> and <code class="constant">to</code> are exchangeable.
|
||
|
||
</p>
|
||
<p><b>Arguments: </b>
|
||
</p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>graph</code></em>:</span></p></td>
|
||
<td><p>
|
||
The graph object.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>eid</code></em>:</span></p></td>
|
||
<td><p>
|
||
Pointer to an integer, the edge ID will be stored here.
|
||
If <em class="parameter"><code>error</code></em> is false and no edge was found, <code class="literal">-1</code>
|
||
will be returned.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>from</code></em>:</span></p></td>
|
||
<td><p>
|
||
The starting point of the edge.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>to</code></em>:</span></p></td>
|
||
<td><p>
|
||
The end point of the edge.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>directed</code></em>:</span></p></td>
|
||
<td><p>
|
||
Boolean, whether to search for directed
|
||
edges in a directed graph. Ignored for undirected graphs.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>error</code></em>:</span></p></td>
|
||
<td><p>
|
||
Boolean, whether to report an error if the edge
|
||
was not found. If it is false, then <code class="literal">-1</code> will be
|
||
assigned to <em class="parameter"><code>eid</code></em>. Note that invalid vertex IDs in input
|
||
arguments (<em class="parameter"><code>from</code></em> or <em class="parameter"><code>to</code></em>) always trigger an error,
|
||
regardless of this setting.
|
||
</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<p>
|
||
</p>
|
||
<p><b>Returns: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
Error code.
|
||
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p></p>
|
||
<p><b>See also: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
<a class="link" href="igraph-Basic.html#igraph_edge" title="5.2.4. igraph_edge — Returns the head and tail vertices of an edge."><code class="function">igraph_edge()</code></a> for the opposite operation, <a class="link" href="igraph-Basic.html#igraph_get_all_eids_between" title="5.2.11. igraph_get_all_eids_between — Returns all edge IDs between a pair of vertices."><code class="function">igraph_get_all_eids_between()</code></a>
|
||
to retrieve all edge IDs between a pair of vertices.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
Time complexity: O(log (d)), where d is smaller of the out-degree
|
||
of <code class="constant">from</code> and in-degree of <code class="constant">to</code> if <em class="parameter"><code>directed</code></em> is true. If <em class="parameter"><code>directed</code></em>
|
||
is false, then it is O(log(d)+log(d2)), where d is the same as before and
|
||
d2 is the minimum of the out-degree of <code class="constant">to</code> and the in-degree of <code class="constant">from</code>.
|
||
|
||
</p>
|
||
<div class="hideshow" onClick="toggle(this, event)">
|
||
<div class="example">
|
||
<a name="id-1.5.6.6.10.10.7"></a><p class="title"><b>Example 4.4. File <code class="code">examples/simple/igraph_get_eid.c</code></b></p>
|
||
<div class="example-contents">
|
||
<pre class="programlisting"><span class="strong"><strong>#include</strong></span> <igraph.h>
|
||
|
||
int <span class="strong"><strong>main</strong></span>(void) {
|
||
igraph_t graph;
|
||
igraph_int_t eid;
|
||
igraph_vector_int_t hist;
|
||
|
||
<span class="emphasis"><em>/* Initialize the library. */</em></span>
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_setup" title="4.1. igraph_setup — Initializes the igraph library.">igraph_setup</a></strong></span>();
|
||
|
||
<span class="emphasis"><em>/* DIRECTED */</em></span>
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Generators.html#igraph_star" title="4.1. igraph_star — Creates a star graph, every vertex connects only to the center.">igraph_star</a></strong></span>(&graph, 10, IGRAPH_STAR_OUT, 0);
|
||
|
||
<span class="strong"><strong>igraph_vector_int_init</strong></span>(&hist, 9);
|
||
|
||
<span class="strong"><strong>for</strong></span> (igraph_int_t i = 1; i < 10; i++) {
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_get_eid" title="5.2.9. igraph_get_eid — Get the edge ID from the endpoints of an edge.">igraph_get_eid</a></strong></span>(&graph, &eid, 0, i, IGRAPH_DIRECTED, <span class="emphasis"><em>/*error=*/</em></span> true);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#VECTOR" title="2.4.1. VECTOR — Accessing an element of a vector.">VECTOR</a></strong></span>(hist)[eid] = 1;
|
||
}
|
||
|
||
<span class="strong"><strong>igraph_vector_int_print</strong></span>(&hist);
|
||
|
||
<span class="strong"><strong>igraph_vector_int_destroy</strong></span>(&hist);
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_destroy" title="5.1.4. igraph_destroy — Frees the memory allocated for a graph object.">igraph_destroy</a></strong></span>(&graph);
|
||
|
||
<span class="emphasis"><em>/* UNDIRECTED */</em></span>
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Generators.html#igraph_star" title="4.1. igraph_star — Creates a star graph, every vertex connects only to the center.">igraph_star</a></strong></span>(&graph, 10, IGRAPH_STAR_UNDIRECTED, 0);
|
||
|
||
<span class="strong"><strong>igraph_vector_int_init</strong></span>(&hist, 9);
|
||
|
||
<span class="strong"><strong>for</strong></span> (igraph_int_t i = 1; i < 10; i++) {
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_get_eid" title="5.2.9. igraph_get_eid — Get the edge ID from the endpoints of an edge.">igraph_get_eid</a></strong></span>(&graph, &eid, 0, i, IGRAPH_UNDIRECTED, <span class="emphasis"><em>/*error=*/</em></span> true);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#VECTOR" title="2.4.1. VECTOR — Accessing an element of a vector.">VECTOR</a></strong></span>(hist)[eid] += 1;
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_get_eid" title="5.2.9. igraph_get_eid — Get the edge ID from the endpoints of an edge.">igraph_get_eid</a></strong></span>(&graph, &eid, i, 0, IGRAPH_DIRECTED, <span class="emphasis"><em>/*error=*/</em></span> true);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#VECTOR" title="2.4.1. VECTOR — Accessing an element of a vector.">VECTOR</a></strong></span>(hist)[eid] += 1;
|
||
}
|
||
<span class="strong"><strong>igraph_vector_int_print</strong></span>(&hist);
|
||
|
||
<span class="strong"><strong>igraph_vector_int_destroy</strong></span>(&hist);
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_destroy" title="5.1.4. igraph_destroy — Frees the memory allocated for a graph object.">igraph_destroy</a></strong></span>(&graph);
|
||
|
||
<span class="strong"><strong>return</strong></span> 0;
|
||
}
|
||
</pre>
|
||
<p></p>
|
||
</div>
|
||
</div>
|
||
<br class="example-break">
|
||
</div>
|
||
<p>
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="igraph_get_eids"></a>5.2.10. <code class="function">igraph_get_eids</code> — Return edge IDs based on the adjacent vertices.</h4></div></div></div>
|
||
<a class="indexterm" name="id-1.5.6.6.11.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_get_eids(const igraph_t *graph, igraph_vector_int_t *eids,
|
||
const igraph_vector_int_t *pairs,
|
||
igraph_bool_t directed, igraph_bool_t error);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
The pairs of vertex IDs for which the edges are looked up are taken
|
||
consecutively from the <code class="constant">pairs</code> vector, i.e. <code class="literal">VECTOR(pairs)[0]</code>
|
||
and <code class="literal">VECTOR(pairs)[1]</code> specify the first pair,
|
||
<code class="literal">VECTOR(pairs)[2]</code> and <code class="literal">VECTOR(pairs)[3]</code> the second
|
||
pair, etc.
|
||
|
||
</p>
|
||
<p>
|
||
If you have a sequence of vertex IDs that describe a <span class="emphasis"><em>path</em></span> on the graph,
|
||
use <a class="link" href="igraph-Basic.html#igraph_expand_path_to_pairs" title='6.4. igraph_expand_path_to_pairs — Helper function to convert a sequence of vertex IDs describing a path into a "pairs" vector.'><code class="function">igraph_expand_path_to_pairs()</code></a> to convert them to a list of vertex
|
||
pairs along the path.
|
||
|
||
</p>
|
||
<p>
|
||
If the <code class="constant">error</code> argument is true, then it is an error to specify pairs
|
||
of vertices that are not connected. Otherwise -1 is reported for vertex pairs
|
||
without at least one edge between them.
|
||
|
||
</p>
|
||
<p>
|
||
If there are multiple edges in the graph, then these are ignored;
|
||
i.e. for a given pair of vertex IDs, igraph always returns the same edge ID,
|
||
even if the pair appears multiple times in <code class="constant">pairs</code>.
|
||
|
||
</p>
|
||
<p><b>Arguments: </b>
|
||
</p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>graph</code></em>:</span></p></td>
|
||
<td><p>
|
||
The input graph.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>eids</code></em>:</span></p></td>
|
||
<td><p>
|
||
Pointer to an initialized vector, the result is stored
|
||
here. It will be resized as needed.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>pairs</code></em>:</span></p></td>
|
||
<td><p>
|
||
Vector giving pairs of vertices to fetch the edges for.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>directed</code></em>:</span></p></td>
|
||
<td><p>
|
||
Boolean, whether to consider edge directions
|
||
in directed graphs. This is ignored for undirected graphs.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>error</code></em>:</span></p></td>
|
||
<td><p>
|
||
Boolean, whether it is an error to supply
|
||
non-connected vertices. If false, then -1 is
|
||
returned for non-connected pairs.
|
||
</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<p>
|
||
</p>
|
||
<p><b>Returns: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
Error code.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
Time complexity: O(n log(d)), where n is the number of queried
|
||
edges and d is the average degree of the vertices.
|
||
|
||
</p>
|
||
<p><b>See also: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
<a class="link" href="igraph-Basic.html#igraph_get_eid" title="5.2.9. igraph_get_eid — Get the edge ID from the endpoints of an edge."><code class="function">igraph_get_eid()</code></a> for a single edge.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
</p>
|
||
<div class="hideshow" onClick="toggle(this, event)">
|
||
<div class="example">
|
||
<a name="id-1.5.6.6.11.13.1"></a><p class="title"><b>Example 4.5. File <code class="code">examples/simple/igraph_get_eids.c</code></b></p>
|
||
<div class="example-contents">
|
||
<pre class="programlisting"><span class="strong"><strong>#include</strong></span> <igraph.h>
|
||
<span class="strong"><strong>#include</strong></span> <stdlib.h>
|
||
|
||
int <span class="strong"><strong>main</strong></span>(void) {
|
||
igraph_t g;
|
||
igraph_int_t nodes = 100;
|
||
igraph_int_t edges = 1000;
|
||
igraph_real_t p = 3.0 / nodes;
|
||
igraph_int_t runs = 10;
|
||
igraph_int_t r, e, ecount;
|
||
igraph_vector_int_t eids, pairs, path;
|
||
|
||
<span class="emphasis"><em>/* Initialize the library. */</em></span>
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_setup" title="4.1. igraph_setup — Initializes the igraph library.">igraph_setup</a></strong></span>();
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Random.html#igraph_rng_seed" title="3.3. igraph_rng_seed — Seeds a random number generator.">igraph_rng_seed</a></strong></span>(<span class="strong"><strong><a class="link" href="igraph-Random.html#igraph_rng_default" title="2.1. igraph_rng_default — Query the default random number generator.">igraph_rng_default</a></strong></span>(), 42); <span class="emphasis"><em>/* make tests deterministic */</em></span>
|
||
|
||
<span class="strong"><strong>igraph_vector_int_init</strong></span>(&pairs, edges * 2);
|
||
<span class="strong"><strong>igraph_vector_int_init</strong></span>(&path, 0);
|
||
<span class="strong"><strong>igraph_vector_int_init</strong></span>(&eids, 0);
|
||
|
||
<span class="strong"><strong>for</strong></span> (r = 0; r < runs; r++) {
|
||
<span class="strong"><strong>igraph_vector_int_resize</strong></span>(&pairs, edges * 2);
|
||
<span class="strong"><strong>igraph_vector_int_clear</strong></span>(&path);
|
||
<span class="strong"><strong>igraph_vector_int_clear</strong></span>(&eids);
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Games.html#igraph_erdos_renyi_game_gnp" title="1.2. igraph_erdos_renyi_game_gnp — Generates a random (Erdős-Rényi) graph with fixed edge probabilities.">igraph_erdos_renyi_game_gnp</a></strong></span>(&g, nodes, p, IGRAPH_UNDIRECTED, IGRAPH_SIMPLE_SW, IGRAPH_EDGE_UNLABELED);
|
||
ecount = <span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_ecount" title="5.2.2. igraph_ecount — The number of edges in a graph.">igraph_ecount</a></strong></span>(&g);
|
||
<span class="strong"><strong>for</strong></span> (e = 0; e < edges; e++) {
|
||
igraph_int_t edge = <span class="strong"><strong>RNG_INTEGER</strong></span>(0, ecount - 1);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#VECTOR" title="2.4.1. VECTOR — Accessing an element of a vector.">VECTOR</a></strong></span>(pairs)[2 * e] = <span class="strong"><strong><a class="link" href="igraph-Basic.html#IGRAPH_FROM" title="5.2.6. IGRAPH_FROM — The source vertex of an edge.">IGRAPH_FROM</a></strong></span>(&g, edge);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#VECTOR" title="2.4.1. VECTOR — Accessing an element of a vector.">VECTOR</a></strong></span>(pairs)[2 * e + 1] = <span class="strong"><strong><a class="link" href="igraph-Basic.html#IGRAPH_TO" title="5.2.7. IGRAPH_TO — The target vertex of an edge.">IGRAPH_TO</a></strong></span>(&g, edge);
|
||
}
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_get_eids" title="5.2.10. igraph_get_eids — Return edge IDs based on the adjacent vertices.">igraph_get_eids</a></strong></span>(&g, &eids, &pairs, IGRAPH_UNDIRECTED, <span class="emphasis"><em>/*error=*/</em></span> true);
|
||
<span class="strong"><strong>for</strong></span> (e = 0; e < edges; e++) {
|
||
igraph_int_t edge = <span class="strong"><strong><a class="link" href="igraph-Data-structures.html#VECTOR" title="2.4.1. VECTOR — Accessing an element of a vector.">VECTOR</a></strong></span>(eids)[e];
|
||
igraph_int_t from1 = <span class="strong"><strong><a class="link" href="igraph-Data-structures.html#VECTOR" title="2.4.1. VECTOR — Accessing an element of a vector.">VECTOR</a></strong></span>(pairs)[2 * e];
|
||
igraph_int_t to1 = <span class="strong"><strong><a class="link" href="igraph-Data-structures.html#VECTOR" title="2.4.1. VECTOR — Accessing an element of a vector.">VECTOR</a></strong></span>(pairs)[2 * e + 1];
|
||
igraph_int_t from2 = <span class="strong"><strong><a class="link" href="igraph-Basic.html#IGRAPH_FROM" title="5.2.6. IGRAPH_FROM — The source vertex of an edge.">IGRAPH_FROM</a></strong></span>(&g, edge);
|
||
igraph_int_t to2 = <span class="strong"><strong><a class="link" href="igraph-Basic.html#IGRAPH_TO" title="5.2.7. IGRAPH_TO — The target vertex of an edge.">IGRAPH_TO</a></strong></span>(&g, edge);
|
||
igraph_int_t min1 = from1 < to1 ? from1 : to1;
|
||
igraph_int_t max1 = from1 < to1 ? to1 : from1;
|
||
igraph_int_t min2 = from2 < to2 ? from2 : to2;
|
||
igraph_int_t max2 = from2 < to2 ? to2 : from2;
|
||
<span class="strong"><strong>if</strong></span> (min1 != min2 || max1 != max2) {
|
||
<span class="strong"><strong>return</strong></span> 11;
|
||
}
|
||
}
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Structural.html#igraph_diameter" title="3.22. igraph_diameter — Calculates the weighted diameter of a graph using Dijkstra's algorithm.">igraph_diameter</a></strong></span>(&g, <span class="emphasis"><em>/*weights=*/</em></span> NULL, <span class="emphasis"><em>/*res=*/</em></span> NULL, <span class="emphasis"><em>/*from=*/</em></span> NULL, <span class="emphasis"><em>/*to=*/</em></span> NULL, &path, NULL,
|
||
IGRAPH_UNDIRECTED, <span class="emphasis"><em>/*unconn=*/</em></span> true);
|
||
<span class="strong"><strong>igraph_vector_int_update</strong></span>(&pairs, &path);
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_expand_path_to_pairs" title='6.4. igraph_expand_path_to_pairs — Helper function to convert a sequence of vertex IDs describing a path into a "pairs" vector.'>igraph_expand_path_to_pairs</a></strong></span>(&pairs);
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_get_eids" title="5.2.10. igraph_get_eids — Return edge IDs based on the adjacent vertices.">igraph_get_eids</a></strong></span>(&g, &eids, &pairs, <span class="emphasis"><em>/* directed= */</em></span> false, <span class="emphasis"><em>/*error=*/</em></span> true);
|
||
<span class="strong"><strong>for</strong></span> (e = 0; e < <span class="strong"><strong>igraph_vector_int_size</strong></span>(&path) - 1; e++) {
|
||
igraph_int_t edge = <span class="strong"><strong><a class="link" href="igraph-Data-structures.html#VECTOR" title="2.4.1. VECTOR — Accessing an element of a vector.">VECTOR</a></strong></span>(eids)[e];
|
||
igraph_int_t from1 = <span class="strong"><strong><a class="link" href="igraph-Data-structures.html#VECTOR" title="2.4.1. VECTOR — Accessing an element of a vector.">VECTOR</a></strong></span>(path)[e];
|
||
igraph_int_t to1 = <span class="strong"><strong><a class="link" href="igraph-Data-structures.html#VECTOR" title="2.4.1. VECTOR — Accessing an element of a vector.">VECTOR</a></strong></span>(path)[e + 1];
|
||
igraph_int_t from2 = <span class="strong"><strong><a class="link" href="igraph-Basic.html#IGRAPH_FROM" title="5.2.6. IGRAPH_FROM — The source vertex of an edge.">IGRAPH_FROM</a></strong></span>(&g, edge);
|
||
igraph_int_t to2 = <span class="strong"><strong><a class="link" href="igraph-Basic.html#IGRAPH_TO" title="5.2.7. IGRAPH_TO — The target vertex of an edge.">IGRAPH_TO</a></strong></span>(&g, edge);
|
||
igraph_int_t min1 = from1 < to1 ? from1 : to1;
|
||
igraph_int_t max1 = from1 < to1 ? to1 : from1;
|
||
igraph_int_t min2 = from2 < to2 ? from2 : to2;
|
||
igraph_int_t max2 = from2 < to2 ? to2 : from2;
|
||
<span class="strong"><strong>if</strong></span> (min1 != min2 || max1 != max2) {
|
||
<span class="strong"><strong>return</strong></span> 12;
|
||
}
|
||
}
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_destroy" title="5.1.4. igraph_destroy — Frees the memory allocated for a graph object.">igraph_destroy</a></strong></span>(&g);
|
||
}
|
||
|
||
<span class="strong"><strong>igraph_vector_int_destroy</strong></span>(&path);
|
||
<span class="strong"><strong>igraph_vector_int_destroy</strong></span>(&pairs);
|
||
<span class="strong"><strong>igraph_vector_int_destroy</strong></span>(&eids);
|
||
|
||
<span class="strong"><strong>return</strong></span> 0;
|
||
}
|
||
</pre>
|
||
<p></p>
|
||
</div>
|
||
</div>
|
||
<br class="example-break">
|
||
</div>
|
||
<p>
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="igraph_get_all_eids_between"></a>5.2.11. <code class="function">igraph_get_all_eids_between</code> — Returns all edge IDs between a pair of vertices.</h4></div></div></div>
|
||
<a class="indexterm" name="id-1.5.6.6.12.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_get_all_eids_between(
|
||
const igraph_t *graph, igraph_vector_int_t *eids,
|
||
igraph_int_t source, igraph_int_t target, igraph_bool_t directed
|
||
);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
</p>
|
||
<p>
|
||
For undirected graphs <code class="constant">source</code> and <code class="constant">target</code> are exchangeable.
|
||
|
||
</p>
|
||
<p><b>Arguments: </b>
|
||
</p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>graph</code></em>:</span></p></td>
|
||
<td><p>
|
||
The input graph.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>eids</code></em>:</span></p></td>
|
||
<td><p>
|
||
Pointer to an initialized vector, the result is stored
|
||
here. It will be resized as needed.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>source</code></em>:</span></p></td>
|
||
<td><p>
|
||
The ID of the source vertex
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>target</code></em>:</span></p></td>
|
||
<td><p>
|
||
The ID of the target vertex
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>directed</code></em>:</span></p></td>
|
||
<td><p>
|
||
Boolean, whether to consider edge directions
|
||
in directed graphs. This is ignored for undirected graphs.
|
||
</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<p>
|
||
</p>
|
||
<p><b>Returns: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
Error code.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
Time complexity: TODO
|
||
|
||
</p>
|
||
<p><b>See also: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
<a class="link" href="igraph-Basic.html#igraph_get_eid" title="5.2.9. igraph_get_eid — Get the edge ID from the endpoints of an edge."><code class="function">igraph_get_eid()</code></a> for a single edge.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="igraph_neighbors"></a>5.2.12. <code class="function">igraph_neighbors</code> — Adjacent vertices to a vertex.</h4></div></div></div>
|
||
<a class="indexterm" name="id-1.5.6.6.13.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_neighbors(
|
||
const igraph_t *graph, igraph_vector_int_t *neis, igraph_int_t pnode,
|
||
igraph_neimode_t mode, igraph_loops_t loops, igraph_bool_t multiple
|
||
);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
|
||
</p>
|
||
<p><b>Arguments: </b>
|
||
</p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>graph</code></em>:</span></p></td>
|
||
<td><p>
|
||
The graph to work on.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>neis</code></em>:</span></p></td>
|
||
<td><p>
|
||
This vector will contain the result. The vector should
|
||
be initialized beforehand and will be resized. Starting from igraph
|
||
version 0.4 this vector is always sorted, the vertex IDs are
|
||
in increasing order. If one neighbor is connected with multiple
|
||
edges, the neighbor will be returned multiple times.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>pnode</code></em>:</span></p></td>
|
||
<td><p>
|
||
The id of the node for which the adjacent vertices are
|
||
to be searched.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>mode</code></em>:</span></p></td>
|
||
<td><p>
|
||
Defines the way adjacent vertices are searched in
|
||
directed graphs. It can have the following values:
|
||
<code class="constant">IGRAPH_OUT</code>, vertices reachable by an
|
||
edge from the specified vertex are searched;
|
||
<code class="constant">IGRAPH_IN</code>, vertices from which the
|
||
specified vertex is reachable are searched;
|
||
<code class="constant">IGRAPH_ALL</code>, both kinds of vertices are
|
||
searched.
|
||
This parameter is ignored for undirected graphs.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>loops</code></em>:</span></p></td>
|
||
<td><p>
|
||
Specifies how to treat loop edges. <code class="constant">IGRAPH_NO_LOOPS</code>
|
||
removes loop edges from the result. <code class="constant">IGRAPH_LOOPS_ONCE</code>
|
||
makes each loop edge appear only once in the result.
|
||
<code class="constant">IGRAPH_LOOPS_TWICE</code> makes loop edges appear <span class="emphasis"><em>twice</em></span> in the
|
||
result if the graph is undirected or <em class="parameter"><code>mode</code></em> is set to <code class="constant">IGRAPH_ALL</code>
|
||
(and once otherwise as returning them twice does not make sense for
|
||
directed graphs).
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>multiple</code></em>:</span></p></td>
|
||
<td><p>
|
||
Specifies how to treat multiple (parallel) edges.
|
||
<code class="constant">IGRAPH_NO_MULTIPLE</code> collapses parallel edges into a single one;
|
||
<code class="constant">IGRAPH_MULTIPLE</code> keeps the multiplicities of parallel edges
|
||
so the same neighbor will appear as many times in the result as the
|
||
number of parallel edges going between the two vertices.
|
||
</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<p>
|
||
</p>
|
||
<p><b>Returns: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
Error code:
|
||
<code class="constant">IGRAPH_EINVVID</code>: invalid vertex ID.
|
||
<code class="constant">IGRAPH_EINVMODE</code>: invalid mode argument.
|
||
<code class="constant">IGRAPH_ENOMEM</code>: not enough memory.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
Time complexity: O(d), d is the number of adjacent vertices to the queried
|
||
vertex.
|
||
|
||
</p>
|
||
<div class="hideshow" onClick="toggle(this, event)">
|
||
<div class="example">
|
||
<a name="id-1.5.6.6.13.8.1"></a><p class="title"><b>Example 4.6. File <code class="code">examples/simple/igraph_neighbors.c</code></b></p>
|
||
<div class="example-contents">
|
||
<pre class="programlisting"><span class="strong"><strong>#include</strong></span> <igraph.h>
|
||
|
||
int <span class="strong"><strong>main</strong></span>(void) {
|
||
igraph_t g;
|
||
igraph_vector_int_t v;
|
||
|
||
<span class="emphasis"><em>/* Initialize the library. */</em></span>
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_setup" title="4.1. igraph_setup — Initializes the igraph library.">igraph_setup</a></strong></span>();
|
||
|
||
<span class="strong"><strong>igraph_vector_int_init</strong></span>(&v, 0);
|
||
<span class="strong"><strong><a class="link" href="igraph-Generators.html#igraph_small" title="2.2. igraph_small — Shorthand to create a small graph, giving the edges as arguments.">igraph_small</a></strong></span>(&g, 4, IGRAPH_DIRECTED, 0,1, 1,2, 2,3, 2,2, -1);
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_neighbors" title="5.2.12. igraph_neighbors — Adjacent vertices to a vertex.">igraph_neighbors</a></strong></span>(&g, &v, 2, IGRAPH_OUT, IGRAPH_LOOPS_ONCE, IGRAPH_MULTIPLE);
|
||
<span class="strong"><strong>igraph_vector_int_sort</strong></span>(&v);
|
||
<span class="strong"><strong>igraph_vector_int_print</strong></span>(&v);
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_neighbors" title="5.2.12. igraph_neighbors — Adjacent vertices to a vertex.">igraph_neighbors</a></strong></span>(&g, &v, 2, IGRAPH_IN, IGRAPH_LOOPS_ONCE, IGRAPH_MULTIPLE);
|
||
<span class="strong"><strong>igraph_vector_int_sort</strong></span>(&v);
|
||
<span class="strong"><strong>igraph_vector_int_print</strong></span>(&v);
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_neighbors" title="5.2.12. igraph_neighbors — Adjacent vertices to a vertex.">igraph_neighbors</a></strong></span>(&g, &v, 2, IGRAPH_ALL, IGRAPH_LOOPS_TWICE, IGRAPH_MULTIPLE);
|
||
<span class="strong"><strong>igraph_vector_int_sort</strong></span>(&v);
|
||
<span class="strong"><strong>igraph_vector_int_print</strong></span>(&v);
|
||
|
||
<span class="strong"><strong>igraph_vector_int_destroy</strong></span>(&v);
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_destroy" title="5.1.4. igraph_destroy — Frees the memory allocated for a graph object.">igraph_destroy</a></strong></span>(&g);
|
||
<span class="strong"><strong>return</strong></span> 0;
|
||
}
|
||
</pre>
|
||
<p></p>
|
||
</div>
|
||
</div>
|
||
<br class="example-break">
|
||
</div>
|
||
<p>
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="igraph_incident"></a>5.2.13. <code class="function">igraph_incident</code> — Gives the incident edges of a vertex.</h4></div></div></div>
|
||
<a class="indexterm" name="id-1.5.6.6.14.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_incident(
|
||
const igraph_t *graph, igraph_vector_int_t *eids, igraph_int_t pnode,
|
||
igraph_neimode_t mode, igraph_loops_t loops
|
||
);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
</p>
|
||
<p><b>Arguments: </b>
|
||
</p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>graph</code></em>:</span></p></td>
|
||
<td><p>
|
||
The graph object.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>eids</code></em>:</span></p></td>
|
||
<td><p>
|
||
An initialized vector. It will be resized to hold the result.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>pnode</code></em>:</span></p></td>
|
||
<td><p>
|
||
A vertex ID.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>mode</code></em>:</span></p></td>
|
||
<td><p>
|
||
Specifies what kind of edges to include for directed
|
||
graphs. <code class="constant">IGRAPH_OUT</code> means only outgoing edges, <code class="constant">IGRAPH_IN</code> means
|
||
only incoming edges, <code class="constant">IGRAPH_ALL</code> means both. This parameter is
|
||
ignored for undirected graphs.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>loops</code></em>:</span></p></td>
|
||
<td><p>
|
||
Specifies how to treat loop edges. <code class="constant">IGRAPH_NO_LOOPS</code>
|
||
removes loop edges from the result. <code class="constant">IGRAPH_LOOPS_ONCE</code>
|
||
makes each loop edge appear only once in the result.
|
||
<code class="constant">IGRAPH_LOOPS_TWICE</code> makes loop edges appear <span class="emphasis"><em>twice</em></span> in the
|
||
result if the graph is undirected or <em class="parameter"><code>mode</code></em> is set to <code class="constant">IGRAPH_ALL</code>
|
||
(and once otherwise as returning them twice does not make sense for
|
||
directed graphs).
|
||
</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<p>
|
||
</p>
|
||
<p><b>Returns: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
Error code:
|
||
<code class="constant">IGRAPH_EINVVID</code>: invalid vertex ID.
|
||
<code class="constant">IGRAPH_EINVMODE</code>: invalid mode argument.
|
||
<code class="constant">IGRAPH_ENOMEM</code>: not enough memory.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
Time complexity: O(d), the number of incident edges to <em class="parameter"><code>pnode</code></em>.
|
||
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="igraph_degree"></a>5.2.14. <code class="function">igraph_degree</code> — The degree of some vertices in a graph.</h4></div></div></div>
|
||
<a class="indexterm" name="id-1.5.6.6.15.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_degree(
|
||
const igraph_t *graph, igraph_vector_int_t *res, const igraph_vs_t vids,
|
||
igraph_neimode_t mode, igraph_loops_t loops
|
||
);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
|
||
</p>
|
||
<p>
|
||
This function calculates the in-, out- or total degree of the
|
||
specified vertices.
|
||
|
||
</p>
|
||
<p>
|
||
This function returns the result as a vector of <code class="constant">igraph_int_t</code>
|
||
values. In applications where <code class="constant">igraph_real_t</code> is desired, use
|
||
<a class="link" href="igraph-Structural.html#igraph_strength" title="11.11. igraph_strength — Strength of the vertices, also called weighted vertex degree."><code class="function">igraph_strength()</code></a> with <code class="constant">NULL</code> weights.
|
||
|
||
</p>
|
||
<p><b>Arguments: </b>
|
||
</p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>graph</code></em>:</span></p></td>
|
||
<td><p>
|
||
The graph.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>res</code></em>:</span></p></td>
|
||
<td><p>
|
||
Integer vector, this will contain the result. It should be
|
||
initialized and will be resized to be the appropriate size.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>vids</code></em>:</span></p></td>
|
||
<td><p>
|
||
Vertex selector, giving the vertex IDs of which the degree will
|
||
be calculated.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>mode</code></em>:</span></p></td>
|
||
<td><p>
|
||
Defines the type of the degree for directed graphs. Valid modes are:
|
||
<code class="constant">IGRAPH_OUT</code>, out-degree;
|
||
<code class="constant">IGRAPH_IN</code>, in-degree;
|
||
<code class="constant">IGRAPH_ALL</code>, total degree (sum of the
|
||
in- and out-degree).
|
||
This parameter is ignored for undirected graphs.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>loops</code></em>:</span></p></td>
|
||
<td><p>
|
||
Constant of type <a class="link" href="igraph-Structural.html#igraph_loops_t" title="27.1. igraph_loops_t — How to interpret self-loops in undirected graphs?"><code class="function">igraph_loops_t</code></a>, specifies how to treat
|
||
loop edges when calculating the degree. <code class="constant">IGRAPH_NO_LOOPS</code> ignores
|
||
loop edges; <code class="constant">IGRAPH_LOOPS_ONCE</code> counts each loop edge only once;
|
||
<code class="constant">IGRAPH_LOOPS_TWICE</code> counts each loop edge twice in undirected
|
||
graphs and once in directed graphs.
|
||
</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<p>
|
||
</p>
|
||
<p><b>Returns: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
Error code:
|
||
<code class="constant">IGRAPH_EINVVID</code>: invalid vertex ID.
|
||
<code class="constant">IGRAPH_EINVMODE</code>: invalid mode argument.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
Time complexity: O(v) if <em class="parameter"><code>loops</code></em> is <code class="constant">true</code>, and
|
||
O(v*d) otherwise. v is the number of
|
||
vertices for which the degree will be calculated, and
|
||
d is their (average) degree.
|
||
|
||
</p>
|
||
<p><b>See also: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
<a class="link" href="igraph-Structural.html#igraph_strength" title="11.11. igraph_strength — Strength of the vertices, also called weighted vertex degree."><code class="function">igraph_strength()</code></a> for the version that takes into account
|
||
edge weights; <a class="link" href="igraph-Basic.html#igraph_degree_1" title="5.2.15. igraph_degree_1 — The degree of of a single vertex in the graph."><code class="function">igraph_degree_1()</code></a> to efficiently compute the
|
||
degree of a single vertex; <a class="link" href="igraph-Structural.html#igraph_maxdegree" title="11.10. igraph_maxdegree — The maximum degree in a graph (or set of vertices)."><code class="function">igraph_maxdegree()</code></a> if you only need
|
||
the largest degree.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
</p>
|
||
<div class="hideshow" onClick="toggle(this, event)">
|
||
<div class="example">
|
||
<a name="id-1.5.6.6.15.12.1"></a><p class="title"><b>Example 4.7. File <code class="code">examples/simple/igraph_degree.c</code></b></p>
|
||
<div class="example-contents">
|
||
<pre class="programlisting"><span class="strong"><strong>#include</strong></span> <igraph.h>
|
||
|
||
igraph_bool_t <span class="strong"><strong>handshaking_lemma</strong></span>(igraph_t *g, igraph_vector_int_t *v) {
|
||
<span class="emphasis"><em>/* Consistency check of the handshaking lemma:</em></span>
|
||
<span class="emphasis"><em> * If d is the sum of all vertex degrees, then d = 2|E|. */</em></span>
|
||
<span class="strong"><strong>return</strong></span> <span class="strong"><strong>igraph_vector_int_sum</strong></span>(v) == 2 * <span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_ecount" title="5.2.2. igraph_ecount — The number of edges in a graph.">igraph_ecount</a></strong></span>(g);
|
||
}
|
||
|
||
int <span class="strong"><strong>main</strong></span>(void) {
|
||
igraph_t g;
|
||
igraph_vector_int_t v;
|
||
igraph_vector_int_t seq;
|
||
igraph_int_t mdeg;
|
||
|
||
<span class="emphasis"><em>/* Initialize the library. */</em></span>
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_setup" title="4.1. igraph_setup — Initializes the igraph library.">igraph_setup</a></strong></span>();
|
||
|
||
<span class="emphasis"><em>/* Create graph */</em></span>
|
||
<span class="strong"><strong>igraph_vector_int_init</strong></span>(&v, 8);
|
||
<span class="strong"><strong><a class="link" href="igraph-Generators.html#igraph_small" title="2.2. igraph_small — Shorthand to create a small graph, giving the edges as arguments.">igraph_small</a></strong></span>(&g, 4, IGRAPH_DIRECTED, 0,1, 1,2, 2,3, 2,2, -1);
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_degree" title="5.2.14. igraph_degree — The degree of some vertices in a graph.">igraph_degree</a></strong></span>(&g, &v, <span class="strong"><strong><a class="link" href="igraph-Iterators.html#igraph_vss_all" title="4.1. igraph_vss_all — All vertices of a graph (immediate version).">igraph_vss_all</a></strong></span>(), IGRAPH_OUT, IGRAPH_NO_LOOPS);
|
||
<span class="strong"><strong>igraph_vector_int_print</strong></span>(&v);
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_degree" title="5.2.14. igraph_degree — The degree of some vertices in a graph.">igraph_degree</a></strong></span>(&g, &v, <span class="strong"><strong><a class="link" href="igraph-Iterators.html#igraph_vss_all" title="4.1. igraph_vss_all — All vertices of a graph (immediate version).">igraph_vss_all</a></strong></span>(), IGRAPH_OUT, IGRAPH_LOOPS);
|
||
<span class="strong"><strong>igraph_vector_int_print</strong></span>(&v);
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_degree" title="5.2.14. igraph_degree — The degree of some vertices in a graph.">igraph_degree</a></strong></span>(&g, &v, <span class="strong"><strong><a class="link" href="igraph-Iterators.html#igraph_vss_all" title="4.1. igraph_vss_all — All vertices of a graph (immediate version).">igraph_vss_all</a></strong></span>(), IGRAPH_IN, IGRAPH_NO_LOOPS);
|
||
<span class="strong"><strong>igraph_vector_int_print</strong></span>(&v);
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_degree" title="5.2.14. igraph_degree — The degree of some vertices in a graph.">igraph_degree</a></strong></span>(&g, &v, <span class="strong"><strong><a class="link" href="igraph-Iterators.html#igraph_vss_all" title="4.1. igraph_vss_all — All vertices of a graph (immediate version).">igraph_vss_all</a></strong></span>(), IGRAPH_IN, IGRAPH_LOOPS);
|
||
<span class="strong"><strong>igraph_vector_int_print</strong></span>(&v);
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_degree" title="5.2.14. igraph_degree — The degree of some vertices in a graph.">igraph_degree</a></strong></span>(&g, &v, <span class="strong"><strong><a class="link" href="igraph-Iterators.html#igraph_vss_all" title="4.1. igraph_vss_all — All vertices of a graph (immediate version).">igraph_vss_all</a></strong></span>(), IGRAPH_ALL, IGRAPH_NO_LOOPS);
|
||
<span class="strong"><strong>igraph_vector_int_print</strong></span>(&v);
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_degree" title="5.2.14. igraph_degree — The degree of some vertices in a graph.">igraph_degree</a></strong></span>(&g, &v, <span class="strong"><strong><a class="link" href="igraph-Iterators.html#igraph_vss_all" title="4.1. igraph_vss_all — All vertices of a graph (immediate version).">igraph_vss_all</a></strong></span>(), IGRAPH_ALL, IGRAPH_LOOPS);
|
||
<span class="strong"><strong>igraph_vector_int_print</strong></span>(&v);
|
||
|
||
<span class="strong"><strong>if</strong></span> (!<span class="strong"><strong>handshaking_lemma</strong></span>(&g, &v)) {
|
||
<span class="strong"><strong>exit</strong></span>(3);
|
||
}
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_destroy" title="5.1.4. igraph_destroy — Frees the memory allocated for a graph object.">igraph_destroy</a></strong></span>(&g);
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Generators.html#igraph_small" title="2.2. igraph_small — Shorthand to create a small graph, giving the edges as arguments.">igraph_small</a></strong></span>(&g, 4, IGRAPH_UNDIRECTED, 0,1, 1,2, 2,3, 2,2, -1);
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_degree" title="5.2.14. igraph_degree — The degree of some vertices in a graph.">igraph_degree</a></strong></span>(&g, &v, <span class="strong"><strong><a class="link" href="igraph-Iterators.html#igraph_vss_all" title="4.1. igraph_vss_all — All vertices of a graph (immediate version).">igraph_vss_all</a></strong></span>(), IGRAPH_OUT, IGRAPH_NO_LOOPS);
|
||
<span class="strong"><strong>igraph_vector_int_print</strong></span>(&v);
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_degree" title="5.2.14. igraph_degree — The degree of some vertices in a graph.">igraph_degree</a></strong></span>(&g, &v, <span class="strong"><strong><a class="link" href="igraph-Iterators.html#igraph_vss_all" title="4.1. igraph_vss_all — All vertices of a graph (immediate version).">igraph_vss_all</a></strong></span>(), IGRAPH_OUT, IGRAPH_LOOPS);
|
||
<span class="strong"><strong>igraph_vector_int_print</strong></span>(&v);
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_degree" title="5.2.14. igraph_degree — The degree of some vertices in a graph.">igraph_degree</a></strong></span>(&g, &v, <span class="strong"><strong><a class="link" href="igraph-Iterators.html#igraph_vss_all" title="4.1. igraph_vss_all — All vertices of a graph (immediate version).">igraph_vss_all</a></strong></span>(), IGRAPH_IN, IGRAPH_NO_LOOPS);
|
||
<span class="strong"><strong>igraph_vector_int_print</strong></span>(&v);
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_degree" title="5.2.14. igraph_degree — The degree of some vertices in a graph.">igraph_degree</a></strong></span>(&g, &v, <span class="strong"><strong><a class="link" href="igraph-Iterators.html#igraph_vss_all" title="4.1. igraph_vss_all — All vertices of a graph (immediate version).">igraph_vss_all</a></strong></span>(), IGRAPH_IN, IGRAPH_LOOPS);
|
||
<span class="strong"><strong>igraph_vector_int_print</strong></span>(&v);
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_degree" title="5.2.14. igraph_degree — The degree of some vertices in a graph.">igraph_degree</a></strong></span>(&g, &v, <span class="strong"><strong><a class="link" href="igraph-Iterators.html#igraph_vss_all" title="4.1. igraph_vss_all — All vertices of a graph (immediate version).">igraph_vss_all</a></strong></span>(), IGRAPH_ALL, IGRAPH_NO_LOOPS);
|
||
<span class="strong"><strong>igraph_vector_int_print</strong></span>(&v);
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_degree" title="5.2.14. igraph_degree — The degree of some vertices in a graph.">igraph_degree</a></strong></span>(&g, &v, <span class="strong"><strong><a class="link" href="igraph-Iterators.html#igraph_vss_all" title="4.1. igraph_vss_all — All vertices of a graph (immediate version).">igraph_vss_all</a></strong></span>(), IGRAPH_ALL, IGRAPH_LOOPS);
|
||
<span class="strong"><strong>igraph_vector_int_print</strong></span>(&v);
|
||
|
||
<span class="strong"><strong>if</strong></span> (!<span class="strong"><strong>handshaking_lemma</strong></span>(&g, &v)) {
|
||
<span class="strong"><strong>exit</strong></span>(4);
|
||
}
|
||
|
||
<span class="emphasis"><em>/* Degree of the same vertex multiple times */</em></span>
|
||
|
||
<span class="strong"><strong>igraph_vector_int_init</strong></span>(&seq, 3);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#VECTOR" title="2.4.1. VECTOR — Accessing an element of a vector.">VECTOR</a></strong></span>(seq)[0] = 2;
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#VECTOR" title="2.4.1. VECTOR — Accessing an element of a vector.">VECTOR</a></strong></span>(seq)[1] = 0;
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#VECTOR" title="2.4.1. VECTOR — Accessing an element of a vector.">VECTOR</a></strong></span>(seq)[2] = 2;
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_degree" title="5.2.14. igraph_degree — The degree of some vertices in a graph.">igraph_degree</a></strong></span>(&g, &v, <span class="strong"><strong><a class="link" href="igraph-Iterators.html#igraph_vss_vector" title="4.4. igraph_vss_vector — Vertex set based on a vector (immediate version).">igraph_vss_vector</a></strong></span>(&seq), IGRAPH_ALL, IGRAPH_LOOPS);
|
||
<span class="strong"><strong>igraph_vector_int_print</strong></span>(&v);
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_destroy" title="5.1.4. igraph_destroy — Frees the memory allocated for a graph object.">igraph_destroy</a></strong></span>(&g);
|
||
<span class="strong"><strong>igraph_vector_int_destroy</strong></span>(&seq);
|
||
|
||
<span class="emphasis"><em>/* Maximum degree */</em></span>
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Generators.html#igraph_ring" title="4.7. igraph_ring — Creates a cycle graph or a path graph.">igraph_ring</a></strong></span>(&g, 10, IGRAPH_UNDIRECTED, <span class="emphasis"><em>/* mutual */</em></span> false, <span class="emphasis"><em>/* circular */</em></span> false);
|
||
<span class="strong"><strong><a class="link" href="igraph-Structural.html#igraph_maxdegree" title="11.10. igraph_maxdegree — The maximum degree in a graph (or set of vertices).">igraph_maxdegree</a></strong></span>(&g, &mdeg, <span class="strong"><strong><a class="link" href="igraph-Iterators.html#igraph_vss_all" title="4.1. igraph_vss_all — All vertices of a graph (immediate version).">igraph_vss_all</a></strong></span>(), IGRAPH_ALL, IGRAPH_LOOPS);
|
||
<span class="strong"><strong>if</strong></span> (mdeg != 2) {
|
||
<span class="strong"><strong>exit</strong></span>(5);
|
||
}
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_degree" title="5.2.14. igraph_degree — The degree of some vertices in a graph.">igraph_degree</a></strong></span>(&g, &v, <span class="strong"><strong><a class="link" href="igraph-Iterators.html#igraph_vss_all" title="4.1. igraph_vss_all — All vertices of a graph (immediate version).">igraph_vss_all</a></strong></span>(), IGRAPH_ALL, IGRAPH_LOOPS);
|
||
<span class="strong"><strong>if</strong></span> (! <span class="strong"><strong>handshaking_lemma</strong></span>(&g, &v)) {
|
||
<span class="strong"><strong>exit</strong></span>(6);
|
||
}
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_destroy" title="5.1.4. igraph_destroy — Frees the memory allocated for a graph object.">igraph_destroy</a></strong></span>(&g);
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Generators.html#igraph_full" title="7.1. igraph_full — Creates a full graph (complete graph).">igraph_full</a></strong></span>(&g, 10, IGRAPH_UNDIRECTED, IGRAPH_NO_LOOPS);
|
||
<span class="strong"><strong><a class="link" href="igraph-Structural.html#igraph_maxdegree" title="11.10. igraph_maxdegree — The maximum degree in a graph (or set of vertices).">igraph_maxdegree</a></strong></span>(&g, &mdeg, <span class="strong"><strong><a class="link" href="igraph-Iterators.html#igraph_vss_all" title="4.1. igraph_vss_all — All vertices of a graph (immediate version).">igraph_vss_all</a></strong></span>(), IGRAPH_ALL, IGRAPH_LOOPS);
|
||
<span class="strong"><strong>if</strong></span> (mdeg != 9) {
|
||
<span class="strong"><strong>exit</strong></span>(7);
|
||
}
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_degree" title="5.2.14. igraph_degree — The degree of some vertices in a graph.">igraph_degree</a></strong></span>(&g, &v, <span class="strong"><strong><a class="link" href="igraph-Iterators.html#igraph_vss_all" title="4.1. igraph_vss_all — All vertices of a graph (immediate version).">igraph_vss_all</a></strong></span>(), IGRAPH_ALL, IGRAPH_LOOPS);
|
||
<span class="strong"><strong>if</strong></span> (! <span class="strong"><strong>handshaking_lemma</strong></span>(&g, &v)) {
|
||
<span class="strong"><strong>exit</strong></span>(8);
|
||
}
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_destroy" title="5.1.4. igraph_destroy — Frees the memory allocated for a graph object.">igraph_destroy</a></strong></span>(&g);
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Generators.html#igraph_star" title="4.1. igraph_star — Creates a star graph, every vertex connects only to the center.">igraph_star</a></strong></span>(&g, 10, IGRAPH_STAR_OUT, <span class="emphasis"><em>/* center */</em></span> 0);
|
||
<span class="strong"><strong><a class="link" href="igraph-Structural.html#igraph_maxdegree" title="11.10. igraph_maxdegree — The maximum degree in a graph (or set of vertices).">igraph_maxdegree</a></strong></span>(&g, &mdeg, <span class="strong"><strong><a class="link" href="igraph-Iterators.html#igraph_vss_all" title="4.1. igraph_vss_all — All vertices of a graph (immediate version).">igraph_vss_all</a></strong></span>(), IGRAPH_OUT, IGRAPH_LOOPS);
|
||
<span class="strong"><strong>if</strong></span> (mdeg != 9) {
|
||
<span class="strong"><strong>exit</strong></span>(9);
|
||
}
|
||
<span class="strong"><strong><a class="link" href="igraph-Structural.html#igraph_maxdegree" title="11.10. igraph_maxdegree — The maximum degree in a graph (or set of vertices).">igraph_maxdegree</a></strong></span>(&g, &mdeg, <span class="strong"><strong><a class="link" href="igraph-Iterators.html#igraph_vss_all" title="4.1. igraph_vss_all — All vertices of a graph (immediate version).">igraph_vss_all</a></strong></span>(), IGRAPH_IN, IGRAPH_LOOPS);
|
||
<span class="strong"><strong>if</strong></span> (mdeg != 1) {
|
||
<span class="strong"><strong>exit</strong></span>(10);
|
||
}
|
||
<span class="strong"><strong><a class="link" href="igraph-Structural.html#igraph_maxdegree" title="11.10. igraph_maxdegree — The maximum degree in a graph (or set of vertices).">igraph_maxdegree</a></strong></span>(&g, &mdeg, <span class="strong"><strong><a class="link" href="igraph-Iterators.html#igraph_vss_all" title="4.1. igraph_vss_all — All vertices of a graph (immediate version).">igraph_vss_all</a></strong></span>(), IGRAPH_ALL, IGRAPH_LOOPS);
|
||
<span class="strong"><strong>if</strong></span> (mdeg != 9) {
|
||
<span class="strong"><strong>exit</strong></span>(11);
|
||
}
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_degree" title="5.2.14. igraph_degree — The degree of some vertices in a graph.">igraph_degree</a></strong></span>(&g, &v, <span class="strong"><strong><a class="link" href="igraph-Iterators.html#igraph_vss_all" title="4.1. igraph_vss_all — All vertices of a graph (immediate version).">igraph_vss_all</a></strong></span>(), IGRAPH_ALL, IGRAPH_LOOPS);
|
||
<span class="strong"><strong>if</strong></span> (! <span class="strong"><strong>handshaking_lemma</strong></span>(&g, &v)) {
|
||
<span class="strong"><strong>exit</strong></span>(12);
|
||
}
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_destroy" title="5.1.4. igraph_destroy — Frees the memory allocated for a graph object.">igraph_destroy</a></strong></span>(&g);
|
||
|
||
<span class="strong"><strong>igraph_vector_int_destroy</strong></span>(&v);
|
||
|
||
<span class="strong"><strong>return</strong></span> 0;
|
||
}
|
||
</pre>
|
||
<p></p>
|
||
</div>
|
||
</div>
|
||
<br class="example-break">
|
||
</div>
|
||
<p>
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="igraph_degree_1"></a>5.2.15. <code class="function">igraph_degree_1</code> — The degree of of a single vertex in the graph.</h4></div></div></div>
|
||
<a class="indexterm" name="id-1.5.6.6.16.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_degree_1(
|
||
const igraph_t *graph, igraph_int_t *deg, igraph_int_t vid,
|
||
igraph_neimode_t mode, igraph_loops_t loops
|
||
);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
|
||
This function calculates the in-, out- or total degree of a single vertex.
|
||
For a single vertex, it is more efficient than calling <a class="link" href="igraph-Basic.html#igraph_degree" title="5.2.14. igraph_degree — The degree of some vertices in a graph."><code class="function">igraph_degree()</code></a>.
|
||
|
||
</p>
|
||
<p><b>Arguments: </b>
|
||
</p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>graph</code></em>:</span></p></td>
|
||
<td><p>
|
||
The graph.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>deg</code></em>:</span></p></td>
|
||
<td><p>
|
||
Pointer to the integer where the computed degree will be stored.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>vid</code></em>:</span></p></td>
|
||
<td><p>
|
||
The vertex for which the degree will be calculated.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>mode</code></em>:</span></p></td>
|
||
<td><p>
|
||
Defines the type of the degree for directed graphs. Valid modes are:
|
||
<code class="constant">IGRAPH_OUT</code>, out-degree;
|
||
<code class="constant">IGRAPH_IN</code>, in-degree;
|
||
<code class="constant">IGRAPH_ALL</code>, total degree (sum of the in- and out-degree).
|
||
This parameter is ignored for undirected graphs.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>loops</code></em>:</span></p></td>
|
||
<td><p>
|
||
Boolean, gives whether the self-loops should be
|
||
counted.
|
||
</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<p>
|
||
</p>
|
||
<p><b>Returns: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
Error code.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
</p>
|
||
<p><b>See also: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
<a class="link" href="igraph-Basic.html#igraph_degree" title="5.2.14. igraph_degree — The degree of some vertices in a graph."><code class="function">igraph_degree()</code></a> to compute the degree of several vertices at once.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
Time complexity: O(1) if <em class="parameter"><code>loops</code></em> is <code class="constant">true</code>, and
|
||
O(d) otherwise, where d is the degree.
|
||
|
||
</p>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h3 class="title">
|
||
<a name="adding-and-deleting-vertices-and-edges"></a>5.3. Adding and deleting vertices and edges</h3></div></div></div>
|
||
<div class="toc"><dl class="toc">
|
||
<dt><span class="section"><a href="igraph-Basic.html#igraph_add_edge">5.3.1. <code class="function">igraph_add_edge</code> — Adds a single edge to a graph.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Basic.html#igraph_add_edges">5.3.2. <code class="function">igraph_add_edges</code> — Adds edges to a graph object.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Basic.html#igraph_add_vertices">5.3.3. <code class="function">igraph_add_vertices</code> — Adds vertices to a graph.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Basic.html#igraph_delete_edges">5.3.4. <code class="function">igraph_delete_edges</code> — Removes edges from a graph.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Basic.html#igraph_delete_vertices">5.3.5. <code class="function">igraph_delete_vertices</code> — Removes some vertices (with all their edges) from the graph.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Basic.html#igraph_delete_vertices_map">5.3.6. <code class="function">igraph_delete_vertices_map</code> — Removes some vertices (with all their edges) from the graph.</a></span></dt>
|
||
</dl></div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="igraph_add_edge"></a>5.3.1. <code class="function">igraph_add_edge</code> — Adds a single edge to a graph.</h4></div></div></div>
|
||
<a class="indexterm" name="id-1.5.6.7.2.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_add_edge(igraph_t *graph, igraph_int_t from, igraph_int_t to);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
</p>
|
||
<p>
|
||
For directed graphs the edge points from <em class="parameter"><code>from</code></em> to <em class="parameter"><code>to</code></em>.
|
||
|
||
</p>
|
||
<p>
|
||
Note that if you want to add many edges to a big graph, then it is
|
||
inefficient to add them one by one, it is better to collect them into
|
||
a vector and add all of them via a single <a class="link" href="igraph-Basic.html#igraph_add_edges" title="5.3.2. igraph_add_edges — Adds edges to a graph object."><code class="function">igraph_add_edges()</code></a> call.
|
||
</p>
|
||
<p><b>Arguments: </b>
|
||
</p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>graph</code></em>:</span></p></td>
|
||
<td><p>
|
||
The graph.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>from</code></em>:</span></p></td>
|
||
<td><p>
|
||
The id of the first vertex of the edge.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>to</code></em>:</span></p></td>
|
||
<td><p>
|
||
The id of the second vertex of the edge.
|
||
</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<p>
|
||
</p>
|
||
<p><b>Returns: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
Error code.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
</p>
|
||
<p><b>See also: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
<a class="link" href="igraph-Basic.html#igraph_add_edges" title="5.3.2. igraph_add_edges — Adds edges to a graph object."><code class="function">igraph_add_edges()</code></a> to add many edges, <a class="link" href="igraph-Basic.html#igraph_delete_edges" title="5.3.4. igraph_delete_edges — Removes edges from a graph."><code class="function">igraph_delete_edges()</code></a> to remove edges and <a class="link" href="igraph-Basic.html#igraph_add_vertices" title="5.3.3. igraph_add_vertices — Adds vertices to a graph."><code class="function">igraph_add_vertices()</code></a> to add vertices.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
Time complexity: O(|V|+|E|), the number of edges plus the number of
|
||
vertices.
|
||
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="igraph_add_edges"></a>5.3.2. <code class="function">igraph_add_edges</code> — Adds edges to a graph object.</h4></div></div></div>
|
||
<a class="indexterm" name="id-1.5.6.7.3.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_add_edges(
|
||
igraph_t *graph, const igraph_vector_int_t *edges,
|
||
const igraph_attribute_record_list_t *attr
|
||
);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
|
||
</p>
|
||
<p>
|
||
The edges are given in a vector, the
|
||
first two elements define the first edge (the order is
|
||
<code class="literal">from</code>, <code class="literal">to</code> for directed
|
||
graphs). The vector
|
||
should contain even number of integer numbers between zero and the
|
||
number of vertices in the graph minus one (inclusive). If you also
|
||
want to add new vertices, call <a class="link" href="igraph-Basic.html#igraph_add_vertices" title="5.3.3. igraph_add_vertices — Adds vertices to a graph."><code class="function">igraph_add_vertices()</code></a> first.
|
||
</p>
|
||
<p><b>Arguments: </b>
|
||
</p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>graph</code></em>:</span></p></td>
|
||
<td><p>
|
||
The graph to which the edges will be added.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>edges</code></em>:</span></p></td>
|
||
<td><p>
|
||
The edges themselves.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>attr</code></em>:</span></p></td>
|
||
<td><p>
|
||
The attributes of the new edges. You can supply a null pointer
|
||
here if you do not need edge attributes.
|
||
</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<p>
|
||
</p>
|
||
<p><b>Returns: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
Error code:
|
||
<code class="constant">IGRAPH_EINVAL</code>: invalid (odd) edges vector length,
|
||
<code class="constant">IGRAPH_EINVVID</code>: invalid vertex ID in edges vector.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
This function invalidates all iterators.
|
||
|
||
</p>
|
||
<p>
|
||
Time complexity: O(|V|+|E|) where |V| is the number of vertices and
|
||
|E| is the number of edges in the <span class="emphasis"><em>new,</em></span> extended graph.
|
||
|
||
</p>
|
||
<div class="hideshow" onClick="toggle(this, event)">
|
||
<div class="example">
|
||
<a name="id-1.5.6.7.3.10.2"></a><p class="title"><b>Example 4.8. File <code class="code">examples/simple/creation.c</code></b></p>
|
||
<div class="example-contents">
|
||
<pre class="programlisting"><span class="strong"><strong>#include</strong></span> <igraph.h>
|
||
<span class="strong"><strong>#include</strong></span> <assert.h>
|
||
|
||
int <span class="strong"><strong>main</strong></span>(void) {
|
||
igraph_t graph;
|
||
igraph_vector_int_t edges;
|
||
|
||
<span class="emphasis"><em>/* Initialize the library. */</em></span>
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_setup" title="4.1. igraph_setup — Initializes the igraph library.">igraph_setup</a></strong></span>();
|
||
|
||
<span class="emphasis"><em>/* Create a directed graph with no vertices or edges. */</em></span>
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_empty" title="5.1.1. igraph_empty — Creates an empty graph with some vertices and no edges.">igraph_empty</a></strong></span>(&graph, 0, IGRAPH_DIRECTED);
|
||
|
||
<span class="emphasis"><em>/* Add 5 vertices. Vertex IDs will range from 0 to 4, inclusive. */</em></span>
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_add_vertices" title="5.3.3. igraph_add_vertices — Adds vertices to a graph.">igraph_add_vertices</a></strong></span>(&graph, 5, NULL);
|
||
|
||
<span class="emphasis"><em>/* Add 5 edges, specified as 5 consecutive pairs of vertex IDs</em></span>
|
||
<span class="emphasis"><em> * stored in an integer vector. */</em></span>
|
||
<span class="strong"><strong>igraph_vector_int_init_int</strong></span>(&edges, 10,
|
||
0,1, 0,2, 3,1, 2,1, 0,4);
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_add_edges" title="5.3.2. igraph_add_edges — Adds edges to a graph object.">igraph_add_edges</a></strong></span>(&graph, &edges, NULL);
|
||
|
||
<span class="strong"><strong>igraph_vector_int_destroy</strong></span>(&edges);
|
||
|
||
<span class="emphasis"><em>/* Now the graph has 5 vertices and 5 edges. */</em></span>
|
||
<span class="strong"><strong>assert</strong></span>(<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_vcount" title="5.2.1. igraph_vcount — The number of vertices in a graph.">igraph_vcount</a></strong></span>(&graph) == 5);
|
||
<span class="strong"><strong>assert</strong></span>(<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_ecount" title="5.2.2. igraph_ecount — The number of edges in a graph.">igraph_ecount</a></strong></span>(&graph) == 5);
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_destroy" title="5.1.4. igraph_destroy — Frees the memory allocated for a graph object.">igraph_destroy</a></strong></span>(&graph);
|
||
|
||
<span class="strong"><strong>return</strong></span> 0;
|
||
}
|
||
</pre>
|
||
<p></p>
|
||
</div>
|
||
</div>
|
||
<br class="example-break">
|
||
</div>
|
||
<p>
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="igraph_add_vertices"></a>5.3.3. <code class="function">igraph_add_vertices</code> — Adds vertices to a graph.</h4></div></div></div>
|
||
<a class="indexterm" name="id-1.5.6.7.4.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_add_vertices(
|
||
igraph_t *graph, igraph_int_t nv, const igraph_attribute_record_list_t *attr
|
||
);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
|
||
</p>
|
||
<p>
|
||
This function invalidates all iterators.
|
||
|
||
</p>
|
||
<p><b>Arguments: </b>
|
||
</p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>graph</code></em>:</span></p></td>
|
||
<td><p>
|
||
The graph object to extend.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>nv</code></em>:</span></p></td>
|
||
<td><p>
|
||
Non-negative integer specifying the number of vertices to add.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>attr</code></em>:</span></p></td>
|
||
<td><p>
|
||
The attributes of the new vertices. You can supply a null pointer
|
||
here if you do not need vertex attributes.
|
||
</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<p>
|
||
</p>
|
||
<p><b>Returns: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
Error code:
|
||
<code class="constant">IGRAPH_EINVAL</code>: invalid number of new vertices.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
Time complexity: O(|V|) where |V| is the number of vertices in the <span class="emphasis"><em>new,</em></span>
|
||
extended graph.
|
||
|
||
</p>
|
||
<div class="hideshow" onClick="toggle(this, event)">
|
||
<div class="example">
|
||
<a name="id-1.5.6.7.4.9.2"></a><p class="title"><b>Example 4.9. File <code class="code">examples/simple/creation.c</code></b></p>
|
||
<div class="example-contents">
|
||
<pre class="programlisting"><span class="strong"><strong>#include</strong></span> <igraph.h>
|
||
<span class="strong"><strong>#include</strong></span> <assert.h>
|
||
|
||
int <span class="strong"><strong>main</strong></span>(void) {
|
||
igraph_t graph;
|
||
igraph_vector_int_t edges;
|
||
|
||
<span class="emphasis"><em>/* Initialize the library. */</em></span>
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_setup" title="4.1. igraph_setup — Initializes the igraph library.">igraph_setup</a></strong></span>();
|
||
|
||
<span class="emphasis"><em>/* Create a directed graph with no vertices or edges. */</em></span>
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_empty" title="5.1.1. igraph_empty — Creates an empty graph with some vertices and no edges.">igraph_empty</a></strong></span>(&graph, 0, IGRAPH_DIRECTED);
|
||
|
||
<span class="emphasis"><em>/* Add 5 vertices. Vertex IDs will range from 0 to 4, inclusive. */</em></span>
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_add_vertices" title="5.3.3. igraph_add_vertices — Adds vertices to a graph.">igraph_add_vertices</a></strong></span>(&graph, 5, NULL);
|
||
|
||
<span class="emphasis"><em>/* Add 5 edges, specified as 5 consecutive pairs of vertex IDs</em></span>
|
||
<span class="emphasis"><em> * stored in an integer vector. */</em></span>
|
||
<span class="strong"><strong>igraph_vector_int_init_int</strong></span>(&edges, 10,
|
||
0,1, 0,2, 3,1, 2,1, 0,4);
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_add_edges" title="5.3.2. igraph_add_edges — Adds edges to a graph object.">igraph_add_edges</a></strong></span>(&graph, &edges, NULL);
|
||
|
||
<span class="strong"><strong>igraph_vector_int_destroy</strong></span>(&edges);
|
||
|
||
<span class="emphasis"><em>/* Now the graph has 5 vertices and 5 edges. */</em></span>
|
||
<span class="strong"><strong>assert</strong></span>(<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_vcount" title="5.2.1. igraph_vcount — The number of vertices in a graph.">igraph_vcount</a></strong></span>(&graph) == 5);
|
||
<span class="strong"><strong>assert</strong></span>(<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_ecount" title="5.2.2. igraph_ecount — The number of edges in a graph.">igraph_ecount</a></strong></span>(&graph) == 5);
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_destroy" title="5.1.4. igraph_destroy — Frees the memory allocated for a graph object.">igraph_destroy</a></strong></span>(&graph);
|
||
|
||
<span class="strong"><strong>return</strong></span> 0;
|
||
}
|
||
</pre>
|
||
<p></p>
|
||
</div>
|
||
</div>
|
||
<br class="example-break">
|
||
</div>
|
||
<p>
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="igraph_delete_edges"></a>5.3.4. <code class="function">igraph_delete_edges</code> — Removes edges from a graph.</h4></div></div></div>
|
||
<a class="indexterm" name="id-1.5.6.7.5.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_delete_edges(igraph_t *graph, igraph_es_t edges);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
|
||
</p>
|
||
<p>
|
||
The edges to remove are specified as an edge selector.
|
||
|
||
</p>
|
||
<p>
|
||
This function cannot remove vertices; vertices will be kept even if they lose
|
||
all their edges.
|
||
|
||
</p>
|
||
<p>
|
||
This function invalidates all iterators.
|
||
</p>
|
||
<p><b>Arguments: </b>
|
||
</p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>graph</code></em>:</span></p></td>
|
||
<td><p>
|
||
The graph to work on.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>edges</code></em>:</span></p></td>
|
||
<td><p>
|
||
The edges to remove.
|
||
</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<p>
|
||
</p>
|
||
<p><b>Returns: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
Error code.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
Time complexity: O(|V|+|E|) where |V| and |E| are the number of vertices
|
||
and edges in the <span class="emphasis"><em>original</em></span> graph, respectively.
|
||
|
||
</p>
|
||
<div class="hideshow" onClick="toggle(this, event)">
|
||
<div class="example">
|
||
<a name="id-1.5.6.7.5.11.2"></a><p class="title"><b>Example 4.10. File <code class="code">examples/simple/igraph_delete_edges.c</code></b></p>
|
||
<div class="example-contents">
|
||
<pre class="programlisting"><span class="strong"><strong>#include</strong></span> <igraph.h>
|
||
|
||
int <span class="strong"><strong>main</strong></span>(void) {
|
||
|
||
igraph_t g;
|
||
igraph_es_t es;
|
||
|
||
<span class="emphasis"><em>/* Initialize the library. */</em></span>
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_setup" title="4.1. igraph_setup — Initializes the igraph library.">igraph_setup</a></strong></span>();
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Generators.html#igraph_small" title="2.2. igraph_small — Shorthand to create a small graph, giving the edges as arguments.">igraph_small</a></strong></span>(&g, 4, IGRAPH_UNDIRECTED, 0,1, 1,2, 2,2, 2,3, -1);
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Iterators.html#igraph_es_pairs_small" title="6.9. igraph_es_pairs_small — Edge selector, multiple edges defined by their endpoints as arguments.">igraph_es_pairs_small</a></strong></span>(&es, IGRAPH_DIRECTED, 3, 2, -1);
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_delete_edges" title="5.3.4. igraph_delete_edges — Removes edges from a graph.">igraph_delete_edges</a></strong></span>(&g, es);
|
||
<span class="strong"><strong>if</strong></span> (<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_ecount" title="5.2.2. igraph_ecount — The number of edges in a graph.">igraph_ecount</a></strong></span>(&g) != 3) {
|
||
<span class="strong"><strong>return</strong></span> 1;
|
||
}
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Iterators.html#igraph_es_destroy" title="8.3. igraph_es_destroy — Destroys an edge selector object.">igraph_es_destroy</a></strong></span>(&es);
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_destroy" title="5.1.4. igraph_destroy — Frees the memory allocated for a graph object.">igraph_destroy</a></strong></span>(&g);
|
||
|
||
<span class="strong"><strong>return</strong></span> 0;
|
||
}
|
||
</pre>
|
||
<p></p>
|
||
</div>
|
||
</div>
|
||
<br class="example-break">
|
||
</div>
|
||
<p>
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="igraph_delete_vertices"></a>5.3.5. <code class="function">igraph_delete_vertices</code> — Removes some vertices (with all their edges) from the graph.</h4></div></div></div>
|
||
<a class="indexterm" name="id-1.5.6.7.6.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_delete_vertices(igraph_t *graph, const igraph_vs_t vertices);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
|
||
</p>
|
||
<p>
|
||
This function changes the IDs of the vertices (except in some very
|
||
special cases, but these should not be relied on anyway).
|
||
|
||
</p>
|
||
<p>
|
||
This function invalidates all iterators.
|
||
|
||
</p>
|
||
<p><b>Arguments: </b>
|
||
</p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>graph</code></em>:</span></p></td>
|
||
<td><p>
|
||
The graph to work on.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>vertices</code></em>:</span></p></td>
|
||
<td><p>
|
||
The IDs of the vertices to remove, in a vector. The vector
|
||
may contain the same ID more than once.
|
||
</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<p>
|
||
</p>
|
||
<p><b>Returns: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
Error code:
|
||
<code class="constant">IGRAPH_EINVVID</code>: invalid vertex ID.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
Time complexity: O(|V|+|E|), |V| and |E| are the number of vertices and
|
||
edges in the original graph.
|
||
|
||
</p>
|
||
<div class="hideshow" onClick="toggle(this, event)">
|
||
<div class="example">
|
||
<a name="id-1.5.6.7.6.10.1"></a><p class="title"><b>Example 4.11. File <code class="code">examples/simple/igraph_delete_vertices.c</code></b></p>
|
||
<div class="example-contents">
|
||
<pre class="programlisting"><span class="strong"><strong>#include</strong></span> <igraph.h>
|
||
|
||
int <span class="strong"><strong>main</strong></span>(void) {
|
||
igraph_t g;
|
||
|
||
<span class="emphasis"><em>/* without edges */</em></span>
|
||
<span class="strong"><strong><a class="link" href="igraph-Generators.html#igraph_small" title="2.2. igraph_small — Shorthand to create a small graph, giving the edges as arguments.">igraph_small</a></strong></span>(&g, 15, IGRAPH_UNDIRECTED, -1);
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_delete_vertices" title="5.3.5. igraph_delete_vertices — Removes some vertices (with all their edges) from the graph.">igraph_delete_vertices</a></strong></span>(&g, <span class="strong"><strong><a class="link" href="igraph-Iterators.html#igraph_vss_1" title="4.3. igraph_vss_1 — Vertex set with a single vertex (immediate version).">igraph_vss_1</a></strong></span>(2));
|
||
<span class="strong"><strong>if</strong></span> (<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_vcount" title="5.2.1. igraph_vcount — The number of vertices in a graph.">igraph_vcount</a></strong></span>(&g) != 14) {
|
||
<span class="strong"><strong>return</strong></span> 2;
|
||
}
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_destroy" title="5.1.4. igraph_destroy — Frees the memory allocated for a graph object.">igraph_destroy</a></strong></span>(&g);
|
||
|
||
<span class="emphasis"><em>/* with edges */</em></span>
|
||
<span class="strong"><strong><a class="link" href="igraph-Generators.html#igraph_small" title="2.2. igraph_small — Shorthand to create a small graph, giving the edges as arguments.">igraph_small</a></strong></span>(&g, 4, IGRAPH_UNDIRECTED, 0,1, 1,2, 2,3, 2,2, -1);
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_delete_vertices" title="5.3.5. igraph_delete_vertices — Removes some vertices (with all their edges) from the graph.">igraph_delete_vertices</a></strong></span>(&g, <span class="strong"><strong><a class="link" href="igraph-Iterators.html#igraph_vss_1" title="4.3. igraph_vss_1 — Vertex set with a single vertex (immediate version).">igraph_vss_1</a></strong></span>(2));
|
||
<span class="strong"><strong>if</strong></span> (<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_vcount" title="5.2.1. igraph_vcount — The number of vertices in a graph.">igraph_vcount</a></strong></span>(&g) != 3) {
|
||
<span class="strong"><strong>return</strong></span> 3;
|
||
}
|
||
<span class="strong"><strong>if</strong></span> (<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_ecount" title="5.2.2. igraph_ecount — The number of edges in a graph.">igraph_ecount</a></strong></span>(&g) != 1) {
|
||
<span class="strong"><strong>return</strong></span> 4;
|
||
}
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_destroy" title="5.1.4. igraph_destroy — Frees the memory allocated for a graph object.">igraph_destroy</a></strong></span>(&g);
|
||
|
||
<span class="strong"><strong>return</strong></span> 0;
|
||
}
|
||
</pre>
|
||
<p></p>
|
||
</div>
|
||
</div>
|
||
<br class="example-break">
|
||
</div>
|
||
<p>
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h4 class="title">
|
||
<a name="igraph_delete_vertices_map"></a>5.3.6. <code class="function">igraph_delete_vertices_map</code> — Removes some vertices (with all their edges) from the graph.</h4></div></div></div>
|
||
<a class="indexterm" name="id-1.5.6.7.7.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_delete_vertices_map(
|
||
igraph_t *graph, const igraph_vs_t vertices, igraph_vector_int_t *map,
|
||
igraph_vector_int_t *invmap
|
||
);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
|
||
</p>
|
||
<p>
|
||
This function changes the IDs of the vertices (except in some very
|
||
special cases, but these should not be relied on anyway). You can use the
|
||
<em class="parameter"><code>map</code></em> argument to obtain the mapping from old vertex IDs to the new ones,
|
||
and the <em class="parameter"><code>newmap</code></em> argument to obtain the reverse mapping.
|
||
|
||
</p>
|
||
<p>
|
||
This function invalidates all iterators.
|
||
|
||
</p>
|
||
<p><b>Arguments: </b>
|
||
</p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>graph</code></em>:</span></p></td>
|
||
<td><p>
|
||
The graph to work on.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>vertices</code></em>:</span></p></td>
|
||
<td><p>
|
||
The IDs of the vertices to remove, in a vector. The vector
|
||
may contain the same ID more than once.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>map</code></em>:</span></p></td>
|
||
<td><p>
|
||
An optional pointer to a vector that provides the mapping from
|
||
the vertex IDs <span class="emphasis"><em>before</em></span> the removal to the vertex IDs <span class="emphasis"><em>after</em></span>
|
||
the removal. You can supply <code class="constant">NULL</code> here if you are not interested.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>invmap</code></em>:</span></p></td>
|
||
<td><p>
|
||
An optional pointer to a vector that provides the mapping from
|
||
the vertex IDs <span class="emphasis"><em>after</em></span> the removal to the vertex IDs <span class="emphasis"><em>before</em></span>
|
||
the removal. You can supply <code class="constant">NULL</code> here if you are not interested.
|
||
</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<p>
|
||
</p>
|
||
<p><b>Returns: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
Error code:
|
||
<code class="constant">IGRAPH_EINVVID</code>: invalid vertex ID.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
Time complexity: O(|V|+|E|), |V| and |E| are the number of vertices and
|
||
edges in the original graph.
|
||
|
||
</p>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||
<a name="misc-helper-functions"></a>6. Miscellaneous macros and helper functions</h2></div></div></div>
|
||
<div class="toc"><dl class="toc">
|
||
<dt><span class="section"><a href="igraph-Basic.html#IGRAPH_VCOUNT_MAX">6.1. <code class="function">IGRAPH_VCOUNT_MAX</code> — The maximum number of vertices supported in igraph graphs.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Basic.html#IGRAPH_ECOUNT_MAX">6.2. <code class="function">IGRAPH_ECOUNT_MAX</code> — The maximum number of edges supported in igraph graphs.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Basic.html#IGRAPH_UNLIMITED">6.3. <code class="function">IGRAPH_UNLIMITED</code> — Constant for "do not limit results".</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Basic.html#igraph_expand_path_to_pairs">6.4. <code class="function">igraph_expand_path_to_pairs</code> — Helper function to convert a sequence of vertex IDs describing a path into a "pairs" vector.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Basic.html#igraph_invalidate_cache">6.5. <code class="function">igraph_invalidate_cache</code> — Invalidates the internal cache of an igraph graph.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Basic.html#igraph_is_same_graph">6.6. <code class="function">igraph_is_same_graph</code> — Are two graphs identical as labelled graphs?</a></span></dt>
|
||
</dl></div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h3 class="title">
|
||
<a name="IGRAPH_VCOUNT_MAX"></a>6.1. <code class="function">IGRAPH_VCOUNT_MAX</code> — The maximum number of vertices supported in igraph graphs.</h3></div></div></div>
|
||
<a class="indexterm" name="id-1.5.7.2.2"></a><p>
|
||
</p>
|
||
<pre class="programlisting">
|
||
#define IGRAPH_VCOUNT_MAX
|
||
</pre>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
The value of this constant is one less than <code class="constant">IGRAPH_INTEGER_MAX</code> .
|
||
When igraph is compiled in 32-bit mode, this means that you are limited
|
||
to 2<sup>31</sup> – 2 (about 2.1 billion) vertices. In
|
||
64-bit mode, the limit is 2<sup>63</sup> – 2 so you are much
|
||
more likely to hit out-of-memory issues due to other reasons before reaching
|
||
this limit.
|
||
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h3 class="title">
|
||
<a name="IGRAPH_ECOUNT_MAX"></a>6.2. <code class="function">IGRAPH_ECOUNT_MAX</code> — The maximum number of edges supported in igraph graphs.</h3></div></div></div>
|
||
<a class="indexterm" name="id-1.5.7.3.2"></a><p>
|
||
</p>
|
||
<pre class="programlisting">
|
||
#define IGRAPH_ECOUNT_MAX
|
||
</pre>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
The value of this constant is half of <code class="constant">IGRAPH_INTEGER_MAX</code> .
|
||
When igraph is compiled in 32-bit mode, this means that you are limited
|
||
to approximately 2<sup>30</sup> (about 1.07 billion)
|
||
vertices. In 64-bit mode, the limit is approximately
|
||
2<sup>62</sup> so you are much more likely to hit
|
||
out-of-memory issues due to other reasons before reaching this limit.
|
||
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h3 class="title">
|
||
<a name="IGRAPH_UNLIMITED"></a>6.3. <code class="function">IGRAPH_UNLIMITED</code> — Constant for "do not limit results".</h3></div></div></div>
|
||
<a class="indexterm" name="id-1.5.7.4.2"></a><p>
|
||
</p>
|
||
<pre class="programlisting">
|
||
#define IGRAPH_UNLIMITED
|
||
</pre>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
A constant signifying that no limitation should be used with various cutoff,
|
||
size limit or result set size parameters, such as minimum or maximum clique
|
||
size, number of results returned, cutoff for path lengths, etc. Currently
|
||
defined to <code class="literal">-1</code>.
|
||
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h3 class="title">
|
||
<a name="igraph_expand_path_to_pairs"></a>6.4. <code class="function">igraph_expand_path_to_pairs</code> — Helper function to convert a sequence of vertex IDs describing a path into a "pairs" vector.</h3></div></div></div>
|
||
<a class="indexterm" name="id-1.5.7.5.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_expand_path_to_pairs(igraph_vector_int_t* path);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
</p>
|
||
<p>
|
||
This function is useful when you have a sequence of vertex IDs in a graph and
|
||
you would like to retrieve the IDs of the edges between them. The function
|
||
duplicates all but the first and the last elements in the vector, effectively
|
||
converting the path into a vector of vertex IDs that can be passed to
|
||
<a class="link" href="igraph-Basic.html#igraph_get_eids" title="5.2.10. igraph_get_eids — Return edge IDs based on the adjacent vertices."><code class="function">igraph_get_eids()</code></a>.
|
||
|
||
</p>
|
||
<p><b>Arguments: </b>
|
||
</p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code>path</code></em>:</span></p></td>
|
||
<td><p>
|
||
the input vector. It will be modified in-place and it will be
|
||
resized as needed. When the vector contains less than two vertex IDs,
|
||
it will be cleared.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
</p>
|
||
<p><b>Returns: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
Error code: <code class="constant">IGRAPH_ENOMEM</code> if there is not enough memory to expand
|
||
the vector.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h3 class="title">
|
||
<a name="igraph_invalidate_cache"></a>6.5. <code class="function">igraph_invalidate_cache</code> — Invalidates the internal cache of an igraph graph.</h3></div></div></div>
|
||
<a class="indexterm" name="id-1.5.7.6.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
void igraph_invalidate_cache(const igraph_t* graph);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
</p>
|
||
<p>
|
||
igraph graphs cache some basic properties about themselves in an internal
|
||
data structure. This function invalidates the contents of the cache and
|
||
forces a recalculation of the cached properties the next time they are
|
||
needed.
|
||
|
||
</p>
|
||
<p>
|
||
You should not need to call this function during normal usage; however, we
|
||
might ask you to call this function explicitly if we suspect that you are
|
||
running into a bug in igraph's cache handling. A tell-tale sign of an invalid
|
||
cache entry is that the result of a cached igraph function (such as
|
||
<a class="link" href="igraph-Cycles.html#igraph_is_dag" title="2.1. igraph_is_dag — Checks whether a graph is a directed acyclic graph (DAG)."><code class="function">igraph_is_dag()</code></a> or <a class="link" href="igraph-Structural.html#igraph_is_simple" title="20.1. igraph_is_simple — Decides whether the input graph is a simple graph."><code class="function">igraph_is_simple()</code></a>) is different before and
|
||
after a cache invalidation.
|
||
|
||
</p>
|
||
<p><b>Arguments: </b>
|
||
</p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code>graph</code></em>:</span></p></td>
|
||
<td><p>
|
||
The graph whose cache is to be invalidated.</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
|
||
Time complexity: O(1).
|
||
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h3 class="title">
|
||
<a name="igraph_is_same_graph"></a>6.6. <code class="function">igraph_is_same_graph</code> — Are two graphs identical as labelled graphs?</h3></div></div></div>
|
||
<a class="indexterm" name="id-1.5.7.7.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_is_same_graph(const igraph_t *graph1, const igraph_t *graph2, igraph_bool_t *res);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
Two graphs are considered to be the same if they have the same vertex and edge sets.
|
||
Graphs which are the same may have multiple different representations in igraph,
|
||
hence the need for this function.
|
||
|
||
</p>
|
||
<p>
|
||
This function verifies that the two graphs have the same directedness, the same
|
||
number of vertices, and that they contain precisely the same edges (regardless of their ordering)
|
||
when written in terms of vertex indices. Graph attributes are not taken into account.
|
||
|
||
</p>
|
||
<p>
|
||
This concept is different from isomorphism. For example, the graphs
|
||
<code class="literal">0-1, 2-1</code> and <code class="literal">1-2, 0-1</code> are considered the same
|
||
because they only differ in the ordering of their edge lists and the ordering
|
||
of vertices in an undirected edge. However, they are not the same as
|
||
<code class="literal">0-2, 1-2</code>, even though they are isomorphic to it.
|
||
Note that this latter graph contains the edge <code class="literal">0-2</code>
|
||
while the former two do not — thus their edge sets differ.
|
||
|
||
</p>
|
||
<p><b>Arguments: </b>
|
||
</p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>graph1</code></em>:</span></p></td>
|
||
<td><p>
|
||
The first graph object.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>graph2</code></em>:</span></p></td>
|
||
<td><p>
|
||
The second graph object.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>res</code></em>:</span></p></td>
|
||
<td><p>
|
||
The result will be stored here.
|
||
</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<p>
|
||
</p>
|
||
<p><b>Returns: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
Error code.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
Time complexity: O(E), the number of edges in the graphs.
|
||
|
||
</p>
|
||
<p><b>See also: </b></p>
|
||
<div class="variablelist"><table border="0" class="variablelist">
|
||
<colgroup>
|
||
<col align="left" valign="top">
|
||
<col>
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
|
||
<td><p>
|
||
<a class="link" href="igraph-Isomorphism.html#igraph_isomorphic" title="1.1. igraph_isomorphic — Are two graphs isomorphic?"><code class="function">igraph_isomorphic()</code></a> to test if two graphs are isomorphic.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
</p>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<table class="navigation-footer" width="100%" summary="Navigation footer" cellpadding="2" cellspacing="0"><tr valign="middle">
|
||
<td align="left"><a accesskey="p" href="igraph-Tutorial.html"><b>← Chapter 3. Tutorial</b></a></td>
|
||
<td align="right"><a accesskey="n" href="igraph-Error.html"><b>Chapter 5. Error handling →</b></a></td>
|
||
</tr></table>
|
||
</body>
|
||
</html>
|