3428 lines
180 KiB
HTML
3428 lines
180 KiB
HTML
<html>
|
||
<head>
|
||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||
<title>Chapter 15. Graph operators</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-Spatial.html" title="Chapter 14. Spatial graphs">
|
||
<link rel="next" href="igraph-Visitors.html" title="Chapter 16. Graph visitors">
|
||
<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-Spatial.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-Visitors.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-Operators"></a>Chapter 15. Graph operators</h1></div></div></div>
|
||
<div class="toc"><dl class="toc">
|
||
<dt><span class="section"><a href="igraph-Operators.html#union-and-intersection">1. Union and intersection</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Operators.html#other-setlike-operators">2. Other set-like operators</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Operators.html#miscellaneous-operators">3. Miscellaneous operators</a></span></dt>
|
||
</dl></div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||
<a name="union-and-intersection"></a>1. Union and intersection</h2></div></div></div>
|
||
<div class="toc"><dl class="toc">
|
||
<dt><span class="section"><a href="igraph-Operators.html#igraph_disjoint_union">1.1. <code class="function">igraph_disjoint_union</code> — Creates the union of two disjoint graphs.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Operators.html#igraph_disjoint_union_many">1.2. <code class="function">igraph_disjoint_union_many</code> — The disjoint union of many graphs.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Operators.html#igraph_join">1.3. <code class="function">igraph_join</code> — Creates the join of two disjoint graphs.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Operators.html#igraph_union">1.4. <code class="function">igraph_union</code> — Calculates the union of two graphs.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Operators.html#igraph_union_many">1.5. <code class="function">igraph_union_many</code> — Creates the union of many graphs.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Operators.html#igraph_intersection">1.6. <code class="function">igraph_intersection</code> — Collect the common edges from two graphs.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Operators.html#igraph_intersection_many">1.7. <code class="function">igraph_intersection_many</code> — The intersection of more than two graphs.</a></span></dt>
|
||
</dl></div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h3 class="title">
|
||
<a name="igraph_disjoint_union"></a>1.1. <code class="function">igraph_disjoint_union</code> — Creates the union of two disjoint graphs.</h3></div></div></div>
|
||
<a class="indexterm" name="id-1.16.2.2.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_disjoint_union(igraph_t *res,
|
||
const igraph_t *left,
|
||
const igraph_t *right);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
First the vertices of the second graph will be relabeled with new
|
||
vertex IDs to have two disjoint sets of vertex IDs, then the union
|
||
of the two graphs will be formed.
|
||
If the two graphs have |V1| and |V2| vertices and |E1| and |E2|
|
||
edges respectively then the new graph will have |V1|+|V2| vertices
|
||
and |E1|+|E2| edges.
|
||
|
||
</p>
|
||
<p>
|
||
The vertex and edge ordering of the graphs will be preserved.
|
||
In other words, the vertex and edge IDs of the first graph map to
|
||
identical values in the new graph, while the vertex and edge IDs
|
||
of the second graph map to IDs incremented by the vertex and edge
|
||
count of the first graph.
|
||
|
||
</p>
|
||
<p>
|
||
Both graphs need to have the same directedness, i.e. either both
|
||
directed or both undirected.
|
||
|
||
</p>
|
||
<p>
|
||
The current version of this function cannot handle graph, vertex
|
||
and edge attributes, they will be lost.
|
||
|
||
</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>res</code></em>:</span></p></td>
|
||
<td><p>
|
||
Pointer to an uninitialized graph object, the result
|
||
will stored here.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>left</code></em>:</span></p></td>
|
||
<td><p>
|
||
The first graph.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>right</code></em>:</span></p></td>
|
||
<td><p>
|
||
The second 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>
|
||
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-Operators.html#igraph_disjoint_union_many" title="1.2. igraph_disjoint_union_many — The disjoint union of many graphs."><code class="function">igraph_disjoint_union_many()</code></a> for creating the disjoint union
|
||
of more than two graphs, <a class="link" href="igraph-Operators.html#igraph_union" title="1.4. igraph_union — Calculates the union of two graphs."><code class="function">igraph_union()</code></a> for non-disjoint
|
||
union.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
Time complexity: O(|V1|+|V2|+|E1|+|E2|).
|
||
|
||
</p>
|
||
<div class="hideshow" onClick="toggle(this, event)">
|
||
<div class="example">
|
||
<a name="id-1.16.2.2.13.1"></a><p class="title"><b>Example 15.1. File <code class="code">examples/simple/igraph_disjoint_union.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> <stdio.h>
|
||
|
||
int <span class="strong"><strong>main</strong></span>(void) {
|
||
igraph_t left, right, uni;
|
||
igraph_vector_ptr_t glist;
|
||
igraph_int_t i, n;
|
||
|
||
<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>(&left, 4, IGRAPH_UNDIRECTED, 0,1, 1,2, 2,2, 2,3, -1);
|
||
<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>(&right, 5, IGRAPH_UNDIRECTED, 0,1, 1,2, 2,2, 2,4, -1);
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Operators.html#igraph_disjoint_union" title="1.1. igraph_disjoint_union — Creates the union of two disjoint graphs.">igraph_disjoint_union</a></strong></span>(&uni, &left, &right);
|
||
<span class="strong"><strong><a class="link" href="igraph-Foreign.html#igraph_write_graph_edgelist" title="1.2. igraph_write_graph_edgelist — Writes the edge list of a graph to a file.">igraph_write_graph_edgelist</a></strong></span>(&uni, stdout);
|
||
<span class="strong"><strong>printf</strong></span>("\n");
|
||
|
||
<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>(&left);
|
||
<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>(&right);
|
||
<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>(&uni);
|
||
|
||
<span class="emphasis"><em>/* Empty graph list; the result is the directed null graph. */</em></span>
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_vector_ptr_init" title="2.17.1. igraph_vector_ptr_init — Initialize a pointer vector (constructor).">igraph_vector_ptr_init</a></strong></span>(&glist, 0);
|
||
<span class="strong"><strong><a class="link" href="igraph-Operators.html#igraph_disjoint_union_many" title="1.2. igraph_disjoint_union_many — The disjoint union of many graphs.">igraph_disjoint_union_many</a></strong></span>(&uni, &glist);
|
||
<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>(&uni) || <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>(&uni) != 0) {
|
||
<span class="strong"><strong>return</strong></span> 1;
|
||
}
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_vector_ptr_destroy" title="2.17.3. igraph_vector_ptr_destroy — Destroys a pointer vector.">igraph_vector_ptr_destroy</a></strong></span>(&glist);
|
||
<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>(&uni);
|
||
|
||
<span class="emphasis"><em>/* Non-empty graph list. */</em></span>
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_vector_ptr_init" title="2.17.1. igraph_vector_ptr_init — Initialize a pointer vector (constructor).">igraph_vector_ptr_init</a></strong></span>(&glist, 10);
|
||
n = <span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_vector_ptr_size" title="2.17.6. igraph_vector_ptr_size — Gives the number of elements in the pointer vector.">igraph_vector_ptr_size</a></strong></span>(&glist);
|
||
<span class="strong"><strong>for</strong></span> (i = 0; i < n; i++) {
|
||
<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>(glist)[i] = <span class="strong"><strong>calloc</strong></span>(1, <span class="strong"><strong>sizeof</strong></span>(igraph_t));
|
||
<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>(<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>(glist)[i], 2, IGRAPH_DIRECTED, 0,1, 1,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>(&uni)) {
|
||
<span class="strong"><strong>return</strong></span> 2;
|
||
}
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Operators.html#igraph_disjoint_union_many" title="1.2. igraph_disjoint_union_many — The disjoint union of many graphs.">igraph_disjoint_union_many</a></strong></span>(&uni, &glist);
|
||
<span class="strong"><strong><a class="link" href="igraph-Foreign.html#igraph_write_graph_edgelist" title="1.2. igraph_write_graph_edgelist — Writes the edge list of a graph to a file.">igraph_write_graph_edgelist</a></strong></span>(&uni, stdout);
|
||
<span class="strong"><strong>printf</strong></span>("\n");
|
||
|
||
<span class="emphasis"><em>/* Destroy and free the graph list. */</em></span>
|
||
n = <span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_vector_ptr_size" title="2.17.6. igraph_vector_ptr_size — Gives the number of elements in the pointer vector.">igraph_vector_ptr_size</a></strong></span>(&glist);
|
||
<span class="strong"><strong>for</strong></span> (i = 0; i < n; i++) {
|
||
<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>(<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>(glist)[i]);
|
||
<span class="strong"><strong>free</strong></span>(<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>(glist)[i]);
|
||
}
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_vector_ptr_destroy" title="2.17.3. igraph_vector_ptr_destroy — Destroys a pointer vector.">igraph_vector_ptr_destroy</a></strong></span>(&glist);
|
||
<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>(&uni);
|
||
|
||
<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><h3 class="title">
|
||
<a name="igraph_disjoint_union_many"></a>1.2. <code class="function">igraph_disjoint_union_many</code> — The disjoint union of many graphs.</h3></div></div></div>
|
||
<a class="indexterm" name="id-1.16.2.3.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_disjoint_union_many(igraph_t *res,
|
||
const igraph_vector_ptr_t *graphs);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
First the vertices in the graphs will be relabeled with new vertex
|
||
IDs to have pairwise disjoint vertex ID sets and then the union of
|
||
the graphs is formed.
|
||
The number of vertices and edges in the result is the total number
|
||
of vertices and edges in the graphs.
|
||
|
||
</p>
|
||
<p>
|
||
The vertex and edge ordering of the input graphs is preserved in
|
||
the output graph.
|
||
|
||
</p>
|
||
<p>
|
||
All graphs need to have the same directedness, i.e. either all
|
||
directed or all undirected. If the graph list has length zero,
|
||
the result will be a <span class="emphasis"><em>directed</em></span> graph with no vertices.
|
||
|
||
</p>
|
||
<p>
|
||
The current version of this function cannot handle graph, vertex
|
||
and edge attributes, they will be lost.
|
||
|
||
</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>res</code></em>:</span></p></td>
|
||
<td><p>
|
||
Pointer to an uninitialized graph object, the result of
|
||
the operation will be stored here.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>graphs</code></em>:</span></p></td>
|
||
<td><p>
|
||
Pointer vector, contains pointers to initialized
|
||
graph objects.
|
||
</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-Operators.html#igraph_disjoint_union" title="1.1. igraph_disjoint_union — Creates the union of two disjoint graphs."><code class="function">igraph_disjoint_union()</code></a> for an easier syntax if you have
|
||
only two graphs, <a class="link" href="igraph-Operators.html#igraph_union_many" title="1.5. igraph_union_many — Creates the union of many graphs."><code class="function">igraph_union_many()</code></a> for non-disjoint union.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
Time complexity: O(|V|+|E|), the number of vertices plus the number
|
||
of edges in the result.
|
||
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h3 class="title">
|
||
<a name="igraph_join"></a>1.3. <code class="function">igraph_join</code> — Creates the join of two disjoint graphs.</h3></div></div></div>
|
||
<a class="indexterm" name="id-1.16.2.4.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_join(igraph_t *res,
|
||
const igraph_t *left,
|
||
const igraph_t *right);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
First the vertices of the second graph will be relabeled with new
|
||
vertex IDs to have two disjoint sets of vertex IDs, then the union
|
||
of the two graphs will be formed. Finally, the vertces from the
|
||
first graph will have edges added to each vertex from the second.
|
||
If the two graphs have |V1| and |V2| vertices and |E1| and |E2|
|
||
edges respectively then the new graph will have |V1|+|V2| vertices
|
||
and |E1|+|E2|+|V1|*|V2| edges.
|
||
|
||
</p>
|
||
<p>
|
||
The vertex ordering of the graphs will be preserved.
|
||
In other words, the vertex IDs of the first graph map to
|
||
identical values in the new graph, while the vertex IDs
|
||
of the second graph map to IDs incremented by the vertex
|
||
count of the first graph. The new edges will be grouped with the
|
||
other edges that share a from vertex.
|
||
|
||
</p>
|
||
<p>
|
||
Both graphs need to have the same directedness, i.e. either both
|
||
directed or both undirected. If both graphs are directed, then for each
|
||
vertex v, u in graphs G1, G2 we add edges (v, u), (u, v) to maintain
|
||
completeness.
|
||
|
||
</p>
|
||
<p>
|
||
The current version of this function cannot handle graph, vertex
|
||
and edge attributes, they will be lost.
|
||
|
||
</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>res</code></em>:</span></p></td>
|
||
<td><p>
|
||
Pointer to an uninitialized graph object, the result
|
||
will be stored here.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>left</code></em>:</span></p></td>
|
||
<td><p>
|
||
The first graph.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>right</code></em>:</span></p></td>
|
||
<td><p>
|
||
The second 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>
|
||
Error code.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
Time complexity: O(|V1|*|V2|+|E1|+|E2|).
|
||
|
||
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h3 class="title">
|
||
<a name="igraph_union"></a>1.4. <code class="function">igraph_union</code> — Calculates the union of two graphs.</h3></div></div></div>
|
||
<a class="indexterm" name="id-1.16.2.5.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_union(
|
||
igraph_t *res,
|
||
const igraph_t *left, const igraph_t *right,
|
||
igraph_vector_int_t *edge_map1, igraph_vector_int_t *edge_map2);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
The number of vertices in the result is that of the larger graph
|
||
from the two arguments. The result graph contains edges which are
|
||
present in at least one of the operand graphs.
|
||
|
||
</p>
|
||
<p>
|
||
The directedness of the operand graphs must be the same.
|
||
|
||
</p>
|
||
<p>
|
||
Edge multiplicities are handled by taking the <span class="emphasis"><em>larger</em></span> of the two
|
||
multiplicities in the input graphs. In other words, if the first graph
|
||
has N edges between a vertex pair (u, v) and the second graph has M edges,
|
||
the result graph will have max(N, M) edges between them.
|
||
|
||
</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>res</code></em>:</span></p></td>
|
||
<td><p>
|
||
Pointer to an uninitialized graph object, the result
|
||
will be stored here.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>left</code></em>:</span></p></td>
|
||
<td><p>
|
||
The first graph.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>right</code></em>:</span></p></td>
|
||
<td><p>
|
||
The second graph.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>edge_map1</code></em>:</span></p></td>
|
||
<td><p>
|
||
Pointer to an initialized vector or a null pointer.
|
||
If not a null pointer, it will contain a mapping from the edges
|
||
of the first argument graph (<em class="parameter"><code>left</code></em>) to the edges of the
|
||
result graph.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>edge_map2</code></em>:</span></p></td>
|
||
<td><p>
|
||
The same as <em class="parameter"><code>edge_map1</code></em>, but for the second
|
||
graph, <em class="parameter"><code>right</code></em>.
|
||
</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-Operators.html#igraph_union_many" title="1.5. igraph_union_many — Creates the union of many graphs."><code class="function">igraph_union_many()</code></a> for the union of many graphs,
|
||
<a class="link" href="igraph-Operators.html#igraph_intersection" title="1.6. igraph_intersection — Collect the common edges from two graphs."><code class="function">igraph_intersection()</code></a> and <a class="link" href="igraph-Operators.html#igraph_difference" title="2.1. igraph_difference — Calculates the difference of two graphs."><code class="function">igraph_difference()</code></a> for other
|
||
operators.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
Time complexity: O(|V|+|E|), |V| is the number of
|
||
vertices, |E| the number of edges in the result graph.
|
||
|
||
</p>
|
||
<div class="hideshow" onClick="toggle(this, event)">
|
||
<div class="example">
|
||
<a name="id-1.16.2.5.12.1"></a><p class="title"><b>Example 15.2. File <code class="code">examples/simple/igraph_union.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> <stdio.h>
|
||
|
||
int <span class="strong"><strong>main</strong></span>(void) {
|
||
igraph_t left, right, uni;
|
||
igraph_vector_int_t edge_map1, edge_map2;
|
||
|
||
<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>(&edge_map1, 0);
|
||
<span class="strong"><strong>igraph_vector_int_init</strong></span>(&edge_map2, 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>(&left, 4, IGRAPH_DIRECTED,
|
||
0,1, 1,2, 2,2, 2,3, 2,3, 3,2,
|
||
-1);
|
||
|
||
<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>(&right, 6, IGRAPH_DIRECTED,
|
||
0,1, 1,2, 2,2, 2,3, 5,2,
|
||
-1);
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Operators.html#igraph_union" title="1.4. igraph_union — Calculates the union of two graphs.">igraph_union</a></strong></span>(&uni, &left, &right, &edge_map1, &edge_map2);
|
||
<span class="strong"><strong><a class="link" href="igraph-Foreign.html#igraph_write_graph_edgelist" title="1.2. igraph_write_graph_edgelist — Writes the edge list of a graph to a file.">igraph_write_graph_edgelist</a></strong></span>(&uni, stdout);
|
||
<span class="strong"><strong>igraph_vector_int_print</strong></span>(&edge_map1);
|
||
<span class="strong"><strong>igraph_vector_int_print</strong></span>(&edge_map2);
|
||
|
||
<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>(&uni);
|
||
<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>(&left);
|
||
<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>(&right);
|
||
|
||
<span class="strong"><strong>igraph_vector_int_destroy</strong></span>(&edge_map2);
|
||
<span class="strong"><strong>igraph_vector_int_destroy</strong></span>(&edge_map1);
|
||
|
||
<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><h3 class="title">
|
||
<a name="igraph_union_many"></a>1.5. <code class="function">igraph_union_many</code> — Creates the union of many graphs.</h3></div></div></div>
|
||
<a class="indexterm" name="id-1.16.2.6.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_union_many(
|
||
igraph_t *res, const igraph_vector_ptr_t *graphs,
|
||
igraph_vector_int_list_t *edgemaps
|
||
);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
The result graph will contain as many vertices as the largest graph
|
||
among the arguments does, and an edge will be included in it if it
|
||
is part of at least one operand graph.
|
||
|
||
</p>
|
||
<p>
|
||
The number of vertices in the result graph will be the maximum
|
||
number of vertices in the argument graphs.
|
||
|
||
</p>
|
||
<p>
|
||
The directedness of the argument graphs must be the same.
|
||
If the graph list has length zero, the result will be a <span class="emphasis"><em>directed</em></span>
|
||
graph with no vertices.
|
||
|
||
</p>
|
||
<p>
|
||
Edge multiplicities are handled by taking the <span class="emphasis"><em>maximum</em></span> multiplicity of the
|
||
all multiplicities for the same vertex pair (u, v) in the input graphs; this
|
||
will be the multiplicity of (u, v) in the result graph.
|
||
|
||
</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>res</code></em>:</span></p></td>
|
||
<td><p>
|
||
Pointer to an uninitialized graph object, this will
|
||
contain the result.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>graphs</code></em>:</span></p></td>
|
||
<td><p>
|
||
Pointer vector, contains pointers to the operands of
|
||
the union operator, graph objects of course.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>edgemaps</code></em>:</span></p></td>
|
||
<td><p>
|
||
If not a null pointer, then it must be an initialized
|
||
list of integer vectors, and the mappings of edges from the graphs to
|
||
the result graph will be stored here, in the same order as
|
||
<em class="parameter"><code>graphs</code></em>. Each mapping is stored in a separate
|
||
<span class="type">igraph_vector_int_t</span> object.
|
||
</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-Operators.html#igraph_union" title="1.4. igraph_union — Calculates the union of two graphs."><code class="function">igraph_union()</code></a> for the union of two graphs, <a class="link" href="igraph-Operators.html#igraph_intersection_many" title="1.7. igraph_intersection_many — The intersection of more than two graphs."><code class="function">igraph_intersection_many()</code></a>, <a class="link" href="igraph-Operators.html#igraph_intersection" title="1.6. igraph_intersection — Collect the common edges from two graphs."><code class="function">igraph_intersection()</code></a> and <a class="link" href="igraph-Operators.html#igraph_difference" title="2.1. igraph_difference — Calculates the difference of two graphs."><code class="function">igraph_difference</code></a> for other operators.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
Time complexity: O(|V|+|E|), |V| is the number of vertices
|
||
in largest graph and |E| is the number of edges in the result graph.
|
||
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h3 class="title">
|
||
<a name="igraph_intersection"></a>1.6. <code class="function">igraph_intersection</code> — Collect the common edges from two graphs.</h3></div></div></div>
|
||
<a class="indexterm" name="id-1.16.2.7.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_intersection(
|
||
igraph_t *res,
|
||
const igraph_t *left, const igraph_t *right,
|
||
igraph_vector_int_t *edge_map1, igraph_vector_int_t *edge_map2);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
The result graph contains only edges present both in the first and
|
||
the second graph. The number of vertices in the result graph is the
|
||
same as the larger from the two arguments.
|
||
|
||
</p>
|
||
<p>
|
||
The directedness of the operand graphs must be the same.
|
||
|
||
</p>
|
||
<p>
|
||
Edge multiplicities are handled by taking the <span class="emphasis"><em>smaller</em></span> of the two
|
||
multiplicities in the input graphs. In other words, if the first graph
|
||
has N edges between a vertex pair (u, v) and the second graph has M edges,
|
||
the result graph will have min(N, M) edges between them.
|
||
|
||
</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>res</code></em>:</span></p></td>
|
||
<td><p>
|
||
Pointer to an uninitialized graph object. This will
|
||
contain the result of the operation.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>left</code></em>:</span></p></td>
|
||
<td><p>
|
||
The first operand, a graph object.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>right</code></em>:</span></p></td>
|
||
<td><p>
|
||
The second operand, a graph object.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>edge_map1</code></em>:</span></p></td>
|
||
<td><p>
|
||
Null pointer, or an initialized vector.
|
||
If the latter, then a mapping from the edges of the result graph, to
|
||
the edges of the <em class="parameter"><code>left</code></em> input graph is stored here. For the edges that
|
||
are not in the intersection, -1 is stored.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>edge_map2</code></em>:</span></p></td>
|
||
<td><p>
|
||
Null pointer, or an initialized vector. The same
|
||
as <em class="parameter"><code>edge_map1</code></em>, but for the <em class="parameter"><code>right</code></em> input graph. For the edges that
|
||
are not in the intersection, -1 is stored.
|
||
</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-Operators.html#igraph_intersection_many" title="1.7. igraph_intersection_many — The intersection of more than two graphs."><code class="function">igraph_intersection_many()</code></a> to calculate the intersection
|
||
of many graphs at once, <a class="link" href="igraph-Operators.html#igraph_union" title="1.4. igraph_union — Calculates the union of two graphs."><code class="function">igraph_union()</code></a>, <a class="link" href="igraph-Operators.html#igraph_difference" title="2.1. igraph_difference — Calculates the difference of two graphs."><code class="function">igraph_difference()</code></a> for other operators.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
Time complexity: O(|V|+|E|), |V| is the number of nodes, |E|
|
||
is the number of edges in the smaller graph of the two. (The one
|
||
containing less vertices is considered smaller.)
|
||
|
||
</p>
|
||
<div class="hideshow" onClick="toggle(this, event)">
|
||
<div class="example">
|
||
<a name="id-1.16.2.7.12.1"></a><p class="title"><b>Example 15.3. File <code class="code">examples/simple/igraph_intersection.c</code></b></p>
|
||
<div class="example-contents">
|
||
<pre class="programlisting"><span class="strong"><strong>#include</strong></span> <igraph.h>
|
||
|
||
void <span class="strong"><strong>print_vector</strong></span>(<a class="link" href="igraph-Data-structures.html#igraph_vector_t" title="2.1. About igraph_vector_t objects">igraph_vector_t</a> *v) {
|
||
igraph_int_t i, l = <span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_vector_size" title="2.11.2. igraph_vector_size — The size of the vector.">igraph_vector_size</a></strong></span>(v);
|
||
<span class="strong"><strong>for</strong></span> (i = 0; i < l; i++) {
|
||
<span class="strong"><strong>printf</strong></span>(" %" IGRAPH_PRId "", (igraph_int_t) <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>(*v)[i]);
|
||
}
|
||
<span class="strong"><strong>printf</strong></span>("\n");
|
||
}
|
||
|
||
int <span class="strong"><strong>main</strong></span>(void) {
|
||
|
||
igraph_t left, right, isec;
|
||
igraph_vector_int_t v;
|
||
igraph_vector_ptr_t glist;
|
||
igraph_t g1, g2, g3;
|
||
igraph_vector_int_t edge_map1, edge_map2;
|
||
|
||
<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_int_end</strong></span>(&v, -1, 0, 1, 1, 2, 2, 3, -1);
|
||
<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>(&left, &v, 0, IGRAPH_DIRECTED);
|
||
<span class="strong"><strong>igraph_vector_int_destroy</strong></span>(&v);
|
||
|
||
<span class="strong"><strong>igraph_vector_int_init_int_end</strong></span>(&v, -1, 1, 0, 5, 4, 1, 2, 3, 2, -1);
|
||
<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>(&right, &v, 0, IGRAPH_DIRECTED);
|
||
<span class="strong"><strong>igraph_vector_int_destroy</strong></span>(&v);
|
||
|
||
<span class="strong"><strong>igraph_vector_int_init</strong></span>(&edge_map1, 0);
|
||
<span class="strong"><strong>igraph_vector_int_init</strong></span>(&edge_map2, 0);
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Operators.html#igraph_intersection" title="1.6. igraph_intersection — Collect the common edges from two graphs.">igraph_intersection</a></strong></span>(&isec, &left, &right, &edge_map1, &edge_map2);
|
||
<span class="strong"><strong>igraph_vector_int_init</strong></span>(&v, 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>(&isec, &v, 0);
|
||
<span class="strong"><strong>printf</strong></span>("---\n");
|
||
<span class="strong"><strong>igraph_vector_int_print</strong></span>(&v);
|
||
<span class="strong"><strong>igraph_vector_int_print</strong></span>(&edge_map1);
|
||
<span class="strong"><strong>igraph_vector_int_print</strong></span>(&edge_map2);
|
||
<span class="strong"><strong>printf</strong></span>("---\n");
|
||
<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>(&left);
|
||
<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>(&right);
|
||
<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>(&isec);
|
||
<span class="strong"><strong>igraph_vector_int_destroy</strong></span>(&edge_map1);
|
||
<span class="strong"><strong>igraph_vector_int_destroy</strong></span>(&edge_map2);
|
||
|
||
<span class="emphasis"><em>/* empty graph list */</em></span>
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_vector_ptr_init" title="2.17.1. igraph_vector_ptr_init — Initialize a pointer vector (constructor).">igraph_vector_ptr_init</a></strong></span>(&glist, 0);
|
||
<span class="strong"><strong><a class="link" href="igraph-Operators.html#igraph_intersection_many" title="1.7. igraph_intersection_many — The intersection of more than two graphs.">igraph_intersection_many</a></strong></span>(&isec, &glist, 0);
|
||
<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>(&isec) != 0 || !<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>(&isec)) {
|
||
<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>(&isec);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_vector_ptr_destroy" title="2.17.3. igraph_vector_ptr_destroy — Destroys a pointer vector.">igraph_vector_ptr_destroy</a></strong></span>(&glist);
|
||
|
||
<span class="emphasis"><em>/* graph list with an empty graph */</em></span>
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_vector_ptr_init" title="2.17.1. igraph_vector_ptr_init — Initialize a pointer vector (constructor).">igraph_vector_ptr_init</a></strong></span>(&glist, 3);
|
||
<span class="strong"><strong>igraph_vector_int_init_int_end</strong></span>(&v, -1, 0, 1, 1, 2, 2, 3, -1);
|
||
<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, &v, 0, IGRAPH_DIRECTED);
|
||
<span class="strong"><strong>igraph_vector_int_destroy</strong></span>(&v);
|
||
<span class="strong"><strong>igraph_vector_int_init_int_end</strong></span>(&v, -1, 0, 1, 1, 2, 2, 3, -1);
|
||
<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>(&g2, &v, 0, IGRAPH_DIRECTED);
|
||
<span class="strong"><strong>igraph_vector_int_destroy</strong></span>(&v);
|
||
<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>(&g3, 10, IGRAPH_DIRECTED);
|
||
|
||
<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>(glist)[0] = &g1;
|
||
<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>(glist)[1] = &g2;
|
||
<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>(glist)[2] = &g3;
|
||
<span class="strong"><strong><a class="link" href="igraph-Operators.html#igraph_intersection_many" title="1.7. igraph_intersection_many — The intersection of more than two graphs.">igraph_intersection_many</a></strong></span>(&isec, &glist, 0);
|
||
<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>(&isec) != 0 || <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>(&isec) != 10) {
|
||
<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>(&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><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>(&g3);
|
||
<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>(&isec);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_vector_ptr_destroy" title="2.17.3. igraph_vector_ptr_destroy — Destroys a pointer vector.">igraph_vector_ptr_destroy</a></strong></span>(&glist);
|
||
|
||
<span class="emphasis"><em>/* "proper" graph list */</em></span>
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_vector_ptr_init" title="2.17.1. igraph_vector_ptr_init — Initialize a pointer vector (constructor).">igraph_vector_ptr_init</a></strong></span>(&glist, 3);
|
||
<span class="strong"><strong>igraph_vector_int_init_int_end</strong></span>(&v, -1, 0, 1, 1, 2, 2, 3, -1);
|
||
<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, &v, 0, IGRAPH_DIRECTED);
|
||
<span class="strong"><strong>igraph_vector_int_destroy</strong></span>(&v);
|
||
<span class="strong"><strong>igraph_vector_int_init_int_end</strong></span>(&v, -1, 0, 1, 1, 2, 2, 3, 3, 2, 4, 5, 6, 5, -1);
|
||
<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>(&g2, &v, 0, IGRAPH_DIRECTED);
|
||
<span class="strong"><strong>igraph_vector_int_destroy</strong></span>(&v);
|
||
<span class="strong"><strong>igraph_vector_int_init_int_end</strong></span>(&v, -1, 2, 3, 1, 0, 1, 2, 3, 2, 4, 5, 6, 5, 2, 3, -1);
|
||
<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>(&g3, &v, 0, IGRAPH_DIRECTED);
|
||
<span class="strong"><strong>igraph_vector_int_destroy</strong></span>(&v);
|
||
|
||
<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>(glist)[0] = &g1;
|
||
<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>(glist)[1] = &g2;
|
||
<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>(glist)[2] = &g3;
|
||
<span class="strong"><strong><a class="link" href="igraph-Operators.html#igraph_intersection_many" title="1.7. igraph_intersection_many — The intersection of more than two graphs.">igraph_intersection_many</a></strong></span>(&isec, &glist, 0);
|
||
<span class="strong"><strong><a class="link" href="igraph-Foreign.html#igraph_write_graph_edgelist" title="1.2. igraph_write_graph_edgelist — Writes the edge list of a graph to a file.">igraph_write_graph_edgelist</a></strong></span>(&isec, stdout);
|
||
<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><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>(&g3);
|
||
<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>(&isec);
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_vector_ptr_destroy" title="2.17.3. igraph_vector_ptr_destroy — Destroys a pointer vector.">igraph_vector_ptr_destroy</a></strong></span>(&glist);
|
||
|
||
<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><h3 class="title">
|
||
<a name="igraph_intersection_many"></a>1.7. <code class="function">igraph_intersection_many</code> — The intersection of more than two graphs.</h3></div></div></div>
|
||
<a class="indexterm" name="id-1.16.2.8.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_intersection_many(
|
||
igraph_t *res, const igraph_vector_ptr_t *graphs,
|
||
igraph_vector_int_list_t *edgemaps
|
||
);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
This function calculates the intersection of the graphs stored in
|
||
the <em class="parameter"><code>graphs</code></em> argument. Only those edges will be included in the
|
||
result graph which are part of every graph in <em class="parameter"><code>graphs</code></em>.
|
||
|
||
</p>
|
||
<p>
|
||
The number of vertices in the result graph will be the maximum
|
||
number of vertices in the argument graphs.
|
||
|
||
</p>
|
||
<p>
|
||
The directedness of the argument graphs must be the same.
|
||
If the graph list has length zero, the result will be a <span class="emphasis"><em>directed</em></span>
|
||
graph with no vertices.
|
||
|
||
</p>
|
||
<p>
|
||
Edge multiplicities are handled by taking the <span class="emphasis"><em>minimum</em></span> multiplicity of the
|
||
all multiplicities for the same vertex pair (u, v) in the input graphs; this
|
||
will be the multiplicity of (u, v) in the result graph.
|
||
|
||
</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>res</code></em>:</span></p></td>
|
||
<td><p>
|
||
Pointer to an uninitialized graph object, the result of
|
||
the operation will be stored here.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>graphs</code></em>:</span></p></td>
|
||
<td><p>
|
||
Pointer vector, contains pointers to graphs objects,
|
||
the operands of the intersection operator.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>edgemaps</code></em>:</span></p></td>
|
||
<td><p>
|
||
If not a null pointer, then it must be an initialized
|
||
list of integer vectors, and the mappings of edges from the graphs to
|
||
the result graph will be stored here, in the same order as
|
||
<em class="parameter"><code>graphs</code></em>. Each mapping is stored in a separate
|
||
<span class="type">igraph_vector_int_t</span> object. For the edges that are not in
|
||
the intersection, -1 is stored.
|
||
</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-Operators.html#igraph_intersection" title="1.6. igraph_intersection — Collect the common edges from two graphs."><code class="function">igraph_intersection()</code></a> for the intersection of two graphs,
|
||
<a class="link" href="igraph-Operators.html#igraph_union_many" title="1.5. igraph_union_many — Creates the union of many graphs."><code class="function">igraph_union_many()</code></a>, <a class="link" href="igraph-Operators.html#igraph_union" title="1.4. igraph_union — Calculates the union of two graphs."><code class="function">igraph_union()</code></a> and <a class="link" href="igraph-Operators.html#igraph_difference" title="2.1. igraph_difference — Calculates the difference of two graphs."><code class="function">igraph_difference()</code></a> for other operators.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
Time complexity: O(|V|+|E|), |V| is the number of vertices,
|
||
|E| is the number of edges in the smallest graph (i.e. the graph having
|
||
the less vertices).
|
||
|
||
</p>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||
<a name="other-setlike-operators"></a>2. Other set-like operators</h2></div></div></div>
|
||
<div class="toc"><dl class="toc">
|
||
<dt><span class="section"><a href="igraph-Operators.html#igraph_difference">2.1. <code class="function">igraph_difference</code> — Calculates the difference of two graphs.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Operators.html#igraph_complementer">2.2. <code class="function">igraph_complementer</code> — Creates the complementer of a graph.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Operators.html#igraph_compose">2.3. <code class="function">igraph_compose</code> — Calculates the composition of two graphs.</a></span></dt>
|
||
</dl></div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h3 class="title">
|
||
<a name="igraph_difference"></a>2.1. <code class="function">igraph_difference</code> — Calculates the difference of two graphs.</h3></div></div></div>
|
||
<a class="indexterm" name="id-1.16.3.2.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_difference(igraph_t *res,
|
||
const igraph_t *orig, const igraph_t *sub);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
The number of vertices in the result is the number of vertices in
|
||
the original graph, i.e. the left, first operand. In the results
|
||
graph only edges will be included from <em class="parameter"><code>orig</code></em> which are not
|
||
present in <em class="parameter"><code>sub</code></em>.
|
||
|
||
</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>res</code></em>:</span></p></td>
|
||
<td><p>
|
||
Pointer to an uninitialized graph object, the result
|
||
will be stored here.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>orig</code></em>:</span></p></td>
|
||
<td><p>
|
||
The left operand of the operator, a graph object.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>sub</code></em>:</span></p></td>
|
||
<td><p>
|
||
The right operand of the operator, a graph object.
|
||
</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-Operators.html#igraph_intersection" title="1.6. igraph_intersection — Collect the common edges from two graphs."><code class="function">igraph_intersection()</code></a> and <a class="link" href="igraph-Operators.html#igraph_union" title="1.4. igraph_union — Calculates the union of two graphs."><code class="function">igraph_union()</code></a> for other
|
||
operators.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
Time complexity: O(|V|+|E|), |V| is the number vertices in
|
||
the smaller graph, |E| is the
|
||
number of edges in the result graph.
|
||
|
||
</p>
|
||
<div class="hideshow" onClick="toggle(this, event)">
|
||
<div class="example">
|
||
<a name="id-1.16.3.2.10.1"></a><p class="title"><b>Example 15.4. File <code class="code">examples/simple/igraph_difference.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 orig, sub, diff;
|
||
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="emphasis"><em>/* Subtract from itself */</em></span>
|
||
<span class="strong"><strong>printf</strong></span>("subtract itself\n");
|
||
<span class="strong"><strong>igraph_vector_int_init_int_end</strong></span>(&v, -1, 0, 1, 1, 2, 2, 1, 4, 5, -1);
|
||
<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>(&orig, &v, 0, IGRAPH_DIRECTED);
|
||
<span class="strong"><strong>igraph_vector_int_destroy</strong></span>(&v);
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Operators.html#igraph_difference" title="2.1. igraph_difference — Calculates the difference of two graphs.">igraph_difference</a></strong></span>(&diff, &orig, &orig);
|
||
<span class="strong"><strong><a class="link" href="igraph-Foreign.html#igraph_write_graph_edgelist" title="1.2. igraph_write_graph_edgelist — Writes the edge list of a graph to a file.">igraph_write_graph_edgelist</a></strong></span>(&diff, stdout);
|
||
<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>(&diff) != 0 ||
|
||
<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>(&diff) != <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>(&orig)) {
|
||
<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>(&orig);
|
||
<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>(&diff);
|
||
|
||
<span class="emphasis"><em>/* Same for undirected graph */</em></span>
|
||
<span class="strong"><strong>printf</strong></span>("subtract itself, undirected\n");
|
||
<span class="strong"><strong>igraph_vector_int_init_int_end</strong></span>(&v, -1, 0, 1, 1, 2, 2, 1, 4, 5, -1);
|
||
<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>(&orig, &v, 0, IGRAPH_UNDIRECTED);
|
||
<span class="strong"><strong>igraph_vector_int_destroy</strong></span>(&v);
|
||
|
||
<span class="strong"><strong>igraph_vector_int_init_int_end</strong></span>(&v, -1, 1, 0, 1, 2, 2, 1, 4, 5, -1);
|
||
<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>(&sub, &v, 0, IGRAPH_UNDIRECTED);
|
||
<span class="strong"><strong>igraph_vector_int_destroy</strong></span>(&v);
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Operators.html#igraph_difference" title="2.1. igraph_difference — Calculates the difference of two graphs.">igraph_difference</a></strong></span>(&diff, &orig, &sub);
|
||
<span class="strong"><strong><a class="link" href="igraph-Foreign.html#igraph_write_graph_edgelist" title="1.2. igraph_write_graph_edgelist — Writes the edge list of a graph to a file.">igraph_write_graph_edgelist</a></strong></span>(&diff, stdout);
|
||
<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>(&diff) != 0 ||
|
||
<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>(&diff) != <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>(&orig)) {
|
||
<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>(&orig);
|
||
<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>(&sub);
|
||
<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>(&diff);
|
||
|
||
<span class="emphasis"><em>/* Subtract the empty graph */</em></span>
|
||
<span class="strong"><strong>printf</strong></span>("subtract empty\n");
|
||
<span class="strong"><strong>igraph_vector_int_init_int_end</strong></span>(&v, -1, 0, 1, 1, 2, 2, 1, 4, 5, -1);
|
||
<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>(&orig, &v, 0, IGRAPH_DIRECTED);
|
||
<span class="strong"><strong>igraph_vector_int_destroy</strong></span>(&v);
|
||
|
||
<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>(&sub, 3, IGRAPH_DIRECTED);
|
||
<span class="strong"><strong><a class="link" href="igraph-Operators.html#igraph_difference" title="2.1. igraph_difference — Calculates the difference of two graphs.">igraph_difference</a></strong></span>(&diff, &orig, &sub);
|
||
<span class="strong"><strong><a class="link" href="igraph-Foreign.html#igraph_write_graph_edgelist" title="1.2. igraph_write_graph_edgelist — Writes the edge list of a graph to a file.">igraph_write_graph_edgelist</a></strong></span>(&diff, stdout);
|
||
<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>(&diff) != <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>(&orig) ||
|
||
<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>(&diff) != <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>(&orig)) {
|
||
<span class="strong"><strong>return</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>(&orig);
|
||
<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>(&sub);
|
||
<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>(&diff);
|
||
|
||
<span class="emphasis"><em>/* A `real' example */</em></span>
|
||
<span class="strong"><strong>printf</strong></span>("real example\n");
|
||
<span class="strong"><strong>igraph_vector_int_init_int_end</strong></span>(&v, -1, 0, 1, 1, 2, 2, 1, 4, 5, 8, 9, -1);
|
||
<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>(&orig, &v, 0, IGRAPH_DIRECTED);
|
||
<span class="strong"><strong>igraph_vector_int_destroy</strong></span>(&v);
|
||
|
||
<span class="strong"><strong>igraph_vector_int_init_int_end</strong></span>(&v, -1, 0, 1, 5, 4, 2, 1, 6, 7, -1);
|
||
<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>(&sub, &v, 0, IGRAPH_DIRECTED);
|
||
<span class="strong"><strong>igraph_vector_int_destroy</strong></span>(&v);
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Operators.html#igraph_difference" title="2.1. igraph_difference — Calculates the difference of two graphs.">igraph_difference</a></strong></span>(&diff, &orig, &sub);
|
||
<span class="strong"><strong><a class="link" href="igraph-Foreign.html#igraph_write_graph_edgelist" title="1.2. igraph_write_graph_edgelist — Writes the edge list of a graph to a file.">igraph_write_graph_edgelist</a></strong></span>(&diff, stdout);
|
||
|
||
<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>(&diff);
|
||
<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>(&orig);
|
||
<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>(&sub);
|
||
|
||
<span class="emphasis"><em>/* undirected version */</em></span>
|
||
<span class="strong"><strong>printf</strong></span>("real example, undirected\n");
|
||
<span class="strong"><strong>igraph_vector_int_init_int_end</strong></span>(&v, -1, 0, 1, 1, 2, 2, 1, 4, 5, 8, 9, 8, 10, 8, 13, 8, 11, 8, 12, -1);
|
||
<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>(&orig, &v, 0, IGRAPH_UNDIRECTED);
|
||
<span class="strong"><strong>igraph_vector_int_destroy</strong></span>(&v);
|
||
|
||
<span class="strong"><strong>igraph_vector_int_init_int_end</strong></span>(&v, -1, 0, 1, 5, 4, 2, 1, 6, 7, 8, 10, 8, 13, -1);
|
||
<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>(&sub, &v, 0, IGRAPH_UNDIRECTED);
|
||
<span class="strong"><strong>igraph_vector_int_destroy</strong></span>(&v);
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Operators.html#igraph_difference" title="2.1. igraph_difference — Calculates the difference of two graphs.">igraph_difference</a></strong></span>(&diff, &orig, &sub);
|
||
<span class="strong"><strong><a class="link" href="igraph-Foreign.html#igraph_write_graph_edgelist" title="1.2. igraph_write_graph_edgelist — Writes the edge list of a graph to a file.">igraph_write_graph_edgelist</a></strong></span>(&diff, stdout);
|
||
|
||
<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>(&diff);
|
||
<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>(&orig);
|
||
<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>(&sub);
|
||
|
||
<span class="emphasis"><em>/* undirected version with loop edge, tests Github issue #597 */</em></span>
|
||
<span class="strong"><strong>printf</strong></span>("Github issue #597, undirected\n");
|
||
<span class="strong"><strong>igraph_vector_int_init_int_end</strong></span>(&v, -1, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 0, -1);
|
||
<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>(&orig, &v, 0, IGRAPH_UNDIRECTED);
|
||
<span class="strong"><strong>igraph_vector_int_destroy</strong></span>(&v);
|
||
|
||
<span class="strong"><strong>igraph_vector_int_init_int_end</strong></span>(&v, -1, 0, 1, 1, 2, 2, 3, 3, 4, 4, 0, -1);
|
||
<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>(&sub, &v, 0, IGRAPH_UNDIRECTED);
|
||
<span class="strong"><strong>igraph_vector_int_destroy</strong></span>(&v);
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Operators.html#igraph_difference" title="2.1. igraph_difference — Calculates the difference of two graphs.">igraph_difference</a></strong></span>(&diff, &orig, &sub);
|
||
<span class="strong"><strong><a class="link" href="igraph-Foreign.html#igraph_write_graph_edgelist" title="1.2. igraph_write_graph_edgelist — Writes the edge list of a graph to a file.">igraph_write_graph_edgelist</a></strong></span>(&diff, stdout);
|
||
|
||
<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>(&diff);
|
||
<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>(&orig);
|
||
<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>(&sub);
|
||
|
||
<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><h3 class="title">
|
||
<a name="igraph_complementer"></a>2.2. <code class="function">igraph_complementer</code> — Creates the complementer of a graph.</h3></div></div></div>
|
||
<a class="indexterm" name="id-1.16.3.3.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_complementer(igraph_t *res, const igraph_t *graph,
|
||
igraph_bool_t loops);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
The complementer graph means that all edges which are
|
||
not part of the original graph will be included in the result.
|
||
|
||
</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>res</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>graph</code></em>:</span></p></td>
|
||
<td><p>
|
||
The original graph.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>loops</code></em>:</span></p></td>
|
||
<td><p>
|
||
Whether to add loop edges to the complementer 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>
|
||
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-Operators.html#igraph_union" title="1.4. igraph_union — Calculates the union of two graphs."><code class="function">igraph_union()</code></a>, <a class="link" href="igraph-Operators.html#igraph_intersection" title="1.6. igraph_intersection — Collect the common edges from two graphs."><code class="function">igraph_intersection()</code></a> and <a class="link" href="igraph-Operators.html#igraph_difference" title="2.1. igraph_difference — Calculates the difference of two graphs."><code class="function">igraph_difference()</code></a>.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
Time complexity: O(|V|+|E1|+|E2|), |V| is the number of
|
||
vertices in the graph, |E1| is the number of edges in the original
|
||
and |E2| in the complementer graph.
|
||
|
||
</p>
|
||
<div class="hideshow" onClick="toggle(this, event)">
|
||
<div class="example">
|
||
<a name="id-1.16.3.3.10.1"></a><p class="title"><b>Example 15.5. File <code class="code">examples/simple/igraph_complementer.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;
|
||
|
||
<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>/* complementer of the empty graph */</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>(&g1, 5, IGRAPH_DIRECTED);
|
||
<span class="strong"><strong><a class="link" href="igraph-Operators.html#igraph_complementer" title="2.2. igraph_complementer — Creates the complementer of a graph.">igraph_complementer</a></strong></span>(&g2, &g1, IGRAPH_LOOPS);
|
||
<span class="strong"><strong><a class="link" href="igraph-Foreign.html#igraph_write_graph_edgelist" title="1.2. igraph_write_graph_edgelist — Writes the edge list of a graph to a file.">igraph_write_graph_edgelist</a></strong></span>(&g2, stdout);
|
||
<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>printf</strong></span>("---\n");
|
||
|
||
<span class="emphasis"><em>/* the same without loops */</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>(&g1, 5, IGRAPH_DIRECTED);
|
||
<span class="strong"><strong><a class="link" href="igraph-Operators.html#igraph_complementer" title="2.2. igraph_complementer — Creates the complementer of a graph.">igraph_complementer</a></strong></span>(&g2, &g1, IGRAPH_NO_LOOPS);
|
||
<span class="strong"><strong><a class="link" href="igraph-Foreign.html#igraph_write_graph_edgelist" title="1.2. igraph_write_graph_edgelist — Writes the edge list of a graph to a file.">igraph_write_graph_edgelist</a></strong></span>(&g2, stdout);
|
||
<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>printf</strong></span>("---\n");
|
||
|
||
<span class="emphasis"><em>/* complementer of the full graph */</em></span>
|
||
<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>(&g1, 5, IGRAPH_DIRECTED, IGRAPH_LOOPS);
|
||
<span class="strong"><strong><a class="link" href="igraph-Operators.html#igraph_complementer" title="2.2. igraph_complementer — Creates the complementer of a graph.">igraph_complementer</a></strong></span>(&g2, &g1, IGRAPH_LOOPS);
|
||
<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>(&g2) != 0) {
|
||
<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>(&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>printf</strong></span>("---\n");
|
||
|
||
<span class="emphasis"><em>/* complementer of the full graph, results loops only */</em></span>
|
||
<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>(&g1, 5, IGRAPH_DIRECTED, IGRAPH_NO_LOOPS);
|
||
<span class="strong"><strong><a class="link" href="igraph-Operators.html#igraph_complementer" title="2.2. igraph_complementer — Creates the complementer of a graph.">igraph_complementer</a></strong></span>(&g2, &g1, IGRAPH_LOOPS);
|
||
<span class="strong"><strong><a class="link" href="igraph-Foreign.html#igraph_write_graph_edgelist" title="1.2. igraph_write_graph_edgelist — Writes the edge list of a graph to a file.">igraph_write_graph_edgelist</a></strong></span>(&g2, stdout);
|
||
<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>printf</strong></span>("---\n");
|
||
|
||
<span class="emphasis"><em>/**************</em></span>
|
||
<span class="emphasis"><em> * undirected *</em></span>
|
||
<span class="emphasis"><em> *************/</em></span>
|
||
|
||
<span class="emphasis"><em>/* complementer of the empty graph */</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>(&g1, 5, IGRAPH_UNDIRECTED);
|
||
<span class="strong"><strong><a class="link" href="igraph-Operators.html#igraph_complementer" title="2.2. igraph_complementer — Creates the complementer of a graph.">igraph_complementer</a></strong></span>(&g2, &g1, IGRAPH_LOOPS);
|
||
<span class="strong"><strong><a class="link" href="igraph-Foreign.html#igraph_write_graph_edgelist" title="1.2. igraph_write_graph_edgelist — Writes the edge list of a graph to a file.">igraph_write_graph_edgelist</a></strong></span>(&g2, stdout);
|
||
<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>printf</strong></span>("---\n");
|
||
|
||
<span class="emphasis"><em>/* the same without loops */</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>(&g1, 5, IGRAPH_UNDIRECTED);
|
||
<span class="strong"><strong><a class="link" href="igraph-Operators.html#igraph_complementer" title="2.2. igraph_complementer — Creates the complementer of a graph.">igraph_complementer</a></strong></span>(&g2, &g1, IGRAPH_NO_LOOPS);
|
||
<span class="strong"><strong><a class="link" href="igraph-Foreign.html#igraph_write_graph_edgelist" title="1.2. igraph_write_graph_edgelist — Writes the edge list of a graph to a file.">igraph_write_graph_edgelist</a></strong></span>(&g2, stdout);
|
||
<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>printf</strong></span>("---\n");
|
||
|
||
<span class="emphasis"><em>/* complementer of the full graph */</em></span>
|
||
<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>(&g1, 5, IGRAPH_UNDIRECTED, IGRAPH_LOOPS);
|
||
<span class="strong"><strong><a class="link" href="igraph-Operators.html#igraph_complementer" title="2.2. igraph_complementer — Creates the complementer of a graph.">igraph_complementer</a></strong></span>(&g2, &g1, IGRAPH_LOOPS);
|
||
<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>(&g2) != 0) {
|
||
<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>(&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>printf</strong></span>("---\n");
|
||
|
||
<span class="emphasis"><em>/* complementer of the full graph, results loops only */</em></span>
|
||
<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>(&g1, 5, IGRAPH_UNDIRECTED, IGRAPH_NO_LOOPS);
|
||
<span class="strong"><strong><a class="link" href="igraph-Operators.html#igraph_complementer" title="2.2. igraph_complementer — Creates the complementer of a graph.">igraph_complementer</a></strong></span>(&g2, &g1, IGRAPH_LOOPS);
|
||
<span class="strong"><strong><a class="link" href="igraph-Foreign.html#igraph_write_graph_edgelist" title="1.2. igraph_write_graph_edgelist — Writes the edge list of a graph to a file.">igraph_write_graph_edgelist</a></strong></span>(&g2, stdout);
|
||
<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><h3 class="title">
|
||
<a name="igraph_compose"></a>2.3. <code class="function">igraph_compose</code> — Calculates the composition of two graphs.</h3></div></div></div>
|
||
<a class="indexterm" name="id-1.16.3.4.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_compose(igraph_t *res,
|
||
const igraph_t *g1,
|
||
const igraph_t *g2,
|
||
igraph_vector_int_t *edge_map1,
|
||
igraph_vector_int_t *edge_map2);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
The composition of graphs contains the same number of vertices as
|
||
the bigger graph of the two operands. It contains an (i,j) edge if
|
||
and only if there is a k vertex, such that the first graph
|
||
contains an (i,k) edge and the second graph a (k,j) edge.
|
||
|
||
</p>
|
||
<p>
|
||
This is of course exactly the composition of two binary relations.
|
||
|
||
</p>
|
||
<p>
|
||
The two graphs must have the same directedness, otherwise the function
|
||
returns with an error. Note that for undirected graphs the two relations
|
||
are by definition symmetric.
|
||
|
||
</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>res</code></em>:</span></p></td>
|
||
<td><p>
|
||
Pointer to an uninitialized graph object, the result
|
||
will be stored here.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>g1</code></em>:</span></p></td>
|
||
<td><p>
|
||
The first operand, a graph object.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>g2</code></em>:</span></p></td>
|
||
<td><p>
|
||
The second operand, another graph object.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>edge_map1</code></em>:</span></p></td>
|
||
<td><p>
|
||
If not a null pointer, then it must be a pointer
|
||
to an initialized vector, and a mapping from the edges of
|
||
the result graph to the edges of the first graph is stored
|
||
here.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>edge_map2</code></em>:</span></p></td>
|
||
<td><p>
|
||
If not a null pointer, then it must be a pointer
|
||
to an initialized vector, and a mapping from the edges of
|
||
the result graph to the edges of the second graph is 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(|V|*d1*d2), |V| is the number of vertices in the
|
||
first graph, d1 and d2 the average degree in the first and second
|
||
graphs.
|
||
|
||
</p>
|
||
<div class="hideshow" onClick="toggle(this, event)">
|
||
<div class="example">
|
||
<a name="id-1.16.3.4.10.1"></a><p class="title"><b>Example 15.6. File <code class="code">examples/simple/igraph_compose.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, res;
|
||
igraph_vector_int_t v;
|
||
igraph_vector_int_t map1, map2;
|
||
|
||
<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>(&map1, 0);
|
||
<span class="strong"><strong>igraph_vector_int_init</strong></span>(&map2, 0);
|
||
|
||
<span class="emphasis"><em>/* composition with the empty graph */</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>(&g1, 5, IGRAPH_DIRECTED);
|
||
<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>(&g2, 5, IGRAPH_DIRECTED, IGRAPH_NO_LOOPS);
|
||
<span class="strong"><strong><a class="link" href="igraph-Operators.html#igraph_compose" title="2.3. igraph_compose — Calculates the composition of two graphs.">igraph_compose</a></strong></span>(&res, &g1, &g2, &map1, &map2);
|
||
<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>(&res) != 0) {
|
||
<span class="strong"><strong>return</strong></span> 1;
|
||
}
|
||
<span class="strong"><strong>if</strong></span> (<span class="strong"><strong>igraph_vector_int_size</strong></span>(&map1) != 0 || <span class="strong"><strong>igraph_vector_int_size</strong></span>(&map2) != 0) {
|
||
<span class="strong"><strong>return</strong></span> 11;
|
||
}
|
||
<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>(&res);
|
||
<span class="strong"><strong><a class="link" href="igraph-Operators.html#igraph_compose" title="2.3. igraph_compose — Calculates the composition of two graphs.">igraph_compose</a></strong></span>(&res, &g2, &g1, &map1, &map2);
|
||
<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>(&res) != 0) {
|
||
<span class="strong"><strong>return</strong></span> 2;
|
||
}
|
||
<span class="strong"><strong>if</strong></span> (<span class="strong"><strong>igraph_vector_int_size</strong></span>(&map1) != 0 || <span class="strong"><strong>igraph_vector_int_size</strong></span>(&map2) != 0) {
|
||
<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>(&res);
|
||
<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="emphasis"><em>/* same but undirected */</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>(&g1, 5, IGRAPH_UNDIRECTED);
|
||
<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>(&g2, 5, IGRAPH_UNDIRECTED, IGRAPH_NO_LOOPS);
|
||
<span class="strong"><strong><a class="link" href="igraph-Operators.html#igraph_compose" title="2.3. igraph_compose — Calculates the composition of two graphs.">igraph_compose</a></strong></span>(&res, &g1, &g2, &map1, &map2);
|
||
<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>(&res) != 0) {
|
||
<span class="strong"><strong>return</strong></span> 1;
|
||
}
|
||
<span class="strong"><strong>if</strong></span> (<span class="strong"><strong>igraph_vector_int_size</strong></span>(&map1) != 0 || <span class="strong"><strong>igraph_vector_int_size</strong></span>(&map2) != 0) {
|
||
<span class="strong"><strong>return</strong></span> 11;
|
||
}
|
||
<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>(&res);
|
||
<span class="strong"><strong><a class="link" href="igraph-Operators.html#igraph_compose" title="2.3. igraph_compose — Calculates the composition of two graphs.">igraph_compose</a></strong></span>(&res, &g2, &g1, &map1, &map2);
|
||
<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>(&res) != 0) {
|
||
<span class="strong"><strong>return</strong></span> 2;
|
||
}
|
||
<span class="strong"><strong>if</strong></span> (<span class="strong"><strong>igraph_vector_int_size</strong></span>(&map1) != 0 || <span class="strong"><strong>igraph_vector_int_size</strong></span>(&map2) != 0) {
|
||
<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>(&res);
|
||
<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="emphasis"><em>/* proper directed graph */</em></span>
|
||
<span class="strong"><strong>igraph_vector_int_init_int_end</strong></span>(&v, -1, 0, 1, 1, 2, 5, 6, -1);
|
||
<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, &v, 0, IGRAPH_DIRECTED);
|
||
<span class="strong"><strong>igraph_vector_int_destroy</strong></span>(&v);
|
||
|
||
<span class="strong"><strong>igraph_vector_int_init_int_end</strong></span>(&v, -1, 0, 1, 2, 4, 5, 6, -1);
|
||
<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>(&g2, &v, 0, IGRAPH_DIRECTED);
|
||
<span class="strong"><strong>igraph_vector_int_destroy</strong></span>(&v);
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Operators.html#igraph_compose" title="2.3. igraph_compose — Calculates the composition of two graphs.">igraph_compose</a></strong></span>(&res, &g1, &g2, &map1, &map2);
|
||
<span class="strong"><strong><a class="link" href="igraph-Foreign.html#igraph_write_graph_edgelist" title="1.2. igraph_write_graph_edgelist — Writes the edge list of a graph to a file.">igraph_write_graph_edgelist</a></strong></span>(&res, stdout);
|
||
<span class="strong"><strong>igraph_vector_int_print</strong></span>(&map1);
|
||
<span class="strong"><strong>igraph_vector_int_print</strong></span>(&map2);
|
||
<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>(&res);
|
||
<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="emphasis"><em>/* undirected graph */</em></span>
|
||
<span class="strong"><strong>igraph_vector_int_init_int_end</strong></span>(&v, -1, 0, 1, 1, 2, 5, 6, -1);
|
||
<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, &v, 0, IGRAPH_UNDIRECTED);
|
||
<span class="strong"><strong>igraph_vector_int_destroy</strong></span>(&v);
|
||
|
||
<span class="strong"><strong>igraph_vector_int_init_int_end</strong></span>(&v, -1, 0, 1, 0, 4, 5, 6, -1);
|
||
<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>(&g2, &v, 0, IGRAPH_UNDIRECTED);
|
||
<span class="strong"><strong>igraph_vector_int_destroy</strong></span>(&v);
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Operators.html#igraph_compose" title="2.3. igraph_compose — Calculates the composition of two graphs.">igraph_compose</a></strong></span>(&res, &g1, &g2, &map1, &map2);
|
||
<span class="strong"><strong><a class="link" href="igraph-Foreign.html#igraph_write_graph_edgelist" title="1.2. igraph_write_graph_edgelist — Writes the edge list of a graph to a file.">igraph_write_graph_edgelist</a></strong></span>(&res, stdout);
|
||
<span class="strong"><strong>igraph_vector_int_print</strong></span>(&map1);
|
||
<span class="strong"><strong>igraph_vector_int_print</strong></span>(&map2);
|
||
<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>(&res);
|
||
<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>igraph_vector_int_destroy</strong></span>(&map2);
|
||
<span class="strong"><strong>igraph_vector_int_destroy</strong></span>(&map1);
|
||
|
||
<span class="strong"><strong>return</strong></span> 0;
|
||
}
|
||
</pre>
|
||
<p></p>
|
||
</div>
|
||
</div>
|
||
<br class="example-break">
|
||
</div>
|
||
<p>
|
||
</p>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||
<a name="miscellaneous-operators"></a>3. Miscellaneous operators</h2></div></div></div>
|
||
<div class="toc"><dl class="toc">
|
||
<dt><span class="section"><a href="igraph-Operators.html#igraph_connect_neighborhood">3.1. <code class="function">igraph_connect_neighborhood</code> — Connects each vertex to its neighborhood.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Operators.html#igraph_contract_vertices">3.2. <code class="function">igraph_contract_vertices</code> — Replace multiple vertices with a single one.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Operators.html#igraph_graph_power">3.3. <code class="function">igraph_graph_power</code> — The k-th power of a graph.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Operators.html#igraph_product">3.4. <code class="function">igraph_product</code> — The graph product of two graphs, according to the chosen product type.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Operators.html#igraph_rooted_product">3.5. <code class="function">igraph_rooted_product</code> — The rooted graph product of two graphs.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Operators.html#igraph_induced_subgraph">3.6. <code class="function">igraph_induced_subgraph</code> — Creates a subgraph induced by the specified vertices.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Operators.html#igraph_induced_subgraph_map">3.7. <code class="function">igraph_induced_subgraph_map</code> — Creates an induced subraph and returns the mapping from the original.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Operators.html#igraph_induced_subgraph_edges">3.8. <code class="function">igraph_induced_subgraph_edges</code> — The edges contained within an induced sugraph.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Operators.html#igraph_linegraph">3.9. <code class="function">igraph_linegraph</code> — Create the line graph of a graph.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Operators.html#igraph_mycielskian">3.10. <code class="function">igraph_mycielskian</code> — Generate the Mycielskian of a graph with <em class="parameter"><code>k</code></em> iterations.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Operators.html#igraph_simplify">3.11. <code class="function">igraph_simplify</code> — Removes loop and/or multiple edges from the graph.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Operators.html#igraph_subgraph_from_edges">3.12. <code class="function">igraph_subgraph_from_edges</code> — Creates a subgraph with the specified edges and their endpoints.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Operators.html#igraph_reverse_edges">3.13. <code class="function">igraph_reverse_edges</code> — Reverses some edges of a directed graph.</a></span></dt>
|
||
</dl></div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h3 class="title">
|
||
<a name="igraph_connect_neighborhood"></a>3.1. <code class="function">igraph_connect_neighborhood</code> — Connects each vertex to its neighborhood.</h3></div></div></div>
|
||
<a class="indexterm" name="id-1.16.4.2.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_connect_neighborhood(igraph_t *graph, igraph_int_t order,
|
||
igraph_neimode_t mode);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
This function adds new edges to the input graph. Each vertex is connected
|
||
to all vertices reachable by at most <em class="parameter"><code>order</code></em> steps from it
|
||
(unless a connection already existed).
|
||
|
||
</p>
|
||
<p>
|
||
Note that the input graph is modified in place, no
|
||
new graph is created. Call <a class="link" href="igraph-Basic.html#igraph_copy" title="5.1.3. igraph_copy — Creates an exact (deep) copy of a graph."><code class="function">igraph_copy()</code></a> if you want to keep
|
||
the original graph as well.
|
||
|
||
</p>
|
||
<p>
|
||
For undirected graphs reachability is always
|
||
symmetric: if vertex A can be reached from vertex B in at
|
||
most <em class="parameter"><code>order</code></em> steps, then the opposite is also true. Only one
|
||
undirected (A,B) edge will be added in this case.
|
||
|
||
</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. It will be modified in-place.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>order</code></em>:</span></p></td>
|
||
<td><p>
|
||
Integer constant, it gives the distance within which
|
||
the vertices will be connected to the source vertex.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>mode</code></em>:</span></p></td>
|
||
<td><p>
|
||
Constant, it specifies how the neighborhood search is
|
||
performed for directed graphs. If <code class="constant">IGRAPH_OUT</code> then vertices
|
||
reachable from the source vertex will be connected, <code class="constant">IGRAPH_IN</code>
|
||
is the opposite. If <code class="constant">IGRAPH_ALL</code> then the directed graph is
|
||
considered as an undirected one.
|
||
</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-Operators.html#igraph_graph_power" title="3.3. igraph_graph_power — The k-th power of a graph."><code class="function">igraph_graph_power()</code></a> to compute the kth power of a graph;
|
||
<a class="link" href="igraph-Generators.html#igraph_square_lattice" title="4.4. igraph_square_lattice — Arbitrary dimensional square lattices."><code class="function">igraph_square_lattice()</code></a> uses this function to connect the
|
||
neighborhood of the vertices.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
Time complexity: O(|V|*d^k), |V| is the number of vertices in the
|
||
graph, d is the average degree and k is the <em class="parameter"><code>order</code></em> argument.
|
||
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h3 class="title">
|
||
<a name="igraph_contract_vertices"></a>3.2. <code class="function">igraph_contract_vertices</code> — Replace multiple vertices with a single one.</h3></div></div></div>
|
||
<a class="indexterm" name="id-1.16.4.3.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_contract_vertices(igraph_t *graph,
|
||
const igraph_vector_int_t *mapping,
|
||
const igraph_attribute_combination_t *vertex_comb);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
This function modifies the graph by merging several vertices
|
||
into one. The vertices in the modified graph correspond
|
||
to groups of vertices in the input graph. No edges are removed,
|
||
thus the modified graph will typically have self-loops
|
||
(corresponding to in-group edges) and multi-edges
|
||
(corresponding to multiple connections between two groups).
|
||
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> to eliminate self-loops and
|
||
merge multi-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>
|
||
The input graph. It will be modified in-place.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>mapping</code></em>:</span></p></td>
|
||
<td><p>
|
||
A vector giving the mapping. For each
|
||
vertex in the original graph, it should contain
|
||
its desired ID in the result graph. In order not to create
|
||
"orphan vertices" that have no corresponding vertices
|
||
in the original graph, ensure that the IDs are consecutive
|
||
integers starting from zero.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>vertex_comb</code></em>:</span></p></td>
|
||
<td><p>
|
||
What to do with the vertex attributes.
|
||
<code class="constant">NULL</code> means that vertex attributes are not kept
|
||
after the contraction (not even for unaffected
|
||
vertices). See the igraph manual section about attributes
|
||
for details.
|
||
</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|), linear in the number
|
||
or vertices plus edges.
|
||
|
||
</p>
|
||
<div class="hideshow" onClick="toggle(this, event)">
|
||
<div class="example">
|
||
<a name="id-1.16.4.3.8.1"></a><p class="title"><b>Example 15.7. File <code class="code">examples/simple/igraph_contract_vertices.c</code></b></p>
|
||
<div class="example-contents">
|
||
<pre class="programlisting"><span class="strong"><strong>#include</strong></span> <igraph.h>
|
||
|
||
<span class="emphasis"><em>/* Create the condensation of a directed graph.</em></span>
|
||
<span class="emphasis"><em> * See </em></span>https://en.wikipedia.org/wiki/Strongly_connected_component<span class="emphasis"><em>#Definitions</em></span>
|
||
<span class="emphasis"><em> * This example demonstrates how to write a basic igraph function, complete</em></span>
|
||
<span class="emphasis"><em> * with error handling. */</em></span>
|
||
<a class="link" href="igraph-Error.html#igraph_error_t" title="3.1. igraph_error_t — Return type for functions returning an error code.">igraph_error_t</a> <span class="strong"><strong>condensation</strong></span>(<span class="strong"><strong>const</strong></span> igraph_t *graph, igraph_t *cond) {
|
||
igraph_vector_int_t membership;
|
||
|
||
<span class="emphasis"><em>/* Data structures such as vector must be initialized in igraph before use. */</em></span>
|
||
<span class="strong"><strong><a class="link" href="igraph-Error.html#IGRAPH_CHECK" title="5.2.5. IGRAPH_CHECK — Checks the return value of a function call.">IGRAPH_CHECK</a></strong></span>(<span class="strong"><strong>igraph_vector_int_init</strong></span>(&membership, 0));
|
||
|
||
<span class="emphasis"><em>/* Adding the initialized vector to the "finally" stack ensures that it will</em></span>
|
||
<span class="emphasis"><em> * be automatically destroyed if an error occurs. */</em></span>
|
||
<span class="strong"><strong><a class="link" href="igraph-Error.html#IGRAPH_FINALLY" title="5.3.1. IGRAPH_FINALLY — Registers an object for deallocation.">IGRAPH_FINALLY</a></strong></span>(igraph_vector_int_destroy, &membership);
|
||
|
||
<span class="emphasis"><em>/* Functions that return an error code can be wrapped in IGRAPH_CHECK to pass that error</em></span>
|
||
<span class="emphasis"><em> * up to the caller. */</em></span>
|
||
<span class="strong"><strong><a class="link" href="igraph-Error.html#IGRAPH_CHECK" title="5.2.5. IGRAPH_CHECK — Checks the return value of a function call.">IGRAPH_CHECK</a></strong></span>(<span class="strong"><strong><a class="link" href="igraph-Structural.html#igraph_connected_components" title="8.2. igraph_connected_components — Calculates the (weakly or strongly) connected components in a graph.">igraph_connected_components</a></strong></span>(graph, &membership, <span class="emphasis"><em>/* csize */</em></span> NULL, <span class="emphasis"><em>/* no */</em></span> NULL, IGRAPH_STRONG));
|
||
|
||
<span class="emphasis"><em>/* To compute the condensation, we simply contract strongly connected components.</em></span>
|
||
<span class="emphasis"><em> * Since igraph_contract_vertices() modifies graphs in-place, we make a copy first. */</em></span>
|
||
<span class="strong"><strong><a class="link" href="igraph-Error.html#IGRAPH_CHECK" title="5.2.5. IGRAPH_CHECK — Checks the return value of a function call.">IGRAPH_CHECK</a></strong></span>(<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>(cond, graph));
|
||
|
||
<span class="emphasis"><em>/* Since we are not done creating the condensation yet, we add 'cond' to the</em></span>
|
||
<span class="emphasis"><em> * "finally" stack, so that it will be destroyed if an error occurs. */</em></span>
|
||
<span class="strong"><strong><a class="link" href="igraph-Error.html#IGRAPH_FINALLY" title="5.3.1. IGRAPH_FINALLY — Registers an object for deallocation.">IGRAPH_FINALLY</a></strong></span>(<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>, cond);
|
||
|
||
<span class="emphasis"><em>/* Contract strongly connected components. */</em></span>
|
||
<span class="strong"><strong><a class="link" href="igraph-Error.html#IGRAPH_CHECK" title="5.2.5. IGRAPH_CHECK — Checks the return value of a function call.">IGRAPH_CHECK</a></strong></span>(<span class="strong"><strong><a class="link" href="igraph-Operators.html#igraph_contract_vertices" title="3.2. igraph_contract_vertices — Replace multiple vertices with a single one.">igraph_contract_vertices</a></strong></span>(cond, &membership, NULL));
|
||
|
||
<span class="emphasis"><em>/* igraph_contract_vertices() preserves all edges, some of which become</em></span>
|
||
<span class="emphasis"><em> * parallel edges or self-loops after the contraction. We simplify these. */</em></span>
|
||
<span class="strong"><strong><a class="link" href="igraph-Error.html#IGRAPH_CHECK" title="5.2.5. IGRAPH_CHECK — Checks the return value of a function call.">IGRAPH_CHECK</a></strong></span>(<span class="strong"><strong><a class="link" href="igraph-Operators.html#igraph_simplify" title="3.11. igraph_simplify — Removes loop and/or multiple edges from the graph.">igraph_simplify</a></strong></span>(cond, <span class="emphasis"><em>/* remove_multiple */</em></span> true, <span class="emphasis"><em>/* remove_loops */</em></span> true, NULL));
|
||
|
||
<span class="emphasis"><em>/* Data structures that are no longer needed must be explicitly destroyed.</em></span>
|
||
<span class="emphasis"><em> * If they were added to the "finally" stack, they must be removed explicitly,</em></span>
|
||
<span class="emphasis"><em> * in the opposite order to how they were added. IGRAPH_FINALLY_CLEAN removes</em></span>
|
||
<span class="emphasis"><em> * the indicated number of entries from the "finally" stack. We remove</em></span>
|
||
<span class="emphasis"><em> * 'membership' because it was destroyed, and 'cond' because the responsibility</em></span>
|
||
<span class="emphasis"><em> * to destroy it is now with the caller. */</em></span>
|
||
<span class="strong"><strong>igraph_vector_int_destroy</strong></span>(&membership);
|
||
<span class="strong"><strong><a class="link" href="igraph-Error.html#IGRAPH_FINALLY_CLEAN" title="5.3.2. IGRAPH_FINALLY_CLEAN — Signals clean deallocation of objects.">IGRAPH_FINALLY_CLEAN</a></strong></span>(2);
|
||
|
||
<span class="strong"><strong>return</strong></span> IGRAPH_SUCCESS; <span class="emphasis"><em>/* return with no error */</em></span>
|
||
}
|
||
|
||
int <span class="strong"><strong>main</strong></span>(void) {
|
||
igraph_t graph, cond;
|
||
|
||
<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 random directed graph with mean degree 2 and compute its condensation. */</em></span>
|
||
<span class="strong"><strong><a class="link" href="igraph-Games.html#igraph_erdos_renyi_game_gnm" title="1.1. igraph_erdos_renyi_game_gnm — Generates a random (Erdős-Rényi) graph with a fixed number of edges.">igraph_erdos_renyi_game_gnm</a></strong></span>(&graph, 100, 200, IGRAPH_DIRECTED, IGRAPH_SIMPLE_SW, IGRAPH_EDGE_UNLABELED);
|
||
<span class="strong"><strong>condensation</strong></span>(&graph, &cond);
|
||
|
||
<span class="strong"><strong>printf</strong></span>("Number of vertices in the condensation: %" IGRAPH_PRId "\n", <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>(&cond));
|
||
<span class="strong"><strong><a class="link" href="igraph-Foreign.html#igraph_write_graph_edgelist" title="1.2. igraph_write_graph_edgelist — Writes the edge list of a graph to a file.">igraph_write_graph_edgelist</a></strong></span>(&cond, stdout);
|
||
|
||
<span class="emphasis"><em>/* Destroy data structures that are no longer needed. */</em></span>
|
||
<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><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>(&cond);
|
||
|
||
<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><h3 class="title">
|
||
<a name="igraph_graph_power"></a>3.3. <code class="function">igraph_graph_power</code> — The k-th power of a graph.</h3></div></div></div>
|
||
<a class="indexterm" name="id-1.16.4.4.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_graph_power(const igraph_t *graph, igraph_t *res,
|
||
igraph_int_t order, igraph_bool_t directed);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
The k-th power of a graph G is a simple graph where vertex <code class="constant">u</code> is connected to
|
||
<code class="constant">v</code> by a single edge if <code class="constant">v</code> is reachable from <code class="constant">u</code> in G within at most k steps.
|
||
By convention, the zeroth power of a graph has no edges. The first power is
|
||
identical to the original graph, except that multiple edges and self-loops
|
||
are removed.
|
||
|
||
</p>
|
||
<p>
|
||
Graph power is usually defined only for undirected graphs. igraph extends the concept
|
||
to directed graphs. To ignore edge directions in the input, set the <em class="parameter"><code>directed</code></em>
|
||
parameter to <code class="constant">false</code>. In this case, the result will be an undirected graph.
|
||
|
||
</p>
|
||
<p>
|
||
Graph and vertex attributes are preserved, but edge attributes are discarded.
|
||
|
||
</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>res</code></em>:</span></p></td>
|
||
<td><p>
|
||
The graph power of the given <em class="parameter"><code>order</code></em>.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>order</code></em>:</span></p></td>
|
||
<td><p>
|
||
Non-negative integer, the power to raise the graph to.
|
||
In other words, vertices within a distance <em class="parameter"><code>order</code></em> will be connected.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>directed</code></em>:</span></p></td>
|
||
<td><p>
|
||
Whether to take edge directions into account.
|
||
</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-Operators.html#igraph_connect_neighborhood" title="3.1. igraph_connect_neighborhood — Connects each vertex to its neighborhood."><code class="function">igraph_connect_neighborhood()</code></a> to connect each vertex to its
|
||
neighborhood, modifying a graph in-place.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
Time complexity: O(|V|*d^k), |V| is the number of vertices in the
|
||
graph, d is the average degree and k is the <em class="parameter"><code>order</code></em> argument.
|
||
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h3 class="title">
|
||
<a name="igraph_product"></a>3.4. <code class="function">igraph_product</code> — The graph product of two graphs, according to the chosen product type.</h3></div></div></div>
|
||
<a class="indexterm" name="id-1.16.4.5.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_product(igraph_t *res,
|
||
const igraph_t *g1,
|
||
const igraph_t *g2,
|
||
igraph_product_t type);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
</p>
|
||
<div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;">
|
||
<h3 class="title">Warning</h3>
|
||
<p>This function is experimental and its signature is not considered final yet.
|
||
We reserve the right to change the function signature without changing the
|
||
major version of igraph. Use it at your own risk.</p>
|
||
</div>
|
||
<p>This function computes the product of two graphs using the graph
|
||
product concept selected by the <em class="parameter"><code>type</code></em> parameter. The two graphs must be of
|
||
the same type, either directed or undirected. If a product of an undirected
|
||
and a directed graph is required, convert one of them to the appropriate type
|
||
using <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> or <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>.
|
||
|
||
</p>
|
||
<p>
|
||
Each vertex of the product graph corresponds to a pair <code class="literal">(u, v)</code>,
|
||
where <code class="constant">u</code> is a vertex from the first graph and <code class="constant">v</code> is a vertex from the
|
||
second graph. Thus the number of vertices in the product graph is
|
||
<code class="literal">|V1| |V2|</code>,
|
||
where <code class="literal">|V1|</code> and <code class="literal">|V2|</code> are the sizes of the vertex
|
||
set of the operands. The pair <code class="literal">(u, v)</code> is mapped to a unique vertex
|
||
index in the product graph using <code class="literal">index = u |V2| + v</code>.
|
||
|
||
</p>
|
||
<p>
|
||
All implemented graph products are associative, but not all are commutative.
|
||
|
||
</p>
|
||
<p>
|
||
The supported graph product types are detailed below. The notation
|
||
<code class="literal">u ~ v</code>
|
||
is used to indicate that vertices <code class="constant">u</code> and <code class="constant">v</code> are adjacent, i.e. there is
|
||
a connection from <code class="constant">u</code> to <code class="constant">v</code>.
|
||
</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_PRODUCT_CARTESIAN</code></span></p></td>
|
||
<td>
|
||
<p>
|
||
|
||
Computes the cartesian product of two graphs. In the product graph,
|
||
there is a connection from <code class="literal">(u1, v1)</code> to <code class="literal">(u2, v2)</code>
|
||
if and only if
|
||
<code class="literal">u1 = u2</code> and <code class="literal">v1 ~ v2</code> or
|
||
<code class="literal">u1 ~ u2</code> and <code class="literal">v1 = v2</code>.
|
||
Thus, the number of edges in the product graph is
|
||
<code class="literal">|V1| |E2| + |V2| |E1|</code>.
|
||
|
||
</p>
|
||
<p>
|
||
Time complexity: O(|V1| |V2| + |V1| |E2| + |V2| |E1|)
|
||
where |V1| and |V2| are the number of vertices, and
|
||
|E1| and |E2| are the number of edges of the operands.
|
||
|
||
|
||
</p>
|
||
</td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">IGRAPH_PRODUCT_LEXICOGRAPHIC</code></span></p></td>
|
||
<td>
|
||
<p>
|
||
|
||
Computes the lexicographic product of two graphs. In the product graph,
|
||
there is a connection from <code class="literal">(u1, v1)</code> to <code class="literal">(u2, v2)</code>
|
||
if and only if
|
||
<code class="literal">u1 = u2</code> and <code class="literal">v1 ~ v2</code> or
|
||
<code class="literal">u1 ~ u2</code>.
|
||
Thus, the number of edges in the product graph is
|
||
<code class="literal">|V1| |E2| + |V2|^2 |E1|</code>. Unlike most other graph products,
|
||
the lexicographic product is not commutative.
|
||
|
||
</p>
|
||
<p>
|
||
Time complexity: O(|V1| |V2| + |V1| |E2| + |V2|^2 |E1|)
|
||
where |V1| and |V2| are the number of vertices, and
|
||
|E1| and |E2| are the number of edges of the operands.
|
||
|
||
|
||
</p>
|
||
</td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">IGRAPH_PRODUCT_STRONG</code></span></p></td>
|
||
<td>
|
||
<p>
|
||
|
||
Computes the strong product (also known as normal product) of two graphs.
|
||
In the product graph, there is a connection from <code class="literal">(u1, v1)</code> to
|
||
<code class="literal">(u2, v2)</code>
|
||
if and only if
|
||
<code class="literal">u1 = u2</code> and <code class="literal">v1 ~ v2</code> or
|
||
<code class="literal">u1 ~ u2</code> and <code class="literal">v1 = v2</code> or
|
||
<code class="literal">u1 ~ u2</code> and <code class="literal">v1 ~ v2</code>.
|
||
Thus, the number of edges in the product graph is
|
||
<code class="literal">|V1| |E2| + |V2| |E1| + |E1| |E2|</code> in the directed case and
|
||
<code class="literal">|V1| |E2| + |V2| |E1| + 2 |E1| |E2|</code> in the undirected case.
|
||
|
||
</p>
|
||
<p>
|
||
Time complexity: O(|V1| |V2| + |V1| |E2| + |V2| |E1| + |E1| |E2|)
|
||
where |V1| and |V2| are the number of vertices, and
|
||
|E1| and |E2| are the number of edges of the operands.
|
||
|
||
|
||
</p>
|
||
</td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">IGRAPH_PRODUCT_TENSOR</code></span></p></td>
|
||
<td>
|
||
<p>
|
||
|
||
Computes the tensor product (also known as categorial product) of two graphs.
|
||
In the product graph, there is a connection from <code class="literal">(u1, v1)</code> to
|
||
<code class="literal">(u2, v2)</code>
|
||
if and only if
|
||
<code class="literal">u1 ~ u2</code> and <code class="literal">v1 ~ v2</code>.
|
||
Thus, the number of edges in the product is
|
||
<code class="literal">|E1| |E2|</code> in the directed case and
|
||
<code class="literal">2 |E1| |E2|</code> in the undirected case.
|
||
|
||
</p>
|
||
<p>
|
||
Time complexity: O(|V1| |V2| + |E1| |E2|)
|
||
where |V1| and |V2| are the number of vertices, and
|
||
|E1| and |E2| are the number of edges of the operands.
|
||
|
||
|
||
</p>
|
||
</td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">IGRAPH_PRODUCT_MODULAR</code></span></p></td>
|
||
<td>
|
||
<p>
|
||
|
||
Computes the modular product of two graphs. In the product graph,
|
||
there is a connection from <code class="literal">(u1, v1)</code> to <code class="literal">(u2, v2)</code>
|
||
if and only if
|
||
<code class="literal">u1 ~ u2</code> and <code class="literal">v1 ~ v2</code> or
|
||
<code class="literal">NOT (u1 ~ u2)</code> and <code class="literal">NOT (v1 ~ v2)</code>.
|
||
The modular product requires both graphs to be simple.
|
||
Thus, the number of edges in the product is
|
||
<code class="literal">|E1| |E2| + |E1'| |E2'|</code> in the directed case and
|
||
<code class="literal">2 |E1| |E2| + 2 |E1'| |E2'|</code> in the undirected case.
|
||
|
||
</p>
|
||
<p>
|
||
Time complexity: O(|V1| |V2| + |E1| |E2| + |E1'| |E2'|)
|
||
where |V1| and |V2| are the number of vertices,
|
||
|E1| and |E2| are the number of edges of the operands, and
|
||
|E1'| and |E2'| are the number of edges of their complement.
|
||
|
||
</p>
|
||
</td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
</p>
|
||
<p>
|
||
Reference:
|
||
|
||
</p>
|
||
<p>
|
||
Richard Hammack, Wilfried Imrich, and Sandi Klavžar (2011).
|
||
Handbook of Product Graphs (2nd ed.). CRC Press.
|
||
<a class="ulink" href="https://doi.org/10.1201/b10959" target="_top">https://doi.org/10.1201/b10959</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>res</code></em>:</span></p></td>
|
||
<td><p>
|
||
Pointer to an uninitialized graph object. The product graph will
|
||
be stored here.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>g1</code></em>:</span></p></td>
|
||
<td><p>
|
||
The first operand graph.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>g2</code></em>:</span></p></td>
|
||
<td><p>
|
||
The second operand graph. It must have the same directedness as <em class="parameter"><code>g1</code></em>.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>type</code></em>:</span></p></td>
|
||
<td><p>
|
||
The type of graph product to compute.</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> if the specified <em class="parameter"><code>type</code></em> is unsupported or the input
|
||
graphs <em class="parameter"><code>g1</code></em> and <em class="parameter"><code>g2</code></em> are incompatible for the requested product.
|
||
</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-Operators.html#igraph_rooted_product" title="3.5. igraph_rooted_product — The rooted graph product of two graphs."><code class="function">igraph_rooted_product()</code></a> for the rooted product.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h3 class="title">
|
||
<a name="igraph_rooted_product"></a>3.5. <code class="function">igraph_rooted_product</code> — The rooted graph product of two graphs.</h3></div></div></div>
|
||
<a class="indexterm" name="id-1.16.4.6.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_rooted_product(igraph_t *res,
|
||
const igraph_t *g1,
|
||
const igraph_t *g2,
|
||
igraph_int_t root);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
</p>
|
||
<div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;">
|
||
<h3 class="title">Warning</h3>
|
||
<p>This function is experimental and its signature is not considered final yet.
|
||
We reserve the right to change the function signature without changing the
|
||
major version of igraph. Use it at your own risk.</p>
|
||
</div>
|
||
<p>This function computes the rooted product of two graphs. The two graphs
|
||
must be of the same type, either directed or undirected. If a product of
|
||
an undirected and a directed graph is required, convert one of them to the
|
||
appropriate type using <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> or <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>.
|
||
|
||
</p>
|
||
<p>
|
||
The vertex IDs in the product graph related to the IDs in the operands in
|
||
the same convention as in <a class="link" href="igraph-Operators.html#igraph_product" title="3.4. igraph_product — The graph product of two graphs, according to the chosen product type."><code class="function">igraph_product()</code></a>.
|
||
|
||
</p>
|
||
<p>
|
||
In the rooted product graph of G and H, with root vertex ID <em class="parameter"><code>root</code></em> in H,
|
||
there is a connection from <code class="literal">(u1, v1)</code> to <code class="literal">(u2, v2)</code>
|
||
if and only if
|
||
<code class="literal">u1 = u2</code> and <code class="literal">v1 ~ v2</code> or
|
||
<code class="literal">u1 ~ u2</code> and <code class="literal">v1 = v2 = root</code>.
|
||
Thus, the number of edges in the product graph is
|
||
<code class="literal">|V1| |E2| + |E1|</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>res</code></em>:</span></p></td>
|
||
<td><p>
|
||
Pointer to an uninitialized graph object. The product graph will
|
||
be stored here.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>g1</code></em>:</span></p></td>
|
||
<td><p>
|
||
The first operand graph.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>g2</code></em>:</span></p></td>
|
||
<td><p>
|
||
The second operand graph. It must have the same directedness as <em class="parameter"><code>g1</code></em>.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>root</code></em>:</span></p></td>
|
||
<td><p>
|
||
The root vertex id of the second 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>
|
||
Error code:
|
||
<code class="constant">IGRAPH_EINVAL</code> if the specified <em class="parameter"><code>type</code></em> is unsupported or the input
|
||
graphs <em class="parameter"><code>g1</code></em> and <em class="parameter"><code>g2</code></em> are incompatible for the requested product.
|
||
<code class="constant">IGRAPH_EINVVID</code> if invalid vertex ID passed as <em class="parameter"><code>root</code></em>.
|
||
</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-Operators.html#igraph_product" title="3.4. igraph_product — The graph product of two graphs, according to the chosen product type."><code class="function">igraph_product()</code></a> for other types of graph products.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
Time complexity: O(|V1| |V2| + |V1| |E2| + |E1|)
|
||
where |V1| and |V2| are the number of vertices, and
|
||
|E1| and |E2| are the number of edges of the operands.
|
||
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h3 class="title">
|
||
<a name="igraph_induced_subgraph"></a>3.6. <code class="function">igraph_induced_subgraph</code> — Creates a subgraph induced by the specified vertices.</h3></div></div></div>
|
||
<a class="indexterm" name="id-1.16.4.7.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_induced_subgraph(const igraph_t *graph, igraph_t *res,
|
||
const igraph_vs_t vids,
|
||
igraph_subgraph_implementation_t impl);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
|
||
This function collects the specified vertices and all edges between
|
||
them to a new graph. As vertex IDs are always contiguos integers starting
|
||
at zero, the IDs in the created subgraph will be different from the IDs in
|
||
the original graph. To get the mappings between them, use
|
||
<a class="link" href="igraph-Operators.html#igraph_induced_subgraph_map" title="3.7. igraph_induced_subgraph_map — Creates an induced subraph and returns the mapping from the original."><code class="function">igraph_induced_subgraph_map()</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 object.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>res</code></em>:</span></p></td>
|
||
<td><p>
|
||
The subgraph, another graph object will be stored here,
|
||
do <span class="emphasis"><em>not</em></span> initialize this object before calling this
|
||
function, and call <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 if you don't need
|
||
it any more.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>vids</code></em>:</span></p></td>
|
||
<td><p>
|
||
A vertex selector describing which vertices to keep. A vertex
|
||
may appear more than once in the selector, but it will be considered
|
||
only once (i.e. it is not possible to duplicate a vertex by adding
|
||
its ID more than once to the selector). The order in which the
|
||
vertices appear in the vertex selector is ignored; the returned
|
||
subgraph will always contain the vertices of the original graph in
|
||
increasing order of vertex IDs.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>impl</code></em>:</span></p></td>
|
||
<td><p>
|
||
This parameter selects which implementation should we
|
||
use when constructing the new graph. Basically there are two
|
||
possibilities: <code class="constant">IGRAPH_SUBGRAPH_COPY_AND_DELETE</code> copies the
|
||
existing graph and deletes the vertices that are not needed
|
||
in the new graph, while <code class="constant">IGRAPH_SUBGRAPH_CREATE_FROM_SCRATCH</code>
|
||
constructs the new graph from scratch without copying the old
|
||
one. The latter is more efficient if you are extracting a
|
||
relatively small subpart of a very large graph, while the
|
||
former is better if you want to extract a subgraph whose size
|
||
is comparable to the size of the whole graph. There is a third
|
||
possibility: <code class="constant">IGRAPH_SUBGRAPH_AUTO</code> will select one of the
|
||
two methods automatically based on the ratio of the number
|
||
of vertices in the new and the old 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>
|
||
Error code:
|
||
<code class="constant">IGRAPH_ENOMEM</code>, not enough memory for
|
||
temporary data.
|
||
<code class="constant">IGRAPH_EINVVID</code>, invalid vertex ID in
|
||
<em class="parameter"><code>vids</code></em>.
|
||
</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>
|
||
<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-Operators.html#igraph_induced_subgraph_map" title="3.7. igraph_induced_subgraph_map — Creates an induced subraph and returns the mapping from the original."><code class="function">igraph_induced_subgraph_map()</code></a> to also retrieve the vertex ID
|
||
mapping between the graph and the extracted subgraph;
|
||
<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."><code class="function">igraph_delete_vertices()</code></a> to delete the specified set of
|
||
vertices from a graph, the opposite of this function.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h3 class="title">
|
||
<a name="igraph_induced_subgraph_map"></a>3.7. <code class="function">igraph_induced_subgraph_map</code> — Creates an induced subraph and returns the mapping from the original.</h3></div></div></div>
|
||
<a class="indexterm" name="id-1.16.4.8.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_induced_subgraph_map(const igraph_t *graph, igraph_t *res,
|
||
const igraph_vs_t vids,
|
||
igraph_subgraph_implementation_t impl,
|
||
igraph_vector_int_t *map,
|
||
igraph_vector_int_t *invmap);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
|
||
This function collects the specified vertices and all edges between
|
||
them to a new graph. As vertex IDs are always contiguos integers starting
|
||
at zero, the IDs in the created subgraph will be different from the IDs in
|
||
the original graph. The mapping between the vertex IDs in the graph and the
|
||
extracted subgraphs are returned in <em class="parameter"><code>map</code></em> and <em class="parameter"><code>invmap</code></em>.
|
||
|
||
</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>res</code></em>:</span></p></td>
|
||
<td><p>
|
||
The subgraph, another graph object will be stored here,
|
||
do <span class="emphasis"><em>not</em></span> initialize this object before calling this
|
||
function, and call <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 if you don't need
|
||
it any more.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>vids</code></em>:</span></p></td>
|
||
<td><p>
|
||
A vertex selector describing which vertices to keep.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>impl</code></em>:</span></p></td>
|
||
<td><p>
|
||
This parameter selects which implementation should be
|
||
used when constructing the new graph. Basically there are two
|
||
possibilities: <code class="constant">IGRAPH_SUBGRAPH_COPY_AND_DELETE</code> copies the
|
||
existing graph and deletes the vertices that are not needed
|
||
in the new graph, while <code class="constant">IGRAPH_SUBGRAPH_CREATE_FROM_SCRATCH</code>
|
||
constructs the new graph from scratch without copying the old
|
||
one. The latter is more efficient if you are extracting a
|
||
relatively small subpart of a very large graph, while the
|
||
former is better if you want to extract a subgraph whose size
|
||
is comparable to the size of the whole graph. There is a third
|
||
possibility: <code class="constant">IGRAPH_SUBGRAPH_AUTO</code> will select one of the
|
||
two methods automatically based on the ratio of the number
|
||
of vertices in the new and the old graph.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>map</code></em>:</span></p></td>
|
||
<td><p>
|
||
Returns a map of the vertices in <em class="parameter"><code>graph</code></em> to the vertices
|
||
in <em class="parameter"><code>res</code></em>. -1 indicates a vertex is not mapped. A value of <code class="constant">i</code> at
|
||
position <code class="constant">j</code> indicates the vertex <code class="constant">j</code> in <em class="parameter"><code>graph</code></em> is mapped
|
||
to vertex i in <em class="parameter"><code>res</code></em>.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>invmap</code></em>:</span></p></td>
|
||
<td><p>
|
||
Returns a map of the vertices in <em class="parameter"><code>res</code></em> to the vertices
|
||
in <em class="parameter"><code>graph</code></em>. A value of <code class="constant">i</code> at position <code class="constant">j</code> indicates that
|
||
vertex <code class="constant">i</code> in <em class="parameter"><code>graph</code></em> is mapped to vertex <code class="constant">j</code> in <em class="parameter"><code>res</code></em>.</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>, not enough memory for
|
||
temporary data.
|
||
<code class="constant">IGRAPH_EINVVID</code>, invalid vertex ID in
|
||
<em class="parameter"><code>vids</code></em>.
|
||
</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>
|
||
<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_delete_vertices" title="5.3.5. igraph_delete_vertices — Removes some vertices (with all their edges) from the graph."><code class="function">igraph_delete_vertices()</code></a> to delete the specified set of
|
||
vertices from a graph, the opposite of this function.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h3 class="title">
|
||
<a name="igraph_induced_subgraph_edges"></a>3.8. <code class="function">igraph_induced_subgraph_edges</code> — The edges contained within an induced sugraph.</h3></div></div></div>
|
||
<a class="indexterm" name="id-1.16.4.9.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_induced_subgraph_edges(const igraph_t *graph, igraph_vs_t vids, igraph_vector_int_t *edges);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
This function finds the IDs of those edges which connect vertices from
|
||
a given list, passed in the <em class="parameter"><code>vids</code></em> parameter.
|
||
|
||
</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>vids</code></em>:</span></p></td>
|
||
<td><p>
|
||
A vertex selector specifying the vertices that make up the subgraph.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>edges</code></em>:</span></p></td>
|
||
<td><p>
|
||
Integer vector. The IDs of edges within the subgraph induces by
|
||
<em class="parameter"><code>vids</code></em> 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(mv log(nv)) where nv is the number of vertices in <em class="parameter"><code>vids</code></em>
|
||
and mv is the sum of degrees of vertices in <em class="parameter"><code>vids</code></em>.
|
||
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h3 class="title">
|
||
<a name="igraph_linegraph"></a>3.9. <code class="function">igraph_linegraph</code> — Create the line graph of a graph.</h3></div></div></div>
|
||
<a class="indexterm" name="id-1.16.4.10.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_linegraph(const igraph_t *graph, igraph_t *linegraph);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
The line graph L(G) of a G undirected graph is defined as follows.
|
||
L(G) has one vertex for each edge in G and two different vertices in L(G)
|
||
are connected by an edge if their corresponding edges share an end point.
|
||
In a multigraph, if two end points are shared, two edges are created.
|
||
The single vertex of an undirected self-loop is counted as two end points.
|
||
|
||
</p>
|
||
<p>
|
||
The line graph L(G) of a G directed graph is slightly different:
|
||
L(G) has one vertex for each edge in G and two vertices in L(G) are connected
|
||
by a directed edge if the target of the first vertex's corresponding edge
|
||
is the same as the source of the second vertex's corresponding edge.
|
||
|
||
</p>
|
||
<p>
|
||
Self-loops are considered self-adjacent, thus their corresponding vertex
|
||
in the line graph will also a have a single self-loop, in both undirected
|
||
and directed graphs.
|
||
|
||
</p>
|
||
<p>
|
||
Edge <span class="emphasis"><em>i</em></span> in the original graph will correspond to vertex <span class="emphasis"><em>i</em></span>
|
||
in the line graph.
|
||
|
||
</p>
|
||
<p>
|
||
The first version of this function was contributed by Vincent Matossian,
|
||
thanks.
|
||
|
||
</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, may be directed or undirected.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>linegraph</code></em>:</span></p></td>
|
||
<td><p>
|
||
Pointer to an uninitialized graph object, the
|
||
result is 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(|V|+|E|), the number of edges plus the number of vertices.
|
||
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h3 class="title">
|
||
<a name="igraph_mycielskian"></a>3.10. <code class="function">igraph_mycielskian</code> — Generate the Mycielskian of a graph with <em class="parameter"><code>k</code></em> iterations.</h3></div></div></div>
|
||
<a class="indexterm" name="id-1.16.4.11.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_mycielskian(const igraph_t *graph, igraph_t *res, igraph_int_t k);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
</p>
|
||
<div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;">
|
||
<h3 class="title">Warning</h3>
|
||
<p>This function is experimental and its signature is not considered final yet.
|
||
We reserve the right to change the function signature without changing the
|
||
major version of igraph. Use it at your own risk.</p>
|
||
</div>
|
||
<p>The Mycielskian of a graph is a larger graph formed using a construction due
|
||
to Jan Mycielski that increases the chromatic number by one while preserving
|
||
the triangle-free property. The Mycielski construction can be used to create
|
||
triangle-free graphs with an arbitrarily large chromatic number.
|
||
|
||
</p>
|
||
<p>
|
||
Let the <code class="constant">n</code> vertices of the given graph <code class="constant">G</code> be <code class="constant">v_1</code>, ..., <code class="constant">v_n</code>.
|
||
The Mycielskian of <code class="constant">G</code>, denoted <code class="literal">M(G)</code>, contains <code class="constant">G</code> itself as
|
||
a subgraph, together with <code class="constant">n</code>+1 additional vertices:
|
||
|
||
</p>
|
||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||
<li class="listitem"><p>
|
||
A vertex <code class="constant">u_i</code> corresponding to each vertex <code class="constant">v_i</code> of <code class="constant">G</code>.
|
||
|
||
</p></li>
|
||
<li class="listitem"><p>
|
||
An extra vertex <code class="constant">w</code>.
|
||
|
||
</p></li>
|
||
</ul></div>
|
||
<p>
|
||
|
||
</p>
|
||
<p>
|
||
The edges are added as follows:
|
||
|
||
</p>
|
||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||
<li class="listitem"><p>
|
||
Each vertex <code class="constant">u_i</code> is connected to <code class="constant">w</code>, forming a star.
|
||
|
||
</p></li>
|
||
<li class="listitem"><p>
|
||
For each edge <code class="literal">(v_i, v_j)</code> in <code class="constant">G</code>, two new edges are added:
|
||
<code class="literal">(u_i, v_j)</code> and <code class="literal">(v_i, u_j)</code>.
|
||
|
||
</p></li>
|
||
</ul></div>
|
||
<p>
|
||
|
||
Thus, if <code class="constant">G</code> has <code class="constant">n</code> vertices and <code class="constant">m</code> edges, the Mycielskian <code class="literal">M(G)</code>
|
||
has <code class="literal">2n + 1</code> vertices, and <code class="literal">3m + n</code> edges.
|
||
|
||
</p>
|
||
<p>
|
||
igraph uses an alternative construction in two special cases:
|
||
|
||
</p>
|
||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||
<li class="listitem"><p>
|
||
The Mycielskian of the null graph is the singleton graph.
|
||
|
||
</p></li>
|
||
<li class="listitem"><p>
|
||
The Mycielskian of the singleton graph is the two-path.
|
||
|
||
</p></li>
|
||
</ul></div>
|
||
<p>
|
||
|
||
This ensures that iterative applications of the construction, starting from
|
||
the null or singleton graph, always yields connected graphs. In fact these
|
||
are the Mycielski graphs that <a class="link" href="igraph-Generators.html#igraph_mycielski_graph" title="9.4. igraph_mycielski_graph — The Mycielski graph of order k."><code class="function">igraph_mycielski_graph()</code></a> produces.
|
||
|
||
</p>
|
||
<p>
|
||
igraph extends the construction to directed graphs, as well as to non-simple
|
||
graphs, by following the above constructions rules literally.
|
||
|
||
</p>
|
||
<p>
|
||
This function can apply the Mycielski transformation an arbitrary number of
|
||
times, controlled by the parameter <em class="parameter"><code>k</code></em>. The k-th iterated Mycielskian has
|
||
<code class="literal">n_k = (n + 1) * 2^k - 1</code>
|
||
vertices and
|
||
<code class="literal">m_k = ((2m + 2n + 1) * 3^k - n_{k+1}) / 2</code>
|
||
edges, where <code class="constant">n</code> and <code class="constant">m</code> are the vertex and edge count of the original
|
||
graph, respectively.
|
||
|
||
</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 input graph.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>res</code></em>:</span></p></td>
|
||
<td><p>
|
||
Pointer to an uninitialized graph object where the Mycielskian
|
||
of the input graph will be stored.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>k</code></em>:</span></p></td>
|
||
<td><p>
|
||
Integer, the number of Mycielskian iterations (must be non-negative).
|
||
</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-Generators.html#igraph_mycielski_graph" title="9.4. igraph_mycielski_graph — The Mycielski graph of order k."><code class="function">igraph_mycielski_graph()</code></a>.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
Time complexity: O(|V| 2^k + |E| 3^k) where |V| and |E| are the vertex and
|
||
edge counts, respectively.
|
||
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h3 class="title">
|
||
<a name="igraph_simplify"></a>3.11. <code class="function">igraph_simplify</code> — Removes loop and/or multiple edges from the graph.</h3></div></div></div>
|
||
<a class="indexterm" name="id-1.16.4.12.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_simplify(igraph_t *graph,
|
||
igraph_bool_t remove_multiple, igraph_bool_t remove_loops,
|
||
const igraph_attribute_combination_t *edge_comb);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
|
||
This function merges parallel edges and removes self-loops, according
|
||
to the <em class="parameter"><code>multiple</code></em> and <em class="parameter"><code>loops</code></em> parameters. Note that this function
|
||
may change the edge order, even if the input was already a simple graph.
|
||
|
||
</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>remove_multiple</code></em>:</span></p></td>
|
||
<td><p>
|
||
If true, multiple edges will be removed.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>remove_loops</code></em>:</span></p></td>
|
||
<td><p>
|
||
If true, loops (self edges) will be removed.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>edge_comb</code></em>:</span></p></td>
|
||
<td><p>
|
||
What to do with the edge attributes. <code class="constant">NULL</code> means to
|
||
discard the edge attributes after the operation, even for edges
|
||
that were unaffected. See the igraph manual section about attributes
|
||
for details.
|
||
</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 we are out of memory.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
Time complexity: O(|V|+|E|).
|
||
|
||
</p>
|
||
<div class="hideshow" onClick="toggle(this, event)">
|
||
<div class="example">
|
||
<a name="id-1.16.4.12.8.1"></a><p class="title"><b>Example 15.8. File <code class="code">examples/simple/igraph_simplify.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="emphasis"><em>/* Multiple 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, 0, IGRAPH_DIRECTED, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, -1);
|
||
<span class="strong"><strong><a class="link" href="igraph-Operators.html#igraph_simplify" title="3.11. igraph_simplify — Removes loop and/or multiple edges from the graph.">igraph_simplify</a></strong></span>(&g, true, true, <span class="emphasis"><em>/*edge_comb=*/</em></span> NULL);
|
||
<span class="strong"><strong><a class="link" href="igraph-Foreign.html#igraph_write_graph_edgelist" title="1.2. igraph_write_graph_edgelist — Writes the edge list of a graph to a file.">igraph_write_graph_edgelist</a></strong></span>(&g, stdout);
|
||
<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, 0, IGRAPH_UNDIRECTED, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, -1);
|
||
<span class="strong"><strong><a class="link" href="igraph-Operators.html#igraph_simplify" title="3.11. igraph_simplify — Removes loop and/or multiple edges from the graph.">igraph_simplify</a></strong></span>(&g, true, true, <span class="emphasis"><em>/*edge_comb=*/</em></span> NULL);
|
||
<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> 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="emphasis"><em>/* Loop 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, 0, IGRAPH_DIRECTED, 0, 0, 1, 1, 2, 2, 1, 2, -1);
|
||
<span class="strong"><strong><a class="link" href="igraph-Operators.html#igraph_simplify" title="3.11. igraph_simplify — Removes loop and/or multiple edges from the graph.">igraph_simplify</a></strong></span>(&g, true, true, <span class="emphasis"><em>/*edge_comb=*/</em></span> NULL);
|
||
<span class="strong"><strong><a class="link" href="igraph-Foreign.html#igraph_write_graph_edgelist" title="1.2. igraph_write_graph_edgelist — Writes the edge list of a graph to a file.">igraph_write_graph_edgelist</a></strong></span>(&g, stdout);
|
||
<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, 0, IGRAPH_UNDIRECTED, 0, 0, 1, 1, 2, 2, 1, 2, -1);
|
||
<span class="strong"><strong><a class="link" href="igraph-Operators.html#igraph_simplify" title="3.11. igraph_simplify — Removes loop and/or multiple edges from the graph.">igraph_simplify</a></strong></span>(&g, true, true, <span class="emphasis"><em>/*edge_comb=*/</em></span> NULL);
|
||
<span class="strong"><strong><a class="link" href="igraph-Foreign.html#igraph_write_graph_edgelist" title="1.2. igraph_write_graph_edgelist — Writes the edge list of a graph to a file.">igraph_write_graph_edgelist</a></strong></span>(&g, stdout);
|
||
<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>/* Loop & multiple 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, 0, IGRAPH_DIRECTED, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, -1);
|
||
<span class="strong"><strong><a class="link" href="igraph-Operators.html#igraph_simplify" title="3.11. igraph_simplify — Removes loop and/or multiple edges from the graph.">igraph_simplify</a></strong></span>(&g, <span class="emphasis"><em>/* remove_multiple */</em></span> true, <span class="emphasis"><em>/* remove_loops */</em></span> false, <span class="emphasis"><em>/*edge_comb=*/</em></span> NULL);
|
||
<span class="strong"><strong><a class="link" href="igraph-Foreign.html#igraph_write_graph_edgelist" title="1.2. igraph_write_graph_edgelist — Writes the edge list of a graph to a file.">igraph_write_graph_edgelist</a></strong></span>(&g, stdout);
|
||
<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, 0, IGRAPH_UNDIRECTED, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, -1);
|
||
<span class="strong"><strong><a class="link" href="igraph-Operators.html#igraph_simplify" title="3.11. igraph_simplify — Removes loop and/or multiple edges from the graph.">igraph_simplify</a></strong></span>(&g, <span class="emphasis"><em>/* remove_multiple */</em></span> true, <span class="emphasis"><em>/* remove_loops */</em></span> false, <span class="emphasis"><em>/*edge_comb=*/</em></span> NULL);
|
||
<span class="strong"><strong><a class="link" href="igraph-Foreign.html#igraph_write_graph_edgelist" title="1.2. igraph_write_graph_edgelist — Writes the edge list of a graph to a file.">igraph_write_graph_edgelist</a></strong></span>(&g, stdout);
|
||
<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, 0, IGRAPH_DIRECTED, 2, 2, 2, 2, 2, 2, 3, 2, -1);
|
||
<span class="strong"><strong><a class="link" href="igraph-Operators.html#igraph_simplify" title="3.11. igraph_simplify — Removes loop and/or multiple edges from the graph.">igraph_simplify</a></strong></span>(&g, <span class="emphasis"><em>/* remove_multiple */</em></span> false, <span class="emphasis"><em>/* remove_loops */</em></span> true, <span class="emphasis"><em>/*edge_comb=*/</em></span> NULL);
|
||
<span class="strong"><strong><a class="link" href="igraph-Foreign.html#igraph_write_graph_edgelist" title="1.2. igraph_write_graph_edgelist — Writes the edge list of a graph to a file.">igraph_write_graph_edgelist</a></strong></span>(&g, stdout);
|
||
<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, 0, IGRAPH_UNDIRECTED, 3, 3, 3, 3, 3, 4, -1);
|
||
<span class="strong"><strong><a class="link" href="igraph-Operators.html#igraph_simplify" title="3.11. igraph_simplify — Removes loop and/or multiple edges from the graph.">igraph_simplify</a></strong></span>(&g, <span class="emphasis"><em>/* remove_multiple */</em></span> false, <span class="emphasis"><em>/* remove_loops */</em></span> true, <span class="emphasis"><em>/*edge_comb=*/</em></span> NULL);
|
||
<span class="strong"><strong><a class="link" href="igraph-Foreign.html#igraph_write_graph_edgelist" title="1.2. igraph_write_graph_edgelist — Writes the edge list of a graph to a file.">igraph_write_graph_edgelist</a></strong></span>(&g, stdout);
|
||
<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, 0, IGRAPH_DIRECTED, 2, 2, 2, 2, 2, 2, 2, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, -1);
|
||
<span class="strong"><strong><a class="link" href="igraph-Operators.html#igraph_simplify" title="3.11. igraph_simplify — Removes loop and/or multiple edges from the graph.">igraph_simplify</a></strong></span>(&g, true, true, <span class="emphasis"><em>/*edge_comb=*/</em></span> NULL);
|
||
<span class="strong"><strong><a class="link" href="igraph-Foreign.html#igraph_write_graph_edgelist" title="1.2. igraph_write_graph_edgelist — Writes the edge list of a graph to a file.">igraph_write_graph_edgelist</a></strong></span>(&g, stdout);
|
||
<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, 0, IGRAPH_UNDIRECTED,
|
||
2, 2, 2, 2, 2, 2, 2, 2, 3, 2, 2, 3, 3, 2, 3, 2, 3, 2, -1);
|
||
<span class="strong"><strong><a class="link" href="igraph-Operators.html#igraph_simplify" title="3.11. igraph_simplify — Removes loop and/or multiple edges from the graph.">igraph_simplify</a></strong></span>(&g, true, true, <span class="emphasis"><em>/*edge_comb=*/</em></span> NULL);
|
||
<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> 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><h3 class="title">
|
||
<a name="igraph_subgraph_from_edges"></a>3.12. <code class="function">igraph_subgraph_from_edges</code> — Creates a subgraph with the specified edges and their endpoints.</h3></div></div></div>
|
||
<a class="indexterm" name="id-1.16.4.13.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_subgraph_from_edges(
|
||
const igraph_t *graph, igraph_t *res, const igraph_es_t eids,
|
||
igraph_bool_t delete_vertices
|
||
);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
|
||
</p>
|
||
<p>
|
||
This function collects the specified edges and their endpoints to a new
|
||
graph. As the edge IDs in a graph are always contiguous integers starting at
|
||
zero, the edge IDs in the extracted subgraph will be different from those
|
||
in the original graph. Vertex IDs will also be reassigned if
|
||
<em class="parameter"><code>delete_vertices</code></em> is set to <code class="constant">true</code>. Attributes are preserved.
|
||
|
||
</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>res</code></em>:</span></p></td>
|
||
<td><p>
|
||
The subgraph, another graph object will be stored here,
|
||
do <span class="emphasis"><em>not</em></span> initialize this object before calling this
|
||
function, and call <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 if you don't need
|
||
it any more.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>eids</code></em>:</span></p></td>
|
||
<td><p>
|
||
An edge selector describing which edges to keep.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>delete_vertices</code></em>:</span></p></td>
|
||
<td><p>
|
||
Whether to delete the vertices not incident on any
|
||
of the specified edges as well. If <code class="constant">false</code>, the number of vertices
|
||
in the result graph will always be equal to the number of vertices
|
||
in the input 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>
|
||
Error code:
|
||
<code class="constant">IGRAPH_ENOMEM</code>, not enough memory for temporary data.
|
||
<code class="constant">IGRAPH_EINVEID</code>, invalid edge ID in <em class="parameter"><code>eids</code></em>.
|
||
</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>
|
||
<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_delete_edges" title="5.3.4. igraph_delete_edges — Removes edges from a graph."><code class="function">igraph_delete_edges()</code></a> to delete the specified set of
|
||
edges from a graph, the opposite of this function.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h3 class="title">
|
||
<a name="igraph_reverse_edges"></a>3.13. <code class="function">igraph_reverse_edges</code> — Reverses some edges of a directed graph.</h3></div></div></div>
|
||
<a class="indexterm" name="id-1.16.4.14.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_reverse_edges(igraph_t *graph, const igraph_es_t eids);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
This function reverses some edges of a directed graph. The modification is done in place.
|
||
All attributes, as well as the ordering of edges and vertices are preserved.
|
||
|
||
</p>
|
||
<p>
|
||
Note that is rarely necessary to reverse <span class="emphasis"><em>all</em></span> edges, as almost all functions that
|
||
handle directed graphs take a <code class="constant">mode</code> argument that can be set to <code class="constant">IGRAPH_IN</code> to
|
||
effectively treat edges as reversed.
|
||
|
||
</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 edges will be reversed.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>eids</code></em>:</span></p></td>
|
||
<td><p>
|
||
The edges to be reversed.
|
||
Pass <code class="literal">igraph_ess_all(IGRAPH_EDGEORDER_ID)</code> to reverse all edges.
|
||
</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(1) if all edges are reversed, otherwise
|
||
O(|E|) where |E| is the number of edges in the graph.
|
||
|
||
</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-Spatial.html"><b>← Chapter 14. Spatial graphs</b></a></td>
|
||
<td align="right"><a accesskey="n" href="igraph-Visitors.html"><b>Chapter 16. Graph visitors →</b></a></td>
|
||
</tr></table>
|
||
</body>
|
||
</html>
|