Add graph references
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2003-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_H
|
||||
#define IGRAPH_H
|
||||
|
||||
#include "igraph_version.h"
|
||||
#include "igraph_memory.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_random.h"
|
||||
#include "igraph_progress.h"
|
||||
#include "igraph_setup.h"
|
||||
#include "igraph_statusbar.h"
|
||||
|
||||
#include "igraph_types.h"
|
||||
#include "igraph_complex.h"
|
||||
#include "igraph_vector.h"
|
||||
#include "igraph_matrix.h"
|
||||
#include "igraph_bitset.h"
|
||||
#include "igraph_dqueue.h"
|
||||
#include "igraph_stack.h"
|
||||
#include "igraph_heap.h"
|
||||
#include "igraph_psumtree.h"
|
||||
#include "igraph_strvector.h"
|
||||
#include "igraph_vector_list.h"
|
||||
#include "igraph_vector_ptr.h"
|
||||
#include "igraph_sparsemat.h"
|
||||
#include "igraph_qsort.h"
|
||||
|
||||
#include "igraph_constants.h"
|
||||
#include "igraph_datatype.h"
|
||||
#include "igraph_graph_list.h"
|
||||
#include "igraph_iterators.h"
|
||||
#include "igraph_interface.h"
|
||||
#include "igraph_constructors.h"
|
||||
#include "igraph_games.h"
|
||||
#include "igraph_centrality.h"
|
||||
#include "igraph_paths.h"
|
||||
#include "igraph_components.h"
|
||||
#include "igraph_structural.h"
|
||||
#include "igraph_transitivity.h"
|
||||
#include "igraph_neighborhood.h"
|
||||
#include "igraph_isomorphism.h"
|
||||
#include "igraph_bipartite.h"
|
||||
#include "igraph_cliques.h"
|
||||
#include "igraph_layout.h"
|
||||
#include "igraph_visitor.h"
|
||||
#include "igraph_community.h"
|
||||
#include "igraph_conversion.h"
|
||||
#include "igraph_foreign.h"
|
||||
#include "igraph_motifs.h"
|
||||
#include "igraph_operators.h"
|
||||
#include "igraph_flow.h"
|
||||
#include "igraph_nongraph.h"
|
||||
#include "igraph_cocitation.h"
|
||||
#include "igraph_adjlist.h"
|
||||
#include "igraph_attributes.h"
|
||||
#include "igraph_blas.h"
|
||||
#include "igraph_lapack.h"
|
||||
#include "igraph_arpack.h"
|
||||
#include "igraph_mixing.h"
|
||||
#include "igraph_separators.h"
|
||||
#include "igraph_cohesive_blocks.h"
|
||||
#include "igraph_eigen.h"
|
||||
#include "igraph_hrg.h"
|
||||
#include "igraph_threading.h"
|
||||
#include "igraph_interrupt.h"
|
||||
#include "igraph_matching.h"
|
||||
#include "igraph_embedding.h"
|
||||
#include "igraph_scan.h"
|
||||
#include "igraph_graphlets.h"
|
||||
#include "igraph_epidemics.h"
|
||||
#include "igraph_lsap.h"
|
||||
#include "igraph_coloring.h"
|
||||
#include "igraph_eulerian.h"
|
||||
#include "igraph_graphicality.h"
|
||||
#include "igraph_cycles.h"
|
||||
#include "igraph_reachability.h"
|
||||
#include "igraph_spatial.h"
|
||||
#include "igraph_sampling.h"
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,220 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2009-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_ADJLIST_H
|
||||
#define IGRAPH_ADJLIST_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_datatype.h"
|
||||
#include "igraph_constants.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_types.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
typedef struct igraph_adjlist_t {
|
||||
igraph_int_t length;
|
||||
igraph_vector_int_t *adjs;
|
||||
} igraph_adjlist_t;
|
||||
|
||||
typedef struct igraph_inclist_t {
|
||||
igraph_int_t length;
|
||||
igraph_vector_int_t *incs;
|
||||
} igraph_inclist_t;
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_adjlist_init(const igraph_t *graph, igraph_adjlist_t *al,
|
||||
igraph_neimode_t mode, igraph_loops_t loops,
|
||||
igraph_bool_t multiple);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_adjlist_init_empty(igraph_adjlist_t *al, igraph_int_t no_of_nodes);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_int_t igraph_adjlist_size(const igraph_adjlist_t *al);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_adjlist_init_complementer(const igraph_t *graph,
|
||||
igraph_adjlist_t *al,
|
||||
igraph_neimode_t mode,
|
||||
igraph_loops_t loops);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_adjlist_init_from_inclist(
|
||||
const igraph_t *graph, igraph_adjlist_t *al, const igraph_inclist_t *il);
|
||||
IGRAPH_EXPORT void igraph_adjlist_destroy(igraph_adjlist_t *al);
|
||||
IGRAPH_EXPORT void igraph_adjlist_clear(igraph_adjlist_t *al);
|
||||
IGRAPH_EXPORT void igraph_adjlist_sort(igraph_adjlist_t *al);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_adjlist_simplify(igraph_adjlist_t *al);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_adjlist_print(const igraph_adjlist_t *al);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_adjlist_fprint(const igraph_adjlist_t *al, FILE *outfile);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_bool_t igraph_adjlist_has_edge(igraph_adjlist_t* al, igraph_int_t from, igraph_int_t to, igraph_bool_t directed);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_adjlist_replace_edge(igraph_adjlist_t* al, igraph_int_t from, igraph_int_t oldto, igraph_int_t newto, igraph_bool_t directed);
|
||||
|
||||
/**
|
||||
* \define igraph_adjlist_get
|
||||
* \brief Query a vector in an adjacency list.
|
||||
*
|
||||
* Returns a pointer to an \ref igraph_vector_int_t object from an
|
||||
* adjacency list. The vector can be modified as desired.
|
||||
*
|
||||
* \param al The adjacency list object.
|
||||
* \param no The vertex whose adjacent vertices will be returned.
|
||||
* \return Pointer to the \ref igraph_vector_int_t object.
|
||||
*
|
||||
* Time complexity: O(1).
|
||||
*/
|
||||
#define igraph_adjlist_get(al,no) (&(al)->adjs[(igraph_int_t)(no)])
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_adjlist(igraph_t *graph, const igraph_adjlist_t *adjlist,
|
||||
igraph_neimode_t mode, igraph_bool_t duplicate);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_inclist_init(const igraph_t *graph,
|
||||
igraph_inclist_t *il,
|
||||
igraph_neimode_t mode,
|
||||
igraph_loops_t loops);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_inclist_init_empty(igraph_inclist_t *il, igraph_int_t n);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_int_t igraph_inclist_size(const igraph_inclist_t *al);
|
||||
IGRAPH_EXPORT void igraph_inclist_destroy(igraph_inclist_t *il);
|
||||
IGRAPH_EXPORT void igraph_inclist_clear(igraph_inclist_t *il);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_inclist_print(const igraph_inclist_t *il);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_inclist_fprint(const igraph_inclist_t *il, FILE *outfile);
|
||||
|
||||
/**
|
||||
* \define igraph_inclist_get
|
||||
* \brief Query a vector in an incidence list.
|
||||
*
|
||||
* Returns a pointer to an <type>igraph_vector_int_t</type> object from an
|
||||
* incidence list containing edge IDs. The vector can be modified,
|
||||
* resized, etc. as desired.
|
||||
* \param il Pointer to the incidence list.
|
||||
* \param no The vertex for which the incident edges are returned.
|
||||
* \return Pointer to an <type>igraph_vector_int_t</type> object.
|
||||
*
|
||||
* Time complexity: O(1).
|
||||
*/
|
||||
#define igraph_inclist_get(il,no) (&(il)->incs[(igraph_int_t)(no)])
|
||||
|
||||
typedef struct igraph_lazy_adjlist_t {
|
||||
const igraph_t *graph;
|
||||
igraph_int_t length;
|
||||
igraph_vector_int_t **adjs;
|
||||
igraph_neimode_t mode;
|
||||
igraph_loops_t loops;
|
||||
igraph_bool_t multiple;
|
||||
} igraph_lazy_adjlist_t;
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_lazy_adjlist_init(const igraph_t *graph,
|
||||
igraph_lazy_adjlist_t *al,
|
||||
igraph_neimode_t mode,
|
||||
igraph_loops_t loops,
|
||||
igraph_bool_t multiple);
|
||||
IGRAPH_EXPORT void igraph_lazy_adjlist_destroy(igraph_lazy_adjlist_t *al);
|
||||
IGRAPH_EXPORT void igraph_lazy_adjlist_clear(igraph_lazy_adjlist_t *al);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_int_t igraph_lazy_adjlist_size(const igraph_lazy_adjlist_t *al);
|
||||
|
||||
/**
|
||||
* \define igraph_lazy_adjlist_has
|
||||
* \brief Are adjacenct vertices already stored in a lazy adjacency list?
|
||||
*
|
||||
* \param al The lazy adjacency list.
|
||||
* \param no The vertex ID to query.
|
||||
* \return True if the adjacent vertices of this vertex are already computed
|
||||
* and stored, false otherwise.
|
||||
*
|
||||
* Time complexity: O(1).
|
||||
*/
|
||||
#define igraph_lazy_adjlist_has(al,no) ((al)->adjs[(igraph_int_t)(no)] != NULL)
|
||||
|
||||
/**
|
||||
* \define igraph_lazy_adjlist_get
|
||||
* \brief Query neighbor vertices.
|
||||
*
|
||||
* If the function is called for the first time for a vertex then the
|
||||
* result is stored in the adjacency list and no further query
|
||||
* operations are needed when the neighbors of the same vertex are
|
||||
* queried again.
|
||||
*
|
||||
* \param al The lazy adjacency list.
|
||||
* \param no The vertex ID to query.
|
||||
* \return Pointer to a vector, or \c NULL upon error. Errors can only
|
||||
* occur the first time this function is called for a given vertex.
|
||||
* It is safe to modify this vector,
|
||||
* modification does not affect the original graph.
|
||||
*
|
||||
* \sa \ref igraph_lazy_adjlist_has() to check if this function has
|
||||
* already been called for a vertex.
|
||||
*
|
||||
* Time complexity: O(d), the number of neighbor vertices for the
|
||||
* first time, O(1) for subsequent calls.
|
||||
*/
|
||||
#define igraph_lazy_adjlist_get(al,no) \
|
||||
(igraph_lazy_adjlist_has(al,no) ? ((al)->adjs[(igraph_int_t)(no)]) \
|
||||
: (igraph_i_lazy_adjlist_get_real(al, no)))
|
||||
IGRAPH_EXPORT igraph_vector_int_t *igraph_i_lazy_adjlist_get_real(igraph_lazy_adjlist_t *al, igraph_int_t no);
|
||||
|
||||
typedef struct igraph_lazy_inclist_t {
|
||||
const igraph_t *graph;
|
||||
igraph_int_t length;
|
||||
igraph_vector_int_t **incs;
|
||||
igraph_neimode_t mode;
|
||||
igraph_loops_t loops;
|
||||
} igraph_lazy_inclist_t;
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_lazy_inclist_init(const igraph_t *graph,
|
||||
igraph_lazy_inclist_t *il,
|
||||
igraph_neimode_t mode,
|
||||
igraph_loops_t loops);
|
||||
IGRAPH_EXPORT void igraph_lazy_inclist_destroy(igraph_lazy_inclist_t *il);
|
||||
IGRAPH_EXPORT void igraph_lazy_inclist_clear(igraph_lazy_inclist_t *il);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_int_t igraph_lazy_inclist_size(const igraph_lazy_inclist_t *il);
|
||||
|
||||
/**
|
||||
* \define igraph_lazy_inclist_has
|
||||
* \brief Are incident edges already stored in a lazy inclist?
|
||||
*
|
||||
* \param il The lazy incidence list.
|
||||
* \param no The vertex ID to query.
|
||||
* \return True if the incident edges of this vertex are already computed
|
||||
* and stored, false otherwise.
|
||||
*
|
||||
* Time complexity: O(1).
|
||||
*/
|
||||
#define igraph_lazy_inclist_has(il,no) ((il)->incs[(igraph_int_t)(no)] != NULL)
|
||||
|
||||
/**
|
||||
* \define igraph_lazy_inclist_get
|
||||
* \brief Query incident edges.
|
||||
*
|
||||
* If the function is called for the first time for a vertex, then the
|
||||
* result is stored in the incidence list and no further query
|
||||
* operations are needed when the incident edges of the same vertex are
|
||||
* queried again.
|
||||
*
|
||||
* \param il The lazy incidence list object.
|
||||
* \param no The vertex ID to query.
|
||||
* \return Pointer to a vector, or \c NULL upon error. Errors can only
|
||||
* occur the first time this function is called for a given vertex.
|
||||
* It is safe to modify this vector,
|
||||
* modification does not affect the original graph.
|
||||
*
|
||||
* \sa \ref igraph_lazy_inclist_has() to check if this function has
|
||||
* already been called for a vertex.
|
||||
*
|
||||
* Time complexity: O(d), the number of incident edges for the first
|
||||
* time, O(1) for subsequent calls with the same \p no argument.
|
||||
*/
|
||||
#define igraph_lazy_inclist_get(il,no) \
|
||||
(igraph_lazy_inclist_has(il,no) ? ((il)->incs[(igraph_int_t)(no)]) \
|
||||
: (igraph_i_lazy_inclist_get_real(il,no)))
|
||||
IGRAPH_EXPORT igraph_vector_int_t *igraph_i_lazy_inclist_get_real(igraph_lazy_inclist_t *il, igraph_int_t no);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,395 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2007-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_ARPACK_H
|
||||
#define IGRAPH_ARPACK_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_matrix.h"
|
||||
#include "igraph_types.h"
|
||||
#include "igraph_vector.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
/**
|
||||
* \section about_arpack ARPACK interface in igraph
|
||||
*
|
||||
* <para>
|
||||
* ARPACK is a library for solving large scale eigenvalue problems.
|
||||
* The package is designed to compute a few eigenvalues and corresponding
|
||||
* eigenvectors of a general \c n by \c n matrix \c A. It is
|
||||
* most appropriate for large sparse or structured matrices \c A where
|
||||
* structured means that a matrix-vector product <code>w <- Av</code> requires
|
||||
* order \c n rather than the usual order <code>n^2</code> floating point
|
||||
* operations. Please see https://github.com/opencollab/arpack-ng for details.
|
||||
* </para>
|
||||
*
|
||||
* <para>
|
||||
* The eigenvalue calculation in ARPACK (in the simplest
|
||||
* case) involves the calculation of the \c Av product where \c A
|
||||
* is the matrix we work with and \c v is an arbitrary vector. A
|
||||
* user-defined function of type \ref igraph_arpack_function_t
|
||||
* is expected to perform this product. If the product can be done
|
||||
* efficiently, e.g. if the matrix is sparse, then ARPACK is usually
|
||||
* able to calculate the eigenvalues very quickly.
|
||||
* </para>
|
||||
*
|
||||
* <para>In igraph, eigenvalue/eigenvector calculations usually
|
||||
* involve the following steps:
|
||||
* \olist
|
||||
* \oli Initialization of an \ref igraph_arpack_options_t data
|
||||
* structure using \ref igraph_arpack_options_init.
|
||||
* \oli Setting some options in the initialized \ref
|
||||
* igraph_arpack_options_t object.
|
||||
* \oli Defining a function of type \ref igraph_arpack_function_t.
|
||||
* The input of this function is a vector, and the output
|
||||
* should be the output matrix multiplied by the input vector.
|
||||
* \oli Calling \ref igraph_arpack_rssolve() (is the matrix is
|
||||
* symmetric), or \ref igraph_arpack_rnsolve().
|
||||
* \endolist
|
||||
* The \ref igraph_arpack_options_t object can be used multiple
|
||||
* times.
|
||||
* </para>
|
||||
*
|
||||
* <para>
|
||||
* If we have many eigenvalue problems to solve, then it might worth
|
||||
* to create an \ref igraph_arpack_storage_t object, and initialize it
|
||||
* via \ref igraph_arpack_storage_init(). This structure contains all
|
||||
* memory needed for ARPACK (with the given upper limit regerding to
|
||||
* the size of the eigenvalue problem). Then many problems can be
|
||||
* solved using the same \ref igraph_arpack_storage_t object, without
|
||||
* always reallocating the required memory.
|
||||
* The \ref igraph_arpack_storage_t object needs to be destroyed by
|
||||
* calling \ref igraph_arpack_storage_destroy() on it, when it is not
|
||||
* needed any more.
|
||||
* </para>
|
||||
*
|
||||
* <para>
|
||||
* igraph does not contain all
|
||||
* ARPACK routines, only the ones dealing with symmetric and
|
||||
* non-symmetric eigenvalue problems using double precision real
|
||||
* numbers.
|
||||
* </para>
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* \struct igraph_arpack_options_t
|
||||
* \brief Options for ARPACK.
|
||||
*
|
||||
* This data structure contains the options of the ARPACK eigenvalue
|
||||
* solver routines. It must be initialized by calling \ref
|
||||
* igraph_arpack_options_init() on it. Then it can be used for
|
||||
* multiple ARPACK calls, as the ARPACK solvers do not modify it.
|
||||
*
|
||||
* Input options:
|
||||
*
|
||||
* \member bmat Character. Whether to solve a standard ('I') ot a
|
||||
* generalized problem ('B').
|
||||
* \member n Dimension of the eigenproblem.
|
||||
* \member which Specifies which eigenvalues/vectors to
|
||||
* compute. Possible values for symmetric matrices:
|
||||
* \clist \cli LA
|
||||
* Compute \c nev largest (algebraic) eigenvalues.
|
||||
* \cli SA
|
||||
* Compute \c nev smallest (algebraic) eigenvalues.
|
||||
* \cli LM
|
||||
* Compute \c nev largest (in magnitude) eigenvalues.
|
||||
* \cli SM
|
||||
* Compute \c nev smallest (in magnitude) eigenvalues.
|
||||
* \cli BE
|
||||
* Compute \c nev eigenvalues, half from each end of
|
||||
* the spectrum. When \c nev is odd, compute one
|
||||
* more from the high en than from the low
|
||||
* end. \endclist
|
||||
* Possible values for non-symmetric matrices:
|
||||
* \clist \cli LM
|
||||
* Compute \c nev largest (in magnitude) eigenvalues.
|
||||
* \cli SM
|
||||
* Compute \c nev smallest (in magnitude) eigenvalues.
|
||||
* \cli LR
|
||||
* Compute \c nev eigenvalues of largest real part.
|
||||
* \cli SR
|
||||
* Compute \c nev eigenvalues of smallest real part.
|
||||
* \cli LI
|
||||
* Compute \c nev eigenvalues of largest imaginary part.
|
||||
* \cli SI
|
||||
* Compute \c nev eigenvalues of smallest imaginary
|
||||
* part. \endclist
|
||||
* \member nev The number of eigenvalues to be computed.
|
||||
* \member tol Stopping criterion: the relative accuracy
|
||||
* of the Ritz value is considered acceptable if its error is less
|
||||
* than \c tol times its estimated value. If this is set to zero
|
||||
* then machine precision is used.
|
||||
* \member ncv Number of Lanczos vectors to be generated. Setting this
|
||||
* to zero means that \ref igraph_arpack_rssolve and \ref igraph_arpack_rnsolve
|
||||
* will determine a suitable value for \c ncv automatically.
|
||||
* \member ldv Numberic scalar. It should be set to
|
||||
* zero in the current igraph implementation.
|
||||
* \member ishift Either zero or one. If zero then the shifts are
|
||||
* provided by the user via reverse communication. If one then exact
|
||||
* shifts with respect to the reduced tridiagonal matrix \c T.
|
||||
* Please always set this to one.
|
||||
* \member mxiter Maximum number of Arnoldi update iterations allowed.
|
||||
* \member nb Blocksize to be used in the recurrence. Please always
|
||||
* leave this on the default value, one.
|
||||
* \member mode The type of the eigenproblem to be solved.
|
||||
* Possible values if the input matrix is symmetric:
|
||||
* \olist
|
||||
* \oli A*x=lambda*x, A is symmetric.
|
||||
* \oli A*x=lambda*M*x, A is
|
||||
* symmetric, M is symmetric positive definite.
|
||||
* \oli K*x=lambda*M*x, K is
|
||||
* symmetric, M is symmetric positive semi-definite.
|
||||
* \oli K*x=lambda*KG*x, K is
|
||||
* symmetric positive semi-definite, KG is symmetric
|
||||
* indefinite.
|
||||
* \oli A*x=lambda*M*x, A is
|
||||
* symmetric, M is symmetric positive
|
||||
* semi-definite. (Cayley transformed mode.) \endolist
|
||||
* Please note that only \c mode ==1 was tested and other values
|
||||
* might not work properly.
|
||||
* Possible values if the input matrix is not symmetric:
|
||||
* \olist
|
||||
* \oli A*x=lambda*x.
|
||||
* \oli A*x=lambda*M*x, M is
|
||||
* symmetric positive definite.
|
||||
* \oli A*x=lambda*M*x, M is
|
||||
* symmetric semi-definite.
|
||||
* \oli A*x=lambda*M*x, M is
|
||||
* symmetric semi-definite. \endolist
|
||||
* Please note that only \c mode == 1 was tested and other values
|
||||
* might not work properly.
|
||||
* \member start Whether to use the supplied starting vector (1), or
|
||||
* use a random starting vector (0). The starting vector must be
|
||||
* supplied in the first column of the \c vectors argument of the
|
||||
* \ref igraph_arpack_rssolve() of \ref igraph_arpack_rnsolve() call.
|
||||
*
|
||||
* Output options:
|
||||
*
|
||||
* \member info Error flag of ARPACK. Possible values:
|
||||
* \clist \cli 0
|
||||
* Normal exit.
|
||||
* \cli 1
|
||||
* Maximum number of iterations taken.
|
||||
* \cli 3
|
||||
* No shifts could be applied during a cycle of the
|
||||
* Implicitly restarted Arnoldi iteration. One possibility
|
||||
* is to increase the size of \c ncv relative to \c
|
||||
* nev. \endclist
|
||||
* ARPACK can return other error flags as well, but these are
|
||||
* converted to igraph errors, see \ref igraph_error_type_t.
|
||||
* \member ierr Error flag of the second ARPACK call (one eigenvalue
|
||||
* computation usually involves two calls to ARPACK). This is
|
||||
* always zero, as other error codes are converted to igraph errors.
|
||||
* \member noiter Number of Arnoldi iterations taken.
|
||||
* \member nconv Number of converged Ritz values. This
|
||||
* represents the number of Ritz values that satisfy the
|
||||
* convergence critetion.
|
||||
* \member numop Total number of matrix-vector multiplications.
|
||||
* \member numopb Not used currently.
|
||||
* \member numreo Total number of steps of re-orthogonalization.
|
||||
*
|
||||
* Internal options:
|
||||
* \member lworkl Do not modify this option.
|
||||
* \member sigma The shift for the shift-invert mode.
|
||||
* \member sigmai The imaginary part of the shift, for the
|
||||
* non-symmetric or complex shift-invert mode.
|
||||
* \member iparam Do not modify this option.
|
||||
* \member ipntr Do not modify this option.
|
||||
*
|
||||
*/
|
||||
|
||||
typedef struct igraph_arpack_options_t {
|
||||
/* INPUT */
|
||||
char bmat[1]; /* I-standard problem, G-generalized */
|
||||
int n; /* Dimension of the eigenproblem */
|
||||
char which[2]; /* LA, SA, LM, SM, BE */
|
||||
int nev; /* Number of eigenvalues to be computed */
|
||||
igraph_real_t tol; /* Stopping criterion */
|
||||
int ncv; /* Number of columns in V */
|
||||
int ldv; /* Leading dimension of V */
|
||||
int ishift; /* 0-reverse comm., 1-exact with tridiagonal */
|
||||
int mxiter; /* Maximum number of update iterations to take */
|
||||
int nb; /* Block size on the recurrence, only 1 works */
|
||||
int mode; /* The kind of problem to be solved (1-5)
|
||||
1: A*x=l*x, A symmetric
|
||||
2: A*x=l*M*x, A symm. M pos. def.
|
||||
3: K*x = l*M*x, K symm., M pos. semidef.
|
||||
4: K*x = l*KG*x, K s. pos. semidef. KG s. indef.
|
||||
5: A*x = l*M*x, A symm., M symm. pos. semidef. */
|
||||
int start; /* 0: random, 1: use the supplied vector */
|
||||
int lworkl; /* Size of temporary storage, default is fine */
|
||||
igraph_real_t sigma; /* The shift for modes 3,4,5 */
|
||||
igraph_real_t sigmai; /* The imaginary part of shift for rnsolve */
|
||||
/* OUTPUT */
|
||||
int info; /* What happened, see docs */
|
||||
int ierr; /* What happened in the dseupd call */
|
||||
int noiter; /* The number of iterations taken */
|
||||
int nconv;
|
||||
int numop; /* Number of OP*x operations */
|
||||
int numopb; /* Number of B*x operations if BMAT='G' */
|
||||
int numreo; /* Number of steps of re-orthogonalizations */
|
||||
/* INTERNAL */
|
||||
int iparam[11];
|
||||
int ipntr[14];
|
||||
} igraph_arpack_options_t;
|
||||
|
||||
/**
|
||||
* \struct igraph_arpack_storage_t
|
||||
* \brief Storage for ARPACK.
|
||||
*
|
||||
* Public members, do not modify them directly, these are considered
|
||||
* to be read-only.
|
||||
* \member maxn Maximum rank of matrix.
|
||||
* \member maxncv Maximum NCV.
|
||||
* \member maxldv Maximum LDV.
|
||||
*
|
||||
* These members are considered to be private:
|
||||
* \member workl Working memory.
|
||||
* \member workd Working memory.
|
||||
* \member d Memory for eigenvalues.
|
||||
* \member resid Memory for residuals.
|
||||
* \member ax Working memory.
|
||||
* \member select Working memory.
|
||||
* \member di Memory for eigenvalues, non-symmetric case only.
|
||||
* \member workev Working memory, non-symmetric case only.
|
||||
*/
|
||||
|
||||
typedef struct igraph_arpack_storage_t {
|
||||
int maxn, maxncv, maxldv;
|
||||
igraph_real_t *v;
|
||||
igraph_real_t *workl;
|
||||
igraph_real_t *workd;
|
||||
igraph_real_t *d;
|
||||
igraph_real_t *resid;
|
||||
igraph_real_t *ax;
|
||||
int *select;
|
||||
/* The following two are only used for non-symmetric problems: */
|
||||
igraph_real_t *di;
|
||||
igraph_real_t *workev;
|
||||
} igraph_arpack_storage_t;
|
||||
|
||||
/**
|
||||
* \typedef igraph_arpack_error_t
|
||||
* \brief Error codes from ARPACK.
|
||||
*
|
||||
* These error codes represent error conditions returned from ARPACK.
|
||||
* They are used internally to format error messages when igraph itself
|
||||
* returns an \c IGRAPH_EARPACK error code from an ARPACK-related function.
|
||||
*
|
||||
* \enumval IGRAPH_ARPACK_NO_ERROR No error was encountered in ARPACK.
|
||||
* \enumval IGRAPH_ARPACK_PROD Matrix-vector product failed (not used any more).
|
||||
* \enumval IGRAPH_ARPACK_NPOS N must be positive.
|
||||
* \enumval IGRAPH_ARPACK_NEVNPOS NEV must be positive.
|
||||
* \enumval IGRAPH_ARPACK_NCVSMALL NCV must be bigger.
|
||||
* \enumval IGRAPH_ARPACK_NONPOSI Maximum number of iterations should be positive.
|
||||
* \enumval IGRAPH_ARPACK_WHICHINV Invalid WHICH parameter.
|
||||
* \enumval IGRAPH_ARPACK_BMATINV Invalid BMAT parameter.
|
||||
* \enumval IGRAPH_ARPACK_WORKLSMALL WORKL is too small.
|
||||
* \enumval IGRAPH_ARPACK_TRIDERR LAPACK error in tridiagonal eigenvalue calculation.
|
||||
* \enumval IGRAPH_ARPACK_ZEROSTART Starting vector is zero.
|
||||
* \enumval IGRAPH_ARPACK_MODEINV MODE is invalid.
|
||||
* \enumval IGRAPH_ARPACK_MODEBMAT MODE and BMAT are not compatible.
|
||||
* \enumval IGRAPH_ARPACK_ISHIFT ISHIFT must be 0 or 1.
|
||||
* \enumval IGRAPH_ARPACK_NEVBE NEV and WHICH='BE' are incompatible.
|
||||
* \enumval IGRAPH_ARPACK_NOFACT Could not build an Arnoldi factorization.
|
||||
* \enumval IGRAPH_ARPACK_FAILED No eigenvalues to sufficient accuracy.
|
||||
* \enumval IGRAPH_ARPACK_HOWMNY HOWMNY is invalid.
|
||||
* \enumval IGRAPH_ARPACK_HOWMNYS HOWMNY='S' is not implemented.
|
||||
* \enumval IGRAPH_ARPACK_EVDIFF Different number of converged Ritz values.
|
||||
* \enumval IGRAPH_ARPACK_SHUR Error from calculation of a real Schur form.
|
||||
* \enumval IGRAPH_ARPACK_LAPACK LAPACK (dtrevc) error for calculating eigenvectors.
|
||||
* \enumval IGRAPH_ARPACK_UNKNOWN Unknown ARPACK error.
|
||||
*/
|
||||
typedef enum {
|
||||
IGRAPH_ARPACK_NO_ERROR = 0,
|
||||
IGRAPH_ARPACK_PROD = 15,
|
||||
IGRAPH_ARPACK_NPOS = 16,
|
||||
IGRAPH_ARPACK_NEVNPOS = 17,
|
||||
IGRAPH_ARPACK_NCVSMALL = 18,
|
||||
IGRAPH_ARPACK_NONPOSI = 19,
|
||||
IGRAPH_ARPACK_WHICHINV = 20,
|
||||
IGRAPH_ARPACK_BMATINV = 21,
|
||||
IGRAPH_ARPACK_WORKLSMALL = 22,
|
||||
IGRAPH_ARPACK_TRIDERR = 23,
|
||||
IGRAPH_ARPACK_ZEROSTART = 24,
|
||||
IGRAPH_ARPACK_MODEINV = 25,
|
||||
IGRAPH_ARPACK_MODEBMAT = 26,
|
||||
IGRAPH_ARPACK_ISHIFT = 27,
|
||||
IGRAPH_ARPACK_NEVBE = 28,
|
||||
IGRAPH_ARPACK_NOFACT = 29,
|
||||
IGRAPH_ARPACK_FAILED = 30,
|
||||
IGRAPH_ARPACK_HOWMNY = 31,
|
||||
IGRAPH_ARPACK_HOWMNYS = 32,
|
||||
IGRAPH_ARPACK_EVDIFF = 33,
|
||||
IGRAPH_ARPACK_SHUR = 34,
|
||||
IGRAPH_ARPACK_LAPACK = 35,
|
||||
IGRAPH_ARPACK_UNKNOWN = 36,
|
||||
IGRAPH_ARPACK_MAXIT = 39,
|
||||
IGRAPH_ARPACK_NOSHIFT = 40,
|
||||
IGRAPH_ARPACK_REORDER = 41,
|
||||
} igraph_arpack_error_t;
|
||||
|
||||
IGRAPH_EXPORT void igraph_arpack_options_init(igraph_arpack_options_t *o);
|
||||
IGRAPH_EXPORT igraph_arpack_options_t* igraph_arpack_options_get_default(void);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_arpack_storage_init(igraph_arpack_storage_t *s, igraph_int_t maxn,
|
||||
igraph_int_t maxncv, igraph_int_t maxldv, igraph_bool_t symm);
|
||||
IGRAPH_EXPORT void igraph_arpack_storage_destroy(igraph_arpack_storage_t *s);
|
||||
|
||||
/**
|
||||
* \typedef igraph_arpack_function_t
|
||||
* \brief Type of the ARPACK callback function.
|
||||
*
|
||||
* \param to Pointer to an \c igraph_real_t, the result of the
|
||||
* matrix-vector product is expected to be stored here.
|
||||
* \param from Pointer to an \c igraph_real_t, the input matrix should
|
||||
* be multiplied by the vector stored here.
|
||||
* \param n The length of the vector (which is the same as the order
|
||||
* of the input matrix).
|
||||
* \param extra Extra argument to the matrix-vector calculation
|
||||
* function. This is coming from the \ref igraph_arpack_rssolve()
|
||||
* or \ref igraph_arpack_rnsolve() function.
|
||||
* \return Error code. If not \c IGRAPH_SUCCESS, then the ARPACK solver considers
|
||||
* this as an error, stops and calls the igraph error handler.
|
||||
*/
|
||||
|
||||
typedef igraph_error_t igraph_arpack_function_t(igraph_real_t *to, const igraph_real_t *from,
|
||||
int n, void *extra);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_arpack_rssolve(igraph_arpack_function_t *fun, void *extra,
|
||||
igraph_arpack_options_t *options,
|
||||
igraph_arpack_storage_t *storage,
|
||||
igraph_vector_t *values, igraph_matrix_t *vectors);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_arpack_rnsolve(igraph_arpack_function_t *fun, void *extra,
|
||||
igraph_arpack_options_t *options,
|
||||
igraph_arpack_storage_t *storage,
|
||||
igraph_matrix_t *values, igraph_matrix_t *vectors);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_arpack_unpack_complex(igraph_matrix_t *vectors, igraph_matrix_t *values,
|
||||
igraph_int_t nev);
|
||||
|
||||
IGRAPH_EXPORT const char* igraph_arpack_error_to_string(igraph_arpack_error_t error);
|
||||
IGRAPH_EXPORT igraph_arpack_error_t igraph_arpack_get_last_error(void);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,931 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2005-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_ATTRIBUTES_H
|
||||
#define IGRAPH_ATTRIBUTES_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_datatype.h"
|
||||
#include "igraph_types.h"
|
||||
#include "igraph_vector.h"
|
||||
#include "igraph_strvector.h"
|
||||
#include "igraph_vector_list.h"
|
||||
#include "igraph_vector_ptr.h"
|
||||
#include "igraph_iterators.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* Attributes */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* \typedef igraph_attribute_type_t
|
||||
* \brief The possible types of the attributes.
|
||||
*
|
||||
* Values of this enum are used by the attribute interface to communicate the
|
||||
* type of an attribute to igraph's C core. When igraph is integrated in a
|
||||
* high-level language, the attribute type reported by the interface may not
|
||||
* necessarily have to match the exact data type in the high-level language as
|
||||
* long as the attribute interface can provide a conversion from the native
|
||||
* high-level attribute value to one of the data types listed here. When the
|
||||
* high-level data type is complex and has no suitable conversion to one of the
|
||||
* atomic igraph attribute types (numeric, string or Boolean), the attribute
|
||||
* interface should report the attribute as having an "object" type, which is
|
||||
* ignored by the C core. See also \ref igraph_attribute_table_t.
|
||||
*
|
||||
* \enumval IGRAPH_ATTRIBUTE_UNSPECIFIED Currently used internally
|
||||
* as a "null value" or "placeholder value" in some algorithms.
|
||||
* Attribute records with this type must not be passed to igraph
|
||||
* functions.
|
||||
* \enumval IGRAPH_ATTRIBUTE_NUMERIC Numeric attribute.
|
||||
* \enumval IGRAPH_ATTRIBUTE_BOOLEAN Logical values, true or false.
|
||||
* \enumval IGRAPH_ATTRIBUTE_STRING String attribute.
|
||||
* \enumval IGRAPH_ATTRIBUTE_OBJECT Custom attribute type, to be
|
||||
* used for special data types by client applications. The R and
|
||||
* Python interfaces use this for attributes that hold R or Python
|
||||
* objects. Usually ignored by igraph functions.
|
||||
*/
|
||||
typedef enum {
|
||||
IGRAPH_ATTRIBUTE_UNSPECIFIED = 0,
|
||||
IGRAPH_ATTRIBUTE_NUMERIC = 1,
|
||||
IGRAPH_ATTRIBUTE_BOOLEAN = 2,
|
||||
IGRAPH_ATTRIBUTE_STRING = 3,
|
||||
IGRAPH_ATTRIBUTE_OBJECT = 127
|
||||
} igraph_attribute_type_t;
|
||||
|
||||
/**
|
||||
* \typedef igraph_attribute_elemtype_t
|
||||
* \brief Types of objects to which attributes can be attached.
|
||||
*
|
||||
* \enumval IGRAPH_ATTRIBUTE_GRAPH Denotes that an attribute belongs to the
|
||||
* entire graph.
|
||||
* \enumval IGRAPH_ATTRIBUTE_VERTEX Denotes that an attribute belongs to the
|
||||
* vertices of a graph.
|
||||
* \enumval IGRAPH_ATTRIBUTE_EDGE Denotes that an attribute belongs to the
|
||||
* edges of a graph.
|
||||
*/
|
||||
typedef enum {
|
||||
IGRAPH_ATTRIBUTE_GRAPH = 0,
|
||||
IGRAPH_ATTRIBUTE_VERTEX,
|
||||
IGRAPH_ATTRIBUTE_EDGE
|
||||
} igraph_attribute_elemtype_t;
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* Attribute records */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* \typedef igraph_attribute_record_t
|
||||
* \brief An attribute record holding the name, type and values of an attribute.
|
||||
*
|
||||
* This composite data type is used in the attribute interface to specify a
|
||||
* name-type-value triplet where the name is the name of a graph, vertex or
|
||||
* edge attribute, the type is the corresponding igraph type of the attribute
|
||||
* and the value is a \em vector of attribute values. Note that for graph
|
||||
* attributes we use a vector of length 1. The type of the vector depends on
|
||||
* the attribute type: it is \ref igraph_vector_t for numeric attributes,
|
||||
* \c igraph_strvector_t for string attributes and \c igraph_vector_bool_t
|
||||
* for Boolean attributes.
|
||||
*
|
||||
* </para><para>
|
||||
* The record also stores default values for the attribute. The default values
|
||||
* are used when the value vector of the record is resized with
|
||||
* \ref igraph_attribute_record_resize(). It is important that the record
|
||||
* stores \em one default value only, corresponding to the type of the
|
||||
* attribute record. The default value is \em cleared when the type of the
|
||||
* record is changed.
|
||||
*/
|
||||
typedef struct igraph_attribute_record_t {
|
||||
char *name;
|
||||
igraph_attribute_type_t type;
|
||||
union {
|
||||
void *as_raw;
|
||||
igraph_vector_t *as_vector;
|
||||
igraph_strvector_t *as_strvector;
|
||||
igraph_vector_bool_t *as_vector_bool;
|
||||
} value;
|
||||
union {
|
||||
igraph_real_t numeric;
|
||||
igraph_bool_t boolean;
|
||||
char *string;
|
||||
} default_value;
|
||||
} igraph_attribute_record_t;
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_attribute_record_init(
|
||||
igraph_attribute_record_t *attr, const char* name, igraph_attribute_type_t type
|
||||
);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_attribute_record_init_copy(
|
||||
igraph_attribute_record_t *to, const igraph_attribute_record_t *from
|
||||
);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_attribute_record_check_type(
|
||||
const igraph_attribute_record_t *attr, igraph_attribute_type_t type
|
||||
);
|
||||
IGRAPH_EXPORT igraph_int_t igraph_attribute_record_size(
|
||||
const igraph_attribute_record_t *attr
|
||||
);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_attribute_record_resize(
|
||||
igraph_attribute_record_t *attr, igraph_int_t new_size
|
||||
);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_attribute_record_set_name(
|
||||
igraph_attribute_record_t *attr, const char* name
|
||||
);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_attribute_record_set_default_numeric(
|
||||
igraph_attribute_record_t *attr, igraph_real_t value
|
||||
);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_attribute_record_set_default_boolean(
|
||||
igraph_attribute_record_t *attr, igraph_bool_t value
|
||||
);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_attribute_record_set_default_string(
|
||||
igraph_attribute_record_t *attr, const char* value
|
||||
);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_attribute_record_set_type(
|
||||
igraph_attribute_record_t *attr, igraph_attribute_type_t type
|
||||
);
|
||||
IGRAPH_EXPORT void igraph_attribute_record_destroy(igraph_attribute_record_t *attr);
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* Attribute combinations */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* \typedef igraph_attribute_combination_type_t
|
||||
* The possible types of attribute combinations.
|
||||
*
|
||||
* \enumval IGRAPH_ATTRIBUTE_COMBINE_IGNORE Ignore old attributes, use an empty value.
|
||||
* \enumval IGRAPH_ATTRIBUTE_COMBINE_DEFAULT Use the default way to combine attributes (decided by the attribute handler implementation).
|
||||
* \enumval IGRAPH_ATTRIBUTE_COMBINE_FUNCTION Supply your own function to combine
|
||||
* attributes.
|
||||
* \enumval IGRAPH_ATTRIBUTE_COMBINE_SUM Take the sum of the attributes.
|
||||
* \enumval IGRAPH_ATTRIBUTE_COMBINE_PROD Take the product of the attributes.
|
||||
* \enumval IGRAPH_ATTRIBUTE_COMBINE_MIN Take the minimum attribute.
|
||||
* \enumval IGRAPH_ATTRIBUTE_COMBINE_MAX Take the maximum attribute.
|
||||
* \enumval IGRAPH_ATTRIBUTE_COMBINE_RANDOM Take a random attribute.
|
||||
* \enumval IGRAPH_ATTRIBUTE_COMBINE_FIRST Take the first attribute.
|
||||
* \enumval IGRAPH_ATTRIBUTE_COMBINE_LAST Take the last attribute.
|
||||
* \enumval IGRAPH_ATTRIBUTE_COMBINE_MEAN Take the mean of the attributes.
|
||||
* \enumval IGRAPH_ATTRIBUTE_COMBINE_MEDIAN Take the median of the attributes.
|
||||
* \enumval IGRAPH_ATTRIBUTE_COMBINE_CONCAT Concatenate the attributes.
|
||||
*/
|
||||
typedef enum {
|
||||
IGRAPH_ATTRIBUTE_COMBINE_IGNORE = 0,
|
||||
IGRAPH_ATTRIBUTE_COMBINE_DEFAULT = 1,
|
||||
IGRAPH_ATTRIBUTE_COMBINE_FUNCTION = 2,
|
||||
IGRAPH_ATTRIBUTE_COMBINE_SUM = 3,
|
||||
IGRAPH_ATTRIBUTE_COMBINE_PROD = 4,
|
||||
IGRAPH_ATTRIBUTE_COMBINE_MIN = 5,
|
||||
IGRAPH_ATTRIBUTE_COMBINE_MAX = 6,
|
||||
IGRAPH_ATTRIBUTE_COMBINE_RANDOM = 7,
|
||||
IGRAPH_ATTRIBUTE_COMBINE_FIRST = 8,
|
||||
IGRAPH_ATTRIBUTE_COMBINE_LAST = 9,
|
||||
IGRAPH_ATTRIBUTE_COMBINE_MEAN = 10,
|
||||
IGRAPH_ATTRIBUTE_COMBINE_MEDIAN = 11,
|
||||
IGRAPH_ATTRIBUTE_COMBINE_CONCAT = 12
|
||||
} igraph_attribute_combination_type_t;
|
||||
|
||||
typedef void (*igraph_function_pointer_t)(void);
|
||||
|
||||
typedef struct igraph_attribute_combination_record_t {
|
||||
const char *name; /* can be NULL, meaning: the rest */
|
||||
igraph_attribute_combination_type_t type;
|
||||
igraph_function_pointer_t func;
|
||||
} igraph_attribute_combination_record_t;
|
||||
|
||||
typedef struct igraph_attribute_combination_t {
|
||||
igraph_vector_ptr_t list;
|
||||
} igraph_attribute_combination_t;
|
||||
|
||||
#define IGRAPH_NO_MORE_ATTRIBUTES ((const char*)0)
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_attribute_combination_init(igraph_attribute_combination_t *comb);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_attribute_combination(igraph_attribute_combination_t *comb, ...);
|
||||
IGRAPH_EXPORT void igraph_attribute_combination_destroy(igraph_attribute_combination_t *comb);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_attribute_combination_add(igraph_attribute_combination_t *comb,
|
||||
const char *name,
|
||||
igraph_attribute_combination_type_t type,
|
||||
igraph_function_pointer_t func);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_attribute_combination_remove(igraph_attribute_combination_t *comb,
|
||||
const char *name);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_attribute_combination_query(const igraph_attribute_combination_t *comb,
|
||||
const char *name,
|
||||
igraph_attribute_combination_type_t *type,
|
||||
igraph_function_pointer_t *func);
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* List of attribute records */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
#define ATTRIBUTE_RECORD_LIST
|
||||
#define BASE_ATTRIBUTE_RECORD
|
||||
#include "igraph_pmt.h"
|
||||
#include "igraph_typed_list_pmt.h"
|
||||
#include "igraph_pmt_off.h"
|
||||
#undef BASE_ATTRIBUTE_RECORD
|
||||
#undef ATTRIBUTE_RECORD_LIST
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* Attribute handler interface */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* \struct igraph_attribute_table_t
|
||||
* \brief Table of functions to perform operations on attributes.
|
||||
*
|
||||
* This type collects the functions defining an attribute handler.
|
||||
* It has the following members:
|
||||
*
|
||||
* \member init This function is called whenever a new graph object is
|
||||
* created, right after it is created but before any vertices or
|
||||
* edges are added. It is supposed to set the \c attr member of the \c
|
||||
* igraph_t object, which is guaranteed to be set to a null pointer
|
||||
* before this function is called. It is expected to set the \c attr member
|
||||
* to a non-null value \em or return an error code. Leaving the \c attr
|
||||
* member at a null value while returning success is invalid and will trigger
|
||||
* an error in the C core of igraph itself.
|
||||
* \member destroy This function is called whenever the graph object
|
||||
* is destroyed, right before freeing the allocated memory. It is supposed
|
||||
* to do any cleanup operations that are need to dispose of the \c attr
|
||||
* member of the \c igraph_t object properly. The caller will set the
|
||||
* \c attr member to a null pointer after this function returns.
|
||||
* \member copy This function is called when the C core wants to populate the
|
||||
* attributes of a graph from another graph. The structure of the target
|
||||
* graph is already initialized by the time this function is called, and the
|
||||
* \c attr member of the graph is set to a null pointer. The function is
|
||||
* supposed to populate the \c attr member of the target \c igraph_t object
|
||||
* to a non-null value \em or return an error code. Leaving the \c attr
|
||||
* member at a null value while returning success is invalid and will trigger
|
||||
* an error in the C core of igraph itself.
|
||||
* \member add_vertices Called when vertices are added to a graph, after the
|
||||
* base data structure was modified. The number of vertices that were added is
|
||||
* supplied as an argument. The function is supposed to set up default values
|
||||
* for each vertex attribute that is currently registered on the graph, for
|
||||
* all the newly added vertices. Expected to return an error code.
|
||||
* \member permute_vertices Called when a new graph is created based on an
|
||||
* existing one such that there is a mapping from the vertices of the new
|
||||
* graph back to the vertices of the old graph (e.g. if vertices are removed
|
||||
* from a graph). The supplied index vector defines which old vertex
|
||||
* a new vertex corresponds to. Its length is the same as the number of
|
||||
* vertices in the new graph, and for each new vertex it provides the ID
|
||||
* of the corresponding vertex in the old graph. The function is supposed to
|
||||
* set up the values of the vertex attributes of the new graph based on the
|
||||
* attributes of the old graph and the provided index vector. Note that the
|
||||
* old and the new graph \em may be the same, in which case it is the
|
||||
* responsibility of the function to ensure that the operation can safely be
|
||||
* performed in-place. If the two graph instances are \em not the same,
|
||||
* implementors may safely assume that the new graph has no vertex attributes
|
||||
* yet (but it may already have graph or edge attributes by the time this
|
||||
* function is called).
|
||||
* \member combine_vertices This function is called when the creation
|
||||
* of a new graph involves a merge (contraction, etc.) of vertices
|
||||
* from another graph. The function is called after the new graph was created.
|
||||
* An argument specifies how several vertices from the old graph map to a
|
||||
* single vertex in the new graph. It is guaranteed that the old and the
|
||||
* new graph instances are different when this callback is called.
|
||||
* Implementors may safely assume that the new graph has no vertex attributes
|
||||
* yet (but it may already have graph or edge attributes by the time this
|
||||
* function is called).
|
||||
* \member add_edges Called when new edges are added to a graph, after the
|
||||
* base data structure was modified. A vector containing the endpoints of the
|
||||
* new edges are supplied as an argument. The function is supposed to set up
|
||||
* default values for each edge attribute that is currently registered on the
|
||||
* graph, for all the newly added edges. Expected to return an error code.
|
||||
* \member permute_edges Called when a new graph is created based on an
|
||||
* existing one such that some of the edges in the new graph should copy the
|
||||
* attributes of some edges from the old graph (this also includes the
|
||||
* deletion of edges). The supplied index vector defines which old edge a new
|
||||
* edge corresponds to. Its length is the same as the number of edges in the
|
||||
* new graph, and for each edge it provides the ID of the corresponding edge
|
||||
* in the old graph. The function is supposed to set up the values of the
|
||||
* edge attributes of the new graph based on the attributes of the old graph
|
||||
* and the provided index vector. Note that the old and the new graph \em may
|
||||
* be the same, in which case it is the responsibility of the function to
|
||||
* ensure that the operation can safely be performed in-place. If the two
|
||||
* graph instances are \em not the same, implementors may safely assume that
|
||||
* the new graph has no edge attributes yet (but it may already have graph or
|
||||
* vertex attributes by the time this function is called).
|
||||
* \member combine_edges This function is called when the creation
|
||||
* of a new graph involves a merge (contraction, etc.) of edges
|
||||
* from another graph. The function is after the new graph was created.
|
||||
* An argument specifies how several edges from the old graph map to a
|
||||
* single edge in the new graph. It is guaranteed that the old and the
|
||||
* new graph instances are different when this callback is called.
|
||||
* Implementors may safely assume that the new graph has no edge attributes
|
||||
* yet (but it may already have graph or vertex attributes by the time this
|
||||
* function is called).
|
||||
* \member get_info Query the attributes of a graph, the names and
|
||||
* types should be returned.
|
||||
* \member has_attr Check whether a graph has the named
|
||||
* graph/vertex/edge attribute.
|
||||
* \member get_type Query the type of a graph/vertex/edge attribute.
|
||||
* \member get_numeric_graph_attr Query a numeric graph attribute. The
|
||||
* value should be appended to the provided \p value vector. No assumptions
|
||||
* should be made about the initial contents of the \p value vector and it is
|
||||
* not guaranteed to be empty.
|
||||
* \member get_string_graph_attr Query a string graph attribute. The
|
||||
* value should be appended to the provided \p value vector. No assumptions
|
||||
* should be made about the initial contents of the \p value vector and it is
|
||||
* not guaranteed to be empty.
|
||||
* \member get_bool_graph_attr Query a boolean graph attribute. The
|
||||
* value should be appended to the provided \p value vector. No assumptions
|
||||
* should be made about the initial contents of the \p value vector and it is
|
||||
* not guaranteed to be empty.
|
||||
* \member get_numeric_vertex_attr Query a numeric vertex attribute,
|
||||
* for the vertices included in \p vs. The attribute values should be
|
||||
* appended to the provided \p value vector. No assumptions should be made
|
||||
* about the initial contents of the \p value vector and it is not guaranteed
|
||||
* to be empty.
|
||||
* \member get_string_vertex_attr Query a string vertex attribute,
|
||||
* for the vertices included in \p vs. The attribute values should be
|
||||
* appended to the provided \p value vector. No assumptions should be made
|
||||
* about the initial contents of the \p value vector and it is not guaranteed
|
||||
* to be empty.
|
||||
* \member get_bool_vertex_attr Query a boolean vertex attribute,
|
||||
* for the vertices included in \p vs. The attribute values should be
|
||||
* appended to the provided \p value vector. No assumptions should be made
|
||||
* about the initial contents of the \p value vector and it is not guaranteed
|
||||
* to be empty.
|
||||
* \member get_numeric_edge_attr Query a numeric edge attribute, for
|
||||
* the edges included in \p es. The attribute values should be appended
|
||||
* to the provided \p value vector. No assumptions should be made
|
||||
* about the initial contents of the \p value vector and it is not guaranteed
|
||||
* to be empty.
|
||||
* \member get_string_edge_attr Query a string edge attribute, for the
|
||||
* the edges included in \p es. The attribute values should be appended
|
||||
* to the provided \p value vector. No assumptions should be made
|
||||
* about the initial contents of the \p value vector and it is not guaranteed
|
||||
* to be empty.
|
||||
* \member get_bool_edge_attr Query a boolean edge attribute, for the
|
||||
* the edges included in \p es. The attribute values should be appended
|
||||
* to the provided \p value vector. No assumptions should be made
|
||||
* about the initial contents of the \p value vector and it is not guaranteed
|
||||
* to be empty.
|
||||
*/
|
||||
|
||||
typedef struct igraph_attribute_table_t {
|
||||
igraph_error_t (*init)(igraph_t *graph, const igraph_attribute_record_list_t *attr);
|
||||
void (*destroy)(igraph_t *graph);
|
||||
igraph_error_t (*copy)(igraph_t *to, const igraph_t *from, igraph_bool_t ga,
|
||||
igraph_bool_t va, igraph_bool_t ea);
|
||||
igraph_error_t (*add_vertices)(
|
||||
igraph_t *graph, igraph_int_t nv,
|
||||
const igraph_attribute_record_list_t *attr
|
||||
);
|
||||
igraph_error_t (*permute_vertices)(const igraph_t *graph,
|
||||
igraph_t *newgraph,
|
||||
const igraph_vector_int_t *idx);
|
||||
igraph_error_t (*combine_vertices)(const igraph_t *graph,
|
||||
igraph_t *newgraph,
|
||||
const igraph_vector_int_list_t *merges,
|
||||
const igraph_attribute_combination_t *comb);
|
||||
igraph_error_t (*add_edges)(
|
||||
igraph_t *graph, const igraph_vector_int_t *edges,
|
||||
const igraph_attribute_record_list_t *attr
|
||||
);
|
||||
igraph_error_t (*permute_edges)(const igraph_t *graph,
|
||||
igraph_t *newgraph, const igraph_vector_int_t *idx);
|
||||
igraph_error_t (*combine_edges)(const igraph_t *graph,
|
||||
igraph_t *newgraph,
|
||||
const igraph_vector_int_list_t *merges,
|
||||
const igraph_attribute_combination_t *comb);
|
||||
igraph_error_t (*get_info)(const igraph_t *graph,
|
||||
igraph_strvector_t *gnames, igraph_vector_int_t *gtypes,
|
||||
igraph_strvector_t *vnames, igraph_vector_int_t *vtypes,
|
||||
igraph_strvector_t *enames, igraph_vector_int_t *etypes);
|
||||
igraph_bool_t (*has_attr)(const igraph_t *graph, igraph_attribute_elemtype_t type,
|
||||
const char *name);
|
||||
igraph_error_t (*get_type)(const igraph_t *graph, igraph_attribute_type_t *type,
|
||||
igraph_attribute_elemtype_t elemtype, const char *name);
|
||||
igraph_error_t (*get_numeric_graph_attr)(const igraph_t *graph, const char *name,
|
||||
igraph_vector_t *value);
|
||||
igraph_error_t (*get_string_graph_attr)(const igraph_t *graph, const char *name,
|
||||
igraph_strvector_t *value);
|
||||
igraph_error_t (*get_bool_graph_attr)(const igraph_t *igraph, const char *name,
|
||||
igraph_vector_bool_t *value);
|
||||
igraph_error_t (*get_numeric_vertex_attr)(const igraph_t *graph, const char *name,
|
||||
igraph_vs_t vs,
|
||||
igraph_vector_t *value);
|
||||
igraph_error_t (*get_string_vertex_attr)(const igraph_t *graph, const char *name,
|
||||
igraph_vs_t vs,
|
||||
igraph_strvector_t *value);
|
||||
igraph_error_t (*get_bool_vertex_attr)(const igraph_t *graph, const char *name,
|
||||
igraph_vs_t vs,
|
||||
igraph_vector_bool_t *value);
|
||||
igraph_error_t (*get_numeric_edge_attr)(const igraph_t *graph, const char *name,
|
||||
igraph_es_t es,
|
||||
igraph_vector_t *value);
|
||||
igraph_error_t (*get_string_edge_attr)(const igraph_t *graph, const char *name,
|
||||
igraph_es_t es,
|
||||
igraph_strvector_t *value);
|
||||
igraph_error_t (*get_bool_edge_attr)(const igraph_t *graph, const char *name,
|
||||
igraph_es_t es,
|
||||
igraph_vector_bool_t *value);
|
||||
} igraph_attribute_table_t;
|
||||
|
||||
IGRAPH_EXPORT igraph_attribute_table_t * igraph_set_attribute_table(const igraph_attribute_table_t * table);
|
||||
|
||||
IGRAPH_EXPORT igraph_bool_t igraph_has_attribute_table(void);
|
||||
|
||||
/* Experimental attribute handler in C */
|
||||
|
||||
IGRAPH_EXPORT extern const igraph_attribute_table_t igraph_cattribute_table;
|
||||
|
||||
IGRAPH_EXPORT igraph_real_t igraph_cattribute_GAN(const igraph_t *graph, const char *name);
|
||||
IGRAPH_EXPORT igraph_bool_t igraph_cattribute_GAB(const igraph_t *graph, const char *name);
|
||||
IGRAPH_EXPORT const char* igraph_cattribute_GAS(const igraph_t *graph, const char *name);
|
||||
IGRAPH_EXPORT igraph_real_t igraph_cattribute_VAN(const igraph_t *graph, const char *name,
|
||||
igraph_int_t vid);
|
||||
IGRAPH_EXPORT igraph_bool_t igraph_cattribute_VAB(const igraph_t *graph, const char *name,
|
||||
igraph_int_t vid);
|
||||
IGRAPH_EXPORT const char* igraph_cattribute_VAS(const igraph_t *graph, const char *name,
|
||||
igraph_int_t vid);
|
||||
IGRAPH_EXPORT igraph_real_t igraph_cattribute_EAN(const igraph_t *graph, const char *name,
|
||||
igraph_int_t eid);
|
||||
IGRAPH_EXPORT igraph_bool_t igraph_cattribute_EAB(const igraph_t *graph, const char *name,
|
||||
igraph_int_t eid);
|
||||
IGRAPH_EXPORT const char* igraph_cattribute_EAS(const igraph_t *graph, const char *name,
|
||||
igraph_int_t eid);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_cattribute_VANV(const igraph_t *graph, const char *name,
|
||||
igraph_vs_t vids, igraph_vector_t *result);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_cattribute_EANV(const igraph_t *graph, const char *name,
|
||||
igraph_es_t eids, igraph_vector_t *result);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_cattribute_VASV(const igraph_t *graph, const char *name,
|
||||
igraph_vs_t vids, igraph_strvector_t *result);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_cattribute_EASV(const igraph_t *graph, const char *name,
|
||||
igraph_es_t eids, igraph_strvector_t *result);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_cattribute_VABV(const igraph_t *graph, const char *name,
|
||||
igraph_vs_t vids, igraph_vector_bool_t *result);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_cattribute_EABV(const igraph_t *graph, const char *name,
|
||||
igraph_es_t eids, igraph_vector_bool_t *result);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_cattribute_list(const igraph_t *graph,
|
||||
igraph_strvector_t *gnames, igraph_vector_int_t *gtypes,
|
||||
igraph_strvector_t *vnames, igraph_vector_int_t *vtypes,
|
||||
igraph_strvector_t *enames, igraph_vector_int_t *etypes);
|
||||
IGRAPH_EXPORT igraph_bool_t igraph_cattribute_has_attr(const igraph_t *graph,
|
||||
igraph_attribute_elemtype_t type,
|
||||
const char *name);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_cattribute_GAN_set(igraph_t *graph, const char *name,
|
||||
igraph_real_t value);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_cattribute_GAB_set(igraph_t *graph, const char *name,
|
||||
igraph_bool_t value);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_cattribute_GAS_set(igraph_t *graph, const char *name,
|
||||
const char *value);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_cattribute_VAN_set(igraph_t *graph, const char *name,
|
||||
igraph_int_t vid, igraph_real_t value);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_cattribute_VAB_set(igraph_t *graph, const char *name,
|
||||
igraph_int_t vid, igraph_bool_t value);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_cattribute_VAS_set(igraph_t *graph, const char *name,
|
||||
igraph_int_t vid, const char *value);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_cattribute_EAN_set(igraph_t *graph, const char *name,
|
||||
igraph_int_t eid, igraph_real_t value);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_cattribute_EAB_set(igraph_t *graph, const char *name,
|
||||
igraph_int_t eid, igraph_bool_t value);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_cattribute_EAS_set(igraph_t *graph, const char *name,
|
||||
igraph_int_t eid, const char *value);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_cattribute_VAN_setv(igraph_t *graph, const char *name,
|
||||
const igraph_vector_t *v);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_cattribute_VAB_setv(igraph_t *graph, const char *name,
|
||||
const igraph_vector_bool_t *v);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_cattribute_VAS_setv(igraph_t *graph, const char *name,
|
||||
const igraph_strvector_t *sv);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_cattribute_EAN_setv(igraph_t *graph, const char *name,
|
||||
const igraph_vector_t *v);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_cattribute_EAB_setv(igraph_t *graph, const char *name,
|
||||
const igraph_vector_bool_t *v);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_cattribute_EAS_setv(igraph_t *graph, const char *name,
|
||||
const igraph_strvector_t *sv);
|
||||
|
||||
IGRAPH_EXPORT void igraph_cattribute_remove_g(igraph_t *graph, const char *name);
|
||||
IGRAPH_EXPORT void igraph_cattribute_remove_v(igraph_t *graph, const char *name);
|
||||
IGRAPH_EXPORT void igraph_cattribute_remove_e(igraph_t *graph, const char *name);
|
||||
IGRAPH_EXPORT void igraph_cattribute_remove_all(igraph_t *graph, igraph_bool_t g,
|
||||
igraph_bool_t v, igraph_bool_t e);
|
||||
|
||||
/**
|
||||
* \define GAN
|
||||
* Query a numeric graph attribute.
|
||||
*
|
||||
* This is shorthand for \ref igraph_cattribute_GAN().
|
||||
* \param graph The graph.
|
||||
* \param n The name of the attribute.
|
||||
* \return The value of the attribute.
|
||||
*/
|
||||
#define GAN(graph,n) (igraph_cattribute_GAN((graph), (n)))
|
||||
/**
|
||||
* \define GAB
|
||||
* Query a boolean graph attribute.
|
||||
*
|
||||
* This is shorthand for \ref igraph_cattribute_GAB().
|
||||
* \param graph The graph.
|
||||
* \param n The name of the attribute.
|
||||
* \return The value of the attribute.
|
||||
*/
|
||||
#define GAB(graph,n) (igraph_cattribute_GAB((graph), (n)))
|
||||
/**
|
||||
* \define GAS
|
||||
* Query a string graph attribute.
|
||||
*
|
||||
* This is shorthand for \ref igraph_cattribute_GAS().
|
||||
* \param graph The graph.
|
||||
* \param n The name of the attribute.
|
||||
* \return The value of the attribute.
|
||||
*/
|
||||
#define GAS(graph,n) (igraph_cattribute_GAS((graph), (n)))
|
||||
/**
|
||||
* \define VAN
|
||||
* Query a numeric vertex attribute.
|
||||
*
|
||||
* This is shorthand for \ref igraph_cattribute_VAN().
|
||||
* \param graph The graph.
|
||||
* \param n The name of the attribute.
|
||||
* \param v The id of the vertex.
|
||||
* \return The value of the attribute.
|
||||
*/
|
||||
#define VAN(graph,n,v) (igraph_cattribute_VAN((graph), (n), (v)))
|
||||
/**
|
||||
* \define VAB
|
||||
* Query a boolean vertex attribute.
|
||||
*
|
||||
* This is shorthand for \ref igraph_cattribute_VAB().
|
||||
* \param graph The graph.
|
||||
* \param n The name of the attribute.
|
||||
* \param v The id of the vertex.
|
||||
* \return The value of the attribute.
|
||||
*/
|
||||
#define VAB(graph,n,v) (igraph_cattribute_VAB((graph), (n), (v)))
|
||||
/**
|
||||
* \define VAS
|
||||
* Query a string vertex attribute.
|
||||
*
|
||||
* This is shorthand for \ref igraph_cattribute_VAS().
|
||||
* \param graph The graph.
|
||||
* \param n The name of the attribute.
|
||||
* \param v The id of the vertex.
|
||||
* \return The value of the attribute.
|
||||
*/
|
||||
#define VAS(graph,n,v) (igraph_cattribute_VAS((graph), (n), (v)))
|
||||
/**
|
||||
* \define VANV
|
||||
* Query a numeric vertex attribute for all vertices.
|
||||
*
|
||||
* This is a shorthand for \ref igraph_cattribute_VANV().
|
||||
* \param graph The graph.
|
||||
* \param n The name of the attribute.
|
||||
* \param vec Pointer to an initialized vector, the result is
|
||||
* stored here. It will be resized, if needed.
|
||||
* \return Error code.
|
||||
*/
|
||||
#define VANV(graph,n,vec) (igraph_cattribute_VANV((graph),(n), \
|
||||
igraph_vss_all(), (vec)))
|
||||
/**
|
||||
* \define VABV
|
||||
* Query a boolean vertex attribute for all vertices.
|
||||
*
|
||||
* This is a shorthand for \ref igraph_cattribute_VABV().
|
||||
* \param graph The graph.
|
||||
* \param n The name of the attribute.
|
||||
* \param vec Pointer to an initialized boolean vector, the result is
|
||||
* stored here. It will be resized, if needed.
|
||||
* \return Error code.
|
||||
*/
|
||||
#define VABV(graph,n,vec) (igraph_cattribute_VABV((graph),(n), \
|
||||
igraph_vss_all(), (vec)))
|
||||
/**
|
||||
* \define VASV
|
||||
* Query a string vertex attribute for all vertices.
|
||||
*
|
||||
* This is a shorthand for \ref igraph_cattribute_VASV().
|
||||
* \param graph The graph.
|
||||
* \param n The name of the attribute.
|
||||
* \param vec Pointer to an initialized string vector, the result is
|
||||
* stored here. It will be resized, if needed.
|
||||
* \return Error code.
|
||||
*/
|
||||
#define VASV(graph,n,vec) (igraph_cattribute_VASV((graph),(n), \
|
||||
igraph_vss_all(), (vec)))
|
||||
/**
|
||||
* \define EAN
|
||||
* Query a numeric edge attribute.
|
||||
*
|
||||
* This is shorthand for \ref igraph_cattribute_EAN().
|
||||
* \param graph The graph.
|
||||
* \param n The name of the attribute.
|
||||
* \param e The id of the edge.
|
||||
* \return The value of the attribute.
|
||||
*/
|
||||
#define EAN(graph,n,e) (igraph_cattribute_EAN((graph), (n), (e)))
|
||||
/**
|
||||
* \define EAB
|
||||
* Query a boolean edge attribute.
|
||||
*
|
||||
* This is shorthand for \ref igraph_cattribute_EAB().
|
||||
* \param graph The graph.
|
||||
* \param n The name of the attribute.
|
||||
* \param e The id of the edge.
|
||||
* \return The value of the attribute.
|
||||
*/
|
||||
#define EAB(graph,n,e) (igraph_cattribute_EAB((graph), (n), (e)))
|
||||
/**
|
||||
* \define EAS
|
||||
* Query a string edge attribute.
|
||||
*
|
||||
* This is shorthand for \ref igraph_cattribute_EAS().
|
||||
* \param graph The graph.
|
||||
* \param n The name of the attribute.
|
||||
* \param e The id of the edge.
|
||||
* \return The value of the attribute.
|
||||
*/
|
||||
#define EAS(graph,n,e) (igraph_cattribute_EAS((graph), (n), (e)))
|
||||
/**
|
||||
* \define EANV
|
||||
* Query a numeric edge attribute for all edges.
|
||||
*
|
||||
* This is a shorthand for \ref igraph_cattribute_EANV().
|
||||
* \param graph The graph.
|
||||
* \param n The name of the attribute.
|
||||
* \param vec Pointer to an initialized vector, the result is
|
||||
* stored here. It will be resized, if needed.
|
||||
* \return Error code.
|
||||
*/
|
||||
#define EANV(graph,n,vec) (igraph_cattribute_EANV((graph),(n), \
|
||||
igraph_ess_all(IGRAPH_EDGEORDER_ID), (vec)))
|
||||
/**
|
||||
* \define EABV
|
||||
* Query a boolean edge attribute for all edges.
|
||||
*
|
||||
* This is a shorthand for \ref igraph_cattribute_EABV().
|
||||
* \param graph The graph.
|
||||
* \param n The name of the attribute.
|
||||
* \param vec Pointer to an initialized vector, the result is
|
||||
* stored here. It will be resized, if needed.
|
||||
* \return Error code.
|
||||
*/
|
||||
#define EABV(graph,n,vec) (igraph_cattribute_EABV((graph),(n), \
|
||||
igraph_ess_all(IGRAPH_EDGEORDER_ID), (vec)))
|
||||
|
||||
/**
|
||||
* \define EASV
|
||||
* Query a string edge attribute for all edges.
|
||||
*
|
||||
* This is a shorthand for \ref igraph_cattribute_EASV().
|
||||
* \param graph The graph.
|
||||
* \param n The name of the attribute.
|
||||
* \param vec Pointer to an initialized string vector, the result is
|
||||
* stored here. It will be resized, if needed.
|
||||
* \return Error code.
|
||||
*/
|
||||
#define EASV(graph,n,vec) (igraph_cattribute_EASV((graph),(n), \
|
||||
igraph_ess_all(IGRAPH_EDGEORDER_ID), (vec)))
|
||||
/**
|
||||
* \define SETGAN
|
||||
* Set a numeric graph attribute
|
||||
*
|
||||
* This is a shorthand for \ref igraph_cattribute_GAN_set().
|
||||
* \param graph The graph.
|
||||
* \param n The name of the attribute.
|
||||
* \param value The new value of the attribute.
|
||||
* \return Error code.
|
||||
*/
|
||||
#define SETGAN(graph,n,value) (igraph_cattribute_GAN_set((graph),(n),(value)))
|
||||
/**
|
||||
* \define SETGAB
|
||||
* Set a boolean graph attribute
|
||||
*
|
||||
* This is a shorthand for \ref igraph_cattribute_GAB_set().
|
||||
* \param graph The graph.
|
||||
* \param n The name of the attribute.
|
||||
* \param value The new value of the attribute.
|
||||
* \return Error code.
|
||||
*/
|
||||
#define SETGAB(graph,n,value) (igraph_cattribute_GAB_set((graph),(n),(value)))
|
||||
/**
|
||||
* \define SETGAS
|
||||
* Set a string graph attribute
|
||||
*
|
||||
* This is a shorthand for \ref igraph_cattribute_GAS_set().
|
||||
* \param graph The graph.
|
||||
* \param n The name of the attribute.
|
||||
* \param value The new value of the attribute.
|
||||
* \return Error code.
|
||||
*/
|
||||
#define SETGAS(graph,n,value) (igraph_cattribute_GAS_set((graph),(n),(value)))
|
||||
/**
|
||||
* \define SETVAN
|
||||
* Set a numeric vertex attribute
|
||||
*
|
||||
* This is a shorthand for \ref igraph_cattribute_VAN_set().
|
||||
* \param graph The graph.
|
||||
* \param n The name of the attribute.
|
||||
* \param vid Ids of the vertices to set.
|
||||
* \param value The new value of the attribute.
|
||||
* \return Error code.
|
||||
*/
|
||||
#define SETVAN(graph,n,vid,value) (igraph_cattribute_VAN_set((graph),(n),(vid),(value)))
|
||||
/**
|
||||
* \define SETVAB
|
||||
* Set a boolean vertex attribute
|
||||
*
|
||||
* This is a shorthand for \ref igraph_cattribute_VAB_set().
|
||||
* \param graph The graph.
|
||||
* \param n The name of the attribute.
|
||||
* \param vid Ids of the vertices to set.
|
||||
* \param value The new value of the attribute.
|
||||
* \return Error code.
|
||||
*/
|
||||
#define SETVAB(graph,n,vid,value) (igraph_cattribute_VAB_set((graph),(n),(vid),(value)))
|
||||
/**
|
||||
* \define SETVAS
|
||||
* Set a string vertex attribute
|
||||
*
|
||||
* This is a shorthand for \ref igraph_cattribute_VAS_set().
|
||||
* \param graph The graph.
|
||||
* \param n The name of the attribute.
|
||||
* \param vid Ids of the vertices to set.
|
||||
* \param value The new value of the attribute.
|
||||
* \return Error code.
|
||||
*/
|
||||
#define SETVAS(graph,n,vid,value) (igraph_cattribute_VAS_set((graph),(n),(vid),(value)))
|
||||
/**
|
||||
* \define SETEAN
|
||||
* Set a numeric edge attribute
|
||||
*
|
||||
* This is a shorthand for \ref igraph_cattribute_EAN_set().
|
||||
* \param graph The graph.
|
||||
* \param n The name of the attribute.
|
||||
* \param eid Ids of the edges to set.
|
||||
* \param value The new value of the attribute.
|
||||
* \return Error code.
|
||||
*/
|
||||
#define SETEAN(graph,n,eid,value) (igraph_cattribute_EAN_set((graph),(n),(eid),(value)))
|
||||
/**
|
||||
* \define SETEAB
|
||||
* Set a boolean edge attribute
|
||||
*
|
||||
* This is a shorthand for \ref igraph_cattribute_EAB_set().
|
||||
* \param graph The graph.
|
||||
* \param n The name of the attribute.
|
||||
* \param eid Ids of the edges to set.
|
||||
* \param value The new value of the attribute.
|
||||
* \return Error code.
|
||||
*/
|
||||
#define SETEAB(graph,n,eid,value) (igraph_cattribute_EAB_set((graph),(n),(eid),(value)))
|
||||
/**
|
||||
* \define SETEAS
|
||||
* Set a string edge attribute
|
||||
*
|
||||
* This is a shorthand for \ref igraph_cattribute_EAS_set().
|
||||
* \param graph The graph.
|
||||
* \param n The name of the attribute.
|
||||
* \param eid Ids of the edges to set.
|
||||
* \param value The new value of the attribute.
|
||||
* \return Error code.
|
||||
*/
|
||||
#define SETEAS(graph,n,eid,value) (igraph_cattribute_EAS_set((graph),(n),(eid),(value)))
|
||||
|
||||
/**
|
||||
* \define SETVANV
|
||||
* Set a numeric vertex attribute for all vertices
|
||||
*
|
||||
* This is a shorthand for \ref igraph_cattribute_VAN_setv().
|
||||
* \param graph The graph.
|
||||
* \param n The name of the attribute.
|
||||
* \param v Vector containing the new values of the attributes.
|
||||
* \return Error code.
|
||||
*/
|
||||
#define SETVANV(graph,n,v) (igraph_cattribute_VAN_setv((graph),(n),(v)))
|
||||
/**
|
||||
* \define SETVABV
|
||||
* Set a boolean vertex attribute for all vertices
|
||||
*
|
||||
* This is a shorthand for \ref igraph_cattribute_VAB_setv().
|
||||
* \param graph The graph.
|
||||
* \param n The name of the attribute.
|
||||
* \param v Vector containing the new values of the attributes.
|
||||
* \return Error code.
|
||||
*/
|
||||
#define SETVABV(graph,n,v) (igraph_cattribute_VAB_setv((graph),(n),(v)))
|
||||
/**
|
||||
* \define SETVASV
|
||||
* Set a string vertex attribute for all vertices
|
||||
*
|
||||
* This is a shorthand for \ref igraph_cattribute_VAS_setv().
|
||||
* \param graph The graph.
|
||||
* \param n The name of the attribute.
|
||||
* \param v Vector containing the new values of the attributes.
|
||||
* \return Error code.
|
||||
*/
|
||||
#define SETVASV(graph,n,v) (igraph_cattribute_VAS_setv((graph),(n),(v)))
|
||||
/**
|
||||
* \define SETEANV
|
||||
* Set a numeric edge attribute for all edges
|
||||
*
|
||||
* This is a shorthand for \ref igraph_cattribute_EAN_setv().
|
||||
* \param graph The graph.
|
||||
* \param n The name of the attribute.
|
||||
* \param v Vector containing the new values of the attributes.
|
||||
*/
|
||||
#define SETEANV(graph,n,v) (igraph_cattribute_EAN_setv((graph),(n),(v)))
|
||||
/**
|
||||
* \define SETEABV
|
||||
* Set a boolean edge attribute for all edges
|
||||
*
|
||||
* This is a shorthand for \ref igraph_cattribute_EAB_setv().
|
||||
* \param graph The graph.
|
||||
* \param n The name of the attribute.
|
||||
* \param v Vector containing the new values of the attributes.
|
||||
*/
|
||||
#define SETEABV(graph,n,v) (igraph_cattribute_EAB_setv((graph),(n),(v)))
|
||||
/**
|
||||
* \define SETEASV
|
||||
* Set a string edge attribute for all edges
|
||||
*
|
||||
* This is a shorthand for \ref igraph_cattribute_EAS_setv().
|
||||
* \param graph The graph.
|
||||
* \param n The name of the attribute.
|
||||
* \param v Vector containing the new values of the attributes.
|
||||
*/
|
||||
#define SETEASV(graph,n,v) (igraph_cattribute_EAS_setv((graph),(n),(v)))
|
||||
|
||||
/**
|
||||
* \define DELGA
|
||||
* Remove a graph attribute.
|
||||
*
|
||||
* A shorthand for \ref igraph_cattribute_remove_g().
|
||||
* \param graph The graph.
|
||||
* \param n The name of the attribute to remove.
|
||||
*/
|
||||
#define DELGA(graph,n) (igraph_cattribute_remove_g((graph),(n)))
|
||||
/**
|
||||
* \define DELVA
|
||||
* Remove a vertex attribute.
|
||||
*
|
||||
* A shorthand for \ref igraph_cattribute_remove_v().
|
||||
* \param graph The graph.
|
||||
* \param n The name of the attribute to remove.
|
||||
*/
|
||||
#define DELVA(graph,n) (igraph_cattribute_remove_v((graph),(n)))
|
||||
/**
|
||||
* \define DELEA
|
||||
* Remove an edge attribute.
|
||||
*
|
||||
* A shorthand for \ref igraph_cattribute_remove_e().
|
||||
* \param graph The graph.
|
||||
* \param n The name of the attribute to remove.
|
||||
*/
|
||||
#define DELEA(graph,n) (igraph_cattribute_remove_e((graph),(n)))
|
||||
/**
|
||||
* \define DELGAS
|
||||
* Remove all graph attributes.
|
||||
*
|
||||
* Calls \ref igraph_cattribute_remove_all().
|
||||
* \param graph The graph.
|
||||
*/
|
||||
#define DELGAS(graph) (igraph_cattribute_remove_all((graph),1,0,0))
|
||||
/**
|
||||
* \define DELVAS
|
||||
* Remove all vertex attributes.
|
||||
*
|
||||
* Calls \ref igraph_cattribute_remove_all().
|
||||
* \param graph The graph.
|
||||
*/
|
||||
#define DELVAS(graph) (igraph_cattribute_remove_all((graph),0,1,0))
|
||||
/**
|
||||
* \define DELEAS
|
||||
* Remove all edge attributes.
|
||||
*
|
||||
* Calls \ref igraph_cattribute_remove_all().
|
||||
* \param graph The graph.
|
||||
*/
|
||||
#define DELEAS(graph) (igraph_cattribute_remove_all((graph),0,0,1))
|
||||
/**
|
||||
* \define DELALL
|
||||
* Remove all attributes.
|
||||
*
|
||||
* All graph, vertex and edges attributes will be removed.
|
||||
* Calls \ref igraph_cattribute_remove_all().
|
||||
* \param graph The graph.
|
||||
*/
|
||||
#define DELALL(graph) (igraph_cattribute_remove_all((graph),1,1,1))
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2009-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_BIPARTITE_H
|
||||
#define IGRAPH_BIPARTITE_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_datatype.h"
|
||||
#include "igraph_constants.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_graphicality.h"
|
||||
#include "igraph_types.h"
|
||||
#include "igraph_vector.h"
|
||||
#include "igraph_matrix.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* Bipartite networks */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_full_bipartite(igraph_t *graph,
|
||||
igraph_vector_bool_t *types,
|
||||
igraph_int_t n1, igraph_int_t n2,
|
||||
igraph_bool_t directed,
|
||||
igraph_neimode_t mode);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_create_bipartite(igraph_t *g, const igraph_vector_bool_t *types,
|
||||
const igraph_vector_int_t *edges,
|
||||
igraph_bool_t directed);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_bipartite_projection_size(const igraph_t *graph,
|
||||
const igraph_vector_bool_t *types,
|
||||
igraph_int_t *vcount1,
|
||||
igraph_int_t *ecount1,
|
||||
igraph_int_t *vcount2,
|
||||
igraph_int_t *ecount2);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_bipartite_projection(const igraph_t *graph,
|
||||
const igraph_vector_bool_t *types,
|
||||
igraph_t *proj1,
|
||||
igraph_t *proj2,
|
||||
igraph_vector_int_t *multiplicity1,
|
||||
igraph_vector_int_t *multiplicity2,
|
||||
igraph_int_t probe1);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_biadjacency(
|
||||
igraph_t *graph,
|
||||
igraph_vector_bool_t *types,
|
||||
const igraph_matrix_t *biadjmatrix,
|
||||
igraph_bool_t directed,
|
||||
igraph_neimode_t mode,
|
||||
igraph_bool_t multiple);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_weighted_biadjacency(
|
||||
igraph_t *graph,
|
||||
igraph_vector_bool_t *types,
|
||||
igraph_vector_t *weights,
|
||||
const igraph_matrix_t *biadjmatrix,
|
||||
igraph_bool_t directed,
|
||||
igraph_neimode_t mode);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_get_biadjacency(const igraph_t *graph,
|
||||
const igraph_vector_bool_t *types,
|
||||
const igraph_vector_t *weights,
|
||||
igraph_matrix_t *res,
|
||||
igraph_vector_int_t *row_ids,
|
||||
igraph_vector_int_t *col_ids);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_is_bipartite(const igraph_t *graph,
|
||||
igraph_bool_t *res,
|
||||
igraph_vector_bool_t *types);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_bipartite_game_gnp(
|
||||
igraph_t *graph,
|
||||
igraph_vector_bool_t *types,
|
||||
igraph_int_t n1, igraph_int_t n2, igraph_real_t p,
|
||||
igraph_bool_t directed, igraph_neimode_t mode,
|
||||
igraph_edge_type_sw_t allowed_edge_types,
|
||||
igraph_bool_t edge_labeled);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_bipartite_game_gnm(
|
||||
igraph_t *graph,
|
||||
igraph_vector_bool_t *types,
|
||||
igraph_int_t n1, igraph_int_t n2, igraph_int_t m,
|
||||
igraph_bool_t directed, igraph_neimode_t mode,
|
||||
igraph_edge_type_sw_t allowed_edge_types,
|
||||
igraph_bool_t edge_labeled);
|
||||
|
||||
IGRAPH_EXPERIMENTAL IGRAPH_EXPORT igraph_error_t igraph_bipartite_iea_game(
|
||||
igraph_t *graph, igraph_vector_bool_t *types,
|
||||
igraph_int_t n1, igraph_int_t n2, igraph_int_t m,
|
||||
igraph_bool_t directed, igraph_neimode_t mode);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,265 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2024-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_BITSET_H
|
||||
#define IGRAPH_BITSET_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_vector.h"
|
||||
#include "igraph_types.h"
|
||||
|
||||
/* Required for MSVC intrinsics such as __popcnt and __popcnt64 */
|
||||
#ifdef _MSC_VER
|
||||
#include "intrin.h"
|
||||
#endif
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
/**
|
||||
* \ingroup bitset
|
||||
* \section igraph_bitset_accessing_elements Accessing elements
|
||||
*
|
||||
* <para>The simplest way to access an element of a bitset is
|
||||
* to use the \ref IGRAPH_BIT_TEST(), \ref IGRAPH_BIT_SET() and \ref IGRAPH_BIT_CLEAR() macros.
|
||||
* </para>
|
||||
*
|
||||
* <para>There are a few other macros which allow manual manipulation of bitsets.
|
||||
* Those are \ref VECTOR(), \ref IGRAPH_BIT_SLOT(), \ref IGRAPH_BIT_MASK() and
|
||||
* \ref IGRAPH_BIT_NSLOTS().</para>
|
||||
*/
|
||||
|
||||
/**
|
||||
* \ingroup bitset
|
||||
* \define IGRAPH_BIT_MASK
|
||||
* \brief Computes mask used to access a specific bit of an integer.
|
||||
*
|
||||
* \experimental
|
||||
*
|
||||
* Used in combination with \ref IGRAPH_BIT_SLOT() to access an element of a bitset.
|
||||
*
|
||||
* Usage:
|
||||
* \verbatim IGRAPH_BIT_MASK(10) \endverbatim
|
||||
* to obtain an integer where only the 11th least significant bit is set.
|
||||
*
|
||||
* Note that passing negative values here results in undefined behaviour.
|
||||
*
|
||||
* \param b The only bit index that should have its bit set.
|
||||
*
|
||||
* Time complexity: O(1).
|
||||
*/
|
||||
#define IGRAPH_BIT_MASK(i) ((igraph_uint_t)(1) << ((i) % IGRAPH_INTEGER_SIZE))
|
||||
|
||||
/**
|
||||
* \ingroup bitset
|
||||
* \define IGRAPH_BIT_SLOT
|
||||
* \brief Computes index used to access a specific slot of a bitset.
|
||||
*
|
||||
* \experimental
|
||||
*
|
||||
* Used in combination with \ref IGRAPH_BIT_MASK to access an element of a bitset.
|
||||
*
|
||||
* Usage:
|
||||
* \verbatim IGRAPH_BIT_SLOT(70) \endverbatim
|
||||
* will return 1 if using 64-bit words or 2 if using 32-bit words.
|
||||
*
|
||||
* \param i The bit index whose slot should be determined.
|
||||
*
|
||||
* Time complexity: O(1).
|
||||
*/
|
||||
#define IGRAPH_BIT_SLOT(i) ((i) / IGRAPH_INTEGER_SIZE)
|
||||
|
||||
/**
|
||||
* \ingroup bitset
|
||||
* \define IGRAPH_BIT_SET
|
||||
* \brief Sets a specific bit in a bitset to 1 without altering other bits.
|
||||
*
|
||||
* \experimental
|
||||
*
|
||||
* Usage:
|
||||
* \verbatim IGRAPH_BIT_SET(bitset, 3) \endverbatim
|
||||
* will set the fourth least significant bit in the bitset to 1.
|
||||
*
|
||||
* \param bitset The bitset
|
||||
* \param i The bit index that should have its bit set to 1 after the operation.
|
||||
*
|
||||
* Time complexity: O(1).
|
||||
*/
|
||||
#define IGRAPH_BIT_SET(bitset, i) (VECTOR((bitset))[IGRAPH_BIT_SLOT(i)] |= IGRAPH_BIT_MASK(i))
|
||||
|
||||
/**
|
||||
* \ingroup bitset
|
||||
* \define IGRAPH_BIT_CLEAR
|
||||
* \brief Sets a specific bit in a bitset to 0 without altering other bits.
|
||||
*
|
||||
* \experimental
|
||||
*
|
||||
* Usage:
|
||||
* \verbatim IGRAPH_BIT_CLEAR(bitset, 4) \endverbatim
|
||||
* will set the fifth least significant bit in the bitset to 0.
|
||||
*
|
||||
* \param bitset The bitset
|
||||
* \param i The bit index that should have its bit set to 0 after the operation.
|
||||
*
|
||||
* Time complexity: O(1).
|
||||
*/
|
||||
#define IGRAPH_BIT_CLEAR(bitset, i) (VECTOR((bitset))[IGRAPH_BIT_SLOT(i)] &= ~IGRAPH_BIT_MASK(i))
|
||||
|
||||
/**
|
||||
* \ingroup bitset
|
||||
* \define IGRAPH_BIT_TEST
|
||||
* \brief Tests whether a bit is set in a bitset.
|
||||
*
|
||||
* \experimental
|
||||
*
|
||||
* Returns 0 if the bit at the specified bit index is not set,
|
||||
* otherwise returns a non-zero value.
|
||||
*
|
||||
* Usage:
|
||||
* \verbatim IGRAPH_BIT_TEST(bitset, 7) \endverbatim
|
||||
* will test the eighth least significant bit in the bitset.
|
||||
*
|
||||
* \param bitset The bitset
|
||||
* \param i The bit index that should have its bit tested.
|
||||
*
|
||||
* Time complexity: O(1).
|
||||
*/
|
||||
#define IGRAPH_BIT_TEST(bitset, i) (VECTOR((bitset))[IGRAPH_BIT_SLOT(i)] & IGRAPH_BIT_MASK(i))
|
||||
|
||||
/**
|
||||
* \ingroup bitset
|
||||
* \define IGRAPH_BIT_NSLOTS
|
||||
* \brief Computes the number of slots required to store a specified number of bits.
|
||||
*
|
||||
* \experimental
|
||||
*
|
||||
* Usage:
|
||||
* \verbatim IGRAPH_BIT_NSLOTS(70) \endverbatim
|
||||
* will return 2 if using 64-bit words and 3 if using 32-bit words.
|
||||
* \verbatim IGRAPH_BIT_NSLOTS(128) \endverbatim
|
||||
* will return 2 if using 64-bit words and 4 if using 32-bit words.
|
||||
*
|
||||
* \param nbits The specified number of bits.
|
||||
*
|
||||
* Time complexity: O(1).
|
||||
*/
|
||||
#define IGRAPH_BIT_NSLOTS(nbits) ((nbits + IGRAPH_INTEGER_SIZE - (igraph_int_t)(1)) / IGRAPH_INTEGER_SIZE)
|
||||
|
||||
|
||||
#if defined(__GNUC__)
|
||||
/* GCC and Clang support these six builtins from very early versions. */
|
||||
|
||||
#define IGRAPH_I_POPCOUNT32(x) __builtin_popcount(x)
|
||||
#define IGRAPH_I_POPCOUNT64(x) __builtin_popcountll(x)
|
||||
|
||||
/* The result of the following four builtins is undefined for zero input,
|
||||
* therefore we handle this specially.
|
||||
* See https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html */
|
||||
#define IGRAPH_I_CTZ32(x) (x ? __builtin_ctz(x) : 32)
|
||||
#define IGRAPH_I_CTZ64(x) (x ? __builtin_ctzll(x) : 64)
|
||||
#define IGRAPH_I_CLZ32(x) (x ? __builtin_clz(x) : 32)
|
||||
#define IGRAPH_I_CLZ64(x) (x ? __builtin_clzll(x) : 64)
|
||||
|
||||
#else
|
||||
/* Non-GNU compilers, i.e. MSVC and others. Attempt to use MSVC intrinsics
|
||||
* when available, otherwise use fallback implementation. */
|
||||
|
||||
#if IGRAPH_INTEGER_SIZE == 32
|
||||
#ifdef HAVE__POPCNT
|
||||
#define IGRAPH_I_POPCOUNT32(x) __popcnt(x)
|
||||
#else
|
||||
igraph_int_t igraph_i_popcnt(igraph_uint_t x);
|
||||
#define IGRAPH_I_POPCOUNT32(x) igraph_i_popcnt(x)
|
||||
#endif
|
||||
#elif IGRAPH_INTEGER_SIZE == 64
|
||||
#ifdef HAVE__POPCNT64
|
||||
#define IGRAPH_I_POPCOUNT64(x) __popcnt64(x)
|
||||
#else
|
||||
igraph_int_t igraph_i_popcnt(igraph_uint_t x);
|
||||
#define IGRAPH_I_POPCOUNT64(x) igraph_i_popcnt(x)
|
||||
#endif
|
||||
#else
|
||||
#error "Unexpected IGRAPH_INTEGER_SIZE value."
|
||||
#endif
|
||||
|
||||
igraph_int_t igraph_i_ctz32(igraph_uint_t x);
|
||||
igraph_int_t igraph_i_ctz64(igraph_uint_t x);
|
||||
igraph_int_t igraph_i_clz32(igraph_uint_t x);
|
||||
igraph_int_t igraph_i_clz64(igraph_uint_t x);
|
||||
#define IGRAPH_I_CTZ32(x) igraph_i_ctz32(x)
|
||||
#define IGRAPH_I_CTZ64(x) igraph_i_ctz64(x)
|
||||
#define IGRAPH_I_CLZ32(x) igraph_i_clz32(x)
|
||||
#define IGRAPH_I_CLZ64(x) igraph_i_clz64(x)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#if IGRAPH_INTEGER_SIZE == 32
|
||||
#define IGRAPH_POPCOUNT IGRAPH_I_POPCOUNT32
|
||||
#define IGRAPH_CLZ IGRAPH_I_CLZ32
|
||||
#define IGRAPH_CTZ IGRAPH_I_CTZ32
|
||||
#elif IGRAPH_INTEGER_SIZE == 64
|
||||
#define IGRAPH_POPCOUNT IGRAPH_I_POPCOUNT64
|
||||
#define IGRAPH_CLZ IGRAPH_I_CLZ64
|
||||
#define IGRAPH_CTZ IGRAPH_I_CTZ64
|
||||
#else
|
||||
#error "Unexpected IGRAPH_INTEGER_SIZE value."
|
||||
#endif
|
||||
|
||||
#define IGRAPH_CLO(x) IGRAPH_CLZ(~(x))
|
||||
#define IGRAPH_CTO(x) IGRAPH_CTZ(~(x))
|
||||
|
||||
typedef struct {
|
||||
igraph_int_t size;
|
||||
igraph_uint_t *stor_begin;
|
||||
igraph_uint_t *stor_end;
|
||||
} igraph_bitset_t;
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_bitset_init(igraph_bitset_t *bitset, igraph_int_t size);
|
||||
IGRAPH_EXPORT void igraph_bitset_destroy(igraph_bitset_t *bitset);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_bitset_init_copy(igraph_bitset_t *dest, const igraph_bitset_t *src);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_bitset_update(igraph_bitset_t *dest, const igraph_bitset_t *src);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_int_t igraph_bitset_capacity(const igraph_bitset_t *bitset);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_int_t igraph_bitset_size(const igraph_bitset_t *bitset);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_bitset_reserve(igraph_bitset_t *bitset, igraph_int_t capacity);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_bitset_resize(igraph_bitset_t *bitset, igraph_int_t new_size);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_int_t igraph_bitset_popcount(const igraph_bitset_t *bitset);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_int_t igraph_bitset_countl_zero(const igraph_bitset_t *bitset);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_int_t igraph_bitset_countl_one(const igraph_bitset_t *bitset);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_int_t igraph_bitset_countr_zero(const igraph_bitset_t *bitset);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_int_t igraph_bitset_countr_one(const igraph_bitset_t *bitset);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_bool_t igraph_bitset_is_all_zero(const igraph_bitset_t *bitset);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_bool_t igraph_bitset_is_all_one(const igraph_bitset_t *bitset);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_bool_t igraph_bitset_is_any_zero(const igraph_bitset_t *bitset);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_bool_t igraph_bitset_is_any_one(const igraph_bitset_t *bitset);
|
||||
IGRAPH_EXPORT void igraph_bitset_or(igraph_bitset_t *dest, const igraph_bitset_t *src1, const igraph_bitset_t *src2);
|
||||
IGRAPH_EXPORT void igraph_bitset_and(igraph_bitset_t *dest, const igraph_bitset_t *src1, const igraph_bitset_t *src2);
|
||||
IGRAPH_EXPORT void igraph_bitset_xor(igraph_bitset_t *dest, const igraph_bitset_t *src1, const igraph_bitset_t *src2);
|
||||
IGRAPH_EXPORT void igraph_bitset_not(igraph_bitset_t *dest, const igraph_bitset_t *src);
|
||||
IGRAPH_EXPORT void igraph_bitset_fill(igraph_bitset_t *bitset, igraph_bool_t value);
|
||||
IGRAPH_EXPORT void igraph_bitset_null(igraph_bitset_t *bitset);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_bitset_fprint(const igraph_bitset_t *bitset, FILE *file);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_bitset_print(const igraph_bitset_t *bitset);
|
||||
|
||||
#define IGRAPH_BITSET_INIT_FINALLY(bitset, size) \
|
||||
do { IGRAPH_CHECK(igraph_bitset_init(bitset, size)); \
|
||||
IGRAPH_FINALLY(igraph_bitset_destroy, bitset); } while (0)
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif /* IGRAPH_BITSET_H */
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2024-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_BITSET_LIST_H
|
||||
#define IGRAPH_BITSET_LIST_H
|
||||
|
||||
#include "igraph_bitset.h"
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_error.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* List of graphs */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
#define BITSET_LIST
|
||||
#define BASE_BITSET
|
||||
#include "igraph_pmt.h"
|
||||
#include "igraph_typed_list_pmt.h"
|
||||
#include "igraph_pmt_off.h"
|
||||
#undef BASE_BITSET
|
||||
#undef BITSET_LIST
|
||||
|
||||
#define IGRAPH_BITSET_LIST_INIT_FINALLY(v, size) \
|
||||
do { IGRAPH_CHECK(igraph_bitset_list_init(v, size)); \
|
||||
IGRAPH_FINALLY(igraph_bitset_list_destroy, v); } while (0)
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2007-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_BLAS_H
|
||||
#define IGRAPH_BLAS_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_types.h"
|
||||
#include "igraph_vector.h"
|
||||
#include "igraph_matrix.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
/**
|
||||
* \section about_blas BLAS interface in igraph
|
||||
*
|
||||
* <para>
|
||||
* BLAS is a highly optimized library for basic linear algebra operations
|
||||
* such as vector-vector, matrix-vector and matrix-matrix product.
|
||||
* Please see http://www.netlib.org/blas/ for details and a reference
|
||||
* implementation in Fortran. igraph contains some wrapper functions
|
||||
* that can be used to call BLAS routines in a somewhat more
|
||||
* user-friendly way. Not all BLAS routines are included in igraph,
|
||||
* and even those which are included might not have wrappers;
|
||||
* the extension of the set of wrapped functions will probably be driven
|
||||
* by igraph's internal requirements. The wrapper functions usually
|
||||
* substitute double-precision floating point arrays used by BLAS with
|
||||
* \type igraph_vector_t and \type igraph_matrix_t instances and also
|
||||
* remove those parameters (such as the number of rows/columns) that
|
||||
* can be inferred from the passed arguments directly.
|
||||
* </para>
|
||||
*/
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_blas_dgemv(igraph_bool_t transpose, igraph_real_t alpha,
|
||||
const igraph_matrix_t* a, const igraph_vector_t* x,
|
||||
igraph_real_t beta, igraph_vector_t* y);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_blas_dgemm(igraph_bool_t transpose_a,
|
||||
igraph_bool_t transpose_b, igraph_real_t alpha, const igraph_matrix_t* a,
|
||||
const igraph_matrix_t* b, igraph_real_t beta, igraph_matrix_t* c);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_blas_dgemv_array(igraph_bool_t transpose, igraph_real_t alpha,
|
||||
const igraph_matrix_t* a, const igraph_real_t* x,
|
||||
igraph_real_t beta, igraph_real_t* y);
|
||||
|
||||
IGRAPH_EXPORT igraph_real_t igraph_blas_dnrm2(const igraph_vector_t *v);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_blas_ddot(const igraph_vector_t *v1, const igraph_vector_t *v2,
|
||||
igraph_real_t *res);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,207 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2009-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_CENTRALITY_H
|
||||
#define IGRAPH_CENTRALITY_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_arpack.h"
|
||||
#include "igraph_constants.h"
|
||||
#include "igraph_datatype.h"
|
||||
#include "igraph_iterators.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_types.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* Centrality */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_closeness(const igraph_t *graph, igraph_vector_t *res,
|
||||
igraph_vector_int_t *reachable_count, igraph_bool_t *all_reachable,
|
||||
igraph_vs_t vids, igraph_neimode_t mode,
|
||||
const igraph_vector_t *weights, igraph_bool_t normalized);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_closeness_cutoff(const igraph_t *graph, igraph_vector_t *res,
|
||||
igraph_vector_int_t *reachable_count, igraph_bool_t *all_reachable,
|
||||
igraph_vs_t vids, igraph_neimode_t mode,
|
||||
const igraph_vector_t *weights,
|
||||
igraph_bool_t normalized,
|
||||
igraph_real_t cutoff);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_harmonic_centrality(const igraph_t *graph, igraph_vector_t *res,
|
||||
igraph_vs_t vids, igraph_neimode_t mode,
|
||||
const igraph_vector_t *weights,
|
||||
igraph_bool_t normalized);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_harmonic_centrality_cutoff(const igraph_t *graph, igraph_vector_t *res,
|
||||
igraph_vs_t vids, igraph_neimode_t mode,
|
||||
const igraph_vector_t *weights,
|
||||
igraph_bool_t normalized,
|
||||
igraph_real_t cutoff);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_betweenness(
|
||||
const igraph_t *graph, const igraph_vector_t *weights,
|
||||
igraph_vector_t *res,
|
||||
igraph_vs_t vids,
|
||||
igraph_bool_t directed, igraph_bool_t normalized);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_betweenness_cutoff(
|
||||
const igraph_t *graph, const igraph_vector_t *weights,
|
||||
igraph_vector_t *res,
|
||||
igraph_vs_t vids,
|
||||
igraph_bool_t directed, igraph_bool_t normalized,
|
||||
igraph_real_t cutoff);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_edge_betweenness(
|
||||
const igraph_t *graph, const igraph_vector_t *weights,
|
||||
igraph_vector_t *res, igraph_es_t eids,
|
||||
igraph_bool_t directed, igraph_bool_t normalized);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_edge_betweenness_cutoff(
|
||||
const igraph_t *graph, const igraph_vector_t *weights,
|
||||
igraph_vector_t *res, igraph_es_t eids,
|
||||
igraph_bool_t directed, igraph_bool_t normalized,
|
||||
igraph_real_t cutoff);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_betweenness_subset(
|
||||
const igraph_t *graph, const igraph_vector_t *weights,
|
||||
igraph_vector_t *res,
|
||||
igraph_vs_t sources, igraph_vs_t targets,
|
||||
igraph_vs_t vids,
|
||||
igraph_bool_t directed, igraph_bool_t normalized);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_edge_betweenness_subset(
|
||||
const igraph_t *graph, const igraph_vector_t *weights,
|
||||
igraph_vector_t *res,
|
||||
igraph_vs_t sources, igraph_vs_t targets,
|
||||
igraph_es_t eids,
|
||||
igraph_bool_t directed, igraph_bool_t normalized);
|
||||
|
||||
/**
|
||||
* \typedef igraph_pagerank_algo_t
|
||||
* \brief PageRank algorithm implementation.
|
||||
*
|
||||
* Algorithms to calculate PageRank.
|
||||
* \enumval IGRAPH_PAGERANK_ALGO_ARPACK Use the ARPACK library, this
|
||||
* was the PageRank implementation in igraph from version 0.5, until
|
||||
* version 0.7.
|
||||
* \enumval IGRAPH_PAGERANK_ALGO_PRPACK Use the PRPACK
|
||||
* library. Currently this implementation is recommended.
|
||||
*/
|
||||
|
||||
typedef enum {
|
||||
IGRAPH_PAGERANK_ALGO_ARPACK = 1,
|
||||
IGRAPH_PAGERANK_ALGO_PRPACK = 2
|
||||
} igraph_pagerank_algo_t;
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_pagerank(
|
||||
const igraph_t *graph, const igraph_vector_t *weights,
|
||||
igraph_vector_t *vector, igraph_real_t *value,
|
||||
igraph_real_t damping, igraph_bool_t directed,
|
||||
igraph_vs_t vids,
|
||||
igraph_pagerank_algo_t algo,
|
||||
igraph_arpack_options_t *options);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_personalized_pagerank(
|
||||
const igraph_t *graph, const igraph_vector_t *weights,
|
||||
igraph_vector_t *vector, igraph_real_t *value,
|
||||
const igraph_vector_t *reset,
|
||||
igraph_real_t damping, igraph_bool_t directed,
|
||||
igraph_vs_t vids,
|
||||
igraph_pagerank_algo_t algo,
|
||||
igraph_arpack_options_t *options);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_personalized_pagerank_vs(
|
||||
const igraph_t *graph, const igraph_vector_t *weights,
|
||||
igraph_vector_t *vector, igraph_real_t *value,
|
||||
igraph_vs_t reset_vids, igraph_real_t damping,
|
||||
igraph_bool_t directed, igraph_vs_t vids,
|
||||
igraph_pagerank_algo_t algo,
|
||||
igraph_arpack_options_t *options);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_eigenvector_centrality(const igraph_t *graph, igraph_vector_t *vector,
|
||||
igraph_real_t *value,
|
||||
igraph_neimode_t mode,
|
||||
const igraph_vector_t *weights,
|
||||
igraph_arpack_options_t *options);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_hub_and_authority_scores(const igraph_t *graph, igraph_vector_t *hub_vector,
|
||||
igraph_vector_t *authority_vector,
|
||||
igraph_real_t *value,
|
||||
const igraph_vector_t *weights,
|
||||
igraph_arpack_options_t *options);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_constraint(const igraph_t *graph, igraph_vector_t *res,
|
||||
igraph_vs_t vids, const igraph_vector_t *weights);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_convergence_degree(const igraph_t *graph, igraph_vector_t *result,
|
||||
igraph_vector_t *ins, igraph_vector_t *outs);
|
||||
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_real_t igraph_centralization(const igraph_vector_t *scores,
|
||||
igraph_real_t theoretical_max,
|
||||
igraph_bool_t normalized);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_centralization_degree(const igraph_t *graph, igraph_vector_t *res,
|
||||
igraph_neimode_t mode, igraph_loops_t loops,
|
||||
igraph_real_t *centralization,
|
||||
igraph_real_t *theoretical_max,
|
||||
igraph_bool_t normalized);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_centralization_degree_tmax(const igraph_t *graph,
|
||||
igraph_int_t nodes,
|
||||
igraph_neimode_t mode,
|
||||
igraph_loops_t loops,
|
||||
igraph_real_t *res);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_centralization_betweenness(const igraph_t *graph,
|
||||
igraph_vector_t *res,
|
||||
igraph_bool_t directed,
|
||||
igraph_real_t *centralization,
|
||||
igraph_real_t *theoretical_max,
|
||||
igraph_bool_t normalized);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_centralization_betweenness_tmax(const igraph_t *graph,
|
||||
igraph_int_t nodes,
|
||||
igraph_bool_t directed,
|
||||
igraph_real_t *res);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_centralization_closeness(const igraph_t *graph,
|
||||
igraph_vector_t *res,
|
||||
igraph_neimode_t mode,
|
||||
igraph_real_t *centralization,
|
||||
igraph_real_t *theoretical_max,
|
||||
igraph_bool_t normalized);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_centralization_closeness_tmax(const igraph_t *graph,
|
||||
igraph_int_t nodes,
|
||||
igraph_neimode_t mode,
|
||||
igraph_real_t *res);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_centralization_eigenvector_centrality(const igraph_t *graph,
|
||||
igraph_vector_t *vector,
|
||||
igraph_real_t *value,
|
||||
igraph_neimode_t mode,
|
||||
igraph_arpack_options_t *options,
|
||||
igraph_real_t *centralization,
|
||||
igraph_real_t *theoretical_max,
|
||||
igraph_bool_t normalized);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_centralization_eigenvector_centrality_tmax(const igraph_t *graph,
|
||||
igraph_int_t nodes,
|
||||
igraph_neimode_t mode,
|
||||
igraph_real_t *res);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2009-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_CLIQUES_H
|
||||
#define IGRAPH_CLIQUES_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_types.h"
|
||||
#include "igraph_datatype.h"
|
||||
#include "igraph_vector_list.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* Cliques, maximal independent vertex sets */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_maximal_cliques(
|
||||
const igraph_t *graph, igraph_vector_int_list_t *res,
|
||||
igraph_int_t min_size, igraph_int_t max_size,
|
||||
igraph_int_t max_results);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_maximal_cliques_file(
|
||||
const igraph_t *graph,
|
||||
FILE *outfile,
|
||||
igraph_int_t min_size, igraph_int_t max_size,
|
||||
igraph_int_t max_results);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_maximal_cliques_count(
|
||||
const igraph_t *graph,
|
||||
igraph_int_t *res,
|
||||
igraph_int_t min_size, igraph_int_t max_size);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_maximal_cliques_subset(
|
||||
const igraph_t *graph, const igraph_vector_int_t *subset,
|
||||
igraph_vector_int_list_t *res, igraph_int_t *no, FILE *outfile,
|
||||
igraph_int_t min_size, igraph_int_t max_size,
|
||||
igraph_int_t max_results);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_maximal_cliques_hist(
|
||||
const igraph_t *graph,
|
||||
igraph_vector_t *hist,
|
||||
igraph_int_t min_size, igraph_int_t max_size);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_cliques(
|
||||
const igraph_t *graph, igraph_vector_int_list_t *res,
|
||||
igraph_int_t min_size, igraph_int_t max_size,
|
||||
igraph_int_t max_results);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_clique_size_hist(
|
||||
const igraph_t *graph, igraph_vector_t *hist,
|
||||
igraph_int_t min_size, igraph_int_t max_size);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_largest_cliques(
|
||||
const igraph_t *graph,
|
||||
igraph_vector_int_list_t *cliques);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_clique_number(const igraph_t *graph, igraph_int_t *no);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_weighted_cliques(
|
||||
const igraph_t *graph, const igraph_vector_t *vertex_weights,
|
||||
igraph_vector_int_list_t *res,
|
||||
igraph_bool_t maximal,
|
||||
igraph_real_t min_weight, igraph_real_t max_weight,
|
||||
igraph_int_t max_results);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_largest_weighted_cliques(
|
||||
const igraph_t *graph, const igraph_vector_t *vertex_weights,
|
||||
igraph_vector_int_list_t *res);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_weighted_clique_number(
|
||||
const igraph_t *graph, const igraph_vector_t *vertex_weights,
|
||||
igraph_real_t *res);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_independent_vertex_sets(
|
||||
const igraph_t *graph,
|
||||
igraph_vector_int_list_t *res,
|
||||
igraph_int_t min_size, igraph_int_t max_size,
|
||||
igraph_int_t max_results);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_largest_independent_vertex_sets(
|
||||
const igraph_t *graph,
|
||||
igraph_vector_int_list_t *res);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_maximal_independent_vertex_sets(
|
||||
const igraph_t *graph,
|
||||
igraph_vector_int_list_t *res,
|
||||
igraph_int_t min_size, igraph_int_t max_size,
|
||||
igraph_int_t max_results);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_independence_number(const igraph_t *graph, igraph_int_t *no);
|
||||
|
||||
/**
|
||||
* \typedef igraph_clique_handler_t
|
||||
* \brief Type of clique handler functions.
|
||||
*
|
||||
* Callback type, called when a clique was found.
|
||||
*
|
||||
* See the details at the documentation of \ref
|
||||
* igraph_cliques_callback().
|
||||
*
|
||||
* \param clique The current clique. The clique is owned by the clique search
|
||||
* routine. You do not need to destroy or free it if you do not want to store
|
||||
* it; however, if you want to hold on to it for a longer period of time, you
|
||||
* need to make a copy of it on your own and store the copy itself.
|
||||
* \param arg This extra argument was passed to \ref
|
||||
* igraph_cliques_callback() when it was called.
|
||||
* \return Error code; \c IGRAPH_SUCCESS to continue the search or
|
||||
* \c IGRAPH_STOP to stop the search without signaling an error.
|
||||
*/
|
||||
typedef igraph_error_t igraph_clique_handler_t(const igraph_vector_int_t *clique, void *arg);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_cliques_callback(
|
||||
const igraph_t *graph,
|
||||
igraph_int_t min_size, igraph_int_t max_size,
|
||||
igraph_clique_handler_t *cliquehandler_fn, void *arg);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_maximal_cliques_callback(
|
||||
const igraph_t *graph,
|
||||
igraph_int_t min_size, igraph_int_t max_size,
|
||||
igraph_clique_handler_t *cliquehandler_fn, void *arg);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2009-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_COCITATION_H
|
||||
#define IGRAPH_COCITATION_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_types.h"
|
||||
#include "igraph_matrix.h"
|
||||
#include "igraph_datatype.h"
|
||||
#include "igraph_iterators.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* Cocitation and other similarity measures */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_cocitation(const igraph_t *graph, igraph_matrix_t *res,
|
||||
igraph_vs_t vids);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_bibcoupling(const igraph_t *graph, igraph_matrix_t *res,
|
||||
igraph_vs_t vids);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_similarity_jaccard(const igraph_t *graph, igraph_matrix_t *res,
|
||||
igraph_vs_t vit_from, igraph_vs_t vit_to,
|
||||
igraph_neimode_t mode, igraph_bool_t loops);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_similarity_jaccard_pairs(const igraph_t *graph, igraph_vector_t *res,
|
||||
const igraph_vector_int_t *pairs, igraph_neimode_t mode, igraph_bool_t loops);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_similarity_jaccard_es(const igraph_t *graph, igraph_vector_t *res,
|
||||
igraph_es_t es, igraph_neimode_t mode, igraph_bool_t loops);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_similarity_dice(const igraph_t *graph, igraph_matrix_t *res,
|
||||
igraph_vs_t vit_from, igraph_vs_t vit_to,
|
||||
igraph_neimode_t mode, igraph_bool_t loops);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_similarity_dice_pairs(const igraph_t *graph, igraph_vector_t *res,
|
||||
const igraph_vector_int_t *pairs, igraph_neimode_t mode, igraph_bool_t loops);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_similarity_dice_es(const igraph_t *graph, igraph_vector_t *res,
|
||||
igraph_es_t es, igraph_neimode_t mode, igraph_bool_t loops);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_similarity_inverse_log_weighted(const igraph_t *graph,
|
||||
igraph_matrix_t *res, igraph_vs_t vids,
|
||||
igraph_neimode_t mode);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2010-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_COHESIVE_BLOCKS_H
|
||||
#define IGRAPH_COHESIVE_BLOCKS_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_datatype.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_vector.h"
|
||||
#include "igraph_vector_list.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_cohesive_blocks(const igraph_t *graph,
|
||||
igraph_vector_int_list_t *blocks,
|
||||
igraph_vector_int_t *cohesion,
|
||||
igraph_vector_int_t *parent,
|
||||
igraph_t *block_tree);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2017-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_COLORING_H
|
||||
#define IGRAPH_COLORING_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_datatype.h"
|
||||
#include "igraph_error.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
/**
|
||||
* \typedef igraph_coloring_greedy_t
|
||||
* \brief Ordering heuristics for greedy graph coloring.
|
||||
*
|
||||
* Ordering heuristics for \ref igraph_vertex_coloring_greedy().
|
||||
*
|
||||
* \enumval IGRAPH_COLORING_GREEDY_COLORED_NEIGHBORS
|
||||
* Choose the vertex with largest number of already colored neighbors.
|
||||
* \enumval IGRAPH_COLORING_GREEDY_DSATUR
|
||||
* Choose the vertex with largest number of unique colors in its neighborhood, i.e. its
|
||||
* "saturation degree". When multiple vertices have the same saturation degree, choose
|
||||
* the one with the most not yet colored neighbors. Added in igraph 0.10.4. This heuristic
|
||||
* is known as "DSatur", and was proposed in
|
||||
* Daniel Brélaz: New methods to color the vertices of a graph,
|
||||
* Commun. ACM 22, 4 (1979), 251–256. https://doi.org/10.1145/359094.359101
|
||||
*/
|
||||
typedef enum {
|
||||
IGRAPH_COLORING_GREEDY_COLORED_NEIGHBORS = 0,
|
||||
IGRAPH_COLORING_GREEDY_DSATUR = 1
|
||||
} igraph_coloring_greedy_t;
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_vertex_coloring_greedy(const igraph_t *graph, igraph_vector_int_t *colors, igraph_coloring_greedy_t heuristic);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_is_vertex_coloring(const igraph_t *graph, const igraph_vector_int_t *types, igraph_bool_t *res);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_is_bipartite_coloring(const igraph_t *graph, const igraph_vector_bool_t *types, igraph_bool_t *res, igraph_neimode_t *mode);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_is_edge_coloring(const igraph_t *graph, const igraph_vector_int_t *types, igraph_bool_t *res);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif /* IGRAPH_COLORING_H */
|
||||
@@ -0,0 +1,280 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2009-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_COMMUNITY_H
|
||||
#define IGRAPH_COMMUNITY_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
|
||||
#include "igraph_arpack.h"
|
||||
#include "igraph_constants.h"
|
||||
#include "igraph_datatype.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_types.h"
|
||||
#include "igraph_vector_list.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* K-Cores and K-Truss */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_coreness(
|
||||
const igraph_t *graph, igraph_vector_int_t *cores, igraph_neimode_t mode);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_trussness(
|
||||
const igraph_t* graph, igraph_vector_int_t* trussness);
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* Community Structure */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
/* TODO: cut.community */
|
||||
/* TODO: edge.type.matrix */
|
||||
/* TODO: */
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_community_optimal_modularity(const igraph_t *graph,
|
||||
const igraph_vector_t *weights,
|
||||
igraph_real_t resolution,
|
||||
igraph_real_t *modularity,
|
||||
igraph_vector_int_t *membership);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_community_spinglass(const igraph_t *graph,
|
||||
const igraph_vector_t *weights,
|
||||
igraph_real_t *modularity,
|
||||
igraph_real_t *temperature,
|
||||
igraph_vector_int_t *membership,
|
||||
igraph_vector_int_t *csize,
|
||||
igraph_int_t spins,
|
||||
igraph_bool_t parupdate,
|
||||
igraph_real_t starttemp,
|
||||
igraph_real_t stoptemp,
|
||||
igraph_real_t coolfact,
|
||||
igraph_spincomm_update_t update_rule,
|
||||
igraph_real_t gamma,
|
||||
igraph_spinglass_implementation_t implementation,
|
||||
igraph_real_t gamma_minus);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_community_spinglass_single(const igraph_t *graph,
|
||||
const igraph_vector_t *weights,
|
||||
igraph_int_t vertex,
|
||||
igraph_vector_int_t *community,
|
||||
igraph_real_t *cohesion,
|
||||
igraph_real_t *adhesion,
|
||||
igraph_real_t *inner_links,
|
||||
igraph_real_t *outer_links,
|
||||
igraph_int_t spins,
|
||||
igraph_spincomm_update_t update_rule,
|
||||
igraph_real_t gamma);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_community_walktrap(const igraph_t *graph,
|
||||
const igraph_vector_t *weights,
|
||||
igraph_int_t steps,
|
||||
igraph_matrix_int_t *merges,
|
||||
igraph_vector_t *modularity,
|
||||
igraph_vector_int_t *membership);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_community_infomap(const igraph_t *graph,
|
||||
const igraph_vector_t *edge_weights,
|
||||
const igraph_vector_t *vertex_weights,
|
||||
igraph_int_t nb_trials,
|
||||
igraph_bool_t is_regularized,
|
||||
igraph_real_t regularization_strength,
|
||||
igraph_vector_int_t *membership,
|
||||
igraph_real_t *codelength);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_community_edge_betweenness(const igraph_t *graph,
|
||||
igraph_vector_int_t *removed_edges,
|
||||
igraph_vector_t *edge_betweenness,
|
||||
igraph_matrix_int_t *merges,
|
||||
igraph_vector_int_t *bridges,
|
||||
igraph_vector_t *modularity,
|
||||
igraph_vector_int_t *membership,
|
||||
igraph_bool_t directed,
|
||||
const igraph_vector_t *weights,
|
||||
const igraph_vector_t *lengths);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_community_eb_get_merges(const igraph_t *graph,
|
||||
igraph_bool_t directed,
|
||||
const igraph_vector_int_t *edges,
|
||||
const igraph_vector_t *weights,
|
||||
igraph_matrix_int_t *merges,
|
||||
igraph_vector_int_t *bridges,
|
||||
igraph_vector_t *modularity,
|
||||
igraph_vector_int_t *membership);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_community_fastgreedy(const igraph_t *graph,
|
||||
const igraph_vector_t *weights,
|
||||
igraph_matrix_int_t *merges,
|
||||
igraph_vector_t *modularity,
|
||||
igraph_vector_int_t *membership);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_community_to_membership(const igraph_matrix_int_t *merges,
|
||||
igraph_int_t nodes,
|
||||
igraph_int_t steps,
|
||||
igraph_vector_int_t *membership,
|
||||
igraph_vector_int_t *csize);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_le_community_to_membership(const igraph_matrix_int_t *merges,
|
||||
igraph_int_t steps,
|
||||
igraph_vector_int_t *membership,
|
||||
igraph_vector_int_t *csize);
|
||||
|
||||
IGRAPH_EXPERIMENTAL IGRAPH_EXPORT igraph_error_t igraph_community_voronoi(
|
||||
const igraph_t *graph,
|
||||
igraph_vector_int_t *membership, igraph_vector_int_t *generators, igraph_real_t *modularity,
|
||||
const igraph_vector_t *lengths, const igraph_vector_t *weights,
|
||||
igraph_neimode_t mode, igraph_real_t r);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_modularity(const igraph_t *graph,
|
||||
const igraph_vector_int_t *membership,
|
||||
const igraph_vector_t *weights,
|
||||
igraph_real_t resolution,
|
||||
igraph_bool_t directed,
|
||||
igraph_real_t *modularity);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_modularity_matrix(const igraph_t *graph,
|
||||
const igraph_vector_t *weights,
|
||||
igraph_real_t resolution,
|
||||
igraph_matrix_t *modmat,
|
||||
igraph_bool_t directed);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_reindex_membership(igraph_vector_int_t *membership,
|
||||
igraph_vector_int_t *new_to_old,
|
||||
igraph_int_t *nb_clusters);
|
||||
|
||||
typedef enum { IGRAPH_LEVC_HIST_SPLIT = 1,
|
||||
IGRAPH_LEVC_HIST_FAILED,
|
||||
IGRAPH_LEVC_HIST_START_FULL,
|
||||
IGRAPH_LEVC_HIST_START_GIVEN
|
||||
} igraph_leading_eigenvector_community_history_t;
|
||||
|
||||
/**
|
||||
* \typedef igraph_community_leading_eigenvector_callback_t
|
||||
* Callback for the leading eigenvector community finding method.
|
||||
*
|
||||
* The leading eigenvector community finding implementation in igraph
|
||||
* is able to call a callback function, after each eigenvalue
|
||||
* calculation. This callback function must be of \c
|
||||
* igraph_community_leading_eigenvector_callback_t type.
|
||||
* The following arguments are passed to the callback:
|
||||
* \param membership The actual membership vector, before recording
|
||||
* the potential change implied by the newly found eigenvalue.
|
||||
* \param comm The id of the community that the algorithm tried to
|
||||
* split in the last iteration. The community IDs are indexed from
|
||||
* zero here!
|
||||
* \param eigenvalue The eigenvalue the algorithm has just found.
|
||||
* \param eigenvector The eigenvector corresponding to the eigenvalue
|
||||
* the algorithm just found.
|
||||
* \param arpack_multiplier A function that was passed to \ref
|
||||
* igraph_arpack_rssolve() to solve the last eigenproblem.
|
||||
* \param arpack_extra The extra argument that was passed to the
|
||||
* ARPACK solver.
|
||||
* \param extra Extra argument that as passed to \ref
|
||||
* igraph_community_leading_eigenvector().
|
||||
*
|
||||
* \sa \ref igraph_community_leading_eigenvector(), \ref
|
||||
* igraph_arpack_function_t, \ref igraph_arpack_rssolve().
|
||||
*/
|
||||
|
||||
typedef igraph_error_t igraph_community_leading_eigenvector_callback_t(
|
||||
const igraph_vector_int_t *membership,
|
||||
igraph_int_t comm,
|
||||
igraph_real_t eigenvalue,
|
||||
const igraph_vector_t *eigenvector,
|
||||
igraph_arpack_function_t *arpack_multiplier,
|
||||
void *arpack_extra,
|
||||
void *extra);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_community_leading_eigenvector(const igraph_t *graph,
|
||||
const igraph_vector_t *weights,
|
||||
igraph_matrix_int_t *merges,
|
||||
igraph_vector_int_t *membership,
|
||||
igraph_int_t steps,
|
||||
igraph_arpack_options_t *options,
|
||||
igraph_real_t *modularity,
|
||||
igraph_bool_t start,
|
||||
igraph_vector_t *eigenvalues,
|
||||
igraph_vector_list_t *eigenvectors,
|
||||
igraph_vector_int_t *history,
|
||||
igraph_community_leading_eigenvector_callback_t *callback,
|
||||
void *callback_extra);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_community_fluid_communities(const igraph_t *graph,
|
||||
igraph_int_t no_of_communities,
|
||||
igraph_vector_int_t *membership);
|
||||
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_community_label_propagation(const igraph_t *graph,
|
||||
igraph_vector_int_t *membership,
|
||||
igraph_neimode_t mode,
|
||||
const igraph_vector_t *weights,
|
||||
const igraph_vector_int_t *initial,
|
||||
const igraph_vector_bool_t *fixed,
|
||||
igraph_lpa_variant_t variant);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_community_multilevel(const igraph_t *graph,
|
||||
const igraph_vector_t *weights,
|
||||
igraph_real_t resolution,
|
||||
igraph_vector_int_t *membership,
|
||||
igraph_matrix_int_t *memberships,
|
||||
igraph_vector_t *modularity);
|
||||
|
||||
typedef enum {
|
||||
IGRAPH_LEIDEN_OBJECTIVE_MODULARITY = 0,
|
||||
IGRAPH_LEIDEN_OBJECTIVE_CPM,
|
||||
IGRAPH_LEIDEN_OBJECTIVE_ER
|
||||
} igraph_leiden_objective_t;
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_community_leiden(
|
||||
const igraph_t *graph,
|
||||
const igraph_vector_t *edge_weights,
|
||||
const igraph_vector_t *vertex_out_weights,
|
||||
const igraph_vector_t *vertex_in_weights,
|
||||
igraph_real_t resolution,
|
||||
igraph_real_t beta,
|
||||
igraph_bool_t start,
|
||||
igraph_int_t n_iterations,
|
||||
igraph_vector_int_t *membership,
|
||||
igraph_int_t *nb_clusters, igraph_real_t *quality);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_community_leiden_simple(
|
||||
const igraph_t *graph,
|
||||
const igraph_vector_t *weights,
|
||||
igraph_leiden_objective_t objective,
|
||||
igraph_real_t resolution,
|
||||
igraph_real_t beta,
|
||||
igraph_bool_t start,
|
||||
igraph_int_t n_iterations,
|
||||
igraph_vector_int_t *membership,
|
||||
igraph_int_t *nb_clusters,
|
||||
igraph_real_t *quality);
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* Community Structure Comparison */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_compare_communities(const igraph_vector_int_t *comm1,
|
||||
const igraph_vector_int_t *comm2,
|
||||
igraph_real_t* result,
|
||||
igraph_community_comparison_t method);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_split_join_distance(const igraph_vector_int_t *comm1,
|
||||
const igraph_vector_int_t *comm2,
|
||||
igraph_int_t* distance12,
|
||||
igraph_int_t* distance21);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2010-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_COMPLEX_H
|
||||
#define IGRAPH_COMPLEX_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_types.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
typedef struct igraph_complex_t {
|
||||
igraph_real_t dat[2];
|
||||
} igraph_complex_t;
|
||||
|
||||
#define IGRAPH_REAL(x) ((x).dat[0])
|
||||
#define IGRAPH_IMAG(x) ((x).dat[1])
|
||||
#define IGRAPH_COMPLEX_EQ(x,y) ((x).dat[0]==(y).dat[0] && (x).dat[1]==(y).dat[1])
|
||||
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_CONST igraph_complex_t igraph_complex(igraph_real_t x, igraph_real_t y);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_CONST igraph_complex_t igraph_complex_polar(igraph_real_t r, igraph_real_t theta);
|
||||
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_CONST igraph_bool_t igraph_complex_almost_equals(igraph_complex_t z1,
|
||||
igraph_complex_t z2,
|
||||
igraph_real_t eps);
|
||||
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_CONST igraph_real_t igraph_complex_arg(igraph_complex_t z);
|
||||
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_CONST igraph_real_t igraph_complex_abs(igraph_complex_t z);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_CONST igraph_real_t igraph_complex_logabs(igraph_complex_t z);
|
||||
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_CONST igraph_complex_t igraph_complex_add(igraph_complex_t z1,
|
||||
igraph_complex_t z2);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_CONST igraph_complex_t igraph_complex_sub(igraph_complex_t z1,
|
||||
igraph_complex_t z2);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_CONST igraph_complex_t igraph_complex_mul(igraph_complex_t z1,
|
||||
igraph_complex_t z2);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_CONST igraph_complex_t igraph_complex_div(igraph_complex_t z1,
|
||||
igraph_complex_t z2);
|
||||
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_CONST igraph_complex_t igraph_complex_add_real(igraph_complex_t z,
|
||||
igraph_real_t x);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_CONST igraph_complex_t igraph_complex_add_imag(igraph_complex_t z,
|
||||
igraph_real_t y);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_CONST igraph_complex_t igraph_complex_sub_real(igraph_complex_t z,
|
||||
igraph_real_t x);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_CONST igraph_complex_t igraph_complex_sub_imag(igraph_complex_t z,
|
||||
igraph_real_t y);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_CONST igraph_complex_t igraph_complex_mul_real(igraph_complex_t z,
|
||||
igraph_real_t x);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_CONST igraph_complex_t igraph_complex_mul_imag(igraph_complex_t z,
|
||||
igraph_real_t y);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_CONST igraph_complex_t igraph_complex_div_real(igraph_complex_t z,
|
||||
igraph_real_t x);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_CONST igraph_complex_t igraph_complex_div_imag(igraph_complex_t z,
|
||||
igraph_real_t y);
|
||||
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_CONST igraph_complex_t igraph_complex_conj(igraph_complex_t z);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_CONST igraph_complex_t igraph_complex_neg(igraph_complex_t z);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_CONST igraph_complex_t igraph_complex_inv(igraph_complex_t z);
|
||||
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_CONST igraph_complex_t igraph_complex_sqrt(igraph_complex_t z);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_CONST igraph_complex_t igraph_complex_sqrt_real(igraph_real_t x);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_CONST igraph_complex_t igraph_complex_exp(igraph_complex_t z);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_CONST igraph_complex_t igraph_complex_pow(igraph_complex_t z1,
|
||||
igraph_complex_t z2);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_CONST igraph_complex_t igraph_complex_pow_real(igraph_complex_t z,
|
||||
igraph_real_t x);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_CONST igraph_complex_t igraph_complex_log(igraph_complex_t z);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_CONST igraph_complex_t igraph_complex_log10(igraph_complex_t z);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_CONST igraph_complex_t igraph_complex_log_b(igraph_complex_t z,
|
||||
igraph_complex_t b);
|
||||
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_CONST igraph_complex_t igraph_complex_sin(igraph_complex_t z);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_CONST igraph_complex_t igraph_complex_cos(igraph_complex_t z);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_CONST igraph_complex_t igraph_complex_tan(igraph_complex_t z);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_CONST igraph_complex_t igraph_complex_sec(igraph_complex_t z);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_CONST igraph_complex_t igraph_complex_csc(igraph_complex_t z);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_CONST igraph_complex_t igraph_complex_cot(igraph_complex_t z);
|
||||
|
||||
IGRAPH_EXPORT int igraph_complex_printf(igraph_complex_t val);
|
||||
IGRAPH_EXPORT int igraph_complex_fprintf(FILE *file, igraph_complex_t val);
|
||||
IGRAPH_EXPORT int igraph_complex_printf_aligned(int width, igraph_complex_t val);
|
||||
IGRAPH_EXPORT int igraph_complex_fprintf_aligned(FILE *file, int width, igraph_complex_t val);
|
||||
IGRAPH_EXPORT int igraph_complex_snprintf(char *str, size_t size, igraph_complex_t val);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2009-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_COMPONENTS_H
|
||||
#define IGRAPH_COMPONENTS_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
|
||||
#include "igraph_constants.h"
|
||||
#include "igraph_datatype.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_graph_list.h"
|
||||
#include "igraph_types.h"
|
||||
#include "igraph_vector.h"
|
||||
#include "igraph_vector_list.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* Components */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_connected_components(const igraph_t *graph, igraph_vector_int_t *membership,
|
||||
igraph_vector_int_t *csize, igraph_int_t *no,
|
||||
igraph_connectedness_t mode);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_is_connected(const igraph_t *graph, igraph_bool_t *res,
|
||||
igraph_connectedness_t mode);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_decompose(const igraph_t *graph, igraph_graph_list_t *components,
|
||||
igraph_connectedness_t mode,
|
||||
igraph_int_t maxcompno, igraph_int_t minelements);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_articulation_points(const igraph_t *graph,
|
||||
igraph_vector_int_t *res);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_biconnected_components(const igraph_t *graph,
|
||||
igraph_int_t *no,
|
||||
igraph_vector_int_list_t *tree_edges,
|
||||
igraph_vector_int_list_t *component_edges,
|
||||
igraph_vector_int_list_t *components,
|
||||
igraph_vector_int_t *articulation_points);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_is_biconnected(const igraph_t *graph, igraph_bool_t *result);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_bridges(const igraph_t *graph, igraph_vector_int_t *bridges);
|
||||
|
||||
IGRAPH_EXPERIMENTAL IGRAPH_EXPORT igraph_error_t igraph_bond_percolation(
|
||||
const igraph_t *graph,
|
||||
igraph_vector_int_t *giant_size,
|
||||
igraph_vector_int_t *vertex_count,
|
||||
const igraph_vector_int_t *edge_order);
|
||||
IGRAPH_EXPERIMENTAL IGRAPH_EXPORT igraph_error_t igraph_site_percolation(
|
||||
const igraph_t *graph,
|
||||
igraph_vector_int_t *giant_size,
|
||||
igraph_vector_int_t *edge_count,
|
||||
const igraph_vector_int_t *vertex_order);
|
||||
IGRAPH_EXPERIMENTAL IGRAPH_EXPORT igraph_error_t igraph_edgelist_percolation(
|
||||
const igraph_vector_int_t *edges,
|
||||
igraph_vector_int_t *giant_size,
|
||||
igraph_vector_int_t *vertex_count);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2011-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_CONFIG_H
|
||||
#define IGRAPH_CONFIG_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
/**
|
||||
* \define IGRAPH_INTEGER_SIZE
|
||||
*
|
||||
* Specifies the size of igraph's integer data type; must be one of 32 (for
|
||||
* 32-bit integers) or 64 (for 64-bit integers).
|
||||
*/
|
||||
#define IGRAPH_INTEGER_SIZE @IGRAPH_INTEGER_SIZE@
|
||||
|
||||
#define IGRAPH_DEPRECATED_ENUMVAL @IGRAPH_DEPRECATED_ENUMVAL@
|
||||
|
||||
/**
|
||||
* \define IGRAPH_BOOL_TYPE
|
||||
*
|
||||
* Specifies the C type to be used for igraph_bool_t. This is added here _only_
|
||||
* to support the R interface, where we want to be able to create views into
|
||||
* R boolean vectors and treat them as an igraph_vector_bool_t, which requires
|
||||
* us to align igraph_bool_t with R's boolean type.
|
||||
*
|
||||
* Any other use-case of overriding igraph's bool type is completely
|
||||
* unsupported.
|
||||
*/
|
||||
#define IGRAPH_BOOL_TYPE bool
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,278 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2009-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_CONSTANTS_H
|
||||
#define IGRAPH_CONSTANTS_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* Constants */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* \define IGRAPH_UNLIMITED
|
||||
* \brief Constant for "do not limit results".
|
||||
*
|
||||
* A constant signifying that no limitation should be used with various cutoff,
|
||||
* size limit or result set size parameters, such as minimum or maximum clique
|
||||
* size, number of results returned, cutoff for path lengths, etc. Currently
|
||||
* defined to <code>-1</code>.
|
||||
*/
|
||||
#define IGRAPH_UNLIMITED (-1)
|
||||
/* Note to maintainers: IGRAPH_UNLIMITED is intended to support readability
|
||||
* when *negative* parameter values indicate "no limit". Do not test
|
||||
* directly against IGRAPH_UNLIMITED in implementations, test for negative
|
||||
* values instead. */
|
||||
|
||||
/* These constants are meant to be used for sake of readability */
|
||||
enum { IGRAPH_UNDIRECTED = 0, IGRAPH_DIRECTED = 1 };
|
||||
enum { IGRAPH_NO_MULTIPLE = 0, IGRAPH_MULTIPLE = 1 };
|
||||
enum { IGRAPH_EDGE_UNLABELED = 0, IGRAPH_EDGE_LABELED = 1 };
|
||||
|
||||
/**
|
||||
* \typedef igraph_loops_t
|
||||
* \brief How to interpret self-loops in undirected graphs?
|
||||
*
|
||||
* Controls the interpretation of self-loops in undirected graphs, typically
|
||||
* in the context of adjacency matrices or degrees.
|
||||
*
|
||||
* </para><para>These constants are also used to improve readability in
|
||||
* boolean contexts, with \c IGRAPH_NO_LOOPS, equivalent to \c false,
|
||||
* signifying that loops should be ignored and \c IGRAPH_LOOPS, equivalent
|
||||
* to \c true, that loops should be considered.
|
||||
*
|
||||
* \enumval IGRAPH_NO_LOOPS Self-loops are ignored.
|
||||
* \enumval IGRAPH_LOOPS_TWICE Self-loops are considered, and counted twice
|
||||
* in undirected graphs. For example, a self-loop contributes two to the
|
||||
* degree of a vertex and to diagonal entries of adjacency matrices. This
|
||||
* is the standard interpretation in graph theory, thus \c IGRAPH_LOOPS
|
||||
* serves as an alias for this option.
|
||||
* \enumval IGRAPH_LOOPS_ONCE Self-loops are considered, and counted only
|
||||
* once in undirected graphs.
|
||||
*/
|
||||
typedef enum {
|
||||
IGRAPH_NO_LOOPS = 0,
|
||||
IGRAPH_LOOPS_TWICE = 1,
|
||||
IGRAPH_LOOPS_ONCE = 2,
|
||||
IGRAPH_LOOPS = IGRAPH_LOOPS_TWICE
|
||||
} igraph_loops_t;
|
||||
/* Note for the enum above: yes, IGRAPH_LOOPS_TWICE is 1, and IGRAPH_LOOPS_ONCE
|
||||
* is 2. This is intentional, for the sake of backwards compatibility with
|
||||
* earlier versions where we only had IGRAPH_LOOPS and it meant
|
||||
* IGRAPH_LOOPS_TWICE */
|
||||
|
||||
typedef enum { IGRAPH_ASCENDING = 0, IGRAPH_DESCENDING = 1 } igraph_order_t;
|
||||
|
||||
/**
|
||||
* \typedef igraph_neimode_t
|
||||
* \brief How to interpret edge directions in directed graphs?
|
||||
*
|
||||
* These "neighbor mode" constants are typically used to specify the treatment
|
||||
* of edge directions in directed graphs, or which vertices to consider as
|
||||
* adjacent to (i.e. neighbor of) a vertex. It is typically ignored in undirected
|
||||
* graphs.
|
||||
*
|
||||
* \enumval IGRAPH_OUT Follow edge directions in directed graphs, or consider
|
||||
* out-neighbors of vertices.
|
||||
* \enumval IGRAPH_IN Follow edges in the reverse direction in directed graphs,
|
||||
* or consider in-neighbors of vertices.
|
||||
* \enumval IGRAPH_ALL Ignore edge directions in directed graphs, or consider
|
||||
* all neighbours (both out and in-neighbors) of vertices.
|
||||
*/
|
||||
typedef enum {
|
||||
IGRAPH_OUT = 1,
|
||||
IGRAPH_IN = 2,
|
||||
IGRAPH_ALL = 3
|
||||
} igraph_neimode_t;
|
||||
/* Do not renumber the vaues above! Some internal code treats them as bitmasks
|
||||
* and assumes that IGRAPH_ALL == IGRAPH_IN | IGRAPH_OUT and IGRAPH_IN & IGRAPH_OUT == 0. */
|
||||
|
||||
/* Reverse IGRAPH_OUT to IGRAPH_IN and vice versa. Leave other values alone. */
|
||||
#define IGRAPH_REVERSE_MODE(mode) \
|
||||
((mode) == IGRAPH_IN ? IGRAPH_OUT : ((mode) == IGRAPH_OUT ? IGRAPH_IN : (mode)))
|
||||
|
||||
typedef enum { IGRAPH_WEAK = 1, IGRAPH_STRONG = 2 } igraph_connectedness_t;
|
||||
|
||||
typedef enum { IGRAPH_RECIPROCITY_DEFAULT = 0,
|
||||
IGRAPH_RECIPROCITY_RATIO = 1
|
||||
} igraph_reciprocity_t;
|
||||
|
||||
typedef enum { IGRAPH_ADJ_DIRECTED = 0,
|
||||
IGRAPH_ADJ_UNDIRECTED,
|
||||
IGRAPH_ADJ_UPPER, IGRAPH_ADJ_LOWER, IGRAPH_ADJ_MIN,
|
||||
IGRAPH_ADJ_PLUS,
|
||||
IGRAPH_ADJ_MAX,
|
||||
} igraph_adjacency_t;
|
||||
|
||||
typedef enum { IGRAPH_STAR_OUT = 0, IGRAPH_STAR_IN,
|
||||
IGRAPH_STAR_UNDIRECTED,
|
||||
IGRAPH_STAR_MUTUAL
|
||||
} igraph_star_mode_t;
|
||||
|
||||
typedef enum { IGRAPH_WHEEL_OUT = 0, IGRAPH_WHEEL_IN,
|
||||
IGRAPH_WHEEL_UNDIRECTED,
|
||||
IGRAPH_WHEEL_MUTUAL
|
||||
} igraph_wheel_mode_t;
|
||||
|
||||
typedef enum { IGRAPH_TREE_OUT = 0, IGRAPH_TREE_IN,
|
||||
IGRAPH_TREE_UNDIRECTED
|
||||
} igraph_tree_mode_t;
|
||||
|
||||
typedef enum { IGRAPH_GET_ADJACENCY_UPPER = 0,
|
||||
IGRAPH_GET_ADJACENCY_LOWER,
|
||||
IGRAPH_GET_ADJACENCY_BOTH
|
||||
} igraph_get_adjacency_t;
|
||||
|
||||
typedef enum { IGRAPH_DEGSEQ_CONFIGURATION = 0, /* Configuration model, allowing non-simple graphs */
|
||||
IGRAPH_DEGSEQ_VL, /* Viger-Latapy, generates simple connected graphs */
|
||||
IGRAPH_DEGSEQ_FAST_HEUR_SIMPLE, /* Fast heuristic, generates simple graphs */
|
||||
IGRAPH_DEGSEQ_CONFIGURATION_SIMPLE, /* Configuration model, generates simple graphs */
|
||||
IGRAPH_DEGSEQ_EDGE_SWITCHING_SIMPLE, /* Edge-switching MCMC, generates simple graphs */
|
||||
} igraph_degseq_t;
|
||||
|
||||
typedef enum { IGRAPH_REALIZE_DEGSEQ_SMALLEST = 0,
|
||||
IGRAPH_REALIZE_DEGSEQ_LARGEST,
|
||||
IGRAPH_REALIZE_DEGSEQ_INDEX
|
||||
} igraph_realize_degseq_t;
|
||||
|
||||
typedef enum { IGRAPH_RANDOM_TREE_PRUFER = 0,
|
||||
IGRAPH_RANDOM_TREE_LERW
|
||||
} igraph_random_tree_t;
|
||||
|
||||
typedef enum { IGRAPH_EDGEORDER_ID = 0,
|
||||
IGRAPH_EDGEORDER_FROM,
|
||||
IGRAPH_EDGEORDER_TO
|
||||
} igraph_edgeorder_type_t;
|
||||
|
||||
typedef enum { IGRAPH_TO_DIRECTED_ARBITRARY = 0,
|
||||
IGRAPH_TO_DIRECTED_MUTUAL,
|
||||
IGRAPH_TO_DIRECTED_RANDOM,
|
||||
IGRAPH_TO_DIRECTED_ACYCLIC
|
||||
} igraph_to_directed_t;
|
||||
|
||||
typedef enum { IGRAPH_TO_UNDIRECTED_EACH = 0,
|
||||
IGRAPH_TO_UNDIRECTED_COLLAPSE,
|
||||
IGRAPH_TO_UNDIRECTED_MUTUAL
|
||||
} igraph_to_undirected_t;
|
||||
|
||||
typedef enum { IGRAPH_VCONN_NEI_ERROR = 0,
|
||||
IGRAPH_VCONN_NEI_NUMBER_OF_NODES,
|
||||
IGRAPH_VCONN_NEI_IGNORE,
|
||||
IGRAPH_VCONN_NEI_NEGATIVE
|
||||
} igraph_vconn_nei_t;
|
||||
|
||||
typedef enum { IGRAPH_SPINCOMM_UPDATE_SIMPLE = 0,
|
||||
IGRAPH_SPINCOMM_UPDATE_CONFIG
|
||||
} igraph_spincomm_update_t;
|
||||
|
||||
typedef enum { IGRAPH_TRANSITIVITY_NAN = 0,
|
||||
IGRAPH_TRANSITIVITY_ZERO
|
||||
} igraph_transitivity_mode_t;
|
||||
|
||||
typedef enum { IGRAPH_SPINCOMM_IMP_ORIG = 0,
|
||||
IGRAPH_SPINCOMM_IMP_NEG
|
||||
} igraph_spinglass_implementation_t;
|
||||
|
||||
typedef enum { IGRAPH_COMMCMP_VI = 0,
|
||||
IGRAPH_COMMCMP_NMI,
|
||||
IGRAPH_COMMCMP_SPLIT_JOIN,
|
||||
IGRAPH_COMMCMP_RAND,
|
||||
IGRAPH_COMMCMP_ADJUSTED_RAND
|
||||
} igraph_community_comparison_t;
|
||||
|
||||
typedef enum { IGRAPH_ADD_WEIGHTS_NO = 0,
|
||||
IGRAPH_ADD_WEIGHTS_YES,
|
||||
IGRAPH_ADD_WEIGHTS_IF_PRESENT
|
||||
} igraph_add_weights_t;
|
||||
|
||||
typedef enum { IGRAPH_BARABASI_BAG = 0,
|
||||
IGRAPH_BARABASI_PSUMTREE,
|
||||
IGRAPH_BARABASI_PSUMTREE_MULTIPLE
|
||||
} igraph_barabasi_algorithm_t;
|
||||
|
||||
typedef enum { IGRAPH_FAS_EXACT_IP = 0,
|
||||
IGRAPH_FAS_APPROX_EADES,
|
||||
IGRAPH_FAS_EXACT_IP_CG,
|
||||
IGRAPH_FAS_EXACT_IP_TI
|
||||
} igraph_fas_algorithm_t;
|
||||
|
||||
typedef enum { IGRAPH_FVS_EXACT_IP = 0
|
||||
} igraph_fvs_algorithm_t;
|
||||
|
||||
typedef enum { IGRAPH_SUBGRAPH_AUTO = 0,
|
||||
IGRAPH_SUBGRAPH_COPY_AND_DELETE,
|
||||
IGRAPH_SUBGRAPH_CREATE_FROM_SCRATCH
|
||||
} igraph_subgraph_implementation_t;
|
||||
|
||||
typedef enum { IGRAPH_LAYOUT_GRID = 0,
|
||||
IGRAPH_LAYOUT_NOGRID,
|
||||
IGRAPH_LAYOUT_AUTOGRID
|
||||
} igraph_layout_grid_t;
|
||||
|
||||
typedef enum { IGRAPH_RANDOM_WALK_STUCK_ERROR = 0,
|
||||
IGRAPH_RANDOM_WALK_STUCK_RETURN
|
||||
} igraph_random_walk_stuck_t;
|
||||
|
||||
typedef enum { IGRAPH_VORONOI_FIRST = 0,
|
||||
IGRAPH_VORONOI_LAST,
|
||||
IGRAPH_VORONOI_RANDOM
|
||||
} igraph_voronoi_tiebreaker_t;
|
||||
|
||||
typedef enum { IGRAPH_CHUNG_LU_ORIGINAL = 0,
|
||||
IGRAPH_CHUNG_LU_MAXENT,
|
||||
IGRAPH_CHUNG_LU_NR
|
||||
} igraph_chung_lu_t;
|
||||
|
||||
typedef enum { IGRAPH_ROW_MAJOR = 0,
|
||||
IGRAPH_COLUMN_MAJOR = 1
|
||||
} igraph_matrix_storage_t;
|
||||
|
||||
typedef enum { IGRAPH_MST_AUTOMATIC = 0,
|
||||
IGRAPH_MST_UNWEIGHTED,
|
||||
IGRAPH_MST_PRIM,
|
||||
IGRAPH_MST_KRUSKAL
|
||||
} igraph_mst_algorithm_t;
|
||||
|
||||
typedef enum { IGRAPH_PRODUCT_CARTESIAN = 0,
|
||||
IGRAPH_PRODUCT_LEXICOGRAPHIC,
|
||||
IGRAPH_PRODUCT_STRONG,
|
||||
IGRAPH_PRODUCT_TENSOR,
|
||||
IGRAPH_PRODUCT_MODULAR
|
||||
} igraph_product_t;
|
||||
|
||||
/**
|
||||
* \typedef igraph_lpa_variant_t
|
||||
* \brief Label propagation algorithm variants of implementation
|
||||
*
|
||||
* Variants to run the label propagation algorithm.
|
||||
* \enumval IGRAPH_LPA_DOMINANCE Check for dominance of all nodes after each iteration
|
||||
* \enumval IGRAPH_LPA_RETENTION Keep current label if among dominant labels, only check if labels changed
|
||||
* \enumval IGRAPH_LPA_FAST Sample from dominant labels, only check neighbors
|
||||
*/
|
||||
typedef enum {
|
||||
IGRAPH_LPA_DOMINANCE = 0, /* Sample from dominant labels, check for dominance after each iteration. */
|
||||
IGRAPH_LPA_RETENTION, /* Keep current label if among dominant labels, only check if labels changed. */
|
||||
IGRAPH_LPA_FAST /* Sample from dominant labels, only check neighbors. */
|
||||
} igraph_lpa_variant_t;
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2009-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_CONSTRUCTORS_H
|
||||
#define IGRAPH_CONSTRUCTORS_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_constants.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_types.h"
|
||||
#include "igraph_matrix.h"
|
||||
#include "igraph_datatype.h"
|
||||
#include "igraph_graphicality.h"
|
||||
#include "igraph_sparsemat.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* Constructors, deterministic */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_create(igraph_t *graph, const igraph_vector_int_t *edges, igraph_int_t n,
|
||||
igraph_bool_t directed);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_small(igraph_t *graph, igraph_int_t n, igraph_bool_t directed,
|
||||
int first, ...);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_adjacency(
|
||||
igraph_t *graph, const igraph_matrix_t *adjmatrix, igraph_adjacency_t mode,
|
||||
igraph_loops_t loops);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_weighted_adjacency(
|
||||
igraph_t *graph, const igraph_matrix_t *adjmatrix, igraph_adjacency_t mode,
|
||||
igraph_vector_t *weights, igraph_loops_t loops);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparse_adjacency(igraph_t *graph, igraph_sparsemat_t *adjmatrix, igraph_adjacency_t mode, igraph_loops_t loops);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparse_weighted_adjacency(igraph_t *graph, igraph_sparsemat_t *adjmatrix, igraph_adjacency_t mode, igraph_vector_t *weights, igraph_loops_t loops);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_star(igraph_t *graph, igraph_int_t n, igraph_star_mode_t mode,
|
||||
igraph_int_t center);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_wheel(igraph_t *graph, igraph_int_t n, igraph_wheel_mode_t mode,
|
||||
igraph_int_t center);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_hypercube(igraph_t *graph,
|
||||
igraph_int_t n, igraph_bool_t directed);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_square_lattice(igraph_t *graph, const igraph_vector_int_t *dimvector, igraph_int_t nei,
|
||||
igraph_bool_t directed, igraph_bool_t mutual, const igraph_vector_bool_t *circular);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_ring(igraph_t *graph, igraph_int_t n, igraph_bool_t directed,
|
||||
igraph_bool_t mutual, igraph_bool_t circular);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_path_graph(
|
||||
igraph_t *graph, igraph_int_t n,
|
||||
igraph_bool_t directed, igraph_bool_t mutual);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_cycle_graph(
|
||||
igraph_t *graph, igraph_int_t n,
|
||||
igraph_bool_t directed, igraph_bool_t mutual);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_kary_tree(igraph_t *graph, igraph_int_t n, igraph_int_t children,
|
||||
igraph_tree_mode_t type);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_symmetric_tree(igraph_t *graph, const igraph_vector_int_t *branches,
|
||||
igraph_tree_mode_t type);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_regular_tree(igraph_t *graph, igraph_int_t h, igraph_int_t k,
|
||||
igraph_tree_mode_t type);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_tree_from_parent_vector(igraph_t *graph, const igraph_vector_int_t *parents,
|
||||
igraph_tree_mode_t mode);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_from_prufer(igraph_t *graph, const igraph_vector_int_t *prufer);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_full(igraph_t *graph, igraph_int_t n, igraph_bool_t directed, igraph_bool_t loops);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_full_multipartite(igraph_t *graph, igraph_vector_int_t *types, const igraph_vector_int_t *n,
|
||||
igraph_bool_t directed, igraph_neimode_t mode);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_turan(igraph_t *graph, igraph_vector_int_t *types, igraph_int_t n, igraph_int_t r);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_full_citation(igraph_t *graph, igraph_int_t n,
|
||||
igraph_bool_t directed);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_atlas(igraph_t *graph, igraph_int_t number);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_extended_chordal_ring(igraph_t *graph, igraph_int_t nodes,
|
||||
const igraph_matrix_int_t *W, igraph_bool_t directed);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_linegraph(const igraph_t *graph, igraph_t *linegraph);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_de_bruijn(igraph_t *graph, igraph_int_t m, igraph_int_t n);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_circulant(igraph_t *graph, igraph_int_t n, const igraph_vector_int_t *l, igraph_bool_t directed);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_generalized_petersen(igraph_t *graph, igraph_int_t n, igraph_int_t k);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_kautz(igraph_t *graph, igraph_int_t m, igraph_int_t n);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_famous(igraph_t *graph, const char *name);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_lcf(igraph_t *graph, igraph_int_t n,
|
||||
const igraph_vector_int_t *shifts,
|
||||
igraph_int_t repeats);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_lcf_small(igraph_t *graph, igraph_int_t n, ...);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_realize_degree_sequence(igraph_t *graph,
|
||||
const igraph_vector_int_t *outdeg, const igraph_vector_int_t *indeg,
|
||||
igraph_edge_type_sw_t allowed_edge_types,
|
||||
igraph_realize_degseq_t method);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_triangular_lattice(igraph_t *graph, const igraph_vector_int_t *dims, igraph_bool_t directed, igraph_bool_t mutual);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_hexagonal_lattice(igraph_t *graph, const igraph_vector_int_t *dims, igraph_bool_t directed, igraph_bool_t mutual);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_realize_bipartite_degree_sequence(igraph_t *graph, const igraph_vector_int_t *deg1, const igraph_vector_int_t *deg2, igraph_edge_type_sw_t allowed_edge_types, igraph_realize_degseq_t method);
|
||||
IGRAPH_EXPERIMENTAL IGRAPH_EXPORT igraph_error_t igraph_mycielski_graph(igraph_t *graph, igraph_int_t k);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2009-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_CONVERSION_H
|
||||
#define IGRAPH_CONVERSION_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_constants.h"
|
||||
#include "igraph_datatype.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_types.h"
|
||||
#include "igraph_matrix.h"
|
||||
#include "igraph_sparsemat.h"
|
||||
#include "igraph_attributes.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* Conversion */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_get_adjacency(
|
||||
const igraph_t *graph, igraph_matrix_t *res, igraph_get_adjacency_t type,
|
||||
const igraph_vector_t *weights, igraph_loops_t loops
|
||||
);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_get_adjacency_sparse(
|
||||
const igraph_t *graph, igraph_sparsemat_t *res, igraph_get_adjacency_t type,
|
||||
const igraph_vector_t *weights, igraph_loops_t loops
|
||||
);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_get_stochastic(
|
||||
const igraph_t *graph, igraph_matrix_t *matrix, igraph_bool_t column_wise,
|
||||
const igraph_vector_t *weights
|
||||
);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_get_stochastic_sparse(
|
||||
const igraph_t *graph, igraph_sparsemat_t *res, igraph_bool_t column_wise,
|
||||
const igraph_vector_t *weights
|
||||
);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_get_edgelist(const igraph_t *graph, igraph_vector_int_t *res, igraph_bool_t bycol);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_to_directed(igraph_t *graph,
|
||||
igraph_to_directed_t flags);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_to_undirected(igraph_t *graph,
|
||||
igraph_to_undirected_t mode,
|
||||
const igraph_attribute_combination_t *edge_comb);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_to_prufer(const igraph_t *graph, igraph_vector_int_t *prufer);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2022-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_CYCLES_H
|
||||
#define IGRAPH_CYCLES_H
|
||||
|
||||
#include "igraph_constants.h"
|
||||
#include "igraph_datatype.h"
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_types.h"
|
||||
#include "igraph_vector_list.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* Directed acyclic graphs */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_topological_sorting(
|
||||
const igraph_t *graph, igraph_vector_int_t *res, igraph_neimode_t mode);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_is_dag(const igraph_t *graph, igraph_bool_t *res);
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* Cycle bases */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
IGRAPH_EXPERIMENTAL IGRAPH_EXPORT igraph_error_t igraph_fundamental_cycles(
|
||||
const igraph_t *graph, const igraph_vector_t *weights,
|
||||
igraph_vector_int_list_t *result,
|
||||
igraph_int_t start_vid, igraph_real_t bfs_cutoff);
|
||||
|
||||
IGRAPH_EXPERIMENTAL IGRAPH_EXPORT igraph_error_t igraph_minimum_cycle_basis(
|
||||
const igraph_t *graph, const igraph_vector_t *weights,
|
||||
igraph_vector_int_list_t *result,
|
||||
igraph_real_t bfs_cutoff,
|
||||
igraph_bool_t complete, igraph_bool_t use_cycle_order);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_find_cycle(
|
||||
const igraph_t *graph,
|
||||
igraph_vector_int_t *vertices,
|
||||
igraph_vector_int_t *edges,
|
||||
igraph_neimode_t mode);
|
||||
|
||||
/**
|
||||
* \typedef igraph_cycle_handler_t
|
||||
* \brief Type of cycle handler functions.
|
||||
*
|
||||
* Callback type, called by \ref igraph_simple_cycles_callback() when
|
||||
* a cycle is found.
|
||||
*
|
||||
* \param vertices The vertices of the current cycle. Must not be modified.
|
||||
* \param edges The edges of the current cycle. Must not be modified.
|
||||
* \param arg The extra parameter passed to \ref igraph_simple_cycles_callback()
|
||||
* \return Error code; \c IGRAPH_SUCCESS to continue the search or
|
||||
* \c IGRAPH_STOP to stop the search without signaling an error.
|
||||
*/
|
||||
typedef igraph_error_t igraph_cycle_handler_t(
|
||||
const igraph_vector_int_t *vertices,
|
||||
const igraph_vector_int_t *edges,
|
||||
void *arg);
|
||||
|
||||
IGRAPH_EXPERIMENTAL IGRAPH_EXPORT igraph_error_t igraph_simple_cycles_callback(
|
||||
const igraph_t *graph,
|
||||
igraph_neimode_t mode,
|
||||
igraph_int_t min_cycle_length,
|
||||
igraph_int_t max_cycle_length,
|
||||
igraph_cycle_handler_t *callback, void *arg);
|
||||
|
||||
IGRAPH_EXPERIMENTAL IGRAPH_EXPORT igraph_error_t igraph_simple_cycles(
|
||||
const igraph_t *graph,
|
||||
igraph_vector_int_list_t *vertices, igraph_vector_int_list_t *edges,
|
||||
igraph_neimode_t mode,
|
||||
igraph_int_t min_cycle_length, igraph_int_t max_cycle_length,
|
||||
igraph_int_t max_results);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_feedback_arc_set(
|
||||
const igraph_t *graph, igraph_vector_int_t *result,
|
||||
const igraph_vector_t *weights, igraph_fas_algorithm_t algo);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_feedback_vertex_set(
|
||||
const igraph_t *graph, igraph_vector_int_t *result,
|
||||
const igraph_vector_t *vertex_weights, igraph_fvs_algorithm_t algo);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2009-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_DATATYPE_H
|
||||
#define IGRAPH_DATATYPE_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_types.h"
|
||||
#include "igraph_vector.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
struct igraph_i_property_cache_t;
|
||||
typedef struct igraph_i_property_cache_t igraph_i_property_cache_t;
|
||||
|
||||
typedef enum {
|
||||
/* Stores whether the graph has at least one self-loop. */
|
||||
IGRAPH_PROP_HAS_LOOP = 0,
|
||||
|
||||
/* Stores whether the graph has at least one multi-edge, taking into account
|
||||
* edge directions in directed graphs. In other words, this property should
|
||||
* be false for a directed graph with edges (a, b) and (b, a), and true
|
||||
* for a directed graph with edges (a, b) and (a, b) again. */
|
||||
IGRAPH_PROP_HAS_MULTI,
|
||||
|
||||
/* Stores whether the graph has at least one reciprocal edge pair. Ignored
|
||||
* in undirected graphs. This property should be true for a directed graph
|
||||
* with edges (a, b) and (b, a), and false for a directed graph with
|
||||
* edges (a, b) and (a, b) again. Self-loops (a, a) are not considered
|
||||
* reciprocal. */
|
||||
IGRAPH_PROP_HAS_MUTUAL,
|
||||
|
||||
/* Stores whether the graph is weakly connected. */
|
||||
IGRAPH_PROP_IS_WEAKLY_CONNECTED,
|
||||
|
||||
/* Stores whether the graph is strongly connected. Ignored in undirected graphs. */
|
||||
IGRAPH_PROP_IS_STRONGLY_CONNECTED,
|
||||
|
||||
/* Stores whether the graph is a directed acyclic graph. Not used for
|
||||
* undirected graphs. */
|
||||
IGRAPH_PROP_IS_DAG,
|
||||
|
||||
/* Stores whether the graph is a forest, i.e. an undirected or directed
|
||||
* graph that is cycle-free even if we ignore edge directions. */
|
||||
IGRAPH_PROP_IS_FOREST,
|
||||
|
||||
/* Dummy value used to count enum values */
|
||||
IGRAPH_PROP_I_SIZE
|
||||
} igraph_cached_property_t;
|
||||
|
||||
/**
|
||||
* \ingroup internal
|
||||
* \struct igraph_t
|
||||
* \brief The internal data structure for storing graphs.
|
||||
*
|
||||
* It is simple and efficient. It has the following members:
|
||||
* - <b>n</b> The number of vertices, redundant.
|
||||
* - <b>directed</b> Whether the graph is directed.
|
||||
* - <b>from</b> The first column of the edge list.
|
||||
* - <b>to</b> The second column of the edge list.
|
||||
* - <b>oi</b> The index of the edge list by the first column. Thus
|
||||
* the first edge according to this order goes from
|
||||
* \c from[oi[0]] to \c to[oi[0]]. The length of
|
||||
* this vector is the same as the number of edges in the graph.
|
||||
* - <b>ii</b> The index of the edge list by the second column.
|
||||
* The length of this vector is the same as the number of edges.
|
||||
* - <b>os</b> Contains pointers to the edgelist (\c from
|
||||
* and \c to for every vertex. The first edge \em from
|
||||
* vertex \c v is edge no. \c from[oi[os[v]]] if
|
||||
* \c os[v]<os[v+1]. If \c os[v]==os[v+1] then
|
||||
* there are no edges \em from node \c v. Its length is
|
||||
* the number of vertices plus one, the last element is always the
|
||||
* same as the number of edges and is contained only to ease the
|
||||
* queries.
|
||||
* - <b>is</b> This is basically the same as <b>os</b>, but this time
|
||||
* for the incoming edges.
|
||||
*
|
||||
* For undirected graphs, the same edge list is stored, i.e. an
|
||||
* undirected edge is stored only once. Currently, undirected edges
|
||||
* are canonicalized so that the index of the 'from' vertex is not greater
|
||||
* than the index of the 'to' vertex. Thus, if v1 <= v2, only the edge (v1, v2)
|
||||
* needs to be searched for, not (v2, v1), to determine if v1 and v2 are connected.
|
||||
* However, this fact is NOT guaranteed by the documented public API,
|
||||
* and should not be relied upon by the implementation of any functions,
|
||||
* except those belonging to the minimal API in type_indexededgelist.c.
|
||||
*
|
||||
* The storage requirements for a graph with \c |V| vertices
|
||||
* and \c |E| edges is \c O(|E|+|V|).
|
||||
*/
|
||||
typedef struct {
|
||||
igraph_int_t n;
|
||||
igraph_bool_t directed;
|
||||
igraph_vector_int_t from;
|
||||
igraph_vector_int_t to;
|
||||
igraph_vector_int_t oi;
|
||||
igraph_vector_int_t ii;
|
||||
igraph_vector_int_t os;
|
||||
igraph_vector_int_t is;
|
||||
void *attr;
|
||||
igraph_i_property_cache_t *cache;
|
||||
} igraph_t;
|
||||
|
||||
IGRAPH_EXPORT void igraph_invalidate_cache(const igraph_t* graph);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2016-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#undef IGRAPH_BEGIN_C_DECLS
|
||||
#undef IGRAPH_END_C_DECLS
|
||||
#ifdef __cplusplus
|
||||
#define IGRAPH_BEGIN_C_DECLS extern "C" {
|
||||
#define IGRAPH_END_C_DECLS }
|
||||
#else
|
||||
#define IGRAPH_BEGIN_C_DECLS /* empty */
|
||||
#define IGRAPH_END_C_DECLS /* empty */
|
||||
#endif
|
||||
|
||||
/* This is to eliminate gcc warnings about unused parameters */
|
||||
#define IGRAPH_UNUSED(x) (void)(x)
|
||||
|
||||
/* The pure function attribute of GCC-compatible compilers indicates
|
||||
* that the function does not have side-effects, i.e. it does not
|
||||
* modify global memory. This enables additional compiler optimizations
|
||||
* such as common subexpression elimination.
|
||||
*
|
||||
* The const attribute is similar but with much more stringent requirements.
|
||||
* The function must also not read global memory. Generally, const functions
|
||||
* should not take pointers, and must compute the return value solely based
|
||||
* on their input.
|
||||
*/
|
||||
#ifdef __GNUC__
|
||||
#define IGRAPH_FUNCATTR_PURE __attribute__((__pure__))
|
||||
#define IGRAPH_FUNCATTR_CONST __attribute__((__const__))
|
||||
#else
|
||||
#define IGRAPH_FUNCATTR_PURE
|
||||
#define IGRAPH_FUNCATTR_CONST
|
||||
#endif
|
||||
|
||||
/* IGRAPH_ASSUME() provides hints to the compiler about conditions
|
||||
* that are true yet the compiler cannot deduce. Use with great care.
|
||||
* Assuming a condition that is not actually true leads to undefined behaviour. */
|
||||
#if defined(__clang__)
|
||||
/* For Clang, see https://clang.llvm.org/docs/LanguageExtensions.html */
|
||||
# if __has_builtin(__builtin_assume)
|
||||
# define IGRAPH_ASSUME(expr) __builtin_assume(expr)
|
||||
# else
|
||||
# define IGRAPH_ASSUME(expr) /* empty */
|
||||
# endif
|
||||
#elif defined(__GNUC__) && !defined(__ICC)
|
||||
/* Introduced in GCC 4.5, https://gcc.gnu.org/gcc-4.5/changes.html */
|
||||
# define IGRAPH_ASSUME(expr) do { if (expr) {} else { __builtin_unreachable(); } } while (0)
|
||||
#elif defined(_MSC_VER) || defined(__ICC)
|
||||
# define IGRAPH_ASSUME(expr) __assume(expr)
|
||||
#else
|
||||
# define IGRAPH_ASSUME(expr) /* empty */
|
||||
#endif
|
||||
|
||||
/* IGRAPH_I_STRINGIFY(X) evaluates X and converts the result to a string. */
|
||||
#define IGRAPH_I_STRINGIFY_I(X) #X
|
||||
#define IGRAPH_I_STRINGIFY(X) IGRAPH_I_STRINGIFY_I(X)
|
||||
|
||||
/* Include the definition of macros controlling symbol visibility */
|
||||
#include "igraph_export.h"
|
||||
|
||||
/* Used instead of IGRAPH_EXPORT with functions that need to be tested,
|
||||
* but are not part of the public API. */
|
||||
#define IGRAPH_PRIVATE_EXPORT IGRAPH_EXPORT
|
||||
|
||||
/* Marks experimental functions. If IGRAPH_WARN_EXPERIMENTAL is defined to a
|
||||
* nonzero value, supported compilers will emit a warning when these functions
|
||||
* are used. */
|
||||
#if defined(__GNUC__) && IGRAPH_WARN_EXPERIMENTAL
|
||||
#define IGRAPH_EXPERIMENTAL __attribute__((__warning__("Experimental function.")))
|
||||
#else
|
||||
#define IGRAPH_EXPERIMENTAL /* empty */
|
||||
#endif
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2009-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_DQUEUE_H
|
||||
#define IGRAPH_DQUEUE_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_types.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* double ended queue, very useful */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
#define BASE_IGRAPH_REAL
|
||||
#include "igraph_pmt.h"
|
||||
#include "igraph_dqueue_pmt.h"
|
||||
#include "igraph_pmt_off.h"
|
||||
#undef BASE_IGRAPH_REAL
|
||||
|
||||
#define BASE_CHAR
|
||||
#include "igraph_pmt.h"
|
||||
#include "igraph_dqueue_pmt.h"
|
||||
#include "igraph_pmt_off.h"
|
||||
#undef BASE_CHAR
|
||||
|
||||
#define BASE_BOOL
|
||||
#include "igraph_pmt.h"
|
||||
#include "igraph_dqueue_pmt.h"
|
||||
#include "igraph_pmt_off.h"
|
||||
#undef BASE_BOOL
|
||||
|
||||
#define BASE_INT
|
||||
#include "igraph_pmt.h"
|
||||
#include "igraph_dqueue_pmt.h"
|
||||
#include "igraph_pmt_off.h"
|
||||
#undef BASE_INT
|
||||
|
||||
#define IGRAPH_DQUEUE_NULL { 0,0,0,0 }
|
||||
#define IGRAPH_DQUEUE_INIT_FINALLY(q, capacity) \
|
||||
do { IGRAPH_CHECK(igraph_dqueue_init(q, capacity)); \
|
||||
IGRAPH_FINALLY(igraph_dqueue_destroy, q); } while (0)
|
||||
#define IGRAPH_DQUEUE_INT_INIT_FINALLY(q, capacity) \
|
||||
do { IGRAPH_CHECK(igraph_dqueue_int_init(q, capacity)); \
|
||||
IGRAPH_FINALLY(igraph_dqueue_int_destroy, q); } while (0)
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2007-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Double ended queue data type.
|
||||
* \ingroup internal
|
||||
*/
|
||||
|
||||
typedef struct TYPE(igraph_dqueue) {
|
||||
BASE *begin;
|
||||
BASE *end;
|
||||
BASE *stor_begin;
|
||||
BASE *stor_end;
|
||||
} TYPE(igraph_dqueue);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_dqueue, init)(TYPE(igraph_dqueue)* q, igraph_int_t capacity);
|
||||
IGRAPH_EXPORT void FUNCTION(igraph_dqueue, destroy)(TYPE(igraph_dqueue)* q);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_bool_t FUNCTION(igraph_dqueue, empty)(const TYPE(igraph_dqueue)* q);
|
||||
IGRAPH_EXPORT void FUNCTION(igraph_dqueue, clear)(TYPE(igraph_dqueue)* q);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_bool_t FUNCTION(igraph_dqueue, full)(TYPE(igraph_dqueue)* q);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_int_t FUNCTION(igraph_dqueue, size)(const TYPE(igraph_dqueue)* q);
|
||||
IGRAPH_EXPORT BASE FUNCTION(igraph_dqueue, pop)(TYPE(igraph_dqueue)* q);
|
||||
IGRAPH_EXPORT BASE FUNCTION(igraph_dqueue, pop_back)(TYPE(igraph_dqueue)* q);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE BASE FUNCTION(igraph_dqueue, head)(const TYPE(igraph_dqueue)* q);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE BASE FUNCTION(igraph_dqueue, back)(const TYPE(igraph_dqueue)* q);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_dqueue, push)(TYPE(igraph_dqueue)* q, BASE elem);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_dqueue, print)(const TYPE(igraph_dqueue)* q);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_dqueue, fprint)(const TYPE(igraph_dqueue)* q, FILE *file);
|
||||
IGRAPH_EXPORT BASE FUNCTION(igraph_dqueue, get)(const TYPE(igraph_dqueue) *q, igraph_int_t idx);
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2010-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_EIGEN_H
|
||||
#define IGRAPH_EIGEN_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_datatype.h"
|
||||
#include "igraph_arpack.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_lapack.h"
|
||||
#include "igraph_sparsemat.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
typedef enum {
|
||||
IGRAPH_EIGEN_AUTO = 0,
|
||||
IGRAPH_EIGEN_LAPACK,
|
||||
IGRAPH_EIGEN_ARPACK,
|
||||
IGRAPH_EIGEN_COMP_AUTO,
|
||||
IGRAPH_EIGEN_COMP_LAPACK,
|
||||
IGRAPH_EIGEN_COMP_ARPACK
|
||||
} igraph_eigen_algorithm_t;
|
||||
|
||||
typedef enum {
|
||||
IGRAPH_EIGEN_LM = 0,
|
||||
IGRAPH_EIGEN_SM, /* 1 */
|
||||
IGRAPH_EIGEN_LA, /* 2 */
|
||||
IGRAPH_EIGEN_SA, /* 3 */
|
||||
IGRAPH_EIGEN_BE, /* 4 */
|
||||
IGRAPH_EIGEN_LR, /* 5 */
|
||||
IGRAPH_EIGEN_SR, /* 6 */
|
||||
IGRAPH_EIGEN_LI, /* 7 */
|
||||
IGRAPH_EIGEN_SI, /* 8 */
|
||||
IGRAPH_EIGEN_ALL, /* 9 */
|
||||
IGRAPH_EIGEN_INTERVAL, /* 10 */
|
||||
IGRAPH_EIGEN_SELECT /* 11 */
|
||||
} igraph_eigen_which_position_t;
|
||||
|
||||
typedef struct igraph_eigen_which_t {
|
||||
igraph_eigen_which_position_t pos;
|
||||
int howmany;
|
||||
int il, iu;
|
||||
igraph_real_t vl, vu;
|
||||
int vestimate;
|
||||
igraph_lapack_dgeevx_balance_t balance;
|
||||
} igraph_eigen_which_t;
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_eigen_matrix_symmetric(const igraph_matrix_t *A,
|
||||
const igraph_sparsemat_t *sA,
|
||||
igraph_arpack_function_t *fun, int n,
|
||||
void *extra,
|
||||
igraph_eigen_algorithm_t algorithm,
|
||||
const igraph_eigen_which_t *which,
|
||||
igraph_arpack_options_t *options,
|
||||
igraph_arpack_storage_t *storage,
|
||||
igraph_vector_t *values,
|
||||
igraph_matrix_t *vectors);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_eigen_matrix(const igraph_matrix_t *A,
|
||||
const igraph_sparsemat_t *sA,
|
||||
igraph_arpack_function_t *fun, int n,
|
||||
void *extra,
|
||||
igraph_eigen_algorithm_t algorithm,
|
||||
const igraph_eigen_which_t *which,
|
||||
igraph_arpack_options_t *options,
|
||||
igraph_arpack_storage_t *storage,
|
||||
igraph_vector_complex_t *values,
|
||||
igraph_matrix_complex_t *vectors);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_eigen_adjacency(const igraph_t *graph,
|
||||
igraph_eigen_algorithm_t algorithm,
|
||||
const igraph_eigen_which_t *which,
|
||||
igraph_arpack_options_t *options,
|
||||
igraph_arpack_storage_t *storage,
|
||||
igraph_vector_t *values,
|
||||
igraph_matrix_t *vectors,
|
||||
igraph_vector_complex_t *cmplxvalues,
|
||||
igraph_matrix_complex_t *cmplxvectors);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2013-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_EMBEDDING_H
|
||||
#define IGRAPH_EMBEDDING_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_datatype.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_arpack.h"
|
||||
#include "igraph_eigen.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_adjacency_spectral_embedding(const igraph_t *graph,
|
||||
igraph_int_t no,
|
||||
const igraph_vector_t *weights,
|
||||
igraph_eigen_which_position_t which,
|
||||
igraph_bool_t scaled,
|
||||
igraph_matrix_t *X,
|
||||
igraph_matrix_t *Y,
|
||||
igraph_vector_t *D,
|
||||
const igraph_vector_t *cvec,
|
||||
igraph_arpack_options_t *options);
|
||||
|
||||
typedef enum {
|
||||
IGRAPH_EMBEDDING_D_A = 0,
|
||||
IGRAPH_EMBEDDING_I_DAD,
|
||||
IGRAPH_EMBEDDING_DAD,
|
||||
IGRAPH_EMBEDDING_OAP
|
||||
} igraph_laplacian_spectral_embedding_type_t;
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_laplacian_spectral_embedding(const igraph_t *graph,
|
||||
igraph_int_t no,
|
||||
const igraph_vector_t *weights,
|
||||
igraph_eigen_which_position_t which,
|
||||
igraph_laplacian_spectral_embedding_type_t type,
|
||||
igraph_bool_t scaled,
|
||||
igraph_matrix_t *X,
|
||||
igraph_matrix_t *Y,
|
||||
igraph_vector_t *D,
|
||||
igraph_arpack_options_t *options);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_dim_select(const igraph_vector_t *sv, igraph_int_t *dim);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2014-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_EPIDEMICS_H
|
||||
#define IGRAPH_EPIDEMICS_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_datatype.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_vector.h"
|
||||
#include "igraph_vector_ptr.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
/**
|
||||
* \struct igraph_sir_t
|
||||
* \brief The result of one SIR model simulation.
|
||||
*
|
||||
* Data structure to store the results of one simulation
|
||||
* of the SIR (susceptible-infected-recovered) model on a graph.
|
||||
*
|
||||
* It has the following members. They are all (real or integer)
|
||||
* vectors, and they are of the same length.
|
||||
*
|
||||
* \member times A vector, the times of the events are stored here.
|
||||
* \member no_s An integer vector, the number of susceptibles in
|
||||
* each time step is stored here.
|
||||
* \member no_i An integer vector, the number of infected individuals
|
||||
* at each time step, is stored here.
|
||||
* \member no_r An integer vector, the number of recovered individuals
|
||||
* is stored here at each time step.
|
||||
*/
|
||||
|
||||
typedef struct igraph_sir_t {
|
||||
igraph_vector_t times;
|
||||
igraph_vector_int_t no_s, no_i, no_r;
|
||||
} igraph_sir_t;
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sir_init(igraph_sir_t *sir);
|
||||
IGRAPH_EXPORT void igraph_sir_destroy(igraph_sir_t *sir);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sir(const igraph_t *graph, igraph_real_t beta,
|
||||
igraph_real_t gamma, igraph_int_t no_sim,
|
||||
igraph_vector_ptr_t *result);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,932 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2003-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_ERROR_H
|
||||
#define IGRAPH_ERROR_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_config.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
/* This file contains the igraph error handling.
|
||||
* Most bits are taken literally from the GSL library (with the GSL_
|
||||
* prefix renamed to IGRAPH_), as I couldn't find a better way to do
|
||||
* them. */
|
||||
|
||||
/* With some compilers, we use function attributes to help diagnostics
|
||||
* and optimizations. These are not part of the public API, do not use
|
||||
* them outside of igraph itself.
|
||||
*
|
||||
* IGRAPH_FUNCATTR_NORETURN indicates to the compiler that a function does not return.
|
||||
* There are standard facilities for this, namely _Noreturn in C11 and [[noreturn]] in C++11.
|
||||
* However, since igraph is currently compiled with older standards, and since
|
||||
* the standard 'noreturn' specification would need to be diferent between C and C++,
|
||||
* we do not use these facilities.
|
||||
*
|
||||
* IGRAPH_FUNCATTR_PRINTFLIKE(string, first) marks a function as having a printf-like syntax,
|
||||
* allowing the compiler to check that the format specifiers match argument types.
|
||||
* 'string' is the index of the string-argument and 'first' is the index of the
|
||||
* first argument to check against format specifiers.
|
||||
*/
|
||||
#if defined(__GNUC__)
|
||||
/* Compilers that support the GNU C syntax. Use __noreturn__ instead of 'noreturn' as the latter is a macro in C11. */
|
||||
#define IGRAPH_FUNCATTR_NORETURN __attribute__((__noreturn__))
|
||||
#define IGRAPH_FUNCATTR_PRINTFLIKE(string, first) __attribute__((__format__(printf, string, first)))
|
||||
#elif defined(_MSC_VER)
|
||||
/* Compilers that support the MSVC syntax. */
|
||||
#define IGRAPH_FUNCATTR_NORETURN __declspec(noreturn)
|
||||
#define IGRAPH_FUNCATTR_PRINTFLIKE(string, first)
|
||||
#else
|
||||
#define IGRAPH_FUNCATTR_NORETURN
|
||||
#define IGRAPH_FUNCATTR_PRINTFLIKE(string, first)
|
||||
#endif
|
||||
|
||||
/* IGRAPH_PREPROCESSOR_WARNING(reason) is a macro that evaluates to nothing
|
||||
* but triggers a preprocessor warning with the given message, if the compiler
|
||||
* supports this functionality.
|
||||
*/
|
||||
#if defined(__GNUC__)
|
||||
#define IGRAPH_PREPROCESSOR_WARNING(reason) _Pragma(IGRAPH_I_STRINGIFY(GCC warning reason))
|
||||
#else
|
||||
#define IGRAPH_PREPROCESSOR_WARNING(reason) /* empty */
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \section error_handling_basics Error handling basics
|
||||
*
|
||||
* <para>\a igraph functions can run into various problems preventing them
|
||||
* from normal operation. The user might have supplied invalid arguments,
|
||||
* e.g. a non-square matrix when a square-matrix was expected, or the program
|
||||
* has run out of memory while some more memory allocation is required, etc.
|
||||
* </para>
|
||||
*
|
||||
* <para>By default \a igraph aborts the program when it runs into an
|
||||
* error. While this behavior might be good enough for smaller programs,
|
||||
* it is without doubt avoidable in larger projects. Please read further
|
||||
* if your project requires more sophisticated error handling. You can
|
||||
* safely skip the rest of this chapter otherwise.
|
||||
* </para>
|
||||
*/
|
||||
|
||||
/**
|
||||
* \section error_handlers Error handlers
|
||||
*
|
||||
* <para>
|
||||
* If \a igraph runs into an error - an invalid argument was supplied
|
||||
* to a function, or we've ran out of memory - the control is
|
||||
* transferred to the \emb error handler \eme function.
|
||||
* </para><para>
|
||||
* The default error handler is \ref igraph_error_handler_abort which
|
||||
* prints an error message and aborts the program.
|
||||
* </para>
|
||||
* <para>
|
||||
* The \ref igraph_set_error_handler() function can be used to set a new
|
||||
* error handler function of type \ref igraph_error_handler_t; see the
|
||||
* documentation of this type for details.
|
||||
* </para>
|
||||
* <para>
|
||||
* There are two other predefined error handler functions,
|
||||
* \ref igraph_error_handler_ignore and \ref igraph_error_handler_printignore.
|
||||
* These deallocate the temporarily allocated memory (more about this
|
||||
* later) and return with the error code. The latter also prints an
|
||||
* error message. If you use these error handlers you need to take
|
||||
* care about possible errors yourself by checking the return value of
|
||||
* (almost) every non-void \a igraph function.
|
||||
* </para><para>
|
||||
* Independently of the error handler installed, all functions in the
|
||||
* library do their best to leave their arguments
|
||||
* \em semantically unchanged if an error
|
||||
* happens. By semantically we mean that the implementation of an
|
||||
* object supplied as an argument might change, but its
|
||||
* \quote meaning \endquote in most cases does not. The rare occasions
|
||||
* when this rule is violated are documented in this manual.
|
||||
* </para>
|
||||
*/
|
||||
|
||||
/**
|
||||
* \section error_codes Error codes
|
||||
*
|
||||
* <para>Every \a igraph function which can fail return a
|
||||
* single integer error code. Some functions are very simple and
|
||||
* cannot run into any error, these may return other types, or
|
||||
* \type void as well. The error codes are defined by the
|
||||
* \ref igraph_error_type_t enumeration.
|
||||
* </para>
|
||||
*/
|
||||
|
||||
/**
|
||||
* \section writing_error_handlers Writing error handlers
|
||||
*
|
||||
* <para>
|
||||
* The contents of the rest of this chapter might be useful only
|
||||
* for those who want to create an interface to \a igraph from another
|
||||
* language, or use igraph from a GUI application. Most readers can
|
||||
* safely skip to the next chapter.
|
||||
* </para>
|
||||
*
|
||||
* <para>
|
||||
* You can write and install error handlers simply by defining a
|
||||
* function of type \ref igraph_error_handler_t and calling
|
||||
* \ref igraph_set_error_handler(). This feature is useful for interface
|
||||
* writers, as \a igraph will have the chance to
|
||||
* signal errors the appropriate way. For example, the R interface uses
|
||||
* R's native printing facilities to communicate errors, while the Python
|
||||
* interface converts them into Python exceptions.
|
||||
* </para>
|
||||
*
|
||||
* <para>
|
||||
* The two main tasks of the error handler are to report the error
|
||||
* (i.e. print the error message) and ensure proper resource cleanup.
|
||||
* This is ensured by calling \ref IGRAPH_FINALLY_FREE(), which deallocates
|
||||
* some of the temporary memory to avoid memory leaks. Note that this may
|
||||
* invalidate the error message buffer \p reason passed to the error handler.
|
||||
* Do not access it after having called \ref IGRAPH_FINALLY_FREE().
|
||||
* </para>
|
||||
*
|
||||
* <para>
|
||||
* As of \a igraph 0.10, temporary memory is dellocated in stages, through
|
||||
* multiple calls to the error handler (and indirectly to \ref IGRAPH_FINALLY_FREE()).
|
||||
* Therefore, error handlers that do not abort the program
|
||||
* immediately are expected to return. The error handler should not perform
|
||||
* a <code>longjmp</code>, as this may lead to some of the memory not
|
||||
* getting freed.
|
||||
* </para>
|
||||
*/
|
||||
|
||||
/**
|
||||
* \section error_handling_internals Error handling internals
|
||||
*
|
||||
* <para>
|
||||
* If an error happens, the functions in the library call the
|
||||
* \ref IGRAPH_ERROR() macro with a textual description of the error and an
|
||||
* \a igraph error code. This macro calls (through the \ref
|
||||
* igraph_error() function) the installed error handler. Another useful
|
||||
* macro is \ref IGRAPH_CHECK(). This checks the return value of its
|
||||
* argument, which is normally a function call, and calls \ref
|
||||
* IGRAPH_ERROR() if it is not \c IGRAPH_SUCCESS.
|
||||
* </para>
|
||||
*/
|
||||
|
||||
/**
|
||||
* \section deallocating_memory Deallocating memory
|
||||
*
|
||||
* <para>
|
||||
* If a function runs into an error (and the program is not aborted)
|
||||
* the error handler should deallocate all temporary memory. This is
|
||||
* done by storing the address and the destroy function of all temporary
|
||||
* objects in a stack. The \ref IGRAPH_FINALLY function declares an object as
|
||||
* temporary by placing its address in the stack. If an \a igraph function returns
|
||||
* with success it calls \ref IGRAPH_FINALLY_CLEAN() with the
|
||||
* number of objects to remove from the stack. If an error happens
|
||||
* however, the error handler should call \ref IGRAPH_FINALLY_FREE() to
|
||||
* deallocate each object added to the stack. This means that the
|
||||
* temporary objects allocated in the calling function (and etc.) will
|
||||
* be freed as well.
|
||||
* </para>
|
||||
*/
|
||||
|
||||
/**
|
||||
* \section writing_functions_error_handling Writing \a igraph functions with
|
||||
* proper error handling
|
||||
*
|
||||
* <para>
|
||||
* There are some simple rules to keep in order to have functions
|
||||
* behaving well in erroneous situations. First, check the arguments
|
||||
* of the functions and call \ref IGRAPH_ERROR() if they are invalid. Second,
|
||||
* call \ref IGRAPH_FINALLY on each dynamically allocated object and call
|
||||
* \ref IGRAPH_FINALLY_CLEAN() with the proper argument before returning. Third, use
|
||||
* \ref IGRAPH_CHECK on all \a igraph function calls which can generate errors.
|
||||
* </para>
|
||||
* <para>
|
||||
* The size of the stack used for this bookkeeping is fixed, and
|
||||
* small. If you want to allocate several objects, write a destroy
|
||||
* function which can deallocate all of these. See the
|
||||
* <filename>adjlist.c</filename> file in the
|
||||
* \a igraph source for an example.
|
||||
* </para>
|
||||
* <para>
|
||||
* For some functions these mechanisms are simply not flexible
|
||||
* enough. These functions should define their own error handlers and
|
||||
* restore the error handler before they return.
|
||||
* </para>
|
||||
*
|
||||
* \example examples/simple/igraph_contract_vertices.c
|
||||
*/
|
||||
|
||||
/**
|
||||
* \typedef igraph_error_type_t
|
||||
* \brief Error code type.
|
||||
* These are the possible values returned by \a igraph functions.
|
||||
* Note that these are interesting only if you defined an error handler
|
||||
* with \ref igraph_set_error_handler(). Otherwise the program is aborted
|
||||
* and the function causing the error never returns.
|
||||
*
|
||||
* \enumval IGRAPH_SUCCESS The function successfully completed its task.
|
||||
* \enumval IGRAPH_FAILURE Something went wrong. You'll almost never
|
||||
* meet this error as normally more specific error codes are used.
|
||||
* \enumval IGRAPH_ENOMEM There wasn't enough memory to allocate
|
||||
* on the heap.
|
||||
* \enumval IGRAPH_PARSEERROR A parse error was found in a file.
|
||||
* \enumval IGRAPH_EINVAL A parameter's value is invalid. E.g. negative
|
||||
* number was specified as the number of vertices.
|
||||
* \enumval IGRAPH_EXISTS A graph/vertex/edge attribute is already
|
||||
* installed with the given name.
|
||||
* \enumval IGRAPH_EINVVID Invalid vertex ID, negative or too big.
|
||||
* \enumval IGRAPH_EINVEID Invalid edge ID, negative or too big.
|
||||
* \enumval IGRAPH_EINVMODE Invalid mode parameter.
|
||||
* \enumval IGRAPH_EFILE A file operation failed. E.g. a file doesn't exist,
|
||||
* or the user has no rights to open it.
|
||||
* \enumval IGRAPH_UNIMPLEMENTED Attempted to call an unimplemented or
|
||||
* disabled (at compile-time) function.
|
||||
* \enumval IGRAPH_DIVERGED A numeric algorithm failed to converge.
|
||||
* \enumval IGRAPH_ARPACK An error happened inside a calculation implemented
|
||||
* in ARPACK. The calculation involved is most likely an eigenvector-related
|
||||
* calculation.
|
||||
* \enumval IGRAPH_ENEGCYCLE Negative cycle detected while calculating shortest paths.
|
||||
* \enumval IGRAPH_EINTERNAL Internal error, likely a bug in igraph.
|
||||
* \enumval IGRAPH_EATTRCOMBINE Unimplemented attribute combination
|
||||
* method for the given attribute type.
|
||||
* \enumval IGRAPH_EOVERFLOW Integer or double overflow.
|
||||
* \enumval IGRAPH_EUNDERFLOW Integer or double underflow.
|
||||
* \enumval IGRAPH_ERWSTUCK Random walk got stuck.
|
||||
* \enumval IGRAPH_ERANGE Maximum vertex or edge count exceeded.
|
||||
* \enumval IGRAPH_ENOSOL Input problem has no solution.
|
||||
*/
|
||||
|
||||
typedef enum {
|
||||
IGRAPH_SUCCESS = 0,
|
||||
IGRAPH_FAILURE = 1,
|
||||
IGRAPH_ENOMEM = 2,
|
||||
IGRAPH_PARSEERROR = 3,
|
||||
IGRAPH_EINVAL = 4,
|
||||
IGRAPH_EXISTS = 5,
|
||||
/* IGRAPH_EINVEVECTOR = 6, */ /* removed in 1.0 */
|
||||
IGRAPH_EINVVID = 7,
|
||||
IGRAPH_EINVEID = 8, /* used to be IGRAPH_NONSQUARE before 1.0 */
|
||||
IGRAPH_EINVMODE = 9,
|
||||
IGRAPH_EFILE = 10,
|
||||
IGRAPH_UNIMPLEMENTED = 12,
|
||||
IGRAPH_INTERRUPTED = 13,
|
||||
IGRAPH_DIVERGED = 14,
|
||||
IGRAPH_EARPACK = 15,
|
||||
/* ARPACK error codes from 15 to 36 were moved to igraph_arpack_error_t in 1.0 */
|
||||
IGRAPH_ENEGCYCLE = 37,
|
||||
IGRAPH_EINTERNAL = 38,
|
||||
/* ARPACK error codes from 39 to 41 were moved to igraph_arpack_error_t in 1.0 */
|
||||
/* IGRAPH_EDIVZERO = 42, */ /* removed in 1.0 */
|
||||
/* IGRAPH_GLP_EBOUND = 43, */ /* removed in 1.0 */
|
||||
/* IGRAPH_GLP_EROOT = 44, */ /* removed in 1.0 */
|
||||
/* IGRAPH_GLP_ENOPFS = 45, */ /* removed in 1.0 */
|
||||
/* IGRAPH_GLP_ENODFS = 46, */ /* removed in 1.0 */
|
||||
/* IGRAPH_GLP_EFAIL = 47, */ /* removed in 1.0 */
|
||||
/* IGRAPH_GLP_EMIPGAP = 48, */ /* removed in 1.0 */
|
||||
/* IGRAPH_GLP_ETMLIM = 49, */ /* removed in 1.0 */
|
||||
/* IGRAPH_GLP_ESTOP = 50, */ /* removed in 1.0 */
|
||||
/* IGRAPH_EATTRIBUTES = 51, */ /* removed in 1.0 */
|
||||
IGRAPH_EATTRCOMBINE = 52,
|
||||
/* IGRAPH_ELAPACK = 53, */ /* removed in 1.0 */
|
||||
/* IGRAPH_EDRL = 54, */ /* deprecated in 0.10.2, removed in 1.0 */
|
||||
IGRAPH_EOVERFLOW = 55,
|
||||
/* IGRAPH_EGLP = 56, */ /* removed in 1.0 */
|
||||
/* IGRAPH_CPUTIME = 57, */ /* removed in 1.0 */
|
||||
IGRAPH_EUNDERFLOW = 58,
|
||||
IGRAPH_ERWSTUCK = 59,
|
||||
IGRAPH_STOP = 60,
|
||||
IGRAPH_ERANGE = 61,
|
||||
IGRAPH_ENOSOL = 62
|
||||
} igraph_error_type_t;
|
||||
/* Each enum value above must have a corresponding error string in
|
||||
* igraph_i_error_strings[] in core/error.c
|
||||
*
|
||||
* Information on undocumented codes:
|
||||
* - IGRAPH_STOP signals a request to stop in functions like igraph_i_maximal_cliques_bk()
|
||||
*/
|
||||
|
||||
/**
|
||||
* \section error_handling_threads Error handling and threads
|
||||
*
|
||||
* <para>
|
||||
* It is likely that the \a igraph error handling
|
||||
* method is \em not thread-safe, mainly because of
|
||||
* the static global stack which is used to store the address of the
|
||||
* temporarily allocated objects. This issue might be addressed in a
|
||||
* later version of \a igraph.
|
||||
* </para>
|
||||
*/
|
||||
|
||||
/**
|
||||
* \typedef igraph_error_t
|
||||
* \brief Return type for functions returning an error code.
|
||||
*
|
||||
* This type is used as the return type of igraph functions that return an
|
||||
* error code. It is a type alias because \type igraph_error_t used to be
|
||||
* an \c int, and was used slightly differenly than \type igraph_error_type_t.
|
||||
*/
|
||||
typedef igraph_error_type_t igraph_error_t;
|
||||
|
||||
/**
|
||||
* \typedef igraph_error_handler_t
|
||||
* \brief The type of error handler functions.
|
||||
*
|
||||
* This is the type of the error handler functions.
|
||||
*
|
||||
* \param reason Textual description of the error.
|
||||
* \param file The source file in which the error is noticed.
|
||||
* \param line The number of the line in the source file which triggered
|
||||
* the error
|
||||
* \param igraph_errno The \a igraph error code.
|
||||
*/
|
||||
|
||||
typedef void igraph_error_handler_t(const char *reason, const char *file,
|
||||
int line, igraph_error_t igraph_errno);
|
||||
|
||||
/**
|
||||
* \var igraph_error_handler_abort
|
||||
* \brief Abort program in case of error.
|
||||
*
|
||||
* The default error handler, prints an error message and aborts the
|
||||
* program.
|
||||
*/
|
||||
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_NORETURN igraph_error_handler_t igraph_error_handler_abort;
|
||||
|
||||
/**
|
||||
* \var igraph_error_handler_ignore
|
||||
* \brief Ignore errors.
|
||||
*
|
||||
* This error handler frees the temporarily allocated memory and returns
|
||||
* with the error code.
|
||||
*/
|
||||
|
||||
IGRAPH_EXPORT igraph_error_handler_t igraph_error_handler_ignore;
|
||||
|
||||
/**
|
||||
* \var igraph_error_handler_printignore
|
||||
* \brief Print and ignore errors.
|
||||
*
|
||||
* Frees temporarily allocated memory, prints an error message to the
|
||||
* standard error and returns with the error code.
|
||||
*/
|
||||
|
||||
IGRAPH_EXPORT igraph_error_handler_t igraph_error_handler_printignore;
|
||||
|
||||
IGRAPH_EXPORT igraph_error_handler_t *igraph_set_error_handler(igraph_error_handler_t* new_handler);
|
||||
|
||||
|
||||
/* We use IGRAPH_FILE_BASENAME instead of __FILE__ to ensure that full
|
||||
* paths don't leak into the library code. IGRAPH_FILE_BASENAME is set up
|
||||
* by the build system when compiling the individual files. However, when
|
||||
* including igraph_error.h in user code, this macro is not defined so we
|
||||
* fall back to __FILE__ here
|
||||
*/
|
||||
#ifndef IGRAPH_FILE_BASENAME
|
||||
# define IGRAPH_FILE_BASENAME __FILE__
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \define IGRAPH_ERROR
|
||||
* \brief Triggers an error.
|
||||
*
|
||||
* \a igraph functions usually use this macro when they notice an error.
|
||||
* It calls
|
||||
* \ref igraph_error() with the proper parameters and if that returns
|
||||
* the macro returns the "calling" function as well, with the error
|
||||
* code. If for some (suspicious) reason you want to call the error
|
||||
* handler without returning from the current function, call
|
||||
* \ref igraph_error() directly.
|
||||
*
|
||||
* \param reason Textual description of the error. This should be
|
||||
* something more descriptive than the text associated with the error
|
||||
* code. E.g. if the error code is \c IGRAPH_EINVAL,
|
||||
* its associated text (see \ref igraph_strerror()) is "Invalid
|
||||
* value" and this string should explain which parameter was invalid
|
||||
* and maybe why.
|
||||
* \param igraph_errno The \a igraph error code.
|
||||
*/
|
||||
|
||||
#define IGRAPH_ERROR(reason, igraph_errno) \
|
||||
do { \
|
||||
igraph_error (reason, IGRAPH_FILE_BASENAME, __LINE__, igraph_errno) ; \
|
||||
return igraph_errno ; \
|
||||
} while (0)
|
||||
|
||||
#define IGRAPH_ERROR_NO_RETURN(reason, igraph_errno) \
|
||||
do { \
|
||||
igraph_error (reason, IGRAPH_FILE_BASENAME, __LINE__, igraph_errno) ; \
|
||||
} while (0)
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_error(const char *reason, const char *file,
|
||||
int line, igraph_error_t igraph_errno);
|
||||
|
||||
/**
|
||||
* \define IGRAPH_ERRORF
|
||||
* \brief Triggers an error, with printf-like syntax.
|
||||
*
|
||||
* \a igraph functions can use this macro when they notice an error and
|
||||
* want to pass on extra information to the user about what went wrong.
|
||||
* It calls \ref igraph_errorf() with the proper parameters and if that
|
||||
* returns the macro returns the "calling" function as well, with the
|
||||
* error code. If for some (suspicious) reason you want to call the
|
||||
* error handler without returning from the current function, call
|
||||
* \ref igraph_errorf() directly.
|
||||
*
|
||||
* \param reason Textual description of the error, a template string
|
||||
* with the same syntax as the standard printf C library function.
|
||||
* This should be something more descriptive than the text associated
|
||||
* with the error code. E.g. if the error code is \c IGRAPH_EINVAL,
|
||||
* its associated text (see \ref igraph_strerror()) is "Invalid
|
||||
* value" and this string should explain which parameter was invalid
|
||||
* and maybe what was expected and what was recieved.
|
||||
* \param igraph_errno The \a igraph error code.
|
||||
* \param ... The additional arguments to be substituted into the
|
||||
* template string.
|
||||
*/
|
||||
|
||||
#define IGRAPH_ERRORF(reason, igraph_errno, ...) \
|
||||
do { \
|
||||
igraph_errorf(reason, IGRAPH_FILE_BASENAME, __LINE__, \
|
||||
igraph_errno, __VA_ARGS__) ; \
|
||||
return igraph_errno; \
|
||||
} while (0)
|
||||
|
||||
|
||||
IGRAPH_FUNCATTR_PRINTFLIKE(1,5)
|
||||
IGRAPH_EXPORT igraph_error_t igraph_errorf(const char *reason, const char *file,
|
||||
int line, igraph_error_t igraph_errno,
|
||||
...);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_errorvf(const char *reason, const char *file,
|
||||
int line, igraph_error_t igraph_errno,
|
||||
va_list ap);
|
||||
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE const char *igraph_strerror(igraph_error_t igraph_errno);
|
||||
|
||||
#define IGRAPH_ERROR_SELECT_2(a,b) ((a) != IGRAPH_SUCCESS ? (a) : ((b) != IGRAPH_SUCCESS ? (b) : IGRAPH_SUCCESS))
|
||||
#define IGRAPH_ERROR_SELECT_3(a,b,c) ((a) != IGRAPH_SUCCESS ? (a) : IGRAPH_ERROR_SELECT_2(b,c))
|
||||
#define IGRAPH_ERROR_SELECT_4(a,b,c,d) ((a) != IGRAPH_SUCCESS ? (a) : IGRAPH_ERROR_SELECT_3(b,c,d))
|
||||
#define IGRAPH_ERROR_SELECT_5(a,b,c,d,e) ((a) != IGRAPH_SUCCESS ? (a) : IGRAPH_ERROR_SELECT_4(b,c,d,e))
|
||||
|
||||
/* Now comes the more convenient error handling macro arsenal.
|
||||
* Ideas taken from exception.{h,c} by Laurent Deniau see
|
||||
* http://cern.ch/Laurent.Deniau/html/oopc/oopc.html#Exceptions for more
|
||||
* information. We don't use the exception handling code though. */
|
||||
|
||||
struct igraph_i_protectedPtr {
|
||||
int level;
|
||||
void *ptr;
|
||||
void (*func)(void*);
|
||||
};
|
||||
|
||||
typedef void igraph_finally_func_t(void *);
|
||||
|
||||
IGRAPH_EXPORT void IGRAPH_FINALLY_REAL(igraph_finally_func_t *func, void *ptr);
|
||||
|
||||
/**
|
||||
* \function IGRAPH_FINALLY_CLEAN
|
||||
* \brief Signals clean deallocation of objects.
|
||||
*
|
||||
* Removes the specified number of objects from the stack of
|
||||
* temporarily allocated objects. It is typically called
|
||||
* immediately after manually destroying the objects:
|
||||
*
|
||||
* <programlisting>
|
||||
* igraph_vector_t vector;
|
||||
* igraph_vector_init(&vector, 10);
|
||||
* IGRAPH_FINALLY(igraph_vector_destroy, &vector);
|
||||
* // use vector
|
||||
* igraph_vector_destroy(&vector);
|
||||
* IGRAPH_FINALLY_CLEAN(1);
|
||||
* </programlisting>
|
||||
*
|
||||
* \param num The number of objects to remove from the bookkeeping
|
||||
* stack.
|
||||
*/
|
||||
|
||||
IGRAPH_EXPORT void IGRAPH_FINALLY_CLEAN(int num);
|
||||
|
||||
/**
|
||||
* \function IGRAPH_FINALLY_FREE
|
||||
* \brief Deallocates objects registered at the current level.
|
||||
*
|
||||
* Calls the destroy function for all objects in the current level
|
||||
* of the stack of temporarily allocated objects, i.e. up to the
|
||||
* nearest mark set by <code>IGRAPH_FINALLY_ENTER()</code>.
|
||||
* This function must only be called from an error handler.
|
||||
* It is \em not appropriate to use it
|
||||
* instead of destroying each unneeded object of a function, as it
|
||||
* destroys the temporary objects of the caller function (and so on)
|
||||
* as well.
|
||||
*/
|
||||
|
||||
IGRAPH_EXPORT void IGRAPH_FINALLY_FREE(void);
|
||||
|
||||
IGRAPH_EXPORT void IGRAPH_FINALLY_ENTER(void);
|
||||
IGRAPH_EXPORT void IGRAPH_FINALLY_EXIT(void);
|
||||
|
||||
/**
|
||||
* \function IGRAPH_FINALLY_STACK_SIZE
|
||||
* \brief The number of registered objects.
|
||||
*
|
||||
* Returns the number of objects in the stack of temporarily allocated
|
||||
* objects. This function is handy if you write an own igraph routine and
|
||||
* you want to make sure it handles errors properly. A properly written
|
||||
* igraph routine should not leave pointers to temporarily allocated objects
|
||||
* in the finally stack, because otherwise an \ref IGRAPH_FINALLY_FREE call
|
||||
* in another igraph function would result in freeing these objects as well
|
||||
* (and this is really hard to debug, since the error will be not in that
|
||||
* function that shows erroneous behaviour). Therefore, it is advised to
|
||||
* write your own test cases and examine \ref IGRAPH_FINALLY_STACK_SIZE
|
||||
* before and after your test cases - the numbers should be equal.
|
||||
*/
|
||||
IGRAPH_EXPORT int IGRAPH_FINALLY_STACK_SIZE(void);
|
||||
|
||||
/**
|
||||
* \define IGRAPH_FINALLY_STACK_EMPTY
|
||||
* \brief Returns true if there are no registered objects, false otherwise.
|
||||
*
|
||||
* This is just a shorthand notation for checking that
|
||||
* \ref IGRAPH_FINALLY_STACK_SIZE() is zero.
|
||||
*/
|
||||
#define IGRAPH_FINALLY_STACK_EMPTY (IGRAPH_FINALLY_STACK_SIZE() == 0)
|
||||
|
||||
/**
|
||||
* \define IGRAPH_FINALLY
|
||||
* \brief Registers an object for deallocation.
|
||||
*
|
||||
* This macro places the address of an object, together with the
|
||||
* address of its destructor on a stack. This stack is used if an
|
||||
* error happens to deallocate temporarily allocated objects to
|
||||
* prevent memory leaks. After manual deallocation, objects are removed
|
||||
* from the stack using \ref IGRAPH_FINALLY_CLEAN().
|
||||
*
|
||||
* </para><para>
|
||||
* The typical usage is just after an initialization:
|
||||
*
|
||||
* <programlisting>
|
||||
* IGRAPH_CHECK(igraph_vector_init(&vector, 0));
|
||||
* IGRAPH_FINALLY(igraph_vector_destroy, &vector);
|
||||
* </programlisting>
|
||||
*
|
||||
* The most commonly used data structures, such as \ref igraph_vector_t,
|
||||
* have associated convenience macros that initialize the object and register
|
||||
* it on this stack in one step. Thus the pattern above can be replaced with a
|
||||
* single line:
|
||||
*
|
||||
* <programlisting>
|
||||
* IGRAPH_VECTOR_INIT_FINALLY(&vector, 0);
|
||||
* </programlisting>
|
||||
*
|
||||
* \param func The function which is normally called to
|
||||
* destroy the object.
|
||||
* \param ptr Pointer to the object itself.
|
||||
*/
|
||||
|
||||
#define IGRAPH_FINALLY(func, ptr) \
|
||||
do { \
|
||||
/* the following branch makes the compiler check the compatibility of \
|
||||
* func and ptr to detect cases when we are accidentally invoking an \
|
||||
* incorrect destructor function with the pointer */ \
|
||||
if (0) { func(ptr); } \
|
||||
IGRAPH_FINALLY_REAL((igraph_finally_func_t*)(func), (ptr)); \
|
||||
} while (0)
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#define IGRAPH_UNLIKELY(a) __builtin_expect(!!(a), 0)
|
||||
#define IGRAPH_LIKELY(a) __builtin_expect(!!(a), 1)
|
||||
#else
|
||||
#define IGRAPH_UNLIKELY(a) a
|
||||
#define IGRAPH_LIKELY(a) a
|
||||
#endif
|
||||
|
||||
#if IGRAPH_VERIFY_FINALLY_STACK == 1
|
||||
#define IGRAPH_CHECK(a) \
|
||||
do { \
|
||||
int enter_stack_size = IGRAPH_FINALLY_STACK_SIZE(); \
|
||||
igraph_error_t igraph_i_ret=(a); \
|
||||
if (IGRAPH_UNLIKELY(igraph_i_ret != IGRAPH_SUCCESS)) {\
|
||||
IGRAPH_ERROR("", igraph_i_ret); \
|
||||
} \
|
||||
if (IGRAPH_UNLIKELY(enter_stack_size != IGRAPH_FINALLY_STACK_SIZE())) { \
|
||||
IGRAPH_FATAL("Non-matching number of IGRAPH_FINALLY and IGRAPH_FINALLY_CLEAN."); \
|
||||
} \
|
||||
} while (0)
|
||||
#else
|
||||
/**
|
||||
* \define IGRAPH_CHECK
|
||||
* \brief Checks the return value of a function call.
|
||||
*
|
||||
* \param expr An expression, usually a function call. It is guaranteed to
|
||||
* be evaluated only once.
|
||||
*
|
||||
* Executes the expression and checks its value. If this is not
|
||||
* \c IGRAPH_SUCCESS, it calls \ref IGRAPH_ERROR with
|
||||
* the value as the error code. Here is an example usage:
|
||||
* \verbatim IGRAPH_CHECK(vector_push_back(&v, 100)); \endverbatim
|
||||
*
|
||||
* </para><para>There is only one reason to use this macro when writing
|
||||
* \a igraph functions. If the user installs an error handler which
|
||||
* returns to the auxiliary calling code (like \ref
|
||||
* igraph_error_handler_ignore and \ref
|
||||
* igraph_error_handler_printignore), and the \a igraph function
|
||||
* signalling the error is called from another \a igraph function
|
||||
* then we need to make sure that the error is propagated back to
|
||||
* the auxiliary (i.e. non-igraph) calling function. This is achieved
|
||||
* by using <function>IGRAPH_CHECK</function> on every \a igraph
|
||||
* call which can return an error code.
|
||||
*/
|
||||
#define IGRAPH_CHECK(expr) \
|
||||
do { \
|
||||
igraph_error_t igraph_i_ret = (expr); \
|
||||
if (IGRAPH_UNLIKELY(igraph_i_ret != IGRAPH_SUCCESS)) {\
|
||||
IGRAPH_ERROR("", igraph_i_ret); \
|
||||
} \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \define IGRAPH_CHECK_CALLBACK
|
||||
* \brief Checks the return value of a callback.
|
||||
*
|
||||
* Identical to \ref IGRAPH_CHECK, but treats \c IGRAPH_STOP as a normal
|
||||
* (non-erroneous) return code. This macro is used in some igraph functions
|
||||
* that allow the user to hook into a long-running calculation with a callback
|
||||
* function. When the user-defined callback function returns \c IGRAPH_SUCCESS,
|
||||
* the calculation will proceed normally. Returning \c IGRAPH_STOP from the
|
||||
* callback will terminate the calculation without reporting an error. Returning
|
||||
* any other value from the callback is treated as an error code, and igraph
|
||||
* will trigger the necessary cleanup functions before exiting the function.
|
||||
*
|
||||
* </para><para>
|
||||
* Note that \c IGRAPH_CHECK_CALLBACK does not handle \c IGRAPH_STOP by any
|
||||
* means except returning it in the variable pointed to by \c code. It is the
|
||||
* responsibility of the caller to handle \c IGRAPH_STOP accordingly.
|
||||
*
|
||||
* \param expr An expression, usually a call to a user-defined callback function.
|
||||
* It is guaranteed to be evaluated only once.
|
||||
* \param code Pointer to an optional variable of type <type>igraph_error_t</type>;
|
||||
* the value of this variable will be set to the error code if it is not a null
|
||||
* pointer.
|
||||
*/
|
||||
#define IGRAPH_CHECK_CALLBACK(expr, code) \
|
||||
do { \
|
||||
igraph_error_t igraph_i_ret = (expr); \
|
||||
*(code) = igraph_i_ret; \
|
||||
if (IGRAPH_UNLIKELY(igraph_i_ret != IGRAPH_SUCCESS && igraph_i_ret != IGRAPH_STOP)) { \
|
||||
IGRAPH_ERROR("", igraph_i_ret); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/**
|
||||
* \define IGRAPH_CHECK_OOM
|
||||
* \brief Checks for out-of-memory conditions after a memory allocation.
|
||||
*
|
||||
* This function should be called on pointers after memory allocations. The
|
||||
* function checks whether the returned pointer is NULL, and if so, sets an
|
||||
* error message with the \c IGRAPH_ENOMEM error code.
|
||||
*
|
||||
* \param ptr The pointer to check.
|
||||
* \param message The error message to use when the pointer is \c NULL.
|
||||
*/
|
||||
#define IGRAPH_CHECK_OOM(ptr, message) \
|
||||
do { \
|
||||
if (IGRAPH_UNLIKELY(!ptr)) { \
|
||||
IGRAPH_ERROR(message, IGRAPH_ENOMEM); /* LCOV_EXCL_LINE */ \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/**
|
||||
* \section about_igraph_warnings Warning messages
|
||||
*
|
||||
* <para>
|
||||
* \a igraph also supports warning messages in addition to error
|
||||
* messages. Warning messages typically do not terminate the
|
||||
* program, but they are usually crucial to the user.
|
||||
* </para>
|
||||
*
|
||||
* <para>
|
||||
* \a igraph warnings are handled similarly to errors. There is a
|
||||
* separate warning handler function that is called whenever
|
||||
* an \a igraph function triggers a warning. This handler can be
|
||||
* set by the \ref igraph_set_warning_handler() function. There are
|
||||
* two predefined simple warning handlers,
|
||||
* \ref igraph_warning_handler_ignore() and
|
||||
* \ref igraph_warning_handler_print(), the latter being the default.
|
||||
* </para>
|
||||
*
|
||||
* <para>
|
||||
* To trigger a warning, \a igraph functions typically use the
|
||||
* \ref IGRAPH_WARNING() macro, the \ref igraph_warning() function,
|
||||
* or if more flexibility is needed, \ref igraph_warningf().
|
||||
* </para>
|
||||
*/
|
||||
|
||||
/**
|
||||
* \typedef igraph_warning_handler_t
|
||||
* \brief The type of igraph warning handler functions.
|
||||
*
|
||||
* Currently it is defined to have the same type as
|
||||
* \ref igraph_error_handler_t, although the last (error code)
|
||||
* argument is not used.
|
||||
*/
|
||||
|
||||
typedef void igraph_warning_handler_t(const char *reason,
|
||||
const char *file, int line);
|
||||
|
||||
|
||||
IGRAPH_EXPORT igraph_warning_handler_t *igraph_set_warning_handler(igraph_warning_handler_t* new_handler);
|
||||
|
||||
IGRAPH_EXPORT extern igraph_warning_handler_t igraph_warning_handler_ignore;
|
||||
IGRAPH_EXPORT extern igraph_warning_handler_t igraph_warning_handler_print;
|
||||
|
||||
IGRAPH_EXPORT void igraph_warning(const char *reason,
|
||||
const char *file, int line);
|
||||
|
||||
/**
|
||||
* \define IGRAPH_WARNINGF
|
||||
* \brief Triggers a warning, with printf-like syntax.
|
||||
*
|
||||
* \a igraph functions can use this macro when they notice a warning and
|
||||
* want to pass on extra information to the user about what went wrong.
|
||||
* It calls \ref igraph_warningf() with the proper parameters and no
|
||||
* error code.
|
||||
* \param reason Textual description of the warning, a template string
|
||||
* with the same syntax as the standard printf C library function.
|
||||
* \param ... The additional arguments to be substituted into the
|
||||
* template string.
|
||||
*/
|
||||
|
||||
#define IGRAPH_WARNINGF(reason, ...) \
|
||||
do { \
|
||||
igraph_warningf(reason, IGRAPH_FILE_BASENAME, __LINE__, \
|
||||
__VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
|
||||
IGRAPH_FUNCATTR_PRINTFLIKE(1,4)
|
||||
IGRAPH_EXPORT void igraph_warningf(const char *reason,
|
||||
const char *file, int line, ...);
|
||||
|
||||
/**
|
||||
* \define IGRAPH_WARNING
|
||||
* \brief Triggers a warning.
|
||||
*
|
||||
* This is the usual way of triggering a warning from an igraph
|
||||
* function. It calls \ref igraph_warning().
|
||||
* \param reason The warning message.
|
||||
*/
|
||||
|
||||
#define IGRAPH_WARNING(reason) \
|
||||
do { \
|
||||
igraph_warning(reason, IGRAPH_FILE_BASENAME, __LINE__); \
|
||||
} while (0)
|
||||
|
||||
|
||||
/**
|
||||
* \section fatal_error_handlers Fatal errors
|
||||
*
|
||||
* <para>
|
||||
* In some rare situations, \a igraph may encounter an internal error
|
||||
* that cannot be fully handled. In this case, it will call the
|
||||
* current fatal error handler. The default fatal error handler
|
||||
* simply prints the error and aborts the program.
|
||||
* </para>
|
||||
*
|
||||
* <para>
|
||||
* Fatal error handlers do not return. Typically, they might abort the
|
||||
* the program immediately, or in the case of the high-level \a igraph
|
||||
* interfaces, they might return to the top level using a
|
||||
* <code>longjmp()</code>. The fatal error handler is only called when
|
||||
* a serious error has occurred, and as a result igraph may be in an
|
||||
* inconsistent state. The purpose of returning to the top level is to
|
||||
* give the user a chance to save their work instead of aborting immediately.
|
||||
* However, the program session should be restarted as soon as possible.
|
||||
* </para>
|
||||
*
|
||||
* <para>
|
||||
* Most projects that use \a igraph will use the default fatal error
|
||||
* handler.
|
||||
* </para>
|
||||
*/
|
||||
|
||||
/**
|
||||
* \typedef igraph_fatal_handler_t
|
||||
* \brief The type of igraph fatal error handler functions.
|
||||
*
|
||||
* Functions of this type \em must not return. Typically they
|
||||
* call <code>abort()</code> or do a <code>longjmp()</code>.
|
||||
*
|
||||
* \param reason Textual description of the error.
|
||||
* \param file The source file in which the error is noticed.
|
||||
* \param line The number of the line in the source file which triggered the error.
|
||||
*/
|
||||
|
||||
typedef void igraph_fatal_handler_t(const char *reason, const char *file, int line);
|
||||
|
||||
IGRAPH_EXPORT igraph_fatal_handler_t *igraph_set_fatal_handler(igraph_fatal_handler_t *new_handler);
|
||||
|
||||
/**
|
||||
* \var igraph_fatal_handler_abort
|
||||
* \brief Abort program in case of fatal error.
|
||||
*
|
||||
* The default fatal error handler, prints an error message and aborts the program.
|
||||
*/
|
||||
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_NORETURN igraph_fatal_handler_t igraph_fatal_handler_abort;
|
||||
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_NORETURN void igraph_fatal(const char *reason,
|
||||
const char *file, int line);
|
||||
IGRAPH_FUNCATTR_PRINTFLIKE(1,4)
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_NORETURN void igraph_fatalf(const char *reason,
|
||||
const char *file, int line, ...);
|
||||
|
||||
/**
|
||||
* \define IGRAPH_FATALF
|
||||
* \brief Triggers a fatal error, with printf-like syntax.
|
||||
*
|
||||
* \a igraph functions can use this macro when a fatal error occurs and
|
||||
* want to pass on extra information to the user about what went wrong.
|
||||
* It calls \ref igraph_fatalf() with the proper parameters.
|
||||
*
|
||||
* \param reason Textual description of the error, a template string
|
||||
* with the same syntax as the standard printf C library function.
|
||||
* \param ... The additional arguments to be substituted into the
|
||||
* template string.
|
||||
*/
|
||||
|
||||
#define IGRAPH_FATALF(reason, ...) \
|
||||
do { \
|
||||
igraph_fatalf(reason, IGRAPH_FILE_BASENAME, __LINE__, \
|
||||
__VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
/**
|
||||
* \define IGRAPH_FATAL
|
||||
* \brief Triggers a fatal error.
|
||||
*
|
||||
* This is the usual way of triggering a fatal error from an igraph
|
||||
* function. It calls \ref igraph_fatal().
|
||||
*
|
||||
* </para><para>
|
||||
* Use this macro only in situations where the error cannot be handled.
|
||||
* The normal way to handle errors is \ref IGRAPH_ERROR().
|
||||
*
|
||||
* \param reason The error message.
|
||||
*/
|
||||
|
||||
#define IGRAPH_FATAL(reason) \
|
||||
do { \
|
||||
igraph_fatal(reason, IGRAPH_FILE_BASENAME, __LINE__); \
|
||||
} while (0)
|
||||
|
||||
/**
|
||||
* \define IGRAPH_ASSERT
|
||||
* \brief igraph-specific replacement for <code>assert()</code>.
|
||||
*
|
||||
* This macro is like the standard <code>assert()</code>, but instead of
|
||||
* calling <code>abort()</code>, it calls \ref igraph_fatal(). This allows for returning
|
||||
* the control to the calling program, e.g. returning to the top level in a high-level
|
||||
* \a igraph interface.
|
||||
*
|
||||
* </para><para>
|
||||
* Unlike <code>assert()</code>, <code>IGRAPH_ASSERT()</code> is not disabled
|
||||
* when the \c NDEBUG macro is defined.
|
||||
*
|
||||
* </para><para>
|
||||
* This macro is meant for internal use by \a igraph.
|
||||
*
|
||||
* </para><para>
|
||||
* Since a typical fatal error handler does a <code>longjmp()</code>, avoid using this
|
||||
* macro in C++ code. With most compilers, destructor will not be called when
|
||||
* <code>longjmp()</code> leaves the current scope.
|
||||
*
|
||||
* \param condition The condition to be checked.
|
||||
*/
|
||||
|
||||
#define IGRAPH_ASSERT(condition) \
|
||||
do { \
|
||||
if (IGRAPH_UNLIKELY(!(condition))) { \
|
||||
igraph_fatal("Assertion failed: " #condition, IGRAPH_FILE_BASENAME, __LINE__); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2020-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_EULERIAN_H
|
||||
#define IGRAPH_EULERIAN_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_datatype.h"
|
||||
#include "igraph_error.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_is_eulerian(const igraph_t *graph, igraph_bool_t *has_path, igraph_bool_t *has_cycle);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_eulerian_path(const igraph_t *graph, igraph_vector_int_t *edge_res, igraph_vector_int_t *vertex_res);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_eulerian_cycle(const igraph_t *graph, igraph_vector_int_t *edge_res, igraph_vector_int_t *vertex_res);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2003-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_FLOW_H
|
||||
#define IGRAPH_FLOW_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_constants.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_types.h"
|
||||
#include "igraph_datatype.h"
|
||||
#include "igraph_vector_list.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* Maximum flows, minimum cuts & such */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* \typedef igraph_maxflow_stats_t
|
||||
* \brief Data structure holding statistics from the push-relabel maximum flow solver.
|
||||
*
|
||||
* \param nopush The number of push operations performed.
|
||||
* \param norelabel The number of relabel operarions performed.
|
||||
* \param nogap The number of times the gap heuristics was used.
|
||||
* \param nogapnodes The total number of vertices that were
|
||||
* omitted form further calculations because of the gap
|
||||
* heuristics.
|
||||
* \param nobfs The number of times the reverse BFS was run to
|
||||
* assign good values to the height function. This includes
|
||||
* an initial run before the whole algorithm, so it is always
|
||||
* at least one.
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
igraph_int_t nopush, norelabel, nogap, nogapnodes, nobfs;
|
||||
} igraph_maxflow_stats_t;
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_maxflow(const igraph_t *graph, igraph_real_t *value,
|
||||
igraph_vector_t *flow, igraph_vector_int_t *cut,
|
||||
igraph_vector_int_t *partition, igraph_vector_int_t *partition2,
|
||||
igraph_int_t source, igraph_int_t target,
|
||||
const igraph_vector_t *capacity,
|
||||
igraph_maxflow_stats_t *stats);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_maxflow_value(const igraph_t *graph, igraph_real_t *value,
|
||||
igraph_int_t source, igraph_int_t target,
|
||||
const igraph_vector_t *capacity,
|
||||
igraph_maxflow_stats_t *stats);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_st_mincut(const igraph_t *graph, igraph_real_t *value,
|
||||
igraph_vector_int_t *cut, igraph_vector_int_t *partition,
|
||||
igraph_vector_int_t *partition2,
|
||||
igraph_int_t source, igraph_int_t target,
|
||||
const igraph_vector_t *capacity);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_st_mincut_value(const igraph_t *graph, igraph_real_t *res,
|
||||
igraph_int_t source, igraph_int_t target,
|
||||
const igraph_vector_t *capacity);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_mincut_value(const igraph_t *graph, igraph_real_t *res,
|
||||
const igraph_vector_t *capacity);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_mincut(const igraph_t *graph,
|
||||
igraph_real_t *value,
|
||||
igraph_vector_int_t *partition,
|
||||
igraph_vector_int_t *partition2,
|
||||
igraph_vector_int_t *cut,
|
||||
const igraph_vector_t *capacity);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_st_vertex_connectivity(const igraph_t *graph,
|
||||
igraph_int_t *res,
|
||||
igraph_int_t source,
|
||||
igraph_int_t target,
|
||||
igraph_vconn_nei_t neighbors);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_vertex_connectivity(const igraph_t *graph, igraph_int_t *res,
|
||||
igraph_bool_t checks);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_st_edge_connectivity(const igraph_t *graph, igraph_int_t *res,
|
||||
igraph_int_t source,
|
||||
igraph_int_t target);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_edge_connectivity(const igraph_t *graph, igraph_int_t *res,
|
||||
igraph_bool_t checks);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_edge_disjoint_paths(const igraph_t *graph, igraph_int_t *res,
|
||||
igraph_int_t source,
|
||||
igraph_int_t target);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_vertex_disjoint_paths(const igraph_t *graph, igraph_int_t *res,
|
||||
igraph_int_t source,
|
||||
igraph_int_t target);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_adhesion(const igraph_t *graph, igraph_int_t *res,
|
||||
igraph_bool_t checks);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_cohesion(const igraph_t *graph, igraph_int_t *res,
|
||||
igraph_bool_t checks);
|
||||
|
||||
/* s-t cut listing related stuff */
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_even_tarjan_reduction(const igraph_t *graph, igraph_t *graphbar,
|
||||
igraph_vector_t *capacity);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_residual_graph(const igraph_t *graph,
|
||||
const igraph_vector_t *capacity,
|
||||
igraph_t *residual,
|
||||
igraph_vector_t *residual_capacity,
|
||||
const igraph_vector_t *flow);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_reverse_residual_graph(const igraph_t *graph,
|
||||
const igraph_vector_t *capacity,
|
||||
igraph_t *residual,
|
||||
const igraph_vector_t *flow);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_dominator_tree(const igraph_t *graph,
|
||||
igraph_int_t root,
|
||||
igraph_vector_int_t *dom,
|
||||
igraph_t *domtree,
|
||||
igraph_vector_int_t *leftout,
|
||||
igraph_neimode_t mode);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_all_st_cuts(const igraph_t *graph,
|
||||
igraph_vector_int_list_t *cuts,
|
||||
igraph_vector_int_list_t *partition1s,
|
||||
igraph_int_t source,
|
||||
igraph_int_t target);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_all_st_mincuts(const igraph_t *graph, igraph_real_t *value,
|
||||
igraph_vector_int_list_t *cuts,
|
||||
igraph_vector_int_list_t *partition1s,
|
||||
igraph_int_t source,
|
||||
igraph_int_t target,
|
||||
const igraph_vector_t *capacity);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_gomory_hu_tree(const igraph_t *graph,
|
||||
igraph_t *tree,
|
||||
igraph_vector_t *flows,
|
||||
const igraph_vector_t *capacity);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2009-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_FOREIGN_H
|
||||
#define IGRAPH_FOREIGN_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_constants.h"
|
||||
#include "igraph_datatype.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_types.h"
|
||||
#include "igraph_strvector.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* Read and write foreign formats */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_read_graph_edgelist(igraph_t *graph, FILE *instream,
|
||||
igraph_int_t n, igraph_bool_t directed);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_read_graph_ncol(igraph_t *graph, FILE *instream,
|
||||
const igraph_strvector_t *predefnames, igraph_bool_t names,
|
||||
igraph_add_weights_t weights, igraph_bool_t directed);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_read_graph_lgl(igraph_t *graph, FILE *instream,
|
||||
igraph_bool_t names, igraph_add_weights_t weights,
|
||||
igraph_bool_t directed);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_read_graph_pajek(igraph_t *graph, FILE *instream);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_read_graph_graphml(igraph_t *graph, FILE *instream,
|
||||
igraph_int_t index);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_read_graph_dimacs_flow(igraph_t *graph, FILE *instream,
|
||||
igraph_strvector_t *problem,
|
||||
igraph_vector_int_t *label,
|
||||
igraph_int_t *source,
|
||||
igraph_int_t *target,
|
||||
igraph_vector_t *capacity,
|
||||
igraph_bool_t directed);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_read_graph_graphdb(igraph_t *graph, FILE *instream,
|
||||
igraph_bool_t directed);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_read_graph_gml(igraph_t *graph, FILE *instream);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_read_graph_dl(igraph_t *graph, FILE *instream,
|
||||
igraph_bool_t directed);
|
||||
|
||||
typedef unsigned int igraph_write_gml_sw_t;
|
||||
|
||||
enum {
|
||||
IGRAPH_WRITE_GML_DEFAULT_SW = 0x0, /* default settings */
|
||||
IGRAPH_WRITE_GML_ENCODE_ONLY_QUOT_SW = 0x1 /* only encode " characters, nothing else */
|
||||
};
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_write_graph_edgelist(const igraph_t *graph, FILE *outstream);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_write_graph_ncol(const igraph_t *graph, FILE *outstream,
|
||||
const char *names, const char *weights);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_write_graph_lgl(const igraph_t *graph, FILE *outstream,
|
||||
const char *names, const char *weights,
|
||||
igraph_bool_t isolates);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_write_graph_graphml(const igraph_t *graph, FILE *outstream,
|
||||
igraph_bool_t prefixattr);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_write_graph_pajek(const igraph_t *graph, FILE *outstream);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_write_graph_dimacs_flow(const igraph_t *graph, FILE *outstream,
|
||||
igraph_int_t source, igraph_int_t target,
|
||||
const igraph_vector_t *capacity);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_write_graph_gml(const igraph_t *graph, FILE *outstream,
|
||||
igraph_write_gml_sw_t options,
|
||||
const igraph_vector_t *id, const char *creator);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_write_graph_dot(const igraph_t *graph, FILE *outstream);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_write_graph_leda(const igraph_t *graph, FILE *outstream,
|
||||
const char* vertex_attr_name, const char* edge_attr_name);
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* Convenience functions for temporary locale setting */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
typedef struct igraph_safelocale_s *igraph_safelocale_t;
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_enter_safelocale(igraph_safelocale_t *loc);
|
||||
IGRAPH_EXPORT void igraph_exit_safelocale(igraph_safelocale_t *loc);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,229 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2009-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_GAMES_H
|
||||
#define IGRAPH_GAMES_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_constants.h"
|
||||
#include "igraph_datatype.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_graphicality.h"
|
||||
#include "igraph_matrix.h"
|
||||
#include "igraph_matrix_list.h"
|
||||
#include "igraph_types.h"
|
||||
#include "igraph_vector.h"
|
||||
#include "igraph_vector_list.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* Constructors, games (=stochastic) */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_barabasi_game(igraph_t *graph, igraph_int_t n,
|
||||
igraph_real_t power,
|
||||
igraph_int_t m,
|
||||
const igraph_vector_int_t *outseq,
|
||||
igraph_bool_t outpref,
|
||||
igraph_real_t A,
|
||||
igraph_bool_t directed,
|
||||
igraph_barabasi_algorithm_t algo,
|
||||
const igraph_t *start_from);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_erdos_renyi_game_gnp(
|
||||
igraph_t *graph,
|
||||
igraph_int_t n, igraph_real_t p,
|
||||
igraph_bool_t directed,
|
||||
igraph_edge_type_sw_t allowed_edge_types,
|
||||
igraph_bool_t edge_labeled);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_erdos_renyi_game_gnm(
|
||||
igraph_t *graph,
|
||||
igraph_int_t n, igraph_int_t m,
|
||||
igraph_bool_t directed,
|
||||
igraph_edge_type_sw_t allowed_edge_types,
|
||||
igraph_bool_t edge_labeled);
|
||||
|
||||
IGRAPH_EXPERIMENTAL IGRAPH_EXPORT igraph_error_t igraph_iea_game(
|
||||
igraph_t *graph,
|
||||
igraph_int_t n, igraph_int_t m,
|
||||
igraph_bool_t directed, igraph_bool_t loops);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_degree_sequence_game(igraph_t *graph, const igraph_vector_int_t *out_deg,
|
||||
const igraph_vector_int_t *in_deg,
|
||||
igraph_degseq_t method);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_growing_random_game(igraph_t *graph, igraph_int_t n,
|
||||
igraph_int_t m, igraph_bool_t directed, igraph_bool_t citation);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_barabasi_aging_game(igraph_t *graph,
|
||||
igraph_int_t nodes,
|
||||
igraph_int_t m,
|
||||
const igraph_vector_int_t *outseq,
|
||||
igraph_bool_t outpref,
|
||||
igraph_real_t pa_exp,
|
||||
igraph_real_t aging_exp,
|
||||
igraph_int_t aging_bin,
|
||||
igraph_real_t zero_deg_appeal,
|
||||
igraph_real_t zero_age_appeal,
|
||||
igraph_real_t deg_coef,
|
||||
igraph_real_t age_coef,
|
||||
igraph_bool_t directed);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_recent_degree_game(igraph_t *graph, igraph_int_t n,
|
||||
igraph_real_t power,
|
||||
igraph_int_t window,
|
||||
igraph_int_t m,
|
||||
const igraph_vector_int_t *outseq,
|
||||
igraph_bool_t outpref,
|
||||
igraph_real_t zero_appeal,
|
||||
igraph_bool_t directed);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_recent_degree_aging_game(igraph_t *graph,
|
||||
igraph_int_t nodes,
|
||||
igraph_int_t m,
|
||||
const igraph_vector_int_t *outseq,
|
||||
igraph_bool_t outpref,
|
||||
igraph_real_t pa_exp,
|
||||
igraph_real_t aging_exp,
|
||||
igraph_int_t aging_bin,
|
||||
igraph_int_t window,
|
||||
igraph_real_t zero_appeal,
|
||||
igraph_bool_t directed);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_callaway_traits_game(igraph_t *graph, igraph_int_t nodes,
|
||||
igraph_int_t types, igraph_int_t edges_per_step,
|
||||
const igraph_vector_t *type_dist,
|
||||
const igraph_matrix_t *pref_matrix,
|
||||
igraph_bool_t directed,
|
||||
igraph_vector_int_t *node_type_vec);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_establishment_game(igraph_t *graph, igraph_int_t nodes,
|
||||
igraph_int_t types, igraph_int_t k,
|
||||
const igraph_vector_t *type_dist,
|
||||
const igraph_matrix_t *pref_matrix,
|
||||
igraph_bool_t directed,
|
||||
igraph_vector_int_t *node_type_vec);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_grg_game(igraph_t *graph, igraph_int_t nodes,
|
||||
igraph_real_t radius, igraph_bool_t torus,
|
||||
igraph_vector_t *x, igraph_vector_t *y);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_preference_game(igraph_t *graph, igraph_int_t nodes,
|
||||
igraph_int_t types,
|
||||
const igraph_vector_t *type_dist,
|
||||
igraph_bool_t fixed_sizes,
|
||||
const igraph_matrix_t *pref_matrix,
|
||||
igraph_vector_int_t *node_type_vec,
|
||||
igraph_bool_t directed, igraph_bool_t loops);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_asymmetric_preference_game(igraph_t *graph, igraph_int_t nodes,
|
||||
igraph_int_t out_types,
|
||||
igraph_int_t in_types,
|
||||
const igraph_matrix_t *type_dist_matrix,
|
||||
const igraph_matrix_t *pref_matrix,
|
||||
igraph_vector_int_t *node_type_out_vec,
|
||||
igraph_vector_int_t *node_type_in_vec,
|
||||
igraph_bool_t loops);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_rewire_edges(igraph_t *graph, igraph_real_t prob,
|
||||
igraph_edge_type_sw_t allowed_edge_types);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_rewire_directed_edges(igraph_t *graph, igraph_real_t prob,
|
||||
igraph_bool_t loops, igraph_neimode_t mode);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_watts_strogatz_game(igraph_t *graph, igraph_int_t dim,
|
||||
igraph_int_t size, igraph_int_t nei,
|
||||
igraph_real_t p,
|
||||
igraph_edge_type_sw_t allowed_edge_types);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_lastcit_game(igraph_t *graph,
|
||||
igraph_int_t nodes, igraph_int_t edges_per_node,
|
||||
igraph_int_t agebins,
|
||||
const igraph_vector_t *preference, igraph_bool_t directed);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_cited_type_game(igraph_t *graph, igraph_int_t nodes,
|
||||
const igraph_vector_int_t *types,
|
||||
const igraph_vector_t *pref,
|
||||
igraph_int_t edges_per_step,
|
||||
igraph_bool_t directed);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_citing_cited_type_game(igraph_t *graph, igraph_int_t nodes,
|
||||
const igraph_vector_int_t *types,
|
||||
const igraph_matrix_t *pref,
|
||||
igraph_int_t edges_per_step,
|
||||
igraph_bool_t directed);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_forest_fire_game(igraph_t *graph, igraph_int_t nodes,
|
||||
igraph_real_t fw_prob, igraph_real_t bw_factor,
|
||||
igraph_int_t ambs, igraph_bool_t directed);
|
||||
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_simple_interconnected_islands_game(
|
||||
igraph_t *graph,
|
||||
igraph_int_t islands_n,
|
||||
igraph_int_t islands_size,
|
||||
igraph_real_t islands_pin,
|
||||
igraph_int_t n_inter);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_static_fitness_game(igraph_t *graph, igraph_int_t no_of_edges,
|
||||
const igraph_vector_t *fitness_out, const igraph_vector_t *fitness_in,
|
||||
igraph_edge_type_sw_t allowed_edge_types);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_static_power_law_game(igraph_t *graph,
|
||||
igraph_int_t no_of_nodes, igraph_int_t no_of_edges,
|
||||
igraph_real_t exponent_out, igraph_real_t exponent_in,
|
||||
igraph_edge_type_sw_t allowed_edge_types,
|
||||
igraph_bool_t finite_size_correction);
|
||||
|
||||
IGRAPH_EXPERIMENTAL IGRAPH_EXPORT igraph_error_t igraph_chung_lu_game(igraph_t *graph,
|
||||
const igraph_vector_t *expected_out_deg,
|
||||
const igraph_vector_t *expected_in_deg,
|
||||
igraph_bool_t loops,
|
||||
igraph_chung_lu_t variant);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_k_regular_game(igraph_t *graph,
|
||||
igraph_int_t no_of_nodes, igraph_int_t k,
|
||||
igraph_bool_t directed, igraph_bool_t multiple);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sbm_game(
|
||||
igraph_t *graph,
|
||||
const igraph_matrix_t *pref_matrix,
|
||||
const igraph_vector_int_t *block_sizes,
|
||||
igraph_bool_t directed,
|
||||
igraph_edge_type_sw_t allowed_edge_types);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_hsbm_game(igraph_t *graph, igraph_int_t n,
|
||||
igraph_int_t m, const igraph_vector_t *rho,
|
||||
const igraph_matrix_t *C, igraph_real_t p);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_hsbm_list_game(igraph_t *graph, igraph_int_t n,
|
||||
const igraph_vector_int_t *mlist,
|
||||
const igraph_vector_list_t *rholist,
|
||||
const igraph_matrix_list_t *Clist,
|
||||
igraph_real_t p);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_correlated_game(igraph_t *new_graph, const igraph_t *old_graph,
|
||||
igraph_real_t corr, igraph_real_t p,
|
||||
const igraph_vector_int_t *permutation);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_correlated_pair_game(igraph_t *graph1, igraph_t *graph2,
|
||||
igraph_int_t n, igraph_real_t corr, igraph_real_t p,
|
||||
igraph_bool_t directed,
|
||||
const igraph_vector_int_t *permutation);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_tree_game(igraph_t *graph, igraph_int_t n, igraph_bool_t directed,
|
||||
igraph_random_tree_t method);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_dot_product_game(igraph_t *graph, const igraph_matrix_t *vecs,
|
||||
igraph_bool_t directed);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2022-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_GRAPH_LIST_H
|
||||
#define IGRAPH_GRAPH_LIST_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_datatype.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_types.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* List of graphs */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
#define GRAPH_LIST
|
||||
#define BASE_GRAPH
|
||||
#define EXTRA_TYPE_FIELDS igraph_bool_t directed;
|
||||
#include "igraph_pmt.h"
|
||||
#include "igraph_typed_list_pmt.h"
|
||||
#include "igraph_pmt_off.h"
|
||||
#undef EXTRA_TYPE_FIELDS
|
||||
#undef BASE_GRAPH
|
||||
#undef GRAPH_LIST
|
||||
|
||||
void igraph_graph_list_set_directed(igraph_graph_list_t* list, igraph_bool_t directed);
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* Helper macros */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
#define IGRAPH_GRAPH_LIST_INIT_FINALLY(v, size) \
|
||||
do { IGRAPH_CHECK(igraph_graph_list_init(v, size)); \
|
||||
IGRAPH_FINALLY(igraph_graph_list_destroy, v); } while (0)
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2020-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_GRAPHICALITY_H
|
||||
#define IGRAPH_GRAPHICALITY_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_vector.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
/**
|
||||
* \typedef igraph_edge_type_sw_t
|
||||
* \brief What types of non-simple edges to allow?
|
||||
*
|
||||
* This type is used with multiple functions to specify what types of non-simple
|
||||
* edges to allow, create or consider a graph. The constants below are treated
|
||||
* as "switches" that can be turned on individually and combined using the
|
||||
* bitwise-or operator. For example,
|
||||
* <code>IGRAPH_LOOPS_SW</code>
|
||||
* allows only self-loops but not multi-edges, while
|
||||
* <code>IGRAPH_LOOPS_SW | IGRAPH_MULTI_SW</code>
|
||||
* allows both.
|
||||
*
|
||||
* \enumval IGRAPH_SIMPLE_SW A shorthand for simple graphs only, which is the default
|
||||
* assumption.
|
||||
* \enumval IGRAPH_LOOPS_SW Allow or consider self-loops.
|
||||
* \enumval IGRAPH_MULTI_SW Allow or consider multi-edges.
|
||||
*/
|
||||
typedef unsigned int igraph_edge_type_sw_t;
|
||||
|
||||
/*
|
||||
* bit 0: self-loops alowed?
|
||||
* bit 1: more than one edge allowed between distinct vertices?
|
||||
* bit 2: more than one self-loop allowed (assuming bit 0 is set)?
|
||||
*/
|
||||
enum {
|
||||
IGRAPH_SIMPLE_SW = 0x00, /* 000 */
|
||||
IGRAPH_LOOPS_SW = 0x01, /* 001 */
|
||||
IGRAPH_MULTI_SW = 0x06 /* 110 */
|
||||
};
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_is_graphical(const igraph_vector_int_t *out_degrees,
|
||||
const igraph_vector_int_t *in_degrees,
|
||||
igraph_edge_type_sw_t allowed_edge_types,
|
||||
igraph_bool_t *res);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_is_bigraphical(const igraph_vector_int_t *degrees1,
|
||||
const igraph_vector_int_t *degrees2,
|
||||
igraph_edge_type_sw_t allowed_edge_types,
|
||||
igraph_bool_t *res);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif // IGRAPH_GRAPHICALITY_H
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2013-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_GRAPHLETS_H
|
||||
#define IGRAPH_GRAPHLETS_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
|
||||
#include "igraph_datatype.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_vector_list.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_graphlets_candidate_basis(const igraph_t *graph,
|
||||
const igraph_vector_t *weights,
|
||||
igraph_vector_int_list_t *cliques,
|
||||
igraph_vector_t *thresholds);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_graphlets_project(const igraph_t *graph,
|
||||
const igraph_vector_t *weights,
|
||||
const igraph_vector_int_list_t *cliques,
|
||||
igraph_vector_t *Mu, igraph_bool_t startMu,
|
||||
igraph_int_t niter);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_graphlets(const igraph_t *graph,
|
||||
const igraph_vector_t *weights,
|
||||
igraph_vector_int_list_t *cliques,
|
||||
igraph_vector_t *Mu, igraph_int_t niter);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2009-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_HEAP_H
|
||||
#define IGRAPH_HEAP_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_types.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* Heap */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Heap data type.
|
||||
* \ingroup internal
|
||||
*/
|
||||
|
||||
#define BASE_IGRAPH_REAL
|
||||
#define HEAP_TYPE_MAX
|
||||
#include "igraph_pmt.h"
|
||||
#include "igraph_heap_pmt.h"
|
||||
#include "igraph_pmt_off.h"
|
||||
#undef HEAP_TYPE_MAX
|
||||
#define HEAP_TYPE_MIN
|
||||
#include "igraph_pmt.h"
|
||||
#include "igraph_heap_pmt.h"
|
||||
#include "igraph_pmt_off.h"
|
||||
#undef HEAP_TYPE_MIN
|
||||
#undef BASE_IGRAPH_REAL
|
||||
|
||||
#define BASE_INT
|
||||
#define HEAP_TYPE_MAX
|
||||
#include "igraph_pmt.h"
|
||||
#include "igraph_heap_pmt.h"
|
||||
#include "igraph_pmt_off.h"
|
||||
#undef HEAP_TYPE_MAX
|
||||
#define HEAP_TYPE_MIN
|
||||
#include "igraph_pmt.h"
|
||||
#include "igraph_heap_pmt.h"
|
||||
#include "igraph_pmt_off.h"
|
||||
#undef HEAP_TYPE_MIN
|
||||
#undef BASE_INT
|
||||
|
||||
#define BASE_CHAR
|
||||
#define HEAP_TYPE_MAX
|
||||
#include "igraph_pmt.h"
|
||||
#include "igraph_heap_pmt.h"
|
||||
#include "igraph_pmt_off.h"
|
||||
#undef HEAP_TYPE_MAX
|
||||
#define HEAP_TYPE_MIN
|
||||
#include "igraph_pmt.h"
|
||||
#include "igraph_heap_pmt.h"
|
||||
#include "igraph_pmt_off.h"
|
||||
#undef HEAP_TYPE_MIN
|
||||
#undef BASE_CHAR
|
||||
|
||||
#define IGRAPH_HEAP_NULL { 0,0,0 }
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2007-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
typedef struct TYPE(igraph_heap) {
|
||||
BASE* stor_begin;
|
||||
BASE* stor_end;
|
||||
BASE* end;
|
||||
} TYPE(igraph_heap);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_heap, init)(TYPE(igraph_heap)* h, igraph_int_t capacity);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_heap, init_array)(TYPE(igraph_heap) *t, const BASE *data, igraph_int_t len);
|
||||
IGRAPH_EXPORT void FUNCTION(igraph_heap, destroy)(TYPE(igraph_heap)* h);
|
||||
IGRAPH_EXPORT void FUNCTION(igraph_heap, clear)(TYPE(igraph_heap)* h);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_bool_t FUNCTION(igraph_heap, empty)(const TYPE(igraph_heap)* h);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_heap, push)(TYPE(igraph_heap)* h, BASE elem);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE BASE FUNCTION(igraph_heap, top)(const TYPE(igraph_heap)* h);
|
||||
IGRAPH_EXPORT BASE FUNCTION(igraph_heap, delete_top)(TYPE(igraph_heap)* h);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_int_t FUNCTION(igraph_heap, size)(const TYPE(igraph_heap)* h);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_heap, reserve)(TYPE(igraph_heap)* h, igraph_int_t capacity);
|
||||
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2009-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_HRG_H
|
||||
#define IGRAPH_HRG_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_datatype.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_graph_list.h"
|
||||
#include "igraph_vector.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
/**
|
||||
* \struct igraph_hrg_t
|
||||
* \brief Data structure to store a hierarchical random graph.
|
||||
*
|
||||
* A hierarchical random graph (HRG) can be given as a binary tree,
|
||||
* where the internal vertices are labeled with real numbers.
|
||||
*
|
||||
* </para><para>Note that you don't necessarily have to know this
|
||||
* internal representation for using the HRG functions, just pass the
|
||||
* HRG objects created by one igraph function, to another igraph
|
||||
* function.
|
||||
*
|
||||
* </para><para>
|
||||
* It has the following members:
|
||||
*
|
||||
* \member left Vector that contains the left children of the internal
|
||||
* tree vertices. The first vertex is always the root vertex, so
|
||||
* the first element of the vector is the left child of the root
|
||||
* vertex. Internal vertices are denoted with negative numbers,
|
||||
* starting from -1 and going down, i.e. the root vertex is
|
||||
* -1. Leaf vertices are denoted by non-negative number, starting
|
||||
* from zero and up.
|
||||
* \member right Vector that contains the right children of the
|
||||
* vertices, with the same encoding as the \c left vector.
|
||||
* \member prob The connection probabilities attached to the internal
|
||||
* vertices, the first number belongs to the root vertex
|
||||
* (i.e. internal vertex -1), the second to internal vertex -2,
|
||||
* etc.
|
||||
* \member edges The number of edges in the subtree below the given
|
||||
* internal vertex.
|
||||
* \member vertices The number of vertices in the subtree below the
|
||||
* given internal vertex, including itself.
|
||||
*/
|
||||
|
||||
typedef struct igraph_hrg_t {
|
||||
igraph_vector_int_t left;
|
||||
igraph_vector_int_t right;
|
||||
igraph_vector_t prob;
|
||||
igraph_vector_int_t vertices;
|
||||
igraph_vector_int_t edges;
|
||||
} igraph_hrg_t;
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_hrg_init(igraph_hrg_t *hrg, igraph_int_t n);
|
||||
IGRAPH_EXPORT void igraph_hrg_destroy(igraph_hrg_t *hrg);
|
||||
IGRAPH_EXPORT igraph_int_t igraph_hrg_size(const igraph_hrg_t *hrg);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_hrg_resize(igraph_hrg_t *hrg, igraph_int_t newsize);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_hrg_fit(
|
||||
const igraph_t *graph, igraph_hrg_t *hrg, igraph_bool_t start,
|
||||
igraph_int_t steps
|
||||
);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_hrg_sample(
|
||||
const igraph_hrg_t *hrg, igraph_t *sample
|
||||
);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_hrg_sample_many(
|
||||
const igraph_hrg_t *hrg, igraph_graph_list_t *samples,
|
||||
igraph_int_t num_samples
|
||||
);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_hrg_game(
|
||||
igraph_t *graph, const igraph_hrg_t *hrg
|
||||
);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_from_hrg_dendrogram(
|
||||
igraph_t *graph, const igraph_hrg_t *hrg, igraph_vector_t *prob
|
||||
);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_hrg_consensus(const igraph_t *graph,
|
||||
igraph_vector_int_t *parents,
|
||||
igraph_vector_t *weights,
|
||||
igraph_hrg_t *hrg,
|
||||
igraph_bool_t start,
|
||||
igraph_int_t num_samples);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_hrg_predict(const igraph_t *graph,
|
||||
igraph_vector_int_t *edges,
|
||||
igraph_vector_t *prob,
|
||||
igraph_hrg_t *hrg,
|
||||
igraph_bool_t start,
|
||||
igraph_int_t num_samples,
|
||||
igraph_int_t num_bins);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_hrg_create(igraph_hrg_t *hrg,
|
||||
const igraph_t *graph,
|
||||
const igraph_vector_t *prob);
|
||||
|
||||
/* Deprecated functions: */
|
||||
|
||||
IGRAPH_DEPRECATED IGRAPH_EXPORT igraph_error_t igraph_hrg_dendrogram(
|
||||
igraph_t *graph, const igraph_hrg_t *hrg
|
||||
);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif /* IGRAPH_HRG_H */
|
||||
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2009-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_INTERFACE_H
|
||||
#define IGRAPH_INTERFACE_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_attributes.h"
|
||||
#include "igraph_datatype.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_iterators.h"
|
||||
#include "igraph_types.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* Interface */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_empty(igraph_t *graph, igraph_int_t n, igraph_bool_t directed);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_empty_attrs(
|
||||
igraph_t *graph, igraph_int_t n, igraph_bool_t directed,
|
||||
const igraph_attribute_record_list_t* attr
|
||||
);
|
||||
IGRAPH_EXPORT void igraph_destroy(igraph_t *graph);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_copy(igraph_t *to, const igraph_t *from);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_add_edges(
|
||||
igraph_t *graph, const igraph_vector_int_t *edges,
|
||||
const igraph_attribute_record_list_t* attr
|
||||
);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_add_vertices(
|
||||
igraph_t *graph, igraph_int_t nv,
|
||||
const igraph_attribute_record_list_t* attr
|
||||
);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_delete_edges(igraph_t *graph, igraph_es_t edges);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_delete_vertices(igraph_t *graph, igraph_vs_t vertices);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_delete_vertices_map(
|
||||
igraph_t *graph, igraph_vs_t vertices, igraph_vector_int_t *map,
|
||||
igraph_vector_int_t *invmap
|
||||
);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_int_t igraph_vcount(const igraph_t *graph);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_int_t igraph_ecount(const igraph_t *graph);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_neighbors(
|
||||
const igraph_t *graph, igraph_vector_int_t *neis, igraph_int_t vid,
|
||||
igraph_neimode_t mode, igraph_loops_t loops, igraph_bool_t multiple
|
||||
);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_bool_t igraph_is_directed(const igraph_t *graph);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_degree_1(
|
||||
const igraph_t *graph, igraph_int_t *deg, igraph_int_t vid,
|
||||
igraph_neimode_t mode, igraph_loops_t loops
|
||||
);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_degree(
|
||||
const igraph_t *graph, igraph_vector_int_t *res, igraph_vs_t vids,
|
||||
igraph_neimode_t mode, igraph_loops_t loops
|
||||
);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_edge(const igraph_t *graph, igraph_int_t eid,
|
||||
igraph_int_t *from, igraph_int_t *to);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_edges(const igraph_t *graph, igraph_es_t eids,
|
||||
igraph_vector_int_t *edges, igraph_bool_t bycol);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_get_eid(const igraph_t *graph, igraph_int_t *eid,
|
||||
igraph_int_t from, igraph_int_t to,
|
||||
igraph_bool_t directed, igraph_bool_t error);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_get_eids(const igraph_t *graph, igraph_vector_int_t *eids,
|
||||
const igraph_vector_int_t *pairs,
|
||||
igraph_bool_t directed, igraph_bool_t error);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_get_all_eids_between(const igraph_t *graph, igraph_vector_int_t *eids,
|
||||
igraph_int_t source, igraph_int_t target, igraph_bool_t directed);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_incident(
|
||||
const igraph_t *graph, igraph_vector_int_t *eids, igraph_int_t pnode,
|
||||
igraph_neimode_t mode, igraph_loops_t loops
|
||||
);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_is_same_graph(const igraph_t *graph1, const igraph_t *graph2, igraph_bool_t *res);
|
||||
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_bool_t igraph_i_property_cache_get_bool(const igraph_t *graph, igraph_cached_property_t prop);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_bool_t igraph_i_property_cache_has(const igraph_t *graph, igraph_cached_property_t prop);
|
||||
IGRAPH_EXPORT void igraph_i_property_cache_set_bool(const igraph_t *graph, igraph_cached_property_t prop, igraph_bool_t value);
|
||||
IGRAPH_EXPORT void igraph_i_property_cache_set_bool_checked(const igraph_t *graph, igraph_cached_property_t prop, igraph_bool_t value);
|
||||
IGRAPH_EXPORT void igraph_i_property_cache_invalidate(const igraph_t *graph, igraph_cached_property_t prop);
|
||||
IGRAPH_EXPORT void igraph_i_property_cache_invalidate_all(const igraph_t *graph);
|
||||
|
||||
#define IGRAPH_RETURN_IF_CACHED_BOOL(graphptr, prop, resptr) \
|
||||
do { \
|
||||
if (igraph_i_property_cache_has((graphptr), (prop))) { \
|
||||
*(resptr) = igraph_i_property_cache_get_bool((graphptr), (prop)); \
|
||||
return IGRAPH_SUCCESS; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/**
|
||||
* \define IGRAPH_FROM
|
||||
* \brief The source vertex of an edge.
|
||||
*
|
||||
* Faster than \ref igraph_edge(), but no error checking is done: \p eid is assumed to be valid.
|
||||
*
|
||||
* \param graph The graph.
|
||||
* \param eid The edge ID.
|
||||
* \return The source vertex of the edge.
|
||||
* \sa \ref igraph_edge() if error checking is desired.
|
||||
*/
|
||||
#define IGRAPH_FROM(graph,eid) ((igraph_int_t)(VECTOR((graph)->from)[(igraph_int_t)(eid)]))
|
||||
|
||||
/**
|
||||
* \define IGRAPH_TO
|
||||
* \brief The target vertex of an edge.
|
||||
*
|
||||
* Faster than \ref igraph_edge(), but no error checking is done: \p eid is assumed to be valid.
|
||||
*
|
||||
* \param graph The graph object.
|
||||
* \param eid The edge ID.
|
||||
* \return The target vertex of the edge.
|
||||
* \sa \ref igraph_edge() if error checking is desired.
|
||||
*/
|
||||
#define IGRAPH_TO(graph,eid) ((igraph_int_t)(VECTOR((graph)->to) [(igraph_int_t)(eid)]))
|
||||
|
||||
/**
|
||||
* \define IGRAPH_OTHER
|
||||
* \brief The other endpoint of an edge.
|
||||
*
|
||||
* Typically used with undirected edges when one endpoint of the edge is known,
|
||||
* and the other endpoint is needed. No error checking is done:
|
||||
* \p eid and \p vid are assumed to be valid.
|
||||
*
|
||||
* \param graph The graph object.
|
||||
* \param eid The edge ID.
|
||||
* \param vid The vertex ID of one endpoint of an edge.
|
||||
* \return The other endpoint of the edge.
|
||||
* \sa \ref IGRAPH_TO() and \ref IGRAPH_FROM() to get the source and target
|
||||
* of directed edges.
|
||||
*/
|
||||
#define IGRAPH_OTHER(graph,eid,vid) \
|
||||
((igraph_int_t)(IGRAPH_TO(graph,(eid))==(vid) ? IGRAPH_FROM((graph),(eid)) : IGRAPH_TO((graph),(eid))))
|
||||
|
||||
IGRAPH_DEPRECATED IGRAPH_EXPORT igraph_error_t igraph_delete_vertices_idx(
|
||||
igraph_t *graph, igraph_vs_t vertices, igraph_vector_int_t *idx,
|
||||
igraph_vector_int_t *invidx
|
||||
);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2003-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_INTERRUPT_H
|
||||
#define IGRAPH_INTERRUPT_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_types.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
/* This file contains the igraph interruption handling. */
|
||||
|
||||
/**
|
||||
* \section interrupthandlers Interruption handlers
|
||||
*
|
||||
* <para>
|
||||
* \a igraph is designed to be embeddable into several higher level
|
||||
* languages (R and Python interfaces are included in the original
|
||||
* package). Since most higher level languages consider internal \a igraph
|
||||
* calls as atomic, interruption requests (like Ctrl-C in Python) must
|
||||
* be handled differently depending on the environment \a igraph embeds
|
||||
* into.</para>
|
||||
* <para>
|
||||
* An \emb interruption handler \eme is a function which is called regularly
|
||||
* by \a igraph during long calculations. A typical usage of the interruption
|
||||
* handler is to check whether the user tried to interrupt the calculation
|
||||
* and return an appropriate value to signal this condition. For example,
|
||||
* in R, one must call an internal R function regularly to check for
|
||||
* interruption requests, and the \a igraph interruption handler is the
|
||||
* perfect place to do that.</para>
|
||||
* <para>
|
||||
* If you are using the plain C interface of \a igraph or if you are
|
||||
* allowed to replace the operating system's interruption handler (like
|
||||
* SIGINT in Un*x systems), these calls are not of much use to you.</para>
|
||||
* <para>
|
||||
* The default interruption handler is empty.
|
||||
* The \ref igraph_set_interruption_handler() function can be used to set a
|
||||
* new interruption handler function of type
|
||||
* \ref igraph_interruption_handler_t, see the
|
||||
* documentation of this type for details.
|
||||
* </para>
|
||||
*/
|
||||
|
||||
/**
|
||||
* \section writing_interruption_handlers Writing interruption handlers
|
||||
*
|
||||
* <para>
|
||||
* You can write and install interruption handlers simply by defining a
|
||||
* function of type \ref igraph_interruption_handler_t and calling
|
||||
* \ref igraph_set_interruption_handler(). This feature is useful for
|
||||
* interface writers, because usually this is the only way to allow handling
|
||||
* of Ctrl-C and similar keypresses properly.
|
||||
* </para>
|
||||
* <para>
|
||||
* Your interruption handler will be called regularly during long operations
|
||||
* (so it is not guaranteed to be called during operations which tend to be
|
||||
* short, like adding single edges). An interruption handler accepts no
|
||||
* parameters and must return \c IGRAPH_SUCCESS if the calculation should go on. All
|
||||
* other return values are considered to be a request for interruption,
|
||||
* and the caller function would return a special error code, \c IGRAPH_INTERRUPTED.
|
||||
* It is up to your error handler function to handle this error properly.
|
||||
* </para>
|
||||
*/
|
||||
|
||||
/**
|
||||
* \section writing_functions_interruption_handling Writing \a igraph functions with
|
||||
* proper interruption handling
|
||||
*
|
||||
* <para>
|
||||
* There is practically a simple rule that should be obeyed when writing
|
||||
* \a igraph functions. If the calculation is expected to take a long time
|
||||
* in large graphs (a simple rule of thumb is to assume this for every
|
||||
* function with a time complexity of at least O(n^2)), call
|
||||
* \ref IGRAPH_ALLOW_INTERRUPTION in regular intervals like every 10th
|
||||
* iteration or so.
|
||||
* </para>
|
||||
*/
|
||||
|
||||
/**
|
||||
* \typedef igraph_interruption_handler_t
|
||||
*
|
||||
* This is the type of the interruption handler functions.
|
||||
*
|
||||
* \return false if the calculation should go on, true if the calculation
|
||||
* should be interrupted.
|
||||
*/
|
||||
|
||||
typedef igraph_bool_t igraph_interruption_handler_t(void);
|
||||
|
||||
/**
|
||||
* \function igraph_allow_interruption
|
||||
*
|
||||
* This is the function which is called (usually via the
|
||||
* \ref IGRAPH_ALLOW_INTERRUPTION macro) if \a igraph is checking for interruption
|
||||
* requests.
|
||||
*
|
||||
* \return false if the calculation should go on, true if the calculation
|
||||
* should be interrupted.
|
||||
*/
|
||||
|
||||
IGRAPH_EXPORT igraph_bool_t igraph_allow_interruption(void);
|
||||
|
||||
IGRAPH_EXPORT igraph_interruption_handler_t * igraph_set_interruption_handler (igraph_interruption_handler_t * new_handler);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,282 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2009-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_ISOMORPHISM_H
|
||||
#define IGRAPH_ISOMORPHISM_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_datatype.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_iterators.h"
|
||||
#include "igraph_types.h"
|
||||
#include "igraph_vector_list.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* Graph isomorphisms */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
/* Common functions */
|
||||
IGRAPH_EXPORT igraph_error_t igraph_simplify_and_colorize(
|
||||
const igraph_t *graph, igraph_t *res,
|
||||
igraph_vector_int_t *vertex_color, igraph_vector_int_t *edge_color);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_invert_permutation(
|
||||
const igraph_vector_int_t *permutation, igraph_vector_int_t *inverse);
|
||||
|
||||
/* Generic interface */
|
||||
IGRAPH_EXPORT igraph_error_t igraph_isomorphic(const igraph_t *graph1, const igraph_t *graph2,
|
||||
igraph_bool_t *iso);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_subisomorphic(const igraph_t *graph1, const igraph_t *graph2,
|
||||
igraph_bool_t *iso);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_count_automorphisms(
|
||||
const igraph_t *graph, const igraph_vector_int_t *colors,
|
||||
igraph_real_t *result);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_automorphism_group(
|
||||
const igraph_t *graph, const igraph_vector_int_t *colors,
|
||||
igraph_vector_int_list_t *generators
|
||||
);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_canonical_permutation(
|
||||
const igraph_t *graph, const igraph_vector_int_t *colors,
|
||||
igraph_vector_int_t *labeling
|
||||
);
|
||||
|
||||
/* LAD */
|
||||
IGRAPH_EXPORT igraph_error_t igraph_subisomorphic_lad(
|
||||
const igraph_t *pattern, const igraph_t *target, const igraph_vector_int_list_t *domains,
|
||||
igraph_bool_t *iso, igraph_vector_int_t *map, igraph_vector_int_list_t *maps,
|
||||
igraph_bool_t induced
|
||||
);
|
||||
|
||||
/* VF2 family*/
|
||||
/**
|
||||
* \typedef igraph_isohandler_t
|
||||
* Callback type, called when an isomorphism was found
|
||||
*
|
||||
* See the details at the documentation of \ref
|
||||
* igraph_get_isomorphisms_vf2_callback().
|
||||
* \param map12 The mapping from the first graph to the second.
|
||||
* \param map21 The mapping from the second graph to the first, the
|
||||
* inverse of \p map12 basically.
|
||||
* \param arg This extra argument was passed to \ref
|
||||
* igraph_get_isomorphisms_vf2_callback() when it was called.
|
||||
* \return \c IGRAPH_SUCCESS to continue the search, \c IGRAPH_STOP to
|
||||
* terminate the search. Any other return value is interpreted as an
|
||||
* igraph error code, which will then abort the search and return the
|
||||
* same error code from the caller function.
|
||||
*/
|
||||
|
||||
|
||||
typedef igraph_error_t igraph_isohandler_t(const igraph_vector_int_t *map12,
|
||||
const igraph_vector_int_t *map21, void *arg);
|
||||
|
||||
/**
|
||||
* \typedef igraph_isocompat_t
|
||||
* Callback type, called to check whether two vertices or edges are compatible
|
||||
*
|
||||
* VF2 (subgraph) isomorphism functions can be restricted by defining
|
||||
* relations on the vertices and/or edges of the graphs, and then checking
|
||||
* whether the vertices (edges) match according to these relations.
|
||||
*
|
||||
* </para><para>This feature is implemented by two callbacks, one for
|
||||
* vertices, one for edges. Every time igraph tries to match a vertex (edge)
|
||||
* of the first (sub)graph to a vertex of the second graph, the vertex
|
||||
* (edge) compatibility callback is called. The callback returns a
|
||||
* logical value, giving whether the two vertices match.
|
||||
*
|
||||
* </para><para>Both callback functions are of type \c igraph_isocompat_t.
|
||||
* \param graph1 The first graph.
|
||||
* \param graph2 The second graph.
|
||||
* \param g1_num The id of a vertex or edge in the first graph.
|
||||
* \param g2_num The id of a vertex or edge in the second graph.
|
||||
* \param arg Extra argument to pass to the callback functions.
|
||||
* \return Logical scalar, whether vertex (or edge) \p g1_num in \p graph1
|
||||
* is compatible with vertex (or edge) \p g2_num in \p graph2.
|
||||
*/
|
||||
|
||||
typedef igraph_bool_t igraph_isocompat_t(const igraph_t *graph1,
|
||||
const igraph_t *graph2,
|
||||
const igraph_int_t g1_num,
|
||||
const igraph_int_t g2_num,
|
||||
void *arg);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_isomorphic_vf2(const igraph_t *graph1, const igraph_t *graph2,
|
||||
const igraph_vector_int_t *vertex_color1,
|
||||
const igraph_vector_int_t *vertex_color2,
|
||||
const igraph_vector_int_t *edge_color1,
|
||||
const igraph_vector_int_t *edge_color2,
|
||||
igraph_bool_t *iso,
|
||||
igraph_vector_int_t *map12,
|
||||
igraph_vector_int_t *map21,
|
||||
igraph_isocompat_t *node_compat_fn,
|
||||
igraph_isocompat_t *edge_compat_fn,
|
||||
void *arg);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_count_isomorphisms_vf2(const igraph_t *graph1, const igraph_t *graph2,
|
||||
const igraph_vector_int_t *vertex_color1,
|
||||
const igraph_vector_int_t *vertex_color2,
|
||||
const igraph_vector_int_t *edge_color1,
|
||||
const igraph_vector_int_t *edge_color2,
|
||||
igraph_int_t *count,
|
||||
igraph_isocompat_t *node_compat_fn,
|
||||
igraph_isocompat_t *edge_compat_fn,
|
||||
void *arg);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_get_isomorphisms_vf2(const igraph_t *graph1,
|
||||
const igraph_t *graph2,
|
||||
const igraph_vector_int_t *vertex_color1,
|
||||
const igraph_vector_int_t *vertex_color2,
|
||||
const igraph_vector_int_t *edge_color1,
|
||||
const igraph_vector_int_t *edge_color2,
|
||||
igraph_vector_int_list_t *maps,
|
||||
igraph_isocompat_t *node_compat_fn,
|
||||
igraph_isocompat_t *edge_compat_fn,
|
||||
void *arg);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_get_isomorphisms_vf2_callback(
|
||||
const igraph_t *graph1, const igraph_t *graph2,
|
||||
const igraph_vector_int_t *vertex_color1, const igraph_vector_int_t *vertex_color2,
|
||||
const igraph_vector_int_t *edge_color1, const igraph_vector_int_t *edge_color2,
|
||||
igraph_vector_int_t *map12, igraph_vector_int_t *map21,
|
||||
igraph_isohandler_t *isohandler_fn, igraph_isocompat_t *node_compat_fn,
|
||||
igraph_isocompat_t *edge_compat_fn, void *arg
|
||||
);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_subisomorphic_vf2(const igraph_t *graph1, const igraph_t *graph2,
|
||||
const igraph_vector_int_t *vertex_color1,
|
||||
const igraph_vector_int_t *vertex_color2,
|
||||
const igraph_vector_int_t *edge_color1,
|
||||
const igraph_vector_int_t *edge_color2,
|
||||
igraph_bool_t *iso,
|
||||
igraph_vector_int_t *map12,
|
||||
igraph_vector_int_t *map21,
|
||||
igraph_isocompat_t *node_compat_fn,
|
||||
igraph_isocompat_t *edge_compat_fn,
|
||||
void *arg);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_count_subisomorphisms_vf2(const igraph_t *graph1, const igraph_t *graph2,
|
||||
const igraph_vector_int_t *vertex_color1,
|
||||
const igraph_vector_int_t *vertex_color2,
|
||||
const igraph_vector_int_t *edge_color1,
|
||||
const igraph_vector_int_t *edge_color2,
|
||||
igraph_int_t *count,
|
||||
igraph_isocompat_t *node_compat_fn,
|
||||
igraph_isocompat_t *edge_compat_fn,
|
||||
void *arg);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_get_subisomorphisms_vf2(const igraph_t *graph1,
|
||||
const igraph_t *graph2,
|
||||
const igraph_vector_int_t *vertex_color1,
|
||||
const igraph_vector_int_t *vertex_color2,
|
||||
const igraph_vector_int_t *edge_color1,
|
||||
const igraph_vector_int_t *edge_color2,
|
||||
igraph_vector_int_list_t *maps,
|
||||
igraph_isocompat_t *node_compat_fn,
|
||||
igraph_isocompat_t *edge_compat_fn,
|
||||
void *arg);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_get_subisomorphisms_vf2_callback(
|
||||
const igraph_t *graph1, const igraph_t *graph2,
|
||||
const igraph_vector_int_t *vertex_color1, const igraph_vector_int_t *vertex_color2,
|
||||
const igraph_vector_int_t *edge_color1, const igraph_vector_int_t *edge_color2,
|
||||
igraph_vector_int_t *map12, igraph_vector_int_t *map21,
|
||||
igraph_isohandler_t *isohandler_fn, igraph_isocompat_t *node_compat_fn,
|
||||
igraph_isocompat_t *edge_compat_fn, void *arg
|
||||
);
|
||||
|
||||
/* BLISS family */
|
||||
/**
|
||||
* \struct igraph_bliss_info_t
|
||||
* \brief Information about a Bliss run.
|
||||
*
|
||||
* Some secondary information found by the Bliss algorithm is stored
|
||||
* here. It is useful if you wany to study the internal working of the
|
||||
* algorithm.
|
||||
*
|
||||
* \member nof_nodes The number of nodes in the search tree.
|
||||
* \member nof_leaf_nodes The number of leaf nodes in the search tree.
|
||||
* \member nof_bad_nodes Number of bad nodes.
|
||||
* \member nof_canupdates Number of canrep updates.
|
||||
* \member nof_generators Number of generators of the automorphism group.
|
||||
* \member max_level Maximum level.
|
||||
* \member group_size The size of the automorphism group of the graph,
|
||||
* given as a string. It should be deallocated via
|
||||
* \ref igraph_free() if not needed any more.
|
||||
*
|
||||
* See https://users.aalto.fi/~tjunttil/bliss/
|
||||
* for details about the algorithm and these parameters.
|
||||
*/
|
||||
typedef struct igraph_bliss_info_t {
|
||||
unsigned long nof_nodes;
|
||||
unsigned long nof_leaf_nodes;
|
||||
unsigned long nof_bad_nodes;
|
||||
unsigned long nof_canupdates;
|
||||
unsigned long nof_generators;
|
||||
unsigned long max_level;
|
||||
char *group_size;
|
||||
} igraph_bliss_info_t;
|
||||
|
||||
/**
|
||||
* \typedef igraph_bliss_sh_t
|
||||
* \brief Splitting heuristics for Bliss.
|
||||
*
|
||||
* \c IGRAPH_BLISS_FL provides good performance for many graphs, and is a reasonable
|
||||
* default choice. \c IGRAPH_BLISS_FSM is recommended for graphs that have some
|
||||
* combinatorial structure, and is the default of the Bliss library's command
|
||||
* line tool.
|
||||
*
|
||||
* \enumval IGRAPH_BLISS_F First non-singleton cell.
|
||||
* \enumval IGRAPH_BLISS_FL First largest non-singleton cell.
|
||||
* \enumval IGRAPH_BLISS_FS First smallest non-singleton cell.
|
||||
* \enumval IGRAPH_BLISS_FM First maximally non-trivially connected
|
||||
* non-singleton cell.
|
||||
* \enumval IGRAPH_BLISS_FLM Largest maximally non-trivially connected
|
||||
* non-singleton cell.
|
||||
* \enumval IGRAPH_BLISS_FSM Smallest maximally non-trivially
|
||||
* connected non-singleton cell.
|
||||
*/
|
||||
|
||||
typedef enum { IGRAPH_BLISS_F = 0, IGRAPH_BLISS_FL,
|
||||
IGRAPH_BLISS_FS, IGRAPH_BLISS_FM,
|
||||
IGRAPH_BLISS_FLM, IGRAPH_BLISS_FSM
|
||||
} igraph_bliss_sh_t;
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_canonical_permutation_bliss(const igraph_t *graph, const igraph_vector_int_t *colors, igraph_vector_int_t *labeling,
|
||||
igraph_bliss_sh_t sh, igraph_bliss_info_t *info);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_isomorphic_bliss(const igraph_t *graph1, const igraph_t *graph2,
|
||||
const igraph_vector_int_t *colors1, const igraph_vector_int_t *colors2,
|
||||
igraph_bool_t *iso, igraph_vector_int_t *map12,
|
||||
igraph_vector_int_t *map21,
|
||||
igraph_bliss_sh_t sh,
|
||||
igraph_bliss_info_t *info1, igraph_bliss_info_t *info2);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_count_automorphisms_bliss(
|
||||
const igraph_t *graph, const igraph_vector_int_t *colors,
|
||||
igraph_bliss_sh_t sh, igraph_bliss_info_t *info);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_automorphism_group_bliss(
|
||||
const igraph_t *graph, const igraph_vector_int_t *colors,
|
||||
igraph_vector_int_list_t *generators, igraph_bliss_sh_t sh,
|
||||
igraph_bliss_info_t *info
|
||||
);
|
||||
|
||||
/* Functions for small graphs (<= 4 vertices for directed graphs, <= 6 for undirected graphs) */
|
||||
IGRAPH_EXPORT igraph_error_t igraph_isoclass(const igraph_t *graph, igraph_int_t *isoclass);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_isoclass_subgraph(const igraph_t *graph, igraph_vs_t vids,
|
||||
igraph_int_t *isoclass);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_isoclass_create(igraph_t *graph, igraph_int_t size,
|
||||
igraph_int_t number, igraph_bool_t directed);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_graph_count(igraph_int_t n, igraph_bool_t directed, igraph_int_t *count);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,416 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2009-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_ITERATORS_H
|
||||
#define IGRAPH_ITERATORS_H
|
||||
|
||||
#include "igraph_datatype.h"
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_constants.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_types.h"
|
||||
#include "igraph_vector.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* Vertex selectors */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
typedef enum {
|
||||
IGRAPH_VS_ALL,
|
||||
IGRAPH_VS_ADJ,
|
||||
IGRAPH_VS_NONE,
|
||||
IGRAPH_VS_1,
|
||||
IGRAPH_VS_VECTORPTR,
|
||||
IGRAPH_VS_VECTOR,
|
||||
IGRAPH_VS_RANGE,
|
||||
IGRAPH_VS_NONADJ,
|
||||
} igraph_vs_type_t;
|
||||
|
||||
typedef struct igraph_vs_t {
|
||||
igraph_vs_type_t type;
|
||||
union {
|
||||
igraph_int_t vid; /* single vertex */
|
||||
const igraph_vector_int_t *vecptr; /* vector of vertices */
|
||||
struct {
|
||||
igraph_int_t vid;
|
||||
igraph_neimode_t mode;
|
||||
igraph_loops_t loops;
|
||||
igraph_bool_t multiple;
|
||||
} adj; /* adjacent vertices */
|
||||
struct {
|
||||
igraph_int_t start; /* first index (inclusive) */
|
||||
igraph_int_t end; /* last index (exclusive) */
|
||||
} range; /* range of vertices */
|
||||
} data;
|
||||
} igraph_vs_t;
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_vs_all(igraph_vs_t *vs);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_CONST igraph_vs_t igraph_vss_all(void);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_vs_adj(
|
||||
igraph_vs_t *vs, igraph_int_t vid, igraph_neimode_t mode,
|
||||
igraph_loops_t loops, igraph_bool_t multiple
|
||||
);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_vs_nonadj(igraph_vs_t *vs, igraph_int_t vid,
|
||||
igraph_neimode_t mode);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_vs_none(igraph_vs_t *vs);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_CONST igraph_vs_t igraph_vss_none(void);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_vs_1(igraph_vs_t *vs, igraph_int_t vid);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_CONST igraph_vs_t igraph_vss_1(igraph_int_t vid);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_vs_vector(igraph_vs_t *vs,
|
||||
const igraph_vector_int_t *v);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_vs_t igraph_vss_vector(const igraph_vector_int_t *v);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_vs_vector_small(igraph_vs_t *vs, ...);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_vs_vector_copy(igraph_vs_t *vs,
|
||||
const igraph_vector_int_t *v);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_vs_range(igraph_vs_t *vs, igraph_int_t start, igraph_int_t end);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_CONST igraph_vs_t igraph_vss_range(igraph_int_t start, igraph_int_t end);
|
||||
|
||||
IGRAPH_EXPORT void igraph_vs_destroy(igraph_vs_t *vs);
|
||||
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_bool_t igraph_vs_is_all(const igraph_vs_t *vs);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_vs_copy(igraph_vs_t* dest, const igraph_vs_t* src);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_vs_as_vector(const igraph_t *graph, igraph_vs_t vs,
|
||||
igraph_vector_int_t *v);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_vs_size(const igraph_t *graph, const igraph_vs_t *vs,
|
||||
igraph_int_t *result);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_vs_type_t igraph_vs_type(const igraph_vs_t *vs);
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* Vertex iterators */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
typedef enum {
|
||||
IGRAPH_VIT_RANGE,
|
||||
IGRAPH_VIT_VECTOR,
|
||||
IGRAPH_VIT_VECTORPTR,
|
||||
} igraph_vit_type_t;
|
||||
|
||||
typedef struct igraph_vit_t {
|
||||
igraph_vit_type_t type;
|
||||
igraph_int_t pos;
|
||||
igraph_int_t start; /* first index */
|
||||
igraph_int_t end; /* one past last index */
|
||||
const igraph_vector_int_t *vec;
|
||||
} igraph_vit_t;
|
||||
|
||||
/**
|
||||
* \section IGRAPH_VIT Stepping over the vertices
|
||||
*
|
||||
* <para>After creating an iterator with \ref igraph_vit_create(), it
|
||||
* points to the first vertex in the vertex determined by the vertex
|
||||
* selector (if there is any). The \ref IGRAPH_VIT_NEXT() macro steps
|
||||
* to the next vertex, \ref IGRAPH_VIT_END() checks whether there are
|
||||
* more vertices to visit, \ref IGRAPH_VIT_SIZE() gives the total size
|
||||
* of the vertices visited so far and to be visited. \ref
|
||||
* IGRAPH_VIT_RESET() resets the iterator, it will point to the first
|
||||
* vertex again. Finally \ref IGRAPH_VIT_GET() gives the current vertex
|
||||
* pointed to by the iterator (call this only if \ref IGRAPH_VIT_END()
|
||||
* is false).
|
||||
* </para>
|
||||
* <para>
|
||||
* Here is an example on how to step over the neighbors of vertex 0:
|
||||
* <informalexample><programlisting>
|
||||
* igraph_vs_t vs;
|
||||
* igraph_vit_t vit;
|
||||
* ...
|
||||
* igraph_vs_adj(&vs, 0, IGRAPH_ALL);
|
||||
* igraph_vit_create(&graph, vs, &vit);
|
||||
* while (!IGRAPH_VIT_END(vit)) {
|
||||
* printf(" %" IGRAPH_PRId, IGRAPH_VIT_GET(vit));
|
||||
* IGRAPH_VIT_NEXT(vit);
|
||||
* }
|
||||
* printf("\n");
|
||||
* ...
|
||||
* igraph_vit_destroy(&vit);
|
||||
* igraph_vs_destroy(&vs);
|
||||
* </programlisting></informalexample>
|
||||
* </para>
|
||||
*/
|
||||
|
||||
/**
|
||||
* \define IGRAPH_VIT_NEXT
|
||||
* \brief Next vertex.
|
||||
*
|
||||
* Steps the iterator to the next vertex. Only call this function if
|
||||
* \ref IGRAPH_VIT_END() returns false.
|
||||
* \param vit The vertex iterator to step.
|
||||
*
|
||||
* Time complexity: O(1).
|
||||
*/
|
||||
#define IGRAPH_VIT_NEXT(vit) (++((vit).pos))
|
||||
/**
|
||||
* \define IGRAPH_VIT_END
|
||||
* \brief Are we at the end?
|
||||
*
|
||||
* Checks whether there are more vertices to step to.
|
||||
* \param vit The vertex iterator to check.
|
||||
* \return Logical value, if true there are no more vertices to step
|
||||
* to.
|
||||
*
|
||||
* Time complexity: O(1).
|
||||
*/
|
||||
#define IGRAPH_VIT_END(vit) ((vit).pos >= (vit).end)
|
||||
/**
|
||||
* \define IGRAPH_VIT_SIZE
|
||||
* \brief Size of a vertex iterator.
|
||||
*
|
||||
* Gives the number of vertices in a vertex iterator.
|
||||
* \param vit The vertex iterator.
|
||||
* \return The number of vertices.
|
||||
*
|
||||
* Time complexity: O(1).
|
||||
*/
|
||||
#define IGRAPH_VIT_SIZE(vit) ((vit).end - (vit).start)
|
||||
/**
|
||||
* \define IGRAPH_VIT_RESET
|
||||
* \brief Reset a vertex iterator.
|
||||
*
|
||||
* Resets a vertex iterator. After calling this macro the iterator
|
||||
* will point to the first vertex.
|
||||
* \param vit The vertex iterator.
|
||||
*
|
||||
* Time complexity: O(1).
|
||||
*/
|
||||
#define IGRAPH_VIT_RESET(vit) ((vit).pos = (vit).start)
|
||||
/**
|
||||
* \define IGRAPH_VIT_GET
|
||||
* \brief Query the current position.
|
||||
*
|
||||
* Gives the vertex ID of the current vertex pointed to by the
|
||||
* iterator.
|
||||
* \param vit The vertex iterator.
|
||||
* \return The vertex ID of the current vertex.
|
||||
*
|
||||
* Time complexity: O(1).
|
||||
*/
|
||||
#define IGRAPH_VIT_GET(vit) \
|
||||
((igraph_int_t)(((vit).type == IGRAPH_VIT_RANGE) ? (vit).pos : \
|
||||
VECTOR(*(vit).vec)[(vit).pos]))
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_vit_create(const igraph_t *graph,
|
||||
igraph_vs_t vs, igraph_vit_t *vit);
|
||||
IGRAPH_EXPORT void igraph_vit_destroy(const igraph_vit_t *vit);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_vit_as_vector(const igraph_vit_t *vit, igraph_vector_int_t *v);
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* Edge Selectors */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
typedef enum {
|
||||
IGRAPH_ES_ALL,
|
||||
IGRAPH_ES_ALLFROM,
|
||||
IGRAPH_ES_ALLTO,
|
||||
IGRAPH_ES_INCIDENT,
|
||||
IGRAPH_ES_NONE,
|
||||
IGRAPH_ES_1,
|
||||
IGRAPH_ES_VECTORPTR,
|
||||
IGRAPH_ES_VECTOR,
|
||||
IGRAPH_ES_RANGE,
|
||||
IGRAPH_ES_PAIRS,
|
||||
IGRAPH_ES_PATH,
|
||||
IGRAPH_ES_ALL_BETWEEN,
|
||||
} igraph_es_type_t;
|
||||
|
||||
typedef struct igraph_es_t {
|
||||
igraph_es_type_t type;
|
||||
union {
|
||||
igraph_int_t vid;
|
||||
igraph_int_t eid;
|
||||
const igraph_vector_int_t *vecptr;
|
||||
struct {
|
||||
igraph_int_t vid;
|
||||
igraph_neimode_t mode;
|
||||
igraph_loops_t loops;
|
||||
} incident;
|
||||
struct {
|
||||
igraph_int_t start; /* first index (inclusive) */
|
||||
igraph_int_t end; /* last index (exclusive) */
|
||||
} range;
|
||||
struct {
|
||||
const igraph_vector_int_t *ptr;
|
||||
igraph_bool_t mode;
|
||||
} path;
|
||||
struct {
|
||||
igraph_int_t from;
|
||||
igraph_int_t to;
|
||||
igraph_bool_t directed;
|
||||
} between;
|
||||
} data;
|
||||
} igraph_es_t;
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_es_all(igraph_es_t *es,
|
||||
igraph_edgeorder_type_t order);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_CONST igraph_es_t igraph_ess_all(igraph_edgeorder_type_t order);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_es_incident(
|
||||
igraph_es_t *es, igraph_int_t vid, igraph_neimode_t mode,
|
||||
igraph_loops_t loops
|
||||
);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_es_none(igraph_es_t *es);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_CONST igraph_es_t igraph_ess_none(void);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_es_1(igraph_es_t *es, igraph_int_t eid);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_CONST igraph_es_t igraph_ess_1(igraph_int_t eid);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_es_vector(igraph_es_t *es,
|
||||
const igraph_vector_int_t *v);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_es_t igraph_ess_vector(const igraph_vector_int_t *v);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_es_range(igraph_es_t *es, igraph_int_t from, igraph_int_t to);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_CONST igraph_es_t igraph_ess_range(igraph_int_t from, igraph_int_t to);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_es_vector_copy(igraph_es_t *es, const igraph_vector_int_t *v);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_es_pairs(igraph_es_t *es, const igraph_vector_int_t *v,
|
||||
igraph_bool_t directed);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_es_pairs_small(igraph_es_t *es, igraph_bool_t directed, int first, ...);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_es_path(igraph_es_t *es, const igraph_vector_int_t *v,
|
||||
igraph_bool_t directed);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_es_path_small(igraph_es_t *es, igraph_bool_t directed, int first, ...);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_es_all_between(
|
||||
igraph_es_t *es, igraph_int_t from, igraph_int_t to,
|
||||
igraph_bool_t directed
|
||||
);
|
||||
|
||||
IGRAPH_EXPORT void igraph_es_destroy(igraph_es_t *es);
|
||||
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_bool_t igraph_es_is_all(const igraph_es_t *es);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_es_copy(igraph_es_t* dest, const igraph_es_t* src);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_es_as_vector(const igraph_t *graph, igraph_es_t es,
|
||||
igraph_vector_int_t *v);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_es_size(const igraph_t *graph, const igraph_es_t *es,
|
||||
igraph_int_t *result);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_es_type_t igraph_es_type(const igraph_es_t *es);
|
||||
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* Edge Iterators */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
typedef enum {
|
||||
IGRAPH_EIT_RANGE,
|
||||
IGRAPH_EIT_VECTOR,
|
||||
IGRAPH_EIT_VECTORPTR,
|
||||
} igraph_eit_type_t;
|
||||
|
||||
typedef struct igraph_eit_t {
|
||||
igraph_eit_type_t type;
|
||||
igraph_int_t pos;
|
||||
igraph_int_t start; /* first index */
|
||||
igraph_int_t end; /* one past last index */
|
||||
const igraph_vector_int_t *vec;
|
||||
} igraph_eit_t;
|
||||
|
||||
/**
|
||||
* \section IGRAPH_EIT Stepping over the edges
|
||||
*
|
||||
* <para>Just like for vertex iterators, macros are provided for
|
||||
* stepping over a sequence of edges: \ref IGRAPH_EIT_NEXT() goes to
|
||||
* the next edge, \ref IGRAPH_EIT_END() checks whether there are more
|
||||
* edges to visit, \ref IGRAPH_EIT_SIZE() gives the number of edges in
|
||||
* the edge sequence, \ref IGRAPH_EIT_RESET() resets the iterator to
|
||||
* the first edge and \ref IGRAPH_EIT_GET() returns the id of the
|
||||
* current edge.</para>
|
||||
*/
|
||||
|
||||
/**
|
||||
* \define IGRAPH_EIT_NEXT
|
||||
* \brief Next edge.
|
||||
*
|
||||
* Steps the iterator to the next edge. Call this function only if
|
||||
* \ref IGRAPH_EIT_END() returns false.
|
||||
* \param eit The edge iterator to step.
|
||||
*
|
||||
* Time complexity: O(1).
|
||||
*/
|
||||
#define IGRAPH_EIT_NEXT(eit) (++((eit).pos))
|
||||
/**
|
||||
* \define IGRAPH_EIT_END
|
||||
* \brief Are we at the end?
|
||||
*
|
||||
* Checks whether there are more edges to step to.
|
||||
* \param wit The edge iterator to check.
|
||||
* \return Logical value, if true there are no more edges
|
||||
* to step to.
|
||||
*
|
||||
* Time complexity: O(1).
|
||||
*/
|
||||
#define IGRAPH_EIT_END(eit) ((eit).pos >= (eit).end)
|
||||
/**
|
||||
* \define IGRAPH_EIT_SIZE
|
||||
* \brief Number of edges in the iterator.
|
||||
*
|
||||
* Gives the number of edges in an edge iterator.
|
||||
* \param eit The edge iterator.
|
||||
* \return The number of edges.
|
||||
*
|
||||
* Time complexity: O(1).
|
||||
*/
|
||||
#define IGRAPH_EIT_SIZE(eit) ((eit).end - (eit).start)
|
||||
/**
|
||||
* \define IGRAPH_EIT_RESET
|
||||
* \brief Reset an edge iterator.
|
||||
*
|
||||
* Resets an edge iterator. After calling this macro the iterator will
|
||||
* point to the first edge.
|
||||
* \param eit The edge iterator.
|
||||
*
|
||||
* Time complexity: O(1).
|
||||
*/
|
||||
#define IGRAPH_EIT_RESET(eit) ((eit).pos = (eit).start)
|
||||
/**
|
||||
* \define IGRAPH_EIT_GET
|
||||
* \brief Query an edge iterator.
|
||||
*
|
||||
* Gives the edge ID of the current edge pointed to by an iterator.
|
||||
* \param eit The edge iterator.
|
||||
* \return The id of the current edge.
|
||||
*
|
||||
* Time complexity: O(1).
|
||||
*/
|
||||
#define IGRAPH_EIT_GET(eit) \
|
||||
(igraph_int_t)((((eit).type == IGRAPH_EIT_RANGE) ? (eit).pos : \
|
||||
VECTOR(*(eit).vec)[(eit).pos]))
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_eit_create(const igraph_t *graph,
|
||||
igraph_es_t es, igraph_eit_t *eit);
|
||||
IGRAPH_EXPORT void igraph_eit_destroy(const igraph_eit_t *eit);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_eit_as_vector(const igraph_eit_t *eit, igraph_vector_int_t *v);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2010-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_LAPACK_H
|
||||
#define IGRAPH_LAPACK_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_vector.h"
|
||||
#include "igraph_matrix.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
/**
|
||||
* \section about_lapack LAPACK interface in igraph
|
||||
*
|
||||
* <para>
|
||||
* LAPACK is written in Fortran90 and provides routines for solving
|
||||
* systems of simultaneous linear equations, least-squares solutions
|
||||
* of linear systems of equations, eigenvalue problems, and singular
|
||||
* value problems. The associated matrix factorizations (LU, Cholesky,
|
||||
* QR, SVD, Schur, generalized Schur) are also provided, as are
|
||||
* related computations such as reordering of the Schur factorizations
|
||||
* and estimating condition numbers. Dense and banded matrices are
|
||||
* handled, but not general sparse matrices. In all areas, similar
|
||||
* functionality is provided for real and complex matrices, in both
|
||||
* single and double precision.
|
||||
* </para>
|
||||
*
|
||||
* <para>
|
||||
* igraph provides an interface to a very limited set of LAPACK
|
||||
* functions, using the regular igraph data structures.
|
||||
* </para>
|
||||
*
|
||||
* <para>
|
||||
* See more about LAPACK at http://www.netlib.org/lapack/
|
||||
* </para>
|
||||
*/
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_lapack_dgetrf(igraph_matrix_t *a, igraph_vector_int_t *ipiv,
|
||||
int *info);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_lapack_dgetrs(igraph_bool_t transpose, const igraph_matrix_t *a,
|
||||
const igraph_vector_int_t *ipiv, igraph_matrix_t *b);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_lapack_dgesv(igraph_matrix_t *a, igraph_vector_int_t *ipiv,
|
||||
igraph_matrix_t *b, int *info);
|
||||
|
||||
typedef enum { IGRAPH_LAPACK_DSYEV_ALL,
|
||||
IGRAPH_LAPACK_DSYEV_INTERVAL,
|
||||
IGRAPH_LAPACK_DSYEV_SELECT
|
||||
} igraph_lapack_dsyev_which_t;
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_lapack_dsyevr(const igraph_matrix_t *A,
|
||||
igraph_lapack_dsyev_which_t which,
|
||||
igraph_real_t vl, igraph_real_t vu, int vestimate,
|
||||
int il, int iu, igraph_real_t abstol,
|
||||
igraph_vector_t *values, igraph_matrix_t *vectors,
|
||||
igraph_vector_int_t *support);
|
||||
|
||||
/* TODO: should we use complex vectors/matrices? */
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_lapack_dgeev(const igraph_matrix_t *A,
|
||||
igraph_vector_t *valuesreal,
|
||||
igraph_vector_t *valuesimag,
|
||||
igraph_matrix_t *vectorsleft,
|
||||
igraph_matrix_t *vectorsright, int *info);
|
||||
|
||||
typedef enum { IGRAPH_LAPACK_DGEEVX_BALANCE_NONE = 0,
|
||||
IGRAPH_LAPACK_DGEEVX_BALANCE_PERM,
|
||||
IGRAPH_LAPACK_DGEEVX_BALANCE_SCALE,
|
||||
IGRAPH_LAPACK_DGEEVX_BALANCE_BOTH
|
||||
}
|
||||
igraph_lapack_dgeevx_balance_t;
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_lapack_dgeevx(igraph_lapack_dgeevx_balance_t balance,
|
||||
const igraph_matrix_t *A,
|
||||
igraph_vector_t *valuesreal,
|
||||
igraph_vector_t *valuesimag,
|
||||
igraph_matrix_t *vectorsleft,
|
||||
igraph_matrix_t *vectorsright,
|
||||
int *ilo, int *ihi, igraph_vector_t *scale,
|
||||
igraph_real_t *abnrm,
|
||||
igraph_vector_t *rconde,
|
||||
igraph_vector_t *rcondv,
|
||||
int *info);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_lapack_dgehrd(const igraph_matrix_t *A,
|
||||
int ilo, int ihi,
|
||||
igraph_matrix_t *result);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,293 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2009-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_LAYOUT_H
|
||||
#define IGRAPH_LAYOUT_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_constants.h"
|
||||
#include "igraph_datatype.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_iterators.h"
|
||||
#include "igraph_matrix.h"
|
||||
#include "igraph_matrix_list.h"
|
||||
#include "igraph_types.h"
|
||||
#include "igraph_vector.h"
|
||||
#include "igraph_vector_ptr.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
/**
|
||||
* \section about_layouts
|
||||
*
|
||||
* <para>Layout generator functions (or at least most of them) try to place the
|
||||
* vertices and edges of a graph on a 2D plane or in 3D space in a way
|
||||
* which visually pleases the human eye.</para>
|
||||
*
|
||||
* <para>They take a graph object and a number of parameters as arguments
|
||||
* and return an \type igraph_matrix_t, in which each row gives the
|
||||
* coordinates of a vertex.</para>
|
||||
*/
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* Layouts */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_layout_random(const igraph_t *graph, igraph_matrix_t *res);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_layout_circle(const igraph_t *graph, igraph_matrix_t *res,
|
||||
igraph_vs_t order);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_layout_star(const igraph_t *graph, igraph_matrix_t *res,
|
||||
igraph_int_t center, const igraph_vector_int_t *order);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_layout_grid(const igraph_t *graph, igraph_matrix_t *res, igraph_int_t width);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_layout_fruchterman_reingold(const igraph_t *graph,
|
||||
igraph_matrix_t *res,
|
||||
igraph_bool_t use_seed,
|
||||
igraph_int_t niter,
|
||||
igraph_real_t start_temp,
|
||||
igraph_layout_grid_t grid,
|
||||
const igraph_vector_t *weights,
|
||||
const igraph_vector_t *minx,
|
||||
const igraph_vector_t *maxx,
|
||||
const igraph_vector_t *miny,
|
||||
const igraph_vector_t *maxy);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_layout_kamada_kawai(const igraph_t *graph, igraph_matrix_t *res,
|
||||
igraph_bool_t use_seed, igraph_int_t maxiter,
|
||||
igraph_real_t epsilon, igraph_real_t kkconst,
|
||||
const igraph_vector_t *weights,
|
||||
const igraph_vector_t *minx, const igraph_vector_t *maxx,
|
||||
const igraph_vector_t *miny, const igraph_vector_t *maxy);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_layout_lgl(const igraph_t *graph, igraph_matrix_t *res,
|
||||
igraph_int_t maxiter, igraph_real_t maxdelta,
|
||||
igraph_real_t area, igraph_real_t coolexp,
|
||||
igraph_real_t repulserad, igraph_real_t cellsize, igraph_int_t root);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_layout_reingold_tilford(const igraph_t *graph, igraph_matrix_t *res,
|
||||
igraph_neimode_t mode,
|
||||
const igraph_vector_int_t *roots,
|
||||
const igraph_vector_int_t *rootlevel);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_layout_reingold_tilford_circular(const igraph_t *graph,
|
||||
igraph_matrix_t *res,
|
||||
igraph_neimode_t mode,
|
||||
const igraph_vector_int_t *roots,
|
||||
const igraph_vector_int_t *rootlevel);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_layout_sugiyama(
|
||||
const igraph_t *graph, igraph_matrix_t *res, igraph_matrix_list_t *routing,
|
||||
const igraph_vector_int_t* layers, igraph_real_t hgap,
|
||||
igraph_real_t vgap, igraph_int_t maxiter, const igraph_vector_t *weights);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_layout_random_3d(const igraph_t *graph, igraph_matrix_t *res);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_layout_sphere(const igraph_t *graph, igraph_matrix_t *res);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_layout_grid_3d(const igraph_t *graph, igraph_matrix_t *res,
|
||||
igraph_int_t width, igraph_int_t height);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_layout_fruchterman_reingold_3d(const igraph_t *graph,
|
||||
igraph_matrix_t *res,
|
||||
igraph_bool_t use_seed,
|
||||
igraph_int_t niter,
|
||||
igraph_real_t start_temp,
|
||||
const igraph_vector_t *weights,
|
||||
const igraph_vector_t *minx,
|
||||
const igraph_vector_t *maxx,
|
||||
const igraph_vector_t *miny,
|
||||
const igraph_vector_t *maxy,
|
||||
const igraph_vector_t *minz,
|
||||
const igraph_vector_t *maxz);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_layout_kamada_kawai_3d(const igraph_t *graph, igraph_matrix_t *res,
|
||||
igraph_bool_t use_seed, igraph_int_t maxiter,
|
||||
igraph_real_t epsilon, igraph_real_t kkconst,
|
||||
const igraph_vector_t *weights,
|
||||
const igraph_vector_t *minx, const igraph_vector_t *maxx,
|
||||
const igraph_vector_t *miny, const igraph_vector_t *maxy,
|
||||
const igraph_vector_t *minz, const igraph_vector_t *maxz);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_layout_graphopt(const igraph_t *graph,
|
||||
igraph_matrix_t *res, igraph_int_t niter,
|
||||
igraph_real_t node_charge, igraph_real_t node_mass,
|
||||
igraph_real_t spring_length,
|
||||
igraph_real_t spring_constant,
|
||||
igraph_real_t max_sa_movement,
|
||||
igraph_bool_t use_seed);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_layout_mds(const igraph_t *graph, igraph_matrix_t *res,
|
||||
const igraph_matrix_t *dist, igraph_int_t dim);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_layout_bipartite(const igraph_t *graph,
|
||||
const igraph_vector_bool_t *types,
|
||||
igraph_matrix_t *res, igraph_real_t hgap,
|
||||
igraph_real_t vgap, igraph_int_t maxiter);
|
||||
|
||||
IGRAPH_EXPERIMENTAL IGRAPH_EXPORT igraph_error_t igraph_layout_umap(const igraph_t *graph,
|
||||
igraph_matrix_t *res,
|
||||
igraph_bool_t use_seed,
|
||||
const igraph_vector_t *distances,
|
||||
igraph_real_t min_dist,
|
||||
igraph_int_t epochs,
|
||||
igraph_bool_t distances_are_weights);
|
||||
|
||||
IGRAPH_EXPERIMENTAL IGRAPH_EXPORT igraph_error_t igraph_layout_umap_3d(const igraph_t *graph,
|
||||
igraph_matrix_t *res,
|
||||
igraph_bool_t use_seed,
|
||||
const igraph_vector_t *distances,
|
||||
igraph_real_t min_dist,
|
||||
igraph_int_t epochs,
|
||||
igraph_bool_t distances_are_weights);
|
||||
|
||||
IGRAPH_EXPERIMENTAL IGRAPH_EXPORT igraph_error_t igraph_layout_umap_compute_weights(const igraph_t *graph,
|
||||
const igraph_vector_t *distances,
|
||||
igraph_vector_t *weights);
|
||||
|
||||
|
||||
/**
|
||||
* \struct igraph_layout_drl_options_t
|
||||
* Parameters for the DrL layout generator
|
||||
*
|
||||
* \member edge_cut The edge cutting parameter.
|
||||
* Edge cutting is done in the late stages of the
|
||||
* algorithm in order to achieve less dense layouts. Edges are cut
|
||||
* if there is a lot of stress on them (a large value in the
|
||||
* objective function sum). The edge cutting parameter is a value
|
||||
* between 0 and 1 with 0 representing no edge cutting and 1
|
||||
* representing maximal edge cutting. The default value is 32/40.
|
||||
* \member init_iterations Number of iterations, initial phase.
|
||||
* \member init_temperature Start temperature, initial phase.
|
||||
* \member init_attraction Attraction, initial phase.
|
||||
* \member init_damping_mult Damping factor, initial phase.
|
||||
* \member liquid_iterations Number of iterations in the liquid phase.
|
||||
* \member liquid_temperature Start temperature in the liquid phase.
|
||||
* \member liquid_attraction Attraction in the liquid phase.
|
||||
* \member liquid_damping_mult Multiplicatie damping factor, liquid phase.
|
||||
* \member expansion_iterations Number of iterations in the expansion phase.
|
||||
* \member expansion_temperature Start temperature in the expansion phase.
|
||||
* \member expansion_attraction Attraction, expansion phase.
|
||||
* \member expansion_damping_mult Damping factor, expansion phase.
|
||||
* \member cooldown_iterations Number of iterations in the cooldown phase.
|
||||
* \member cooldown_temperature Start temperature in the cooldown phase.
|
||||
* \member cooldown_attraction Attraction in the cooldown phase.
|
||||
* \member cooldown_damping_mult Damping fact int the cooldown phase.
|
||||
* \member crunch_iterations Number of iterations in the crunch phase.
|
||||
* \member crunch_temperature Start temperature in the crunch phase.
|
||||
* \member crunch_attraction Attraction in the crunch phase.
|
||||
* \member crunch_damping_mult Damping factor in the crunch phase.
|
||||
* \member simmer_iterations Number of iterations in the simmer phase.
|
||||
* \member simmer_temperature Start temperature in te simmer phase.
|
||||
* \member simmer_attraction Attraction in the simmer phase.
|
||||
* \member simmer_damping_mult Multiplicative damping factor in the simmer phase.
|
||||
*/
|
||||
|
||||
typedef struct igraph_layout_drl_options_t {
|
||||
igraph_real_t edge_cut;
|
||||
igraph_int_t init_iterations;
|
||||
igraph_real_t init_temperature;
|
||||
igraph_real_t init_attraction;
|
||||
igraph_real_t init_damping_mult;
|
||||
igraph_int_t liquid_iterations;
|
||||
igraph_real_t liquid_temperature;
|
||||
igraph_real_t liquid_attraction;
|
||||
igraph_real_t liquid_damping_mult;
|
||||
igraph_int_t expansion_iterations;
|
||||
igraph_real_t expansion_temperature;
|
||||
igraph_real_t expansion_attraction;
|
||||
igraph_real_t expansion_damping_mult;
|
||||
igraph_int_t cooldown_iterations;
|
||||
igraph_real_t cooldown_temperature;
|
||||
igraph_real_t cooldown_attraction;
|
||||
igraph_real_t cooldown_damping_mult;
|
||||
igraph_int_t crunch_iterations;
|
||||
igraph_real_t crunch_temperature;
|
||||
igraph_real_t crunch_attraction;
|
||||
igraph_real_t crunch_damping_mult;
|
||||
igraph_int_t simmer_iterations;
|
||||
igraph_real_t simmer_temperature;
|
||||
igraph_real_t simmer_attraction;
|
||||
igraph_real_t simmer_damping_mult;
|
||||
} igraph_layout_drl_options_t;
|
||||
|
||||
/**
|
||||
* \typedef igraph_layout_drl_default_t
|
||||
* Predefined parameter templates for the DrL layout generator
|
||||
*
|
||||
* These constants can be used to initialize a set of DrL parameters.
|
||||
* These can then be modified according to the user's needs.
|
||||
* \enumval IGRAPH_LAYOUT_DRL_DEFAULT The deafult parameters.
|
||||
* \enumval IGRAPH_LAYOUT_DRL_COARSEN Slightly modified parameters to
|
||||
* get a coarser layout.
|
||||
* \enumval IGRAPH_LAYOUT_DRL_COARSEST An even coarser layout.
|
||||
* \enumval IGRAPH_LAYOUT_DRL_REFINE Refine an already calculated layout.
|
||||
* \enumval IGRAPH_LAYOUT_DRL_FINAL Finalize an already refined layout.
|
||||
*/
|
||||
|
||||
typedef enum { IGRAPH_LAYOUT_DRL_DEFAULT = 0,
|
||||
IGRAPH_LAYOUT_DRL_COARSEN,
|
||||
IGRAPH_LAYOUT_DRL_COARSEST,
|
||||
IGRAPH_LAYOUT_DRL_REFINE,
|
||||
IGRAPH_LAYOUT_DRL_FINAL
|
||||
} igraph_layout_drl_default_t;
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_layout_drl_options_init(igraph_layout_drl_options_t *options,
|
||||
igraph_layout_drl_default_t templ);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_layout_drl(const igraph_t *graph, igraph_matrix_t *res,
|
||||
igraph_bool_t use_seed,
|
||||
const igraph_layout_drl_options_t *options,
|
||||
const igraph_vector_t *weights);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_layout_drl_3d(const igraph_t *graph, igraph_matrix_t *res,
|
||||
igraph_bool_t use_seed,
|
||||
const igraph_layout_drl_options_t *options,
|
||||
const igraph_vector_t *weights);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_layout_merge_dla(const igraph_vector_ptr_t *graphs,
|
||||
const igraph_matrix_list_t *coords,
|
||||
igraph_matrix_t *res);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_layout_gem(const igraph_t *graph, igraph_matrix_t *res,
|
||||
igraph_bool_t use_seed, igraph_int_t maxiter,
|
||||
igraph_real_t temp_max, igraph_real_t temp_min,
|
||||
igraph_real_t temp_init);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_layout_davidson_harel(const igraph_t *graph, igraph_matrix_t *res,
|
||||
igraph_bool_t use_seed, igraph_int_t maxiter,
|
||||
igraph_int_t fineiter, igraph_real_t cool_fact,
|
||||
igraph_real_t weight_node_dist, igraph_real_t weight_border,
|
||||
igraph_real_t weight_edge_lengths,
|
||||
igraph_real_t weight_edge_crossings,
|
||||
igraph_real_t weight_node_edge_dist);
|
||||
|
||||
/**
|
||||
* \typedef igraph_root_choice_t
|
||||
* \brief Root choice heuristic for tree visualizations.
|
||||
*
|
||||
* Used with \ref igraph_roots_for_tree_layout().
|
||||
*/
|
||||
|
||||
typedef enum {
|
||||
IGRAPH_ROOT_CHOICE_DEGREE,
|
||||
IGRAPH_ROOT_CHOICE_ECCENTRICITY
|
||||
} igraph_root_choice_t;
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_roots_for_tree_layout(
|
||||
const igraph_t *graph,
|
||||
igraph_neimode_t mode,
|
||||
igraph_vector_int_t *roots,
|
||||
igraph_root_choice_t use_eccentricity);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_layout_align(const igraph_t *graph, igraph_matrix_t *layout);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2014-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_LSAP_H
|
||||
#define IGRAPH_LSAP_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_matrix.h"
|
||||
#include "igraph_vector.h"
|
||||
#include "igraph_types.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_solve_lsap(const igraph_matrix_t *c, igraph_int_t n,
|
||||
igraph_vector_int_t *p);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2012-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_MATCHING_H
|
||||
#define IGRAPH_MATCHING_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_datatype.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_types.h"
|
||||
#include "igraph_vector.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* Matchings in graphs */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_is_matching(const igraph_t* graph,
|
||||
const igraph_vector_bool_t* types, const igraph_vector_int_t* matching,
|
||||
igraph_bool_t* result);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_is_maximal_matching(const igraph_t* graph,
|
||||
const igraph_vector_bool_t* types, const igraph_vector_int_t* matching,
|
||||
igraph_bool_t* result);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_maximum_bipartite_matching(const igraph_t* graph,
|
||||
const igraph_vector_bool_t* types, igraph_int_t* matching_size,
|
||||
igraph_real_t* matching_weight, igraph_vector_int_t* matching,
|
||||
const igraph_vector_t* weights, igraph_real_t eps);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2009-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_MATRIX_H
|
||||
#define IGRAPH_MATRIX_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_vector.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* Matrix, very similar to vector */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
#define BASE_IGRAPH_REAL
|
||||
#include "igraph_pmt.h"
|
||||
#include "igraph_matrix_pmt.h"
|
||||
#include "igraph_pmt_off.h"
|
||||
#undef BASE_IGRAPH_REAL
|
||||
|
||||
#define BASE_INT
|
||||
#include "igraph_pmt.h"
|
||||
#include "igraph_matrix_pmt.h"
|
||||
#include "igraph_pmt_off.h"
|
||||
#undef BASE_INT
|
||||
|
||||
#define BASE_CHAR
|
||||
#include "igraph_pmt.h"
|
||||
#include "igraph_matrix_pmt.h"
|
||||
#include "igraph_pmt_off.h"
|
||||
#undef BASE_CHAR
|
||||
|
||||
#define BASE_BOOL
|
||||
#include "igraph_pmt.h"
|
||||
#include "igraph_matrix_pmt.h"
|
||||
#include "igraph_pmt_off.h"
|
||||
#undef BASE_BOOL
|
||||
|
||||
#define BASE_COMPLEX
|
||||
#include "igraph_pmt.h"
|
||||
#include "igraph_matrix_pmt.h"
|
||||
#include "igraph_pmt_off.h"
|
||||
#undef BASE_COMPLEX
|
||||
|
||||
#define IGRAPH_MATRIX_NULL { IGRAPH_VECTOR_NULL, 0, 0 }
|
||||
#define IGRAPH_MATRIX_INIT_FINALLY(m, nr, nc) \
|
||||
do { IGRAPH_CHECK(igraph_matrix_init(m, nr, nc)); \
|
||||
IGRAPH_FINALLY(igraph_matrix_destroy, m); } while (0)
|
||||
#define IGRAPH_MATRIX_INT_INIT_FINALLY(m, nr, nc) \
|
||||
do { IGRAPH_CHECK(igraph_matrix_int_init(m, nr, nc)); \
|
||||
IGRAPH_FINALLY(igraph_matrix_int_destroy, m); } while (0)
|
||||
|
||||
/**
|
||||
* \ingroup matrix
|
||||
* \define MATRIX
|
||||
* \brief Accessing an element of a matrix.
|
||||
*
|
||||
* Note that there are no range checks right now.
|
||||
* This functionality might be redefined as a proper function later.
|
||||
* \param m The matrix object.
|
||||
* \param i The index of the row, starting with zero.
|
||||
* \param j The index of the column, starting with zero.
|
||||
*
|
||||
* Time complexity: O(1).
|
||||
*/
|
||||
#define MATRIX(m,i,j) ((m).data.stor_begin[(m).nrow*(j)+(i)])
|
||||
|
||||
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_bool_t igraph_matrix_all_almost_e(const igraph_matrix_t *lhs,
|
||||
const igraph_matrix_t *rhs,
|
||||
igraph_real_t eps);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_matrix_zapsmall(igraph_matrix_t *m, igraph_real_t tol);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_matrix_complex_zapsmall(igraph_matrix_complex_t *m, igraph_real_t tol);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2022-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_MATRIX_LIST_H
|
||||
#define IGRAPH_MATRIX_LIST_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_matrix.h"
|
||||
#include "igraph_types.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* Flexible list of matrices */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
/* Indicate to igraph_typed_list_pmt.h that we are going to work with _matrices_
|
||||
* of the base type, not the base type directly */
|
||||
#define MATRIX_LIST
|
||||
|
||||
#define BASE_IGRAPH_REAL
|
||||
#include "igraph_pmt.h"
|
||||
#include "igraph_typed_list_pmt.h"
|
||||
#include "igraph_pmt_off.h"
|
||||
#undef BASE_IGRAPH_REAL
|
||||
|
||||
#undef MATRIX_LIST
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* Helper macros */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
#define IGRAPH_MATRIX_LIST_INIT_FINALLY(v, size) \
|
||||
do { IGRAPH_CHECK(igraph_matrix_list_init(v, size)); \
|
||||
IGRAPH_FINALLY(igraph_matrix_list_destroy, v); } while (0)
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,251 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2007-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
typedef struct TYPE(igraph_matrix) {
|
||||
TYPE(igraph_vector) data;
|
||||
igraph_int_t nrow, ncol;
|
||||
} TYPE(igraph_matrix);
|
||||
|
||||
/*---------------*/
|
||||
/* Allocation */
|
||||
/*---------------*/
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_matrix, init)(
|
||||
TYPE(igraph_matrix) *m, igraph_int_t nrow, igraph_int_t ncol);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_matrix, init_array)(
|
||||
TYPE(igraph_matrix)* m, const BASE* data, igraph_int_t nrow, igraph_int_t ncol, igraph_matrix_storage_t storage);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_matrix, init_copy)(
|
||||
TYPE(igraph_matrix) *to, const TYPE(igraph_matrix) *from);
|
||||
IGRAPH_EXPORT void FUNCTION(igraph_matrix, destroy)(TYPE(igraph_matrix) *m);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_int_t FUNCTION(igraph_matrix, capacity)(const TYPE(igraph_matrix) *m);
|
||||
|
||||
/*--------------------*/
|
||||
/* Accessing elements */
|
||||
/*--------------------*/
|
||||
|
||||
/* MATRIX */
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE BASE FUNCTION(igraph_matrix, get)(
|
||||
const TYPE(igraph_matrix) *m, igraph_int_t row, igraph_int_t col);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE BASE* FUNCTION(igraph_matrix, get_ptr)(
|
||||
const TYPE(igraph_matrix) *m, igraph_int_t row, igraph_int_t col);
|
||||
IGRAPH_EXPORT void FUNCTION(igraph_matrix, set)(
|
||||
TYPE(igraph_matrix)* m, igraph_int_t row, igraph_int_t col, BASE value);
|
||||
|
||||
/*------------------------------*/
|
||||
/* Initializing matrix elements */
|
||||
/*------------------------------*/
|
||||
|
||||
IGRAPH_EXPORT void FUNCTION(igraph_matrix, null)(TYPE(igraph_matrix) *m);
|
||||
IGRAPH_EXPORT void FUNCTION(igraph_matrix, fill)(TYPE(igraph_matrix) *m, BASE e);
|
||||
|
||||
/*-----------------------*/
|
||||
/* Matrix views */
|
||||
/*-----------------------*/
|
||||
|
||||
IGRAPH_EXPORT TYPE(igraph_matrix) FUNCTION(igraph_matrix, view)(
|
||||
const BASE *data,
|
||||
igraph_int_t nrow, igraph_int_t ncol);
|
||||
IGRAPH_EXPORT TYPE(igraph_matrix) FUNCTION(igraph_matrix, view_from_vector)(
|
||||
const TYPE(igraph_vector) *v,
|
||||
igraph_int_t ncol
|
||||
);
|
||||
|
||||
/*------------------*/
|
||||
/* Copying matrices */
|
||||
/*------------------*/
|
||||
|
||||
IGRAPH_EXPORT void FUNCTION(igraph_matrix, copy_to)(const TYPE(igraph_matrix) *m, BASE *to, igraph_matrix_storage_t storage);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_matrix, update)(TYPE(igraph_matrix) *to,
|
||||
const TYPE(igraph_matrix) *from);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_matrix, rbind)(TYPE(igraph_matrix) *to,
|
||||
const TYPE(igraph_matrix) *from);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_matrix, cbind)(TYPE(igraph_matrix) *to,
|
||||
const TYPE(igraph_matrix) *from);
|
||||
IGRAPH_EXPORT void FUNCTION(igraph_matrix, swap)(TYPE(igraph_matrix) *m1, TYPE(igraph_matrix) *m2);
|
||||
|
||||
/*--------------------------*/
|
||||
/* Copying rows and columns */
|
||||
/*--------------------------*/
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_matrix, get_row)(
|
||||
const TYPE(igraph_matrix) *m, TYPE(igraph_vector) *res, igraph_int_t index);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_matrix, get_col)(
|
||||
const TYPE(igraph_matrix) *m, TYPE(igraph_vector) *res, igraph_int_t index);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_matrix, set_row)(
|
||||
TYPE(igraph_matrix) *m, const TYPE(igraph_vector) *v, igraph_int_t index);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_matrix, set_col)(
|
||||
TYPE(igraph_matrix) *m, const TYPE(igraph_vector) *v, igraph_int_t index);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_matrix, select_rows)(
|
||||
const TYPE(igraph_matrix) *m, TYPE(igraph_matrix) *res, const igraph_vector_int_t *rows);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_matrix, select_cols)(
|
||||
const TYPE(igraph_matrix) *m, TYPE(igraph_matrix) *res, const igraph_vector_int_t *cols);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_matrix, select_rows_cols)(
|
||||
const TYPE(igraph_matrix) *m, TYPE(igraph_matrix) *res,
|
||||
const igraph_vector_int_t *rows, const igraph_vector_int_t *cols);
|
||||
|
||||
/*-----------------------------*/
|
||||
/* Exchanging rows and columns */
|
||||
/*-----------------------------*/
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_matrix, swap_rows)(
|
||||
TYPE(igraph_matrix) *m, igraph_int_t i, igraph_int_t j);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_matrix, swap_cols)(
|
||||
TYPE(igraph_matrix) *m, igraph_int_t i, igraph_int_t j);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_matrix, swap_rowcol)(
|
||||
TYPE(igraph_matrix) *m, igraph_int_t i, igraph_int_t j);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_matrix, transpose)(TYPE(igraph_matrix) *m);
|
||||
|
||||
/*-----------------------------*/
|
||||
/* Matrix operations */
|
||||
/*-----------------------------*/
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_matrix, add)(TYPE(igraph_matrix) *m1,
|
||||
const TYPE(igraph_matrix) *m2);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_matrix, sub)(TYPE(igraph_matrix) *m1,
|
||||
const TYPE(igraph_matrix) *m2);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_matrix, mul_elements)(TYPE(igraph_matrix) *m1,
|
||||
const TYPE(igraph_matrix) *m2);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_matrix, div_elements)(TYPE(igraph_matrix) *m1,
|
||||
const TYPE(igraph_matrix) *m2);
|
||||
IGRAPH_EXPORT void FUNCTION(igraph_matrix, scale)(TYPE(igraph_matrix) *m, BASE by);
|
||||
IGRAPH_EXPORT void FUNCTION(igraph_matrix, add_constant)(TYPE(igraph_matrix) *m, BASE plus);
|
||||
|
||||
/*-----------------------------*/
|
||||
/* Finding minimum and maximum */
|
||||
/*-----------------------------*/
|
||||
|
||||
#ifndef NOTORDERED
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_real_t FUNCTION(igraph_matrix, min)(const TYPE(igraph_matrix) *m);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_real_t FUNCTION(igraph_matrix, max)(const TYPE(igraph_matrix) *m);
|
||||
IGRAPH_EXPORT void FUNCTION(igraph_matrix, which_min)(
|
||||
const TYPE(igraph_matrix) *m, igraph_int_t *i, igraph_int_t *j);
|
||||
IGRAPH_EXPORT void FUNCTION(igraph_matrix, which_max)(
|
||||
const TYPE(igraph_matrix) *m, igraph_int_t *i, igraph_int_t *j);
|
||||
IGRAPH_EXPORT void FUNCTION(igraph_matrix, minmax)(
|
||||
const TYPE(igraph_matrix) *m, BASE *min, BASE *max);
|
||||
IGRAPH_EXPORT void FUNCTION(igraph_matrix, which_minmax)(
|
||||
const TYPE(igraph_matrix) *m, igraph_int_t *imin, igraph_int_t *jmin,
|
||||
igraph_int_t *imax, igraph_int_t *jmax);
|
||||
#endif
|
||||
|
||||
/*------------------------------*/
|
||||
/* Comparison */
|
||||
/*------------------------------*/
|
||||
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_bool_t FUNCTION(igraph_matrix, all_e)(const TYPE(igraph_matrix) *lhs,
|
||||
const TYPE(igraph_matrix) *rhs);
|
||||
#ifndef NOTORDERED
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_bool_t FUNCTION(igraph_matrix, all_l)(const TYPE(igraph_matrix) *lhs,
|
||||
const TYPE(igraph_matrix) *rhs);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_bool_t FUNCTION(igraph_matrix, all_g)(const TYPE(igraph_matrix) *lhs,
|
||||
const TYPE(igraph_matrix) *rhs);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_bool_t FUNCTION(igraph_matrix, all_le)(const TYPE(igraph_matrix) *lhs,
|
||||
const TYPE(igraph_matrix) *rhs);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_bool_t FUNCTION(igraph_matrix, all_ge)(const TYPE(igraph_matrix) *lhs,
|
||||
const TYPE(igraph_matrix) *rhs);
|
||||
#endif
|
||||
|
||||
/*-------------------*/
|
||||
/* Matrix properties */
|
||||
/*-------------------*/
|
||||
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_bool_t FUNCTION(igraph_matrix, isnull)(const TYPE(igraph_matrix) *m);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_bool_t FUNCTION(igraph_matrix, empty)(const TYPE(igraph_matrix) *m);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_int_t FUNCTION(igraph_matrix, size)(const TYPE(igraph_matrix) *m);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_int_t FUNCTION(igraph_matrix, nrow)(const TYPE(igraph_matrix) *m);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_int_t FUNCTION(igraph_matrix, ncol)(const TYPE(igraph_matrix) *m);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_bool_t FUNCTION(igraph_matrix, is_symmetric)(const TYPE(igraph_matrix) *m);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE BASE FUNCTION(igraph_matrix, sum)(const TYPE(igraph_matrix) *m);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE BASE FUNCTION(igraph_matrix, prod)(const TYPE(igraph_matrix) *m);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_matrix, rowsum)(const TYPE(igraph_matrix) *m,
|
||||
TYPE(igraph_vector) *res);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_matrix, colsum)(const TYPE(igraph_matrix) *m,
|
||||
TYPE(igraph_vector) *res);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_bool_t FUNCTION(igraph_matrix, is_equal)(const TYPE(igraph_matrix) *m1,
|
||||
const TYPE(igraph_matrix) *m2);
|
||||
#ifndef NOTORDERED
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_real_t FUNCTION(igraph_matrix, maxdifference)(const TYPE(igraph_matrix) *m1,
|
||||
const TYPE(igraph_matrix) *m2);
|
||||
#endif
|
||||
|
||||
/*------------------------*/
|
||||
/* Searching for elements */
|
||||
/*------------------------*/
|
||||
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_bool_t FUNCTION(igraph_matrix, contains)(
|
||||
const TYPE(igraph_matrix) *m, BASE e);
|
||||
IGRAPH_EXPORT igraph_bool_t FUNCTION(igraph_matrix, search)(
|
||||
const TYPE(igraph_matrix) *m, igraph_int_t from, BASE what,
|
||||
igraph_int_t *pos, igraph_int_t *row, igraph_int_t *col);
|
||||
|
||||
/*------------------------*/
|
||||
/* Resizing operations */
|
||||
/*------------------------*/
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_matrix, resize)(
|
||||
TYPE(igraph_matrix) *m, igraph_int_t nrow, igraph_int_t ncol);
|
||||
IGRAPH_EXPORT void FUNCTION(igraph_matrix, resize_min)(
|
||||
TYPE(igraph_matrix) *m);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_matrix, add_cols)(
|
||||
TYPE(igraph_matrix) *m, igraph_int_t n);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_matrix, add_rows)(
|
||||
TYPE(igraph_matrix) *m, igraph_int_t n);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_matrix, remove_col)(
|
||||
TYPE(igraph_matrix) *m, igraph_int_t col);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_matrix, remove_row)(
|
||||
TYPE(igraph_matrix) *m, igraph_int_t row);
|
||||
|
||||
/*------------------------*/
|
||||
/* Print as text */
|
||||
/*------------------------*/
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_matrix, print)(const TYPE(igraph_matrix) *m);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_matrix, fprint)(const TYPE(igraph_matrix) *m, FILE *file);
|
||||
|
||||
#ifdef OUT_FORMAT
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_matrix, printf)(const TYPE(igraph_matrix) *m, const char *format);
|
||||
#endif /* OUT_FORMAT */
|
||||
|
||||
/*-----------------------------------------*/
|
||||
/* Operations specific to complex matrices */
|
||||
/*-----------------------------------------*/
|
||||
|
||||
#ifdef BASE_COMPLEX
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_matrix_complex_real(const igraph_matrix_complex_t *v,
|
||||
igraph_matrix_t *real);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_matrix_complex_imag(const igraph_matrix_complex_t *v,
|
||||
igraph_matrix_t *imag);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_matrix_complex_realimag(const igraph_matrix_complex_t *v,
|
||||
igraph_matrix_t *real,
|
||||
igraph_matrix_t *imag);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_matrix_complex_create(igraph_matrix_complex_t *v,
|
||||
const igraph_matrix_t *real,
|
||||
const igraph_matrix_t *imag);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_matrix_complex_create_polar(igraph_matrix_complex_t *v,
|
||||
const igraph_matrix_t *r,
|
||||
const igraph_matrix_t *theta);
|
||||
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_bool_t igraph_matrix_complex_all_almost_e(igraph_matrix_complex_t *lhs,
|
||||
igraph_matrix_complex_t *rhs,
|
||||
igraph_real_t eps);
|
||||
|
||||
#endif /* BASE_COMPLEX */
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_matrix, permdelete_rows)(
|
||||
TYPE(igraph_matrix) *m, igraph_int_t *index, igraph_int_t nremove);
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2003-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_MEMORY_H
|
||||
#define IGRAPH_MEMORY_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
/* Helper macro to check if n*sizeof(t) overflows in IGRAPH_CALLOC and IGRAPH_REALLOC */
|
||||
#define IGRAPH_I_ALLOC_CHECK_OVERFLOW(n,t,expr) \
|
||||
(t*) ((0 <= (n) && ((size_t)(n)) <= SIZE_MAX / sizeof(t)) ? (expr) : NULL)
|
||||
|
||||
#define IGRAPH_CALLOC(n,t) IGRAPH_I_ALLOC_CHECK_OVERFLOW(n, t, calloc(sizeof(t) * ((n) > 0 ? (n) : 1), 1))
|
||||
#define IGRAPH_MALLOC(n) malloc( (size_t) ((n) > 0 ? (n) : 1) )
|
||||
#define IGRAPH_REALLOC(p,n,t) IGRAPH_I_ALLOC_CHECK_OVERFLOW(n, t, realloc((void*)(p), sizeof(t) * ((n) > 0 ? (n) : 1)))
|
||||
#define IGRAPH_FREE(p) (free( (void *)(p) ), (p) = NULL)
|
||||
|
||||
IGRAPH_EXPORT void *igraph_calloc(size_t count, size_t size);
|
||||
IGRAPH_EXPORT void *igraph_malloc(size_t size);
|
||||
IGRAPH_EXPORT void *igraph_realloc(void* ptr, size_t size);
|
||||
IGRAPH_EXPORT void igraph_free(void *ptr);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2009-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_MIXING_H
|
||||
#define IGRAPH_MIXING_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_types.h"
|
||||
#include "igraph_datatype.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_vector.h"
|
||||
#include "igraph_matrix.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_assortativity_nominal(
|
||||
const igraph_t *graph, const igraph_vector_t *weights,
|
||||
const igraph_vector_int_t *types,
|
||||
igraph_real_t *res,
|
||||
igraph_bool_t directed, igraph_bool_t normalized);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_assortativity(
|
||||
const igraph_t *graph, const igraph_vector_t *weights,
|
||||
const igraph_vector_t *values, const igraph_vector_t *values_in,
|
||||
igraph_real_t *res,
|
||||
igraph_bool_t directed, igraph_bool_t normalized);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_assortativity_degree(const igraph_t *graph,
|
||||
igraph_real_t *res,
|
||||
igraph_bool_t directed);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_joint_degree_matrix(
|
||||
const igraph_t *graph, const igraph_vector_t *weights,
|
||||
igraph_matrix_t *jdm,
|
||||
igraph_int_t dout, igraph_int_t din);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_joint_degree_distribution(
|
||||
const igraph_t *graph, const igraph_vector_t *weights, igraph_matrix_t *p,
|
||||
igraph_neimode_t from_mode, igraph_neimode_t to_mode,
|
||||
igraph_bool_t directed_neighbors,
|
||||
igraph_bool_t normalized,
|
||||
igraph_int_t max_from_degree, igraph_int_t max_to_degree);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_joint_type_distribution(
|
||||
const igraph_t *graph, const igraph_vector_t *weights,
|
||||
igraph_matrix_t *p,
|
||||
const igraph_vector_int_t *from_types, const igraph_vector_int_t *to_types,
|
||||
igraph_bool_t directed, igraph_bool_t normalized);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2009-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_MOTIFS_H
|
||||
#define IGRAPH_MOTIFS_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_types.h"
|
||||
#include "igraph_datatype.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_iterators.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* Graph motifs */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* \typedef igraph_motifs_handler_t
|
||||
* \brief Callback type for \c igraph_motifs_randesu_callback.
|
||||
*
|
||||
* \ref igraph_motifs_randesu_callback() calls a specified callback
|
||||
* function whenever a new motif is found during a motif search. This
|
||||
* callback function must be of type \c igraph_motifs_handler_t. It has
|
||||
* the following arguments:
|
||||
*
|
||||
* \param graph The graph that that algorithm is working on. Of course
|
||||
* this must not be modified.
|
||||
* \param vids The IDs of the vertices in the motif that has just been
|
||||
* found. This vector is owned by the motif search algorithm, so do not
|
||||
* modify or destroy it; make a copy of it if you need it later.
|
||||
* \param isoclass The isomorphism class of the motif that has just been
|
||||
* found. Use \ref igraph_graph_count() to find the maximum possible
|
||||
* isoclass for graphs of a given size. See \ref igraph_isoclass and
|
||||
* \ref igraph_isoclass_subgraph for more information.
|
||||
* \param extra The extra argument that was passed to \ref
|
||||
* igraph_motifs_randesu_callback().
|
||||
* \return \c IGRAPH_SUCCESS to continue the motif search,
|
||||
* \c IGRAPH_STOP to stop the motif search and return to the caller
|
||||
* normally. Any other return value is interpreted as an igraph error code,
|
||||
* which will terminate the search and return the same error code to the
|
||||
* caller.
|
||||
*
|
||||
* \sa \ref igraph_motifs_randesu_callback()
|
||||
*/
|
||||
|
||||
typedef igraph_error_t igraph_motifs_handler_t(const igraph_t *graph,
|
||||
const igraph_vector_int_t *vids,
|
||||
igraph_int_t isoclass,
|
||||
void *extra);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_motifs_randesu(const igraph_t *graph, igraph_vector_t *hist,
|
||||
igraph_int_t size, const igraph_vector_t *cut_prob);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_motifs_randesu_callback(const igraph_t *graph, igraph_int_t size,
|
||||
const igraph_vector_t *cut_prob,
|
||||
igraph_motifs_handler_t *callback,
|
||||
void* extra);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_motifs_randesu_estimate(const igraph_t *graph, igraph_real_t *est,
|
||||
igraph_int_t size, const igraph_vector_t *cut_prob,
|
||||
igraph_int_t sample_size,
|
||||
const igraph_vector_int_t *sample);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_motifs_randesu_no(const igraph_t *graph, igraph_real_t *no,
|
||||
igraph_int_t size, const igraph_vector_t *cut_prob);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_dyad_census(const igraph_t *graph, igraph_real_t *mut,
|
||||
igraph_real_t *asym, igraph_real_t *null);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_triad_census(const igraph_t *igraph, igraph_vector_t *res);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_count_adjacent_triangles(const igraph_t *graph,
|
||||
igraph_vector_t *res,
|
||||
igraph_vs_t vids);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_list_triangles(const igraph_t *graph,
|
||||
igraph_vector_int_t *res);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_count_triangles(const igraph_t *graph, igraph_real_t *res);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2009-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_NEIGHBORHOOD_H
|
||||
#define IGRAPH_NEIGHBORHOOD_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_datatype.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_graph_list.h"
|
||||
#include "igraph_iterators.h"
|
||||
#include "igraph_vector_list.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_neighborhood_size(const igraph_t *graph, igraph_vector_int_t *res,
|
||||
igraph_vs_t vids, igraph_int_t order,
|
||||
igraph_neimode_t mode, igraph_int_t mindist);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_neighborhood(const igraph_t *graph, igraph_vector_int_list_t *res,
|
||||
igraph_vs_t vids, igraph_int_t order,
|
||||
igraph_neimode_t mode, igraph_int_t mindist);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_neighborhood_graphs(const igraph_t *graph, igraph_graph_list_t *res,
|
||||
igraph_vs_t vids, igraph_int_t order,
|
||||
igraph_neimode_t mode,
|
||||
igraph_int_t mindist);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2009-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_NONGRAPH_H
|
||||
#define IGRAPH_NONGRAPH_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_types.h"
|
||||
#include "igraph_vector.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
/**
|
||||
* \def IGRAPH_SHORTEST_PATH_EPSILON
|
||||
*
|
||||
* Relative error threshold used in weighted shortest path calculations
|
||||
* to decide whether two shortest paths are of equal length.
|
||||
*/
|
||||
#define IGRAPH_SHORTEST_PATH_EPSILON 1e-10
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* Other, not graph related */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* \struct igraph_plfit_result_t
|
||||
* \brief Result of fitting a power-law distribution to a vector.
|
||||
*
|
||||
* This data structure contains the result of \ref igraph_power_law_fit(),
|
||||
* which tries to fit a power-law distribution to a vector of numbers. The
|
||||
* structure contains the following members:
|
||||
*
|
||||
* \member continuous Whether the fitted power-law distribution was continuous
|
||||
* or discrete.
|
||||
* \member alpha The exponent of the fitted power-law distribution.
|
||||
* \member xmin The minimum value from which the power-law distribution was
|
||||
* fitted. In other words, only the values larger than \c xmin
|
||||
* were used from the input vector.
|
||||
* \member L The log-likelihood of the fitted parameters; in other words,
|
||||
* the probability of observing the input vector given the
|
||||
* parameters.
|
||||
* \member D The test statistic of a Kolmogorov-Smirnov test that compares
|
||||
* the fitted distribution with the input vector. Smaller scores
|
||||
* denote better fit.
|
||||
* \member p The p-value of the Kolmogorov-Smirnov test; \c NaN if it has
|
||||
* not been calculated yet. Small p-values (less than 0.05)
|
||||
* indicate that the test rejected the hypothesis that the
|
||||
* original data could have been drawn from the fitted power-law
|
||||
* distribution.
|
||||
* \member data The vector containing the original input data. May not be valid
|
||||
* any more if the caller already destroyed the vector.
|
||||
*/
|
||||
typedef struct igraph_plfit_result_t {
|
||||
igraph_bool_t continuous;
|
||||
igraph_real_t alpha;
|
||||
igraph_real_t xmin;
|
||||
igraph_real_t L;
|
||||
igraph_real_t D;
|
||||
const igraph_vector_t* data;
|
||||
} igraph_plfit_result_t;
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_running_mean(const igraph_vector_t *data, igraph_vector_t *res,
|
||||
igraph_int_t binwidth);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_random_sample(igraph_vector_int_t *res, igraph_int_t l, igraph_int_t h,
|
||||
igraph_int_t length);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_CONST igraph_bool_t igraph_almost_equals(double a, double b, double eps);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_CONST int igraph_cmp_epsilon(double a, double b, double eps);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_power_law_fit(
|
||||
const igraph_vector_t* vector, igraph_plfit_result_t* result,
|
||||
igraph_real_t xmin, igraph_bool_t force_continuous
|
||||
);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_plfit_result_calculate_p_value(
|
||||
const igraph_plfit_result_t* model, igraph_real_t* result, igraph_real_t precision
|
||||
);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2009-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_OPERATORS_H
|
||||
#define IGRAPH_OPERATORS_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_attributes.h"
|
||||
#include "igraph_constants.h"
|
||||
#include "igraph_datatype.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_graphicality.h"
|
||||
#include "igraph_types.h"
|
||||
#include "igraph_vector_list.h"
|
||||
#include "igraph_vector_ptr.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* Graph operators */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* \typedef igraph_rewiring_stats_t
|
||||
* \brief Data structure holding statistics from graph rewiring.
|
||||
*
|
||||
* \param successful_swaps Number of successful rewiring trials (successful swaps).
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
igraph_int_t successful_swaps;
|
||||
|
||||
/* unused members added at the end to allow us to extend the stats in the future
|
||||
* without breaking ABI compatibility. Do not use these fields in your own code */
|
||||
|
||||
igraph_int_t unused1_;
|
||||
igraph_int_t unused2_;
|
||||
igraph_int_t unused3_;
|
||||
} igraph_rewiring_stats_t;
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_add_edge(igraph_t *graph, igraph_int_t from, igraph_int_t to);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_disjoint_union(igraph_t *res,
|
||||
const igraph_t *left, const igraph_t *right);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_disjoint_union_many(igraph_t *res,
|
||||
const igraph_vector_ptr_t *graphs);
|
||||
IGRAPH_EXPORT 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);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_union_many(igraph_t *res, const igraph_vector_ptr_t *graphs,
|
||||
igraph_vector_int_list_t *edgemaps);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_join(igraph_t *res, const igraph_t *left,
|
||||
const igraph_t *right);
|
||||
IGRAPH_EXPORT 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);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_intersection_many(igraph_t *res,
|
||||
const igraph_vector_ptr_t *graphs,
|
||||
igraph_vector_int_list_t *edgemaps);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_difference(igraph_t *res,
|
||||
const igraph_t *orig, const igraph_t *sub);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_complementer(igraph_t *res, const igraph_t *graph,
|
||||
igraph_bool_t loops);
|
||||
IGRAPH_EXPORT 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);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_contract_vertices(igraph_t *graph,
|
||||
const igraph_vector_int_t *mapping,
|
||||
const igraph_attribute_combination_t *vertex_comb);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_permute_vertices(const igraph_t *graph, igraph_t *res,
|
||||
const igraph_vector_int_t *permutation);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_connect_neighborhood(igraph_t *graph, igraph_int_t order,
|
||||
igraph_neimode_t mode);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_graph_power(const igraph_t *graph, igraph_t *res,
|
||||
igraph_int_t order, igraph_bool_t directed);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_rewire(igraph_t *graph, igraph_int_t n, igraph_edge_type_sw_t allowed_edge_types,
|
||||
igraph_rewiring_stats_t *stats);
|
||||
IGRAPH_EXPORT 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);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_induced_subgraph_map(const igraph_t *graph, igraph_t *res,
|
||||
igraph_vs_t vids,
|
||||
igraph_subgraph_implementation_t impl,
|
||||
igraph_vector_int_t *map,
|
||||
igraph_vector_int_t *invmap);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_induced_subgraph(const igraph_t *graph, igraph_t *res,
|
||||
igraph_vs_t vids, igraph_subgraph_implementation_t impl);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_induced_subgraph_edges(
|
||||
const igraph_t *graph, igraph_vs_t vids, igraph_vector_int_t *edges);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_subgraph_from_edges(const igraph_t *graph, igraph_t *res,
|
||||
igraph_es_t eids, igraph_bool_t delete_vertices);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_reverse_edges(igraph_t *graph, igraph_es_t eids);
|
||||
IGRAPH_EXPERIMENTAL IGRAPH_EXPORT igraph_error_t igraph_product(igraph_t *res,
|
||||
const igraph_t *g1,
|
||||
const igraph_t *g2,
|
||||
igraph_product_t type);
|
||||
IGRAPH_EXPERIMENTAL IGRAPH_EXPORT igraph_error_t igraph_rooted_product(igraph_t *res,
|
||||
const igraph_t *g1,
|
||||
const igraph_t *g2,
|
||||
igraph_int_t root);
|
||||
IGRAPH_EXPERIMENTAL IGRAPH_EXPORT igraph_error_t igraph_mycielskian(const igraph_t *graph, igraph_t *res, igraph_int_t k);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,301 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2009-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_PATHS_H
|
||||
#define IGRAPH_PATHS_H
|
||||
|
||||
#include "igraph_constants.h"
|
||||
#include "igraph_datatype.h"
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_iterators.h"
|
||||
#include "igraph_matrix.h"
|
||||
#include "igraph_types.h"
|
||||
#include "igraph_vector.h"
|
||||
#include "igraph_vector_list.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
/**
|
||||
* \typedef igraph_astar_heuristic_func_t
|
||||
* \brief Distance estimator for A* algorithm.
|
||||
*
|
||||
* \ref igraph_get_shortest_path_astar() uses a heuristic based on a distance
|
||||
* estimate to the target vertex to guide its search, and determine
|
||||
* which vertex to try next. The heuristic function is expected to compute
|
||||
* an estimate of the distance between \p from and \p to. In order for
|
||||
* \ref igraph_get_shortest_path_astar() to find an exact shortest path,
|
||||
* the distance must not be overestimated, i.e. the heuristic function
|
||||
* must be \em admissible.
|
||||
*
|
||||
* \param result The result of the heuristic, i.e. the estimated distance.
|
||||
* A lower value will mean this vertex will be a better candidate for
|
||||
* exploration.
|
||||
* \param from The vertex ID of the candidate vertex will be passed here.
|
||||
* \param to The vertex ID of the endpoint of the path, i.e. the \c to parameter
|
||||
* given to \ref igraph_get_shortest_path_astar(), will be passed here.
|
||||
* \param extra The \c extra argument that was passed to
|
||||
* \ref igraph_get_shortest_path_astar().
|
||||
* \return Error code. Must return \c IGRAPH_SUCCESS if there were no errors.
|
||||
* This can be used to break off the algorithm if something unexpected happens,
|
||||
* like a failed memory allocation (\c IGRAPH_ENOMEM).
|
||||
*
|
||||
* \sa \ref igraph_get_shortest_path_astar()
|
||||
*/
|
||||
typedef igraph_error_t igraph_astar_heuristic_func_t(
|
||||
igraph_real_t *result,
|
||||
igraph_int_t from, igraph_int_t to,
|
||||
void *extra);
|
||||
|
||||
typedef enum {
|
||||
IGRAPH_FLOYD_WARSHALL_AUTOMATIC = 0,
|
||||
IGRAPH_FLOYD_WARSHALL_ORIGINAL = 1,
|
||||
IGRAPH_FLOYD_WARSHALL_TREE = 2
|
||||
} igraph_floyd_warshall_algorithm_t;
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_diameter(
|
||||
const igraph_t *graph, const igraph_vector_t *weights, igraph_real_t *res,
|
||||
igraph_int_t *from, igraph_int_t *to,
|
||||
igraph_vector_int_t *vertex_path, igraph_vector_int_t *edge_path,
|
||||
igraph_bool_t directed, igraph_bool_t unconn
|
||||
);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_distances(
|
||||
const igraph_t *graph, const igraph_vector_t *weights, igraph_matrix_t *res,
|
||||
igraph_vs_t from, igraph_vs_t to, igraph_neimode_t mode
|
||||
);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_distances_bellman_ford(const igraph_t *graph,
|
||||
igraph_matrix_t *res,
|
||||
igraph_vs_t from,
|
||||
igraph_vs_t to,
|
||||
const igraph_vector_t *weights,
|
||||
igraph_neimode_t mode);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_distances_dijkstra(const igraph_t *graph,
|
||||
igraph_matrix_t *res,
|
||||
igraph_vs_t from,
|
||||
igraph_vs_t to,
|
||||
const igraph_vector_t *weights,
|
||||
igraph_neimode_t mode);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_distances_johnson(const igraph_t *graph,
|
||||
igraph_matrix_t *res,
|
||||
igraph_vs_t from,
|
||||
igraph_vs_t to,
|
||||
const igraph_vector_t *weights,
|
||||
igraph_neimode_t mode);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_distances_floyd_warshall(const igraph_t *graph,
|
||||
igraph_matrix_t *res,
|
||||
igraph_vs_t from,
|
||||
igraph_vs_t to,
|
||||
const igraph_vector_t *weights,
|
||||
igraph_neimode_t mode,
|
||||
igraph_floyd_warshall_algorithm_t method);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_distances_cutoff(
|
||||
const igraph_t *graph, const igraph_vector_t *weights, igraph_matrix_t *res,
|
||||
igraph_vs_t from, igraph_vs_t to, igraph_neimode_t mode, igraph_real_t cutoff
|
||||
);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_distances_dijkstra_cutoff(
|
||||
const igraph_t *graph, igraph_matrix_t *res, igraph_vs_t from, igraph_vs_t to,
|
||||
const igraph_vector_t *weights, igraph_neimode_t mode, igraph_real_t cutoff
|
||||
);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_get_shortest_paths(
|
||||
const igraph_t *graph, const igraph_vector_t *weights,
|
||||
igraph_vector_int_list_t *vertices, igraph_vector_int_list_t *edges,
|
||||
igraph_int_t from, igraph_vs_t to, igraph_neimode_t mode,
|
||||
igraph_vector_int_t *parents, igraph_vector_int_t *inbound_edges
|
||||
);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_get_shortest_paths_bellman_ford(const igraph_t *graph,
|
||||
igraph_vector_int_list_t *vertices,
|
||||
igraph_vector_int_list_t *edges,
|
||||
igraph_int_t from,
|
||||
igraph_vs_t to,
|
||||
const igraph_vector_t *weights,
|
||||
igraph_neimode_t mode,
|
||||
igraph_vector_int_t *parents,
|
||||
igraph_vector_int_t *inbound_edges);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_get_shortest_paths_dijkstra(const igraph_t *graph,
|
||||
igraph_vector_int_list_t *vertices,
|
||||
igraph_vector_int_list_t *edges,
|
||||
igraph_int_t from,
|
||||
igraph_vs_t to,
|
||||
const igraph_vector_t *weights,
|
||||
igraph_neimode_t mode,
|
||||
igraph_vector_int_t *parents,
|
||||
igraph_vector_int_t *inbound_edges);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_get_shortest_path(
|
||||
const igraph_t *graph, const igraph_vector_t *weights,
|
||||
igraph_vector_int_t *vertices, igraph_vector_int_t *edges,
|
||||
igraph_int_t from, igraph_int_t to, igraph_neimode_t mode
|
||||
);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_get_shortest_path_bellman_ford(const igraph_t *graph,
|
||||
igraph_vector_int_t *vertices,
|
||||
igraph_vector_int_t *edges,
|
||||
igraph_int_t from,
|
||||
igraph_int_t to,
|
||||
const igraph_vector_t *weights,
|
||||
igraph_neimode_t mode);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_get_shortest_path_dijkstra(const igraph_t *graph,
|
||||
igraph_vector_int_t *vertices,
|
||||
igraph_vector_int_t *edges,
|
||||
igraph_int_t from,
|
||||
igraph_int_t to,
|
||||
const igraph_vector_t *weights,
|
||||
igraph_neimode_t mode);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_get_shortest_path_astar(const igraph_t *graph,
|
||||
igraph_vector_int_t *vertices,
|
||||
igraph_vector_int_t *edges,
|
||||
igraph_int_t from,
|
||||
igraph_int_t to,
|
||||
const igraph_vector_t *weights,
|
||||
igraph_neimode_t mode,
|
||||
igraph_astar_heuristic_func_t *heuristic,
|
||||
void *extra);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_get_all_shortest_paths(
|
||||
const igraph_t *graph, const igraph_vector_t *weights,
|
||||
igraph_vector_int_list_t *vertices, igraph_vector_int_list_t *edges,
|
||||
igraph_vector_int_t *nrgeo, igraph_int_t from, igraph_vs_t to,
|
||||
igraph_neimode_t mode
|
||||
);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_get_all_shortest_paths_dijkstra(const igraph_t *graph,
|
||||
igraph_vector_int_list_t *vertices,
|
||||
igraph_vector_int_list_t *edges,
|
||||
igraph_vector_int_t *nrgeo,
|
||||
igraph_int_t from, igraph_vs_t to,
|
||||
const igraph_vector_t *weights,
|
||||
igraph_neimode_t mode);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_average_path_length(
|
||||
const igraph_t *graph, const igraph_vector_t *weights, igraph_real_t *res,
|
||||
igraph_real_t *unconn_pairs, igraph_bool_t directed, igraph_bool_t unconn
|
||||
);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_path_length_hist(const igraph_t *graph, igraph_vector_t *res,
|
||||
igraph_real_t *unconnected, igraph_bool_t directed);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_global_efficiency(
|
||||
const igraph_t *graph, const igraph_vector_t *weights, igraph_real_t *res,
|
||||
igraph_bool_t directed
|
||||
);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_local_efficiency(
|
||||
const igraph_t *graph, const igraph_vector_t *weights, igraph_vector_t *res,
|
||||
igraph_vs_t vids, igraph_bool_t directed, igraph_neimode_t mode
|
||||
);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_average_local_efficiency(
|
||||
const igraph_t *graph, const igraph_vector_t *weights, igraph_real_t *res,
|
||||
igraph_bool_t directed, igraph_neimode_t mode
|
||||
);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_eccentricity(
|
||||
const igraph_t *graph, const igraph_vector_t *weights, igraph_vector_t *res,
|
||||
igraph_vs_t vids, igraph_neimode_t mode
|
||||
);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_radius(
|
||||
const igraph_t *graph, const igraph_vector_t *weights, igraph_real_t *radius,
|
||||
igraph_neimode_t mode
|
||||
);
|
||||
|
||||
IGRAPH_EXPERIMENTAL IGRAPH_EXPORT igraph_error_t igraph_graph_center(
|
||||
const igraph_t *graph, const igraph_vector_t *weights,
|
||||
igraph_vector_int_t *res, igraph_neimode_t mode
|
||||
);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_pseudo_diameter(
|
||||
const igraph_t *graph, const igraph_vector_t *weights,
|
||||
igraph_real_t *diameter, igraph_int_t vid_start,
|
||||
igraph_int_t *from, igraph_int_t *to,
|
||||
igraph_bool_t directed, igraph_bool_t unconn
|
||||
);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t
|
||||
igraph_get_all_simple_paths(const igraph_t *graph, igraph_vector_int_list_t *res, igraph_int_t from,
|
||||
const igraph_vs_t to, igraph_neimode_t mode, igraph_int_t minlen,
|
||||
igraph_int_t maxlen, igraph_int_t max_results);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_random_walk(const igraph_t *graph,
|
||||
const igraph_vector_t *weights,
|
||||
igraph_vector_int_t *vertices,
|
||||
igraph_vector_int_t *edges,
|
||||
igraph_int_t start,
|
||||
igraph_neimode_t mode,
|
||||
igraph_int_t steps,
|
||||
igraph_random_walk_stuck_t stuck);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_get_k_shortest_paths(const igraph_t *graph,
|
||||
const igraph_vector_t *weights,
|
||||
igraph_vector_int_list_t *vertex_paths,
|
||||
igraph_vector_int_list_t *edge_paths,
|
||||
igraph_int_t k,
|
||||
igraph_int_t from,
|
||||
igraph_int_t to,
|
||||
igraph_neimode_t mode);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_spanner(const igraph_t *graph,
|
||||
igraph_vector_int_t *spanner,
|
||||
igraph_real_t stretch,
|
||||
const igraph_vector_t *weights);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_get_widest_paths(const igraph_t *graph,
|
||||
igraph_vector_int_list_t *vertices,
|
||||
igraph_vector_int_list_t *edges,
|
||||
igraph_int_t from,
|
||||
igraph_vs_t to,
|
||||
const igraph_vector_t *weights,
|
||||
igraph_neimode_t mode,
|
||||
igraph_vector_int_t *parents,
|
||||
igraph_vector_int_t *inbound_edges);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_get_widest_path(const igraph_t *graph,
|
||||
igraph_vector_int_t *vertices,
|
||||
igraph_vector_int_t *edges,
|
||||
igraph_int_t from,
|
||||
igraph_int_t to,
|
||||
const igraph_vector_t *weights,
|
||||
igraph_neimode_t mode);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_widest_path_widths_floyd_warshall(const igraph_t *graph,
|
||||
igraph_matrix_t *res,
|
||||
igraph_vs_t from,
|
||||
igraph_vs_t to,
|
||||
const igraph_vector_t *weights,
|
||||
igraph_neimode_t mode);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_widest_path_widths_dijkstra(const igraph_t *graph,
|
||||
igraph_matrix_t *res,
|
||||
igraph_vs_t from,
|
||||
igraph_vs_t to,
|
||||
const igraph_vector_t *weights,
|
||||
igraph_neimode_t mode);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_voronoi(const igraph_t *graph,
|
||||
igraph_vector_int_t *membership,
|
||||
igraph_vector_t *distances,
|
||||
const igraph_vector_int_t *generators,
|
||||
const igraph_vector_t *weights,
|
||||
igraph_neimode_t mode,
|
||||
igraph_voronoi_tiebreaker_t tiebreaker);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_expand_path_to_pairs(igraph_vector_int_t *path);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_vertex_path_from_edge_path(
|
||||
const igraph_t *graph, igraph_int_t start,
|
||||
const igraph_vector_int_t *edge_path, igraph_vector_int_t *vertex_path,
|
||||
igraph_neimode_t mode);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,205 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2007-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define CONCAT2x(a,b) a ## _ ## b
|
||||
#define CONCAT2(a,b) CONCAT2x(a,b)
|
||||
#define CONCAT3x(a,b,c) a ## _ ## b ## _ ## c
|
||||
#define CONCAT3(a,b,c) CONCAT3x(a,b,c)
|
||||
#define CONCAT4x(a,b,c,d) a ## _ ## b ## _ ## c ## _ ## d
|
||||
#define CONCAT4(a,b,c,d) CONCAT4x(a,b,c,d)
|
||||
#define CONCAT5x(a,b,c,d,e) a ## _ ## b ## _ ## c ## _ ## d ## _ ## e
|
||||
#define CONCAT5(a,b,c,d,e) CONCAT5x(a,b,c,d,e)
|
||||
|
||||
#if defined(BASE_IGRAPH_REAL)
|
||||
#define BASE igraph_real_t
|
||||
#define BASE_VECTOR igraph_vector_t
|
||||
#define BASE_MATRIX igraph_matrix_t
|
||||
#define SHORT
|
||||
#define OUT_FORMAT "%g"
|
||||
#define PRINTFUNC(val) igraph_real_printf(val)
|
||||
#define SNPRINTFUNC(str, size, val) igraph_real_snprintf(str, size, val)
|
||||
#define FPRINTFUNC_ALIGNED(file, width, val) igraph_real_fprintf_aligned(file, width, val)
|
||||
#define FPRINTFUNC(file, val) igraph_real_fprintf(file, val)
|
||||
#define ZERO 0.0
|
||||
#define ONE 1.0
|
||||
#define MULTIPLICITY 1
|
||||
|
||||
#elif defined(BASE_CHAR)
|
||||
#define BASE char
|
||||
#define BASE_VECTOR igraph_vector_char_t
|
||||
#define BASE_MATRIX igraph_matrix_char_t
|
||||
#define SHORT char
|
||||
#define OUT_FORMAT "%d"
|
||||
#define ZERO 0
|
||||
#define ONE 1
|
||||
#define MULTIPLICITY 1
|
||||
|
||||
#elif defined(BASE_BOOL)
|
||||
#define BASE igraph_bool_t
|
||||
#define BASE_VECTOR igraph_vector_bool_t
|
||||
#define BASE_MATRIX igraph_matrix_bool_t
|
||||
#define SHORT bool
|
||||
#define OUT_FORMAT "%d"
|
||||
#define ZERO 0
|
||||
#define ONE 1
|
||||
#define MULTIPLICITY 1
|
||||
#define NOTORDERED 1
|
||||
#define NOABS 1
|
||||
#define EQ(a,b) ((a && b) || (!a && !b))
|
||||
|
||||
#elif defined(BASE_INT)
|
||||
#define BASE igraph_int_t
|
||||
#define BASE_VECTOR igraph_vector_int_t
|
||||
#define BASE_MATRIX igraph_matrix_int_t
|
||||
#define SHORT int
|
||||
#define OUT_FORMAT "%" IGRAPH_PRId
|
||||
#define ZERO 0
|
||||
#define ONE 1
|
||||
#define MULTIPLICITY 1
|
||||
|
||||
#elif defined(BASE_FORTRAN_INT)
|
||||
#define BASE int
|
||||
#define SHORT fortran_int
|
||||
#define OUT_FORMAT "%d"
|
||||
#define ZERO 0
|
||||
#define ONE 1
|
||||
#define MULTIPLICITY 1
|
||||
|
||||
#elif defined(BASE_PTR)
|
||||
#define BASE void*
|
||||
#define SHORT ptr
|
||||
#define ZERO 0
|
||||
#define MULTIPLICITY 1
|
||||
|
||||
#elif defined(BASE_COMPLEX)
|
||||
#undef complex
|
||||
#define BASE igraph_complex_t
|
||||
#define BASE_VECTOR igraph_vector_complex_t
|
||||
#define BASE_MATRIX igraph_matrix_complex_t
|
||||
#define SHORT complex
|
||||
#define PRINTFUNC(val) igraph_complex_printf(val)
|
||||
#define SNPRINTFUNC(str, size, val) igraph_complex_snprintf(str, size, val)
|
||||
#define FPRINTFUNC_ALIGNED(file, width, val) igraph_complex_fprintf_aligned(file, width, val)
|
||||
#define FPRINTFUNC(file, val) igraph_complex_fprintf(file, val)
|
||||
#define ZERO {{0.0, 0.0}}
|
||||
#define ONE {{1.0, 0.0}}
|
||||
#define MULTIPLICITY 2
|
||||
#define NOTORDERED 1
|
||||
#define NOABS 1
|
||||
#define SUM(a,b,c) ((a) = igraph_complex_add((b),(c)))
|
||||
#define DIFF(a,b,c) ((a) = igraph_complex_sub((b),(c)))
|
||||
#define PROD(a,b,c) ((a) = igraph_complex_mul((b),(c)))
|
||||
#define DIV(a,b,c) ((a) = igraph_complex_div((b),(c)))
|
||||
#define EQ(a,b) IGRAPH_COMPLEX_EQ((a),(b))
|
||||
#define SQ(a) IGRAPH_REAL(igraph_complex_mul((a),(a)))
|
||||
|
||||
#elif defined(BASE_GRAPH)
|
||||
#define BASE igraph_t
|
||||
|
||||
#elif defined(BASE_ATTRIBUTE_RECORD)
|
||||
#define BASE igraph_attribute_record_t
|
||||
|
||||
#elif defined(BASE_BITSET)
|
||||
#define BASE igraph_bitset_t
|
||||
|
||||
#else
|
||||
#error unknown BASE_ directive
|
||||
#endif
|
||||
|
||||
#if defined(VECTOR_LIST)
|
||||
#if defined(BASE_IGRAPH_REAL)
|
||||
#define FUNCTION(c) CONCAT2x(igraph_vector_list,c)
|
||||
#define INTERNAL_FUNCTION(c) CONCAT2x(igraph_i_vector_list,c)
|
||||
#define TYPE igraph_vector_list_t
|
||||
#elif defined(BASE_BOOL)
|
||||
/* Special case because stdbool.h defines bool as a macro to _Bool which would
|
||||
* screw things up */
|
||||
#define FUNCTION(c) CONCAT2x(igraph_vector_bool_list,c)
|
||||
#define INTERNAL_FUNCTION(c) CONCAT2x(igraph_i_vector_bool_list,c)
|
||||
#define TYPE igraph_vector_bool_list_t
|
||||
#else
|
||||
#define FUNCTION(c) CONCAT4(igraph_vector,SHORT,list,c)
|
||||
#define INTERNAL_FUNCTION(c) CONCAT4(igraph_i_vector,SHORT,list,c)
|
||||
#define TYPE CONCAT3(igraph_vector,SHORT,list_t)
|
||||
#endif
|
||||
#elif defined(MATRIX_LIST)
|
||||
#if defined(BASE_IGRAPH_REAL)
|
||||
#define FUNCTION(c) CONCAT2x(igraph_matrix_list,c)
|
||||
#define INTERNAL_FUNCTION(c) CONCAT2x(igraph_i_matrix_list,c)
|
||||
#define TYPE igraph_matrix_list_t
|
||||
#elif defined(BASE_BOOL)
|
||||
/* Special case because stdbool.h defines bool as a macro to _Bool which would
|
||||
* screw things up */
|
||||
#define FUNCTION(c) CONCAT2x(igraph_matrix_bool_list,c)
|
||||
#define INTERNAL_FUNCTION(c) CONCAT2x(igraph_i_matrix_bool_list,c)
|
||||
#define TYPE igraph_matrix_bool_list_t
|
||||
#else
|
||||
#define FUNCTION(c) CONCAT4(igraph_matrix,SHORT,list,c)
|
||||
#define INTERNAL_FUNCTION(c) CONCAT4(igraph_i_matrix,SHORT,list,c)
|
||||
#define TYPE CONCAT3(igraph_matrix,SHORT,list_t)
|
||||
#endif
|
||||
#elif defined(GRAPH_LIST)
|
||||
#define FUNCTION(c) CONCAT2x(igraph_graph_list,c)
|
||||
#define INTERNAL_FUNCTION(c) CONCAT2x(igraph_i_graph_list,c)
|
||||
#define TYPE igraph_graph_list_t
|
||||
#elif defined(ATTRIBUTE_RECORD_LIST)
|
||||
#define FUNCTION(c) CONCAT2x(igraph_attribute_record_list,c)
|
||||
#define INTERNAL_FUNCTION(c) CONCAT2x(igraph_i_attribute_record_list,c)
|
||||
#define TYPE igraph_attribute_record_list_t
|
||||
#elif defined(BITSET_LIST)
|
||||
#define FUNCTION(c) CONCAT2x(igraph_bitset_list,c)
|
||||
#define INTERNAL_FUNCTION(c) CONCAT2x(igraph_i_bitset_list,c)
|
||||
#define TYPE igraph_bitset_list_t
|
||||
#else
|
||||
#if defined(BASE_IGRAPH_REAL)
|
||||
#define FUNCTION(a,c) CONCAT2(a,c)
|
||||
#define TYPE(a) CONCAT2(a,t)
|
||||
#elif defined(BASE_BOOL)
|
||||
/* Special case because stdbool.h defines bool as a macro to _Bool which would
|
||||
* screw things up */
|
||||
#define FUNCTION(a,c) CONCAT3x(a,bool,c)
|
||||
#define TYPE(a) CONCAT3x(a,bool,t)
|
||||
#else
|
||||
#define FUNCTION(a,c) CONCAT3(a,SHORT,c)
|
||||
#define TYPE(a) CONCAT3(a,SHORT,t)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(HEAP_TYPE_MIN)
|
||||
#define HEAPMORE <
|
||||
#define HEAPMOREEQ <=
|
||||
#define HEAPLESS >
|
||||
#define HEAPLESSEQ >=
|
||||
#undef FUNCTION
|
||||
#undef INTERNAL_FUNCTION
|
||||
#undef TYPE
|
||||
#if defined(BASE_IGRAPH_REAL)
|
||||
#define FUNCTION(dir,name) CONCAT3(dir,min,name)
|
||||
#define TYPE(dir) CONCAT3(dir,min,t)
|
||||
#else
|
||||
#define FUNCTION(a,c) CONCAT4(a,min,SHORT,c)
|
||||
#define TYPE(dir) CONCAT4(dir,min,SHORT,t)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(HEAP_TYPE_MAX)
|
||||
#define HEAPMORE >
|
||||
#define HEAPMOREEQ >=
|
||||
#define HEAPLESS <
|
||||
#define HEAPLESSEQ <=
|
||||
#endif
|
||||
@@ -0,0 +1,181 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2007-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef ATOMIC
|
||||
#undef ATOMIC
|
||||
#endif
|
||||
|
||||
#ifdef ATOMIC_IO
|
||||
#undef ATOMIC_IO
|
||||
#endif
|
||||
|
||||
#ifdef BASE
|
||||
#undef BASE
|
||||
#endif
|
||||
|
||||
#ifdef BASE_EPSILON
|
||||
#undef BASE_EPSILON
|
||||
#endif
|
||||
|
||||
#ifdef BASE_MATRIX
|
||||
#undef BASE_MATRIX
|
||||
#endif
|
||||
|
||||
#ifdef BASE_VECTOR
|
||||
#undef BASE_VECTOR
|
||||
#endif
|
||||
|
||||
#ifdef CONCAT2
|
||||
#undef CONCAT2
|
||||
#endif
|
||||
|
||||
#ifdef CONCAT2x
|
||||
#undef CONCAT2x
|
||||
#endif
|
||||
|
||||
#ifdef CONCAT3
|
||||
#undef CONCAT3
|
||||
#endif
|
||||
|
||||
#ifdef CONCAT3x
|
||||
#undef CONCAT3x
|
||||
#endif
|
||||
|
||||
#ifdef CONCAT4
|
||||
#undef CONCAT4
|
||||
#endif
|
||||
|
||||
#ifdef CONCAT4x
|
||||
#undef CONCAT4x
|
||||
#endif
|
||||
|
||||
#ifdef CONCAT5
|
||||
#undef CONCAT5
|
||||
#endif
|
||||
|
||||
#ifdef CONCAT5x
|
||||
#undef CONCAT5x
|
||||
#endif
|
||||
|
||||
#ifdef FP
|
||||
#undef FP
|
||||
#endif
|
||||
|
||||
#ifdef FUNCTION
|
||||
#undef FUNCTION
|
||||
#endif
|
||||
|
||||
#ifdef IN_FORMAT
|
||||
#undef IN_FORMAT
|
||||
#endif
|
||||
|
||||
#ifdef INTERNAL_FUNCTION
|
||||
#undef INTERNAL_FUNCTION
|
||||
#endif
|
||||
|
||||
#ifdef MULTIPLICITY
|
||||
#undef MULTIPLICITY
|
||||
#endif
|
||||
|
||||
#ifdef ONE
|
||||
#undef ONE
|
||||
#endif
|
||||
|
||||
#ifdef OUT_FORMAT
|
||||
#undef OUT_FORMAT
|
||||
#endif
|
||||
|
||||
#ifdef SHORT
|
||||
#undef SHORT
|
||||
#endif
|
||||
|
||||
#ifdef TYPE
|
||||
#undef TYPE
|
||||
#endif
|
||||
|
||||
#ifdef ZERO
|
||||
#undef ZERO
|
||||
#endif
|
||||
|
||||
#ifdef HEAPMORE
|
||||
#undef HEAPMORE
|
||||
#endif
|
||||
|
||||
#ifdef HEAPLESS
|
||||
#undef HEAPLESS
|
||||
#endif
|
||||
|
||||
#ifdef HEAPMOREEQ
|
||||
#undef HEAPMOREEQ
|
||||
#endif
|
||||
|
||||
#ifdef HEAPLESSEQ
|
||||
#undef HEAPLESSEQ
|
||||
#endif
|
||||
|
||||
#ifdef SUM
|
||||
#undef SUM
|
||||
#endif
|
||||
|
||||
#ifdef SQ
|
||||
#undef SQ
|
||||
#endif
|
||||
|
||||
#ifdef PROD
|
||||
#undef PROD
|
||||
#endif
|
||||
|
||||
#ifdef NOTORDERED
|
||||
#undef NOTORDERED
|
||||
#endif
|
||||
|
||||
#ifdef EQ
|
||||
#undef EQ
|
||||
#endif
|
||||
|
||||
#ifdef DIFF
|
||||
#undef DIFF
|
||||
#endif
|
||||
|
||||
#ifdef DIV
|
||||
#undef DIV
|
||||
#endif
|
||||
|
||||
#ifdef NOABS
|
||||
#undef NOABS
|
||||
#endif
|
||||
|
||||
#ifdef PRINTFUNC
|
||||
#undef PRINTFUNC
|
||||
#endif
|
||||
|
||||
#ifdef SNPRINTFUNC
|
||||
#undef SNPRINTFUNC
|
||||
#endif
|
||||
|
||||
#ifdef FPRINTFUNC_ALIGNED
|
||||
#undef FPRINTFUNC_ALIGNED
|
||||
#endif
|
||||
|
||||
#ifdef FPRINTFUNC
|
||||
#undef FPRINTFUNC
|
||||
#endif
|
||||
|
||||
#ifdef UNSIGNED
|
||||
#undef UNSIGNED
|
||||
#endif
|
||||
@@ -0,0 +1,197 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2009-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_PROGRESS_H
|
||||
#define IGRAPH_PROGRESS_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_types.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
/**
|
||||
* \section about_progress_handlers About progress handlers
|
||||
*
|
||||
* <para>It is often useful to report the progress of some long
|
||||
* calculation, to allow the user to follow the computation and
|
||||
* guess the total running time. A couple of igraph functions
|
||||
* support this at the time of writing, hopefully more will support it
|
||||
* in the future.
|
||||
* </para>
|
||||
*
|
||||
* <para>
|
||||
* To see the progress of a computation, the user has to install a
|
||||
* progress handler, as there is none installed by default.
|
||||
* If an igraph function supports progress reporting, then it
|
||||
* calls the installed progress handler periodically, and passes a
|
||||
* percentage value to it, the percentage of computation already
|
||||
* performed. To install a progress handler, you need to call
|
||||
* \ref igraph_set_progress_handler(). Currently there is a single
|
||||
* pre-defined progress handler, called \ref
|
||||
* igraph_progress_handler_stderr().
|
||||
* </para>
|
||||
*/
|
||||
|
||||
/**
|
||||
* \section writing_progress_handlers Writing progress handlers
|
||||
*
|
||||
* <para>
|
||||
* To write a new progress handler, one needs to create a function of
|
||||
* type \ref igraph_progress_handler_t. The new progress handler
|
||||
* can then be installed with the \ref igraph_set_progress_handler()
|
||||
* function.
|
||||
* </para>
|
||||
*
|
||||
* <para>
|
||||
* One can assume that the first progress handler call from a
|
||||
* calculation will be call with zero as the \p percentage argument,
|
||||
* and the last call from a function will have 100 as the \p
|
||||
* percentage argument. Note, however, that if an error happens in the
|
||||
* middle of a computation, then the 100 percent call might be
|
||||
* omitted.
|
||||
* </para>
|
||||
*/
|
||||
|
||||
/**
|
||||
* \section igraph_functions_with_progress Writing igraph functions with progress reporting
|
||||
*
|
||||
* <para>
|
||||
* If you want to write a function that uses igraph and supports
|
||||
* progress reporting, you need to include \ref igraph_progress()
|
||||
* calls in your function, usually via the \ref IGRAPH_PROGRESS()
|
||||
* macro.
|
||||
* </para>
|
||||
*
|
||||
* <para>
|
||||
* It is good practice to always include a call to \ref
|
||||
* igraph_progress() with a zero \p percentage argument, before the
|
||||
* computation; and another call with 100 \p percentage value
|
||||
* after the computation is completed.
|
||||
* </para>
|
||||
*
|
||||
* <para>
|
||||
* It is also good practice \em not to call \ref igraph_progress() too
|
||||
* often, as this would slow down the computation. It might not be
|
||||
* worth to support progress reporting in functions with linear or
|
||||
* log-linear time complexity, as these are fast, even with a large
|
||||
* amount of data. For functions with quadratic or higher time
|
||||
* complexity make sure that the time complexity of the progress
|
||||
* reporting is constant or at least linear. In practice this means
|
||||
* having at most O(n) progress checks and at most 100
|
||||
* \ref igraph_progress() calls.
|
||||
* </para>
|
||||
*/
|
||||
|
||||
/**
|
||||
* \section progress_and_threads Multi-threaded programs
|
||||
*
|
||||
* <para>
|
||||
* In multi-threaded programs, each thread has its own progress
|
||||
* handler, if thread-local storage is supported and igraph is
|
||||
* thread-safe. See the \ref IGRAPH_THREAD_SAFE macro for checking
|
||||
* whether an igraph build is thread-safe.
|
||||
* </para>
|
||||
*/
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* Progress handlers */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* \typedef igraph_progress_handler_t
|
||||
* \brief Type of progress handler functions
|
||||
*
|
||||
* This is the type of the igraph progress handler functions.
|
||||
* There is currently one such predefined function,
|
||||
* \ref igraph_progress_handler_stderr(), but the user can
|
||||
* write and set up more sophisticated ones.
|
||||
* \param message A string describing the function or algorithm
|
||||
* that is reporting the progress. Current igraph functions
|
||||
* always use the name \p message argument if reporting from the
|
||||
* same function.
|
||||
* \param percent Numeric, the percentage that was completed by the
|
||||
* algorithm or function.
|
||||
* \param data User-defined data. Current igraph functions that
|
||||
* report progress pass a null pointer here. Users can
|
||||
* write their own progress handlers and functions with progress
|
||||
* reporting, and then pass some meaningfull context here.
|
||||
* \return If the return value of the progress handler is not
|
||||
* \c IGRAPH_SUCCESS, then \ref igraph_progress() returns the
|
||||
* error code from the progress handler intact. The \ref IGRAPH_PROGRESS()
|
||||
* macro also frees all allocated memory.
|
||||
*/
|
||||
|
||||
typedef igraph_error_t igraph_progress_handler_t(const char *message, igraph_real_t percent,
|
||||
void *data);
|
||||
|
||||
IGRAPH_EXPORT extern igraph_progress_handler_t igraph_progress_handler_stderr;
|
||||
|
||||
IGRAPH_EXPORT igraph_progress_handler_t * igraph_set_progress_handler(igraph_progress_handler_t new_handler);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_progress(const char *message, igraph_real_t percent, void *data);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_progressf(const char *message, igraph_real_t percent, void *data,
|
||||
...);
|
||||
|
||||
/**
|
||||
* \define IGRAPH_PROGRESS
|
||||
* \brief Report the progress of a calculation from an igraph function (macro variant).
|
||||
*
|
||||
* The standard way to report progress from an igraph function
|
||||
* \param message A string, a textual message that references the
|
||||
* calculation under progress.
|
||||
* \param percent Numeric scalar, the percentage that is complete.
|
||||
* \param data User-defined data, this can be used in user-defined
|
||||
* progress handler functions, from user-written igraph functions.
|
||||
* \return If the return value of the progress handler is not
|
||||
* \c IGRAPH_SUCCESS, then \ref igraph_progress() returns the
|
||||
* error code from the progress handler intact. The \ref IGRAPH_PROGRESS()
|
||||
* macro also frees all allocated memory.
|
||||
*/
|
||||
|
||||
#define IGRAPH_PROGRESS(message, percent, data) \
|
||||
do { \
|
||||
IGRAPH_CHECK(igraph_progress((message), (percent), (data))); \
|
||||
} while (0)
|
||||
|
||||
/**
|
||||
* \define IGRAPH_PROGRESSF
|
||||
* \brief Report the progress of a calculation from an igraph function, printf-like (macro variant).
|
||||
*
|
||||
* This is the more flexible version of \ref IGRAPH_PROGRESS(),
|
||||
* having a printf-like syntax. As this macro takes variable
|
||||
* number of arguments, they must be all supplied as a single
|
||||
* argument, enclosed in parentheses. \ref igraph_progressf() is then
|
||||
* called with the given arguments.
|
||||
*
|
||||
* \param args The arguments to pass to \ref igraph_progressf().
|
||||
* \return If the progress handler returns with a value other than
|
||||
* \c IGRAPH_SUCCESS, then the function that called this
|
||||
* macro returns as well, with the same error code, after
|
||||
* cleaning up all allocated memory as needed.
|
||||
*/
|
||||
|
||||
#define IGRAPH_PROGRESSF(args) \
|
||||
do { \
|
||||
IGRAPH_CHECK(igraph_progressf args); \
|
||||
} while (0)
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2009-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_PSUMTREE_H
|
||||
#define IGRAPH_PSUMTREE_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_vector.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
typedef struct {
|
||||
igraph_vector_t v;
|
||||
igraph_int_t size;
|
||||
igraph_int_t offset;
|
||||
} igraph_psumtree_t;
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_psumtree_init(igraph_psumtree_t *t, igraph_int_t size);
|
||||
IGRAPH_EXPORT void igraph_psumtree_reset(igraph_psumtree_t *t);
|
||||
IGRAPH_EXPORT void igraph_psumtree_destroy(igraph_psumtree_t *t);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_real_t igraph_psumtree_get(const igraph_psumtree_t *t, igraph_int_t idx);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_int_t igraph_psumtree_size(const igraph_psumtree_t *t);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_psumtree_search(const igraph_psumtree_t *t, igraph_int_t *idx,
|
||||
igraph_real_t elem);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_psumtree_update(igraph_psumtree_t *t, igraph_int_t idx,
|
||||
igraph_real_t new_value);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_real_t igraph_psumtree_sum(const igraph_psumtree_t *t);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2011-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_QSORT_H
|
||||
#define IGRAPH_QSORT_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
IGRAPH_EXPORT void igraph_qsort(void *base, size_t nel, size_t width,
|
||||
int (*compar)(const void *, const void *));
|
||||
IGRAPH_EXPORT void igraph_qsort_r(void *base, size_t nel, size_t width, void *thunk,
|
||||
int (*compar)(void *, const void *, const void *));
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2003-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_RANDOM_H
|
||||
#define IGRAPH_RANDOM_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_types.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
/* The new RNG interface is (somewhat) modelled on the GSL */
|
||||
|
||||
/* When implementing your own RNG in igraph, the following methods must be
|
||||
* supplied in the corresponding igraph_rng_type_t structure:
|
||||
*
|
||||
* - init()
|
||||
* - destroy()
|
||||
* - seed()
|
||||
* - get()
|
||||
*
|
||||
* Optionally, you can provide specialized routines for several distributions
|
||||
* in the following functions:
|
||||
*
|
||||
* - get_int()
|
||||
* - get_real()
|
||||
* - get_norm()
|
||||
* - get_geom()
|
||||
* - get_binom()
|
||||
* - get_exp()
|
||||
* - get_gamma()
|
||||
* - get_pois()
|
||||
*
|
||||
* The best is probably to define get() leave the others as NULL; igraph will use
|
||||
* default implementations for these.
|
||||
*
|
||||
* Note that if all that you would do in a get_real() implementation is to
|
||||
* generate random bits with get() and divide by the maximum, don't do that;
|
||||
* The default implementation takes care of calling get() a sufficient number of
|
||||
* times to utilize most of the precision of the igraph_real_t type, and generate
|
||||
* accurate variates. Inaccuracies in the output of get_real() can get magnified
|
||||
* when using the default generators for non-uniform distributions.
|
||||
* When implementing get_real(), the sampling range must be half-open, i.e. [0, 1).
|
||||
* If unsure, leave get_real() unimplemented and igraph will provide an implementation
|
||||
* in terms of get().
|
||||
*
|
||||
* When implementing get_int(), you do not need to check whether lo < hi;
|
||||
* the caller is responsible for ensuring that this is the case. You can always
|
||||
* assume that hi > lo. Note that both endpoints are _inclusive_, and you must
|
||||
* make sure that your generation scheme works for both 32-bit and 64-bit
|
||||
* versions of igraph_int_t as igraph can be compiled for both cases. If
|
||||
* you are unsure, leave get_int() unimplemented and igraph will provide its
|
||||
* own implementation based on get().
|
||||
*/
|
||||
typedef struct igraph_rng_type_t {
|
||||
const char *name;
|
||||
uint8_t bits;
|
||||
|
||||
/* Initialization and destruction */
|
||||
igraph_error_t (*init)(void **state);
|
||||
void (*destroy)(void *state);
|
||||
|
||||
/* Seeding */
|
||||
igraph_error_t (*seed)(void *state, igraph_uint_t seed);
|
||||
|
||||
/* Fundamental generator: return as many random bits as the RNG supports in
|
||||
* a single round */
|
||||
igraph_uint_t (*get)(void *state);
|
||||
|
||||
/* Optional generators; defaults are provided by igraph that rely solely
|
||||
* on get() */
|
||||
igraph_int_t (*get_int)(void *state, igraph_int_t l, igraph_int_t h);
|
||||
igraph_real_t (*get_real)(void *state);
|
||||
igraph_real_t (*get_norm)(void *state);
|
||||
igraph_real_t (*get_geom)(void *state, igraph_real_t p);
|
||||
igraph_real_t (*get_binom)(void *state, igraph_int_t n, igraph_real_t p);
|
||||
igraph_real_t (*get_exp)(void *state, igraph_real_t rate);
|
||||
igraph_real_t (*get_gamma)(void *state, igraph_real_t shape,
|
||||
igraph_real_t scale);
|
||||
igraph_real_t (*get_pois)(void *state, igraph_real_t mu);
|
||||
} igraph_rng_type_t;
|
||||
|
||||
typedef struct igraph_rng_t {
|
||||
const igraph_rng_type_t *type;
|
||||
void *state;
|
||||
igraph_bool_t is_seeded;
|
||||
} igraph_rng_t;
|
||||
|
||||
/* --------------------------------- */
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_rng_init(igraph_rng_t *rng, const igraph_rng_type_t *type);
|
||||
IGRAPH_EXPORT void igraph_rng_destroy(igraph_rng_t *rng);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_rng_seed(igraph_rng_t *rng, igraph_uint_t seed);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_int_t igraph_rng_bits(const igraph_rng_t* rng);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_uint_t igraph_rng_max(const igraph_rng_t *rng);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE const char *igraph_rng_name(const igraph_rng_t *rng);
|
||||
|
||||
IGRAPH_EXPORT igraph_bool_t igraph_rng_get_bool(igraph_rng_t *rng) ;
|
||||
IGRAPH_EXPORT igraph_int_t igraph_rng_get_integer(
|
||||
igraph_rng_t *rng, igraph_int_t l, igraph_int_t h
|
||||
);
|
||||
IGRAPH_EXPORT igraph_real_t igraph_rng_get_normal(
|
||||
igraph_rng_t *rng, igraph_real_t m, igraph_real_t s
|
||||
);
|
||||
IGRAPH_EXPORT igraph_real_t igraph_rng_get_unif(
|
||||
igraph_rng_t *rng, igraph_real_t l, igraph_real_t h
|
||||
);
|
||||
IGRAPH_EXPORT igraph_real_t igraph_rng_get_unif01(igraph_rng_t *rng);
|
||||
IGRAPH_EXPORT igraph_real_t igraph_rng_get_geom(igraph_rng_t *rng, igraph_real_t p);
|
||||
IGRAPH_EXPORT igraph_real_t igraph_rng_get_binom(
|
||||
igraph_rng_t *rng, igraph_int_t n, igraph_real_t p
|
||||
);
|
||||
IGRAPH_EXPORT igraph_real_t igraph_rng_get_exp(igraph_rng_t *rng, igraph_real_t rate);
|
||||
IGRAPH_EXPORT igraph_real_t igraph_rng_get_gamma(
|
||||
igraph_rng_t *rng, igraph_real_t shape, igraph_real_t scale
|
||||
);
|
||||
IGRAPH_EXPORT igraph_real_t igraph_rng_get_pois(igraph_rng_t *rng, igraph_real_t rate);
|
||||
|
||||
/* --------------------------------- */
|
||||
|
||||
IGRAPH_EXPORT extern const igraph_rng_type_t igraph_rngtype_glibc2;
|
||||
IGRAPH_EXPORT extern const igraph_rng_type_t igraph_rngtype_mt19937;
|
||||
IGRAPH_EXPORT extern const igraph_rng_type_t igraph_rngtype_pcg32;
|
||||
IGRAPH_EXPORT extern const igraph_rng_type_t igraph_rngtype_pcg64;
|
||||
|
||||
IGRAPH_EXPORT igraph_rng_t *igraph_rng_default(void);
|
||||
IGRAPH_EXPORT igraph_rng_t *igraph_rng_set_default(igraph_rng_t *rng);
|
||||
|
||||
/* --------------------------------- */
|
||||
|
||||
#define RNG_BOOL() (igraph_rng_get_bool(igraph_rng_default()))
|
||||
#define RNG_INTEGER(l,h) (igraph_rng_get_integer(igraph_rng_default(),(l),(h)))
|
||||
#define RNG_NORMAL(m,s) (igraph_rng_get_normal(igraph_rng_default(),(m),(s)))
|
||||
#define RNG_UNIF(l,h) (igraph_rng_get_unif(igraph_rng_default(),(l),(h)))
|
||||
#define RNG_UNIF01() (igraph_rng_get_unif01(igraph_rng_default()))
|
||||
#define RNG_GEOM(p) (igraph_rng_get_geom(igraph_rng_default(),(p)))
|
||||
#define RNG_BINOM(n,p) (igraph_rng_get_binom(igraph_rng_default(),(n),(p)))
|
||||
#define RNG_EXP(rate) (igraph_rng_get_exp(igraph_rng_default(),(rate)))
|
||||
#define RNG_POIS(rate) (igraph_rng_get_pois(igraph_rng_default(),(rate)))
|
||||
#define RNG_GAMMA(shape, scale) \
|
||||
(igraph_rng_get_gamma(igraph_rng_default(), (shape), (scale)))
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2024-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_REACHABILITY_H
|
||||
#define IGRAPH_REACHABILITY_H
|
||||
|
||||
#include "igraph_bitset_list.h"
|
||||
#include "igraph_datatype.h"
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_vector.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_reachability(
|
||||
const igraph_t *graph,
|
||||
igraph_vector_int_t *membership,
|
||||
igraph_vector_int_t *csize,
|
||||
igraph_int_t *no_of_components,
|
||||
igraph_bitset_list_t *reach,
|
||||
igraph_neimode_t mode);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_count_reachable(
|
||||
const igraph_t *graph,
|
||||
igraph_vector_int_t *counts,
|
||||
igraph_neimode_t mode);
|
||||
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_transitive_closure(const igraph_t *graph,
|
||||
igraph_t* closure);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif // IGRAPH_REACHABILITY_H
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2003-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_SAMPLING_H
|
||||
#define IGRAPH_SAMPLING_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_matrix.h"
|
||||
#include "igraph_random.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_rng_sample_sphere_surface(
|
||||
igraph_rng_t* rng, igraph_int_t dim, igraph_int_t n, igraph_real_t radius,
|
||||
igraph_bool_t positive, igraph_matrix_t *res
|
||||
);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_rng_sample_sphere_volume(
|
||||
igraph_rng_t* rng, igraph_int_t dim, igraph_int_t n, igraph_real_t radius,
|
||||
igraph_bool_t positive, igraph_matrix_t *res
|
||||
);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_rng_sample_dirichlet(
|
||||
igraph_rng_t* rng, igraph_int_t n, const igraph_vector_t *alpha, igraph_matrix_t *res
|
||||
);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2013-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_SCAN_H
|
||||
#define IGRAPH_SCAN_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_datatype.h"
|
||||
#include "igraph_constants.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_vector_list.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_local_scan_0(const igraph_t *graph, igraph_vector_t *res,
|
||||
const igraph_vector_t *weights, igraph_neimode_t mode);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_local_scan_0_them(const igraph_t *us, const igraph_t *them,
|
||||
igraph_vector_t *res,
|
||||
const igraph_vector_t *weights_them,
|
||||
igraph_neimode_t mode);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_local_scan_1_ecount(const igraph_t *graph, igraph_vector_t *res,
|
||||
const igraph_vector_t *weights,
|
||||
igraph_neimode_t mode);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_local_scan_1_ecount_them(const igraph_t *us, const igraph_t *them,
|
||||
igraph_vector_t *res,
|
||||
const igraph_vector_t *weights,
|
||||
igraph_neimode_t mode);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_local_scan_k_ecount(const igraph_t *graph, igraph_int_t k,
|
||||
igraph_vector_t *res,
|
||||
const igraph_vector_t *weights,
|
||||
igraph_neimode_t mode);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_local_scan_k_ecount_them(const igraph_t *us, const igraph_t *them,
|
||||
igraph_int_t k, igraph_vector_t *res,
|
||||
const igraph_vector_t *weights_them,
|
||||
igraph_neimode_t mode);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_local_scan_neighborhood_ecount(const igraph_t *graph,
|
||||
igraph_vector_t *res,
|
||||
const igraph_vector_t *weights,
|
||||
const igraph_vector_int_list_t *neighborhoods);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_local_scan_subset_ecount(const igraph_t *graph,
|
||||
igraph_vector_t *res,
|
||||
const igraph_vector_t *weights,
|
||||
const igraph_vector_int_list_t *neighborhoods);
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2010-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_SEPARATORS_H
|
||||
#define IGRAPH_SEPARATORS_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_datatype.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_iterators.h"
|
||||
#include "igraph_types.h"
|
||||
#include "igraph_vector_list.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_is_separator(const igraph_t *graph,
|
||||
igraph_vs_t candidate,
|
||||
igraph_bool_t *res);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_all_minimal_st_separators(const igraph_t *graph,
|
||||
igraph_vector_int_list_t *separators);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_is_minimal_separator(const igraph_t *graph,
|
||||
igraph_vs_t candidate,
|
||||
igraph_bool_t *res);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_minimum_size_separators(const igraph_t *graph,
|
||||
igraph_vector_int_list_t *separators);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2003-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_SETUP_H
|
||||
#define IGRAPH_SETUP_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_error.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_setup(void);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,287 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2010-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_SPARSEMAT_H
|
||||
#define IGRAPH_SPARSEMAT_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_types.h"
|
||||
#include "igraph_vector.h"
|
||||
#include "igraph_arpack.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
/*
|
||||
* These types are private to igraph, and customized to use igraph_int_t.
|
||||
* Do not attempt to access them using a separate copy of the CXSparse library.
|
||||
* Use the public igraph_sparsemat_... types instead.
|
||||
*/
|
||||
struct cs_igraph_sparse;
|
||||
struct cs_igraph_symbolic;
|
||||
struct cs_igraph_numeric;
|
||||
|
||||
typedef struct {
|
||||
struct cs_igraph_sparse *cs;
|
||||
} igraph_sparsemat_t;
|
||||
|
||||
typedef struct {
|
||||
struct cs_igraph_symbolic *symbolic;
|
||||
} igraph_sparsemat_symbolic_t;
|
||||
|
||||
typedef struct {
|
||||
struct cs_igraph_numeric *numeric;
|
||||
} igraph_sparsemat_numeric_t;
|
||||
|
||||
typedef enum { IGRAPH_SPARSEMAT_TRIPLET,
|
||||
IGRAPH_SPARSEMAT_CC
|
||||
} igraph_sparsemat_type_t;
|
||||
|
||||
typedef struct {
|
||||
const igraph_sparsemat_t *mat;
|
||||
igraph_int_t pos;
|
||||
igraph_int_t col;
|
||||
} igraph_sparsemat_iterator_t;
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_init(
|
||||
igraph_sparsemat_t *A, igraph_int_t rows, igraph_int_t cols,
|
||||
igraph_int_t nzmax
|
||||
);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_init_copy(
|
||||
igraph_sparsemat_t *to, const igraph_sparsemat_t *from);
|
||||
IGRAPH_EXPORT void igraph_sparsemat_destroy(igraph_sparsemat_t *A);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_realloc(igraph_sparsemat_t *A, igraph_int_t nzmax);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_init_eye(igraph_sparsemat_t *A,
|
||||
igraph_int_t n, igraph_int_t nzmax,
|
||||
igraph_real_t value, igraph_bool_t compress);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_init_diag(igraph_sparsemat_t *A,
|
||||
igraph_int_t nzmax, const igraph_vector_t *values,
|
||||
igraph_bool_t compress);
|
||||
|
||||
IGRAPH_EXPORT igraph_int_t igraph_sparsemat_nrow(const igraph_sparsemat_t *A);
|
||||
IGRAPH_EXPORT igraph_int_t igraph_sparsemat_ncol(const igraph_sparsemat_t *B);
|
||||
IGRAPH_EXPORT igraph_sparsemat_type_t igraph_sparsemat_type(const igraph_sparsemat_t *A);
|
||||
IGRAPH_EXPORT igraph_bool_t igraph_sparsemat_is_triplet(const igraph_sparsemat_t *A);
|
||||
IGRAPH_EXPORT igraph_bool_t igraph_sparsemat_is_cc(const igraph_sparsemat_t *A);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_permute(const igraph_sparsemat_t *A,
|
||||
const igraph_vector_int_t *p,
|
||||
const igraph_vector_int_t *q,
|
||||
igraph_sparsemat_t *res);
|
||||
|
||||
IGRAPH_EXPORT igraph_real_t igraph_sparsemat_get(
|
||||
const igraph_sparsemat_t *A, igraph_int_t row, igraph_int_t col
|
||||
);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_index(const igraph_sparsemat_t *A,
|
||||
const igraph_vector_int_t *p,
|
||||
const igraph_vector_int_t *q,
|
||||
igraph_sparsemat_t *res,
|
||||
igraph_real_t *constres);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_entry(igraph_sparsemat_t *A,
|
||||
igraph_int_t row, igraph_int_t col, igraph_real_t elem);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_compress(const igraph_sparsemat_t *A,
|
||||
igraph_sparsemat_t *res);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_transpose(
|
||||
const igraph_sparsemat_t *A, igraph_sparsemat_t *res
|
||||
);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_is_symmetric(const igraph_sparsemat_t *A, igraph_bool_t *result);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_dupl(igraph_sparsemat_t *A);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_fkeep(igraph_sparsemat_t *A,
|
||||
igraph_int_t (*fkeep)(igraph_int_t, igraph_int_t, igraph_real_t, void*),
|
||||
void *other);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_dropzeros(igraph_sparsemat_t *A);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_droptol(igraph_sparsemat_t *A, igraph_real_t tol);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_multiply(const igraph_sparsemat_t *A,
|
||||
const igraph_sparsemat_t *B,
|
||||
igraph_sparsemat_t *res);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_add(const igraph_sparsemat_t *A,
|
||||
const igraph_sparsemat_t *B,
|
||||
igraph_real_t alpha,
|
||||
igraph_real_t beta,
|
||||
igraph_sparsemat_t *res);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_gaxpy(const igraph_sparsemat_t *A,
|
||||
const igraph_vector_t *x,
|
||||
igraph_vector_t *res);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_lsolve(const igraph_sparsemat_t *A,
|
||||
const igraph_vector_t *b,
|
||||
igraph_vector_t *res);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_ltsolve(const igraph_sparsemat_t *A,
|
||||
const igraph_vector_t *b,
|
||||
igraph_vector_t *res);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_usolve(const igraph_sparsemat_t *A,
|
||||
const igraph_vector_t *b,
|
||||
igraph_vector_t *res);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_utsolve(const igraph_sparsemat_t *A,
|
||||
const igraph_vector_t *b,
|
||||
igraph_vector_t *res);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_cholsol(const igraph_sparsemat_t *A,
|
||||
const igraph_vector_t *b,
|
||||
igraph_vector_t *res,
|
||||
igraph_int_t order);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_lusol(const igraph_sparsemat_t *A,
|
||||
const igraph_vector_t *b,
|
||||
igraph_vector_t *res,
|
||||
igraph_int_t order,
|
||||
igraph_real_t tol);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_print(const igraph_sparsemat_t *A,
|
||||
FILE *outstream);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_matrix_as_sparsemat(igraph_sparsemat_t *res,
|
||||
const igraph_matrix_t *mat,
|
||||
igraph_real_t tol);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_as_matrix(igraph_matrix_t *res,
|
||||
const igraph_sparsemat_t *spmat);
|
||||
|
||||
typedef enum { IGRAPH_SPARSEMAT_SOLVE_LU,
|
||||
IGRAPH_SPARSEMAT_SOLVE_QR
|
||||
} igraph_sparsemat_solve_t;
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_arpack_rssolve(const igraph_sparsemat_t *A,
|
||||
igraph_arpack_options_t *options,
|
||||
igraph_arpack_storage_t *storage,
|
||||
igraph_vector_t *values,
|
||||
igraph_matrix_t *vectors,
|
||||
igraph_sparsemat_solve_t solvemethod);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_arpack_rnsolve(const igraph_sparsemat_t *A,
|
||||
igraph_arpack_options_t *options,
|
||||
igraph_arpack_storage_t *storage,
|
||||
igraph_matrix_t *values,
|
||||
igraph_matrix_t *vectors);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_lu(const igraph_sparsemat_t *A,
|
||||
const igraph_sparsemat_symbolic_t *dis,
|
||||
igraph_sparsemat_numeric_t *din, double tol);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_qr(const igraph_sparsemat_t *A,
|
||||
const igraph_sparsemat_symbolic_t *dis,
|
||||
igraph_sparsemat_numeric_t *din);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_luresol(const igraph_sparsemat_symbolic_t *dis,
|
||||
const igraph_sparsemat_numeric_t *din,
|
||||
const igraph_vector_t *b,
|
||||
igraph_vector_t *res);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_qrresol(const igraph_sparsemat_symbolic_t *dis,
|
||||
const igraph_sparsemat_numeric_t *din,
|
||||
const igraph_vector_t *b,
|
||||
igraph_vector_t *res);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_symbqr(igraph_int_t order, const igraph_sparsemat_t *A,
|
||||
igraph_sparsemat_symbolic_t *dis);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_symblu(igraph_int_t order, const igraph_sparsemat_t *A,
|
||||
igraph_sparsemat_symbolic_t *dis);
|
||||
|
||||
|
||||
IGRAPH_EXPORT void igraph_sparsemat_symbolic_destroy(igraph_sparsemat_symbolic_t *dis);
|
||||
IGRAPH_EXPORT void igraph_sparsemat_numeric_destroy(igraph_sparsemat_numeric_t *din);
|
||||
|
||||
IGRAPH_EXPORT igraph_real_t igraph_sparsemat_max(igraph_sparsemat_t *A);
|
||||
IGRAPH_EXPORT igraph_real_t igraph_sparsemat_min(igraph_sparsemat_t *A);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_minmax(igraph_sparsemat_t *A,
|
||||
igraph_real_t *min, igraph_real_t *max);
|
||||
|
||||
IGRAPH_EXPORT igraph_int_t igraph_sparsemat_count_nonzero(igraph_sparsemat_t *A);
|
||||
IGRAPH_EXPORT igraph_int_t igraph_sparsemat_count_nonzerotol(igraph_sparsemat_t *A,
|
||||
igraph_real_t tol);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_rowsums(const igraph_sparsemat_t *A,
|
||||
igraph_vector_t *res);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_colsums(const igraph_sparsemat_t *A,
|
||||
igraph_vector_t *res);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_rowmins(igraph_sparsemat_t *A,
|
||||
igraph_vector_t *res);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_colmins(igraph_sparsemat_t *A,
|
||||
igraph_vector_t *res);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_rowmaxs(igraph_sparsemat_t *A,
|
||||
igraph_vector_t *res);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_colmaxs(igraph_sparsemat_t *A,
|
||||
igraph_vector_t *res);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_which_min_rows(igraph_sparsemat_t *A,
|
||||
igraph_vector_t *res,
|
||||
igraph_vector_int_t *pos);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_which_min_cols(igraph_sparsemat_t *A,
|
||||
igraph_vector_t *res,
|
||||
igraph_vector_int_t *pos);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_scale(igraph_sparsemat_t *A, igraph_real_t by);
|
||||
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_add_rows(igraph_sparsemat_t *A, igraph_int_t n);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_add_cols(igraph_sparsemat_t *A, igraph_int_t n);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_resize(igraph_sparsemat_t *A,
|
||||
igraph_int_t nrow, igraph_int_t ncol, igraph_int_t nzmax);
|
||||
IGRAPH_EXPORT igraph_int_t igraph_sparsemat_nonzero_storage(const igraph_sparsemat_t *A);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_getelements(const igraph_sparsemat_t *A,
|
||||
igraph_vector_int_t *i,
|
||||
igraph_vector_int_t *j,
|
||||
igraph_vector_t *x);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_getelements_sorted(const igraph_sparsemat_t *A,
|
||||
igraph_vector_int_t *i,
|
||||
igraph_vector_int_t *j,
|
||||
igraph_vector_t *x);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_scale_rows(igraph_sparsemat_t *A,
|
||||
const igraph_vector_t *fact);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_scale_cols(igraph_sparsemat_t *A,
|
||||
const igraph_vector_t *fact);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_multiply_by_dense(const igraph_sparsemat_t *A,
|
||||
const igraph_matrix_t *B,
|
||||
igraph_matrix_t *res);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_dense_multiply(const igraph_matrix_t *A,
|
||||
const igraph_sparsemat_t *B,
|
||||
igraph_matrix_t *res);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_sort(const igraph_sparsemat_t *A,
|
||||
igraph_sparsemat_t *sorted);
|
||||
|
||||
IGRAPH_EXPORT igraph_int_t igraph_sparsemat_nzmax(const igraph_sparsemat_t *A);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_neg(igraph_sparsemat_t *A);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_normalize_cols(igraph_sparsemat_t *sparsemat,
|
||||
igraph_bool_t allow_zeros);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_normalize_rows(igraph_sparsemat_t *sparsemat,
|
||||
igraph_bool_t allow_zeros);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_iterator_init(
|
||||
igraph_sparsemat_iterator_t *it, const igraph_sparsemat_t *sparsemat
|
||||
);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sparsemat_iterator_reset(igraph_sparsemat_iterator_t *it);
|
||||
IGRAPH_EXPORT igraph_bool_t igraph_sparsemat_iterator_end(const igraph_sparsemat_iterator_t *it);
|
||||
IGRAPH_EXPORT igraph_int_t igraph_sparsemat_iterator_row(const igraph_sparsemat_iterator_t *it);
|
||||
IGRAPH_EXPORT igraph_int_t igraph_sparsemat_iterator_col(const igraph_sparsemat_iterator_t *it);
|
||||
IGRAPH_EXPORT igraph_int_t igraph_sparsemat_iterator_idx(const igraph_sparsemat_iterator_t *it);
|
||||
IGRAPH_EXPORT igraph_real_t igraph_sparsemat_iterator_get(const igraph_sparsemat_iterator_t *it);
|
||||
IGRAPH_EXPORT igraph_int_t igraph_sparsemat_iterator_next(igraph_sparsemat_iterator_t *it);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_SPATIAL_H
|
||||
#define IGRAPH_SPATIAL_H
|
||||
|
||||
#include "igraph_datatype.h"
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_types.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_matrix.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
IGRAPH_EXPERIMENTAL IGRAPH_EXPORT igraph_error_t igraph_delaunay_graph(
|
||||
igraph_t *graph,
|
||||
const igraph_matrix_t *points);
|
||||
|
||||
IGRAPH_EXPERIMENTAL IGRAPH_EXPORT igraph_error_t igraph_lune_beta_skeleton(
|
||||
igraph_t *graph,
|
||||
const igraph_matrix_t *points,
|
||||
igraph_real_t beta);
|
||||
|
||||
IGRAPH_EXPERIMENTAL IGRAPH_EXPORT igraph_error_t igraph_circle_beta_skeleton(
|
||||
igraph_t *graph,
|
||||
const igraph_matrix_t *points,
|
||||
igraph_real_t beta);
|
||||
|
||||
IGRAPH_EXPERIMENTAL IGRAPH_EXPORT igraph_error_t igraph_beta_weighted_gabriel_graph(
|
||||
igraph_t *graph,
|
||||
igraph_vector_t *weights,
|
||||
const igraph_matrix_t *points,
|
||||
igraph_real_t max_beta);
|
||||
|
||||
IGRAPH_EXPERIMENTAL IGRAPH_EXPORT igraph_error_t igraph_gabriel_graph(
|
||||
igraph_t *graph, const igraph_matrix_t *points);
|
||||
|
||||
IGRAPH_EXPERIMENTAL IGRAPH_EXPORT igraph_error_t igraph_relative_neighborhood_graph(
|
||||
igraph_t *graph, const igraph_matrix_t *points);
|
||||
|
||||
/**
|
||||
* \typedef igraph_metric_t
|
||||
* \brief Metric functions for use with spatial computation.
|
||||
*
|
||||
* \enumval IGRAPH_METRIC_EUCLIDEAN The Euclidean distance, i.e. L2 metric.
|
||||
* \enumval IGRAPH_METRIC_MANHATTAN The Manhattan distance, i.e. L1 metric.
|
||||
*/
|
||||
typedef enum {
|
||||
IGRAPH_METRIC_EUCLIDEAN = 0,
|
||||
IGRAPH_METRIC_L2 = IGRAPH_METRIC_EUCLIDEAN,
|
||||
IGRAPH_METRIC_MANHATTAN = 1,
|
||||
IGRAPH_METRIC_L1 = IGRAPH_METRIC_MANHATTAN
|
||||
} igraph_metric_t;
|
||||
|
||||
IGRAPH_EXPERIMENTAL IGRAPH_EXPORT igraph_error_t igraph_nearest_neighbor_graph(
|
||||
igraph_t *graph,
|
||||
const igraph_matrix_t *points,
|
||||
igraph_metric_t metric,
|
||||
igraph_int_t neighbors,
|
||||
igraph_real_t cutoff,
|
||||
igraph_bool_t directed);
|
||||
|
||||
IGRAPH_EXPERIMENTAL IGRAPH_EXPORT igraph_error_t igraph_spatial_edge_lengths(
|
||||
const igraph_t *graph,
|
||||
igraph_vector_t *lengths,
|
||||
const igraph_matrix_t *points,
|
||||
igraph_metric_t metric);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_convex_hull_2d(
|
||||
const igraph_matrix_t *data,
|
||||
igraph_vector_int_t *resverts,
|
||||
igraph_matrix_t *rescoords);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2009-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_STACK_H
|
||||
#define IGRAPH_STACK_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_types.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* Plain stack */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
#define BASE_IGRAPH_REAL
|
||||
#include "igraph_pmt.h"
|
||||
#include "igraph_stack_pmt.h"
|
||||
#include "igraph_pmt_off.h"
|
||||
#undef BASE_IGRAPH_REAL
|
||||
|
||||
#define BASE_INT
|
||||
#include "igraph_pmt.h"
|
||||
#include "igraph_stack_pmt.h"
|
||||
#include "igraph_pmt_off.h"
|
||||
#undef BASE_INT
|
||||
|
||||
#define BASE_CHAR
|
||||
#include "igraph_pmt.h"
|
||||
#include "igraph_stack_pmt.h"
|
||||
#include "igraph_pmt_off.h"
|
||||
#undef BASE_CHAR
|
||||
|
||||
#define BASE_BOOL
|
||||
#include "igraph_pmt.h"
|
||||
#include "igraph_stack_pmt.h"
|
||||
#include "igraph_pmt_off.h"
|
||||
#undef BASE_BOOL
|
||||
|
||||
#define IGRAPH_STACK_NULL { 0,0,0 }
|
||||
#define IGRAPH_STACK_INIT_FINALLY(s, capacity) \
|
||||
do { IGRAPH_CHECK(igraph_stack_init(s, capacity)); \
|
||||
IGRAPH_FINALLY(igraph_stack_destroy, s); } while (0)
|
||||
#define IGRAPH_STACK_INT_INIT_FINALLY(s, capacity) \
|
||||
do { IGRAPH_CHECK(igraph_stack_int_init(s, capacity)); \
|
||||
IGRAPH_FINALLY(igraph_stack_int_destroy, s); } while (0)
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2007-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/**
|
||||
* Stack data type.
|
||||
* \ingroup internal
|
||||
*/
|
||||
|
||||
typedef struct TYPE(igraph_stack) {
|
||||
BASE* stor_begin;
|
||||
BASE* stor_end;
|
||||
BASE* end;
|
||||
} TYPE(igraph_stack);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_stack, init)(TYPE(igraph_stack)* s, igraph_int_t capacity);
|
||||
IGRAPH_EXPORT void FUNCTION(igraph_stack, destroy)(TYPE(igraph_stack)* s);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_stack, reserve)(TYPE(igraph_stack)* s, igraph_int_t capacity);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_bool_t FUNCTION(igraph_stack, empty)(TYPE(igraph_stack)* s);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_int_t FUNCTION(igraph_stack, size)(const TYPE(igraph_stack)* s);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_int_t FUNCTION(igraph_stack, capacity)(const TYPE(igraph_stack)* s);
|
||||
IGRAPH_EXPORT void FUNCTION(igraph_stack, clear)(TYPE(igraph_stack)* s);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_stack, push)(TYPE(igraph_stack)* s, BASE elem);
|
||||
IGRAPH_EXPORT BASE FUNCTION(igraph_stack, pop)(TYPE(igraph_stack)* s);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE BASE FUNCTION(igraph_stack, top)(const TYPE(igraph_stack)* s);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_stack, print)(const TYPE(igraph_stack)* s);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_stack, fprint)(const TYPE(igraph_stack)* s, FILE *file);
|
||||
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2010-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_STATUSBAR_H
|
||||
#define IGRAPH_STATUSBAR_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_error.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
/**
|
||||
* \section about_status_handlers Status reporting
|
||||
*
|
||||
* <para>
|
||||
* In addition to the possibility of reporting the progress of an
|
||||
* igraph computation via \ref igraph_progress(), it is also possible
|
||||
* to report simple status messages from within igraph functions,
|
||||
* without having to judge how much of the computation was performed
|
||||
* already. For this one needs to install a status handler function.
|
||||
* </para>
|
||||
*
|
||||
* <para>
|
||||
* Status handler functions must be of type \ref igraph_status_handler_t
|
||||
* and they can be installed by a call to \ref igraph_set_status_handler().
|
||||
* Currently there is a simple predefined status handler function,
|
||||
* called \ref igraph_status_handler_stderr(), but the user can define
|
||||
* new ones.
|
||||
* </para>
|
||||
*
|
||||
* <para>
|
||||
* igraph functions report their status via a call to the
|
||||
* \ref IGRAPH_STATUS() or the \ref IGRAPH_STATUSF() macro.
|
||||
* </para>
|
||||
*/
|
||||
|
||||
/**
|
||||
* \typedef igraph_status_handler_t
|
||||
*
|
||||
* The type of the igraph status handler functions
|
||||
* \param message The status message.
|
||||
* \param data Additional context, with user-defined semantics.
|
||||
* Existing igraph functions pass a null pointer here.
|
||||
* \return Error code. The current calculation will abort if you return anything
|
||||
* else than \c IGRAPH_SUCCESS here.
|
||||
*/
|
||||
|
||||
typedef igraph_error_t igraph_status_handler_t(const char *message, void *data);
|
||||
|
||||
IGRAPH_EXPORT extern igraph_status_handler_t igraph_status_handler_stderr;
|
||||
|
||||
IGRAPH_EXPORT igraph_status_handler_t *igraph_set_status_handler(igraph_status_handler_t new_handler);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_status(const char *message, void *data);
|
||||
|
||||
/**
|
||||
* \define IGRAPH_STATUS
|
||||
* Report the status of an igraph function.
|
||||
*
|
||||
* Typically this function is called only a handful of times from
|
||||
* an igraph function. E.g. if an algorithm has three major
|
||||
* steps, then it is logical to call it three times, to
|
||||
* signal the three major steps.
|
||||
* \param message The status message.
|
||||
* \param data Additional context, with user-defined semantics.
|
||||
* Existing igraph functions pass a null pointer here.
|
||||
* \return If the status handler returns with a value other than
|
||||
* \c IGRAPH_SUCCESS, then the function that called this
|
||||
* macro returns as well, with the same error code, after
|
||||
* cleaning up all allocated memory as needed.
|
||||
*/
|
||||
|
||||
#define IGRAPH_STATUS(message, data) \
|
||||
do { \
|
||||
IGRAPH_CHECK(igraph_status((message), (data))); \
|
||||
} while (0)
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_statusf(const char *message, void *data, ...);
|
||||
|
||||
/**
|
||||
* \define IGRAPH_STATUSF
|
||||
* Report the status from an igraph function
|
||||
*
|
||||
* This is the more flexible version of \ref IGRAPH_STATUS(),
|
||||
* having a printf-like syntax. As this macro takes variable
|
||||
* number of arguments, they must be all supplied as a single
|
||||
* argument, enclosed in parentheses. \ref igraph_statusf() is then
|
||||
* called with the given arguments.
|
||||
*
|
||||
* \param args The arguments to pass to \ref igraph_statusf().
|
||||
* \return If the status handler returns with a value other than
|
||||
* \c IGRAPH_SUCCESS, then the function that called this
|
||||
* macro returns as well, with the same error code, after
|
||||
* cleaning up all allocated memory as needed.
|
||||
*/
|
||||
|
||||
#define IGRAPH_STATUSF(args) \
|
||||
do { \
|
||||
IGRAPH_CHECK(igraph_statusf args); \
|
||||
} while (0)
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,173 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2009-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_STRUCTURAL_H
|
||||
#define IGRAPH_STRUCTURAL_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_datatype.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_constants.h"
|
||||
#include "igraph_iterators.h"
|
||||
#include "igraph_matrix.h"
|
||||
#include "igraph_sparsemat.h"
|
||||
#include "igraph_types.h"
|
||||
#include "igraph_vector.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* Basic query functions */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_are_adjacent(const igraph_t *graph, igraph_int_t v1, igraph_int_t v2, igraph_bool_t *res);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_count_multiple(const igraph_t *graph, igraph_vector_int_t *res, igraph_es_t es);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_count_multiple_1(const igraph_t *graph, igraph_int_t *res, igraph_int_t eid);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_density(const igraph_t *graph, const igraph_vector_t *weights,
|
||||
igraph_real_t *res, igraph_bool_t loops);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_diversity(const igraph_t *graph, const igraph_vector_t *weights,
|
||||
igraph_vector_t *res, igraph_vs_t vs);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_girth(const igraph_t *graph, igraph_real_t *girth,
|
||||
igraph_vector_int_t *circle);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_has_loop(const igraph_t *graph, igraph_bool_t *res);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_has_multiple(const igraph_t *graph, igraph_bool_t *res);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_count_loops(const igraph_t *graph, igraph_int_t *loop_count);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_is_loop(const igraph_t *graph, igraph_vector_bool_t *res,
|
||||
igraph_es_t es);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_is_multiple(const igraph_t *graph, igraph_vector_bool_t *res,
|
||||
igraph_es_t es);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_is_mutual(const igraph_t *graph, igraph_vector_bool_t *res, igraph_es_t es, igraph_bool_t loops);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_has_mutual(const igraph_t *graph, igraph_bool_t *res, igraph_bool_t loops);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_is_simple(const igraph_t *graph, igraph_bool_t *res, igraph_bool_t directed);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_is_tree(const igraph_t *graph, igraph_bool_t *res, igraph_int_t *root, igraph_neimode_t mode);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_is_acyclic(const igraph_t *graph, igraph_bool_t *res);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_is_forest(const igraph_t *graph, igraph_bool_t *res,
|
||||
igraph_vector_int_t *roots, igraph_neimode_t mode);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_maxdegree(const igraph_t *graph, igraph_int_t *res,
|
||||
igraph_vs_t vids, igraph_neimode_t mode,
|
||||
igraph_loops_t loops);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_mean_degree(const igraph_t *graph, igraph_real_t *res,
|
||||
igraph_bool_t loops);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_reciprocity(const igraph_t *graph, igraph_real_t *res,
|
||||
igraph_bool_t ignore_loops,
|
||||
igraph_reciprocity_t mode);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_strength(
|
||||
const igraph_t *graph, igraph_vector_t *res, igraph_vs_t vids,
|
||||
igraph_neimode_t mode, igraph_loops_t loops, const igraph_vector_t *weights
|
||||
);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_sort_vertex_ids_by_degree(
|
||||
const igraph_t *graph, igraph_vector_int_t *outvids, igraph_vs_t vids,
|
||||
igraph_neimode_t mode, igraph_loops_t loops, igraph_order_t order,
|
||||
igraph_bool_t only_indices
|
||||
);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_is_perfect(const igraph_t *graph, igraph_bool_t *perfect);
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* Structural properties */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_is_complete(const igraph_t *graph, igraph_bool_t *res);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_is_clique(const igraph_t *graph, igraph_vs_t candidate,
|
||||
igraph_bool_t directed, igraph_bool_t *res);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_is_independent_vertex_set(const igraph_t *graph, igraph_vs_t candidate,
|
||||
igraph_bool_t *res);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_minimum_spanning_tree(
|
||||
const igraph_t *graph, igraph_vector_int_t *res,
|
||||
const igraph_vector_t *weights, igraph_mst_algorithm_t method);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_random_spanning_tree(const igraph_t *graph, igraph_vector_int_t *res,
|
||||
igraph_int_t vid);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_subcomponent(const igraph_t *graph, igraph_vector_int_t *res, igraph_int_t vid,
|
||||
igraph_neimode_t mode);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_unfold_tree(const igraph_t *graph, igraph_t *tree,
|
||||
igraph_neimode_t mode, const igraph_vector_int_t *roots,
|
||||
igraph_vector_int_t *vertex_index);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_maximum_cardinality_search(const igraph_t *graph,
|
||||
igraph_vector_int_t *alpha,
|
||||
igraph_vector_int_t *alpham1);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_is_chordal(const igraph_t *graph,
|
||||
const igraph_vector_int_t *alpha,
|
||||
const igraph_vector_int_t *alpham1,
|
||||
igraph_bool_t *chordal,
|
||||
igraph_vector_int_t *fill_in,
|
||||
igraph_t *newgraph);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_avg_nearest_neighbor_degree(const igraph_t *graph,
|
||||
igraph_vs_t vids,
|
||||
igraph_neimode_t mode,
|
||||
igraph_neimode_t neighbor_degree_mode,
|
||||
igraph_vector_t *knn,
|
||||
igraph_vector_t *knnk,
|
||||
const igraph_vector_t *weights);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_degree_correlation_vector(
|
||||
const igraph_t *graph, const igraph_vector_t *weights,
|
||||
igraph_vector_t *knnk,
|
||||
igraph_neimode_t from_mode, igraph_neimode_t to_mode,
|
||||
igraph_bool_t directed_neighbors);
|
||||
|
||||
IGRAPH_EXPERIMENTAL IGRAPH_EXPORT igraph_error_t igraph_rich_club_sequence(
|
||||
const igraph_t *graph,
|
||||
const igraph_vector_t *weights,
|
||||
igraph_vector_t *res,
|
||||
const igraph_vector_int_t *vertex_order,
|
||||
igraph_bool_t normalized,
|
||||
igraph_bool_t loops,
|
||||
igraph_bool_t directed);
|
||||
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* Spectral Properties */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* \typedef igraph_laplacian_normalization_t
|
||||
* \brief Normalization methods for a Laplacian matrix.
|
||||
*
|
||||
* Normalization methods for \ref igraph_get_laplacian() and
|
||||
* \ref igraph_get_laplacian_sparse(). In the following, \c A refers to the
|
||||
* (possibly weighted) adjacency matrix and \c D is a diagonal matrix containing
|
||||
* degrees (unweighted case) or strengths (weighted case). Out-, in- or total degrees
|
||||
* are used according to the \p mode parameter.
|
||||
*
|
||||
* \enumval IGRAPH_LAPLACIAN_UNNORMALIZED Unnormalized Laplacian, <code>L = D - A</code>.
|
||||
* \enumval IGRAPH_LAPLACIAN_SYMMETRIC Symmetrically normalized Laplacian, <code>L = I - D^(-1/2) A D^(-1/2)</code>.
|
||||
* \enumval IGRAPH_LAPLACIAN_LEFT Left-stochastic normalized Laplacian, <code>L = I - D^-1 A</code>.
|
||||
* \enumval IGRAPH_LAPLACIAN_RIGHT Right-stochastic normalized Laplacian, <code>L = I - A D^-1</code>.
|
||||
*/
|
||||
typedef enum {
|
||||
IGRAPH_LAPLACIAN_UNNORMALIZED = 0,
|
||||
IGRAPH_LAPLACIAN_SYMMETRIC = 1,
|
||||
IGRAPH_LAPLACIAN_LEFT = 2,
|
||||
IGRAPH_LAPLACIAN_RIGHT = 3
|
||||
} igraph_laplacian_normalization_t;
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_get_laplacian(
|
||||
const igraph_t *graph, igraph_matrix_t *res, igraph_neimode_t mode,
|
||||
igraph_laplacian_normalization_t normalization,
|
||||
const igraph_vector_t *weights
|
||||
);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_get_laplacian_sparse(
|
||||
const igraph_t *graph, igraph_sparsemat_t *sparseres, igraph_neimode_t mode,
|
||||
igraph_laplacian_normalization_t normalization,
|
||||
const igraph_vector_t *weights
|
||||
);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2009-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_STRVECTOR_H
|
||||
#define IGRAPH_STRVECTOR_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_vector.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
/**
|
||||
* Vector of strings
|
||||
* \ingroup internal
|
||||
*/
|
||||
|
||||
typedef struct s_igraph_strvector {
|
||||
/* Empty strings "" are represented using NULL. */
|
||||
const char **stor_begin;
|
||||
const char **stor_end;
|
||||
const char **end;
|
||||
} igraph_strvector_t;
|
||||
|
||||
/**
|
||||
* \define STR
|
||||
* \brief Indexing string vectors.
|
||||
*
|
||||
* This is a macro that allows to query the elements of a string vector, just
|
||||
* like \ref igraph_strvector_get(). Note this macro cannot be used to set an
|
||||
* element. Use \ref igraph_strvector_set() to set an element instead.
|
||||
*
|
||||
* \param sv The string vector
|
||||
* \param i The index of the element.
|
||||
* \return The element at position \p i.
|
||||
*
|
||||
* Time complexity: O(1).
|
||||
*
|
||||
* \deprecated-by igraph_strvector_get 0.10.9
|
||||
*/
|
||||
#define STR(sv,i) \
|
||||
(IGRAPH_PREPROCESSOR_WARNING("STR() is deprecated. Use igraph_strvector_get() instead.") \
|
||||
igraph_strvector_get(&sv, i))
|
||||
|
||||
#define IGRAPH_STRVECTOR_NULL { 0,0,0 }
|
||||
#define IGRAPH_STRVECTOR_INIT_FINALLY(sv, size) \
|
||||
do { IGRAPH_CHECK(igraph_strvector_init(sv, size)); \
|
||||
IGRAPH_FINALLY( igraph_strvector_destroy, sv); } while (0)
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_strvector_init(igraph_strvector_t *sv, igraph_int_t len);
|
||||
IGRAPH_EXPORT void igraph_strvector_destroy(igraph_strvector_t *sv);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_int_t igraph_strvector_size(const igraph_strvector_t *sv);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_int_t igraph_strvector_capacity(const igraph_strvector_t *sv);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE const char *igraph_strvector_get(const igraph_strvector_t *sv, igraph_int_t idx);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_strvector_set(
|
||||
igraph_strvector_t *sv, igraph_int_t idx, const char *value);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_strvector_set_len(
|
||||
igraph_strvector_t *sv, igraph_int_t idx, const char *value, size_t len);
|
||||
IGRAPH_EXPORT void igraph_strvector_clear(igraph_strvector_t *sv);
|
||||
IGRAPH_EXPORT void igraph_strvector_remove_section(
|
||||
igraph_strvector_t *v, igraph_int_t from, igraph_int_t to);
|
||||
IGRAPH_EXPORT void igraph_strvector_remove(
|
||||
igraph_strvector_t *v, igraph_int_t elem);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_strvector_init_copy(
|
||||
igraph_strvector_t *to, const igraph_strvector_t *from);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_strvector_append(
|
||||
igraph_strvector_t *to, const igraph_strvector_t *from);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_strvector_merge(
|
||||
igraph_strvector_t *to, igraph_strvector_t *from);
|
||||
IGRAPH_EXPORT void igraph_strvector_swap(igraph_strvector_t *v1, igraph_strvector_t *v2);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_strvector_update(
|
||||
igraph_strvector_t *to, const igraph_strvector_t *from);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_strvector_resize(
|
||||
igraph_strvector_t* v, igraph_int_t newsize);
|
||||
IGRAPH_EXPORT void igraph_strvector_resize_min(igraph_strvector_t *sv);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_strvector_push_back(igraph_strvector_t *v,
|
||||
const char *value);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_strvector_push_back_len(igraph_strvector_t *v,
|
||||
const char *value, size_t len);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_strvector_fprint(const igraph_strvector_t *v, FILE *file,
|
||||
const char *sep);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_strvector_print(const igraph_strvector_t *v,
|
||||
const char *sep);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_strvector_index(const igraph_strvector_t *v,
|
||||
igraph_strvector_t *newv,
|
||||
const igraph_vector_int_t *idx);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_strvector_reserve(igraph_strvector_t *sv,
|
||||
igraph_int_t capacity);
|
||||
|
||||
IGRAPH_EXPORT void igraph_strvector_swap_elements(igraph_strvector_t *sv,
|
||||
igraph_int_t i, igraph_int_t j);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2011-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_THREADING_H
|
||||
#define IGRAPH_THREADING_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
/**
|
||||
* \define IGRAPH_THREAD_SAFE
|
||||
*
|
||||
* Specifies whether igraph was built in thread-safe mode.
|
||||
*
|
||||
* This macro is defined to 1 if the current build of the igraph library is
|
||||
* built in thread-safe mode, and 0 if it is not. A thread-safe igraph library
|
||||
* attempts to use thread-local data structures instead of global ones, but
|
||||
* note that this is not (and can not) be guaranteed for third-party libraries
|
||||
* that igraph links to.
|
||||
*/
|
||||
|
||||
#cmakedefine01 IGRAPH_THREAD_SAFE
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2009-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_TRANSITIVITY_H
|
||||
#define IGRAPH_TRANSITIVITY_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_datatype.h"
|
||||
#include "igraph_constants.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_iterators.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_transitivity_undirected(const igraph_t *graph,
|
||||
igraph_real_t *res,
|
||||
igraph_transitivity_mode_t mode);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_transitivity_local_undirected(const igraph_t *graph,
|
||||
igraph_vector_t *res,
|
||||
igraph_vs_t vids,
|
||||
igraph_transitivity_mode_t mode);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_transitivity_avglocal_undirected(const igraph_t *graph,
|
||||
igraph_real_t *res,
|
||||
igraph_transitivity_mode_t mode);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_transitivity_barrat(const igraph_t *graph,
|
||||
igraph_vector_t *res,
|
||||
igraph_vs_t vids,
|
||||
const igraph_vector_t *weights,
|
||||
igraph_transitivity_mode_t mode);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_ecc(const igraph_t *graph,
|
||||
igraph_vector_t *res,
|
||||
igraph_es_t eids,
|
||||
igraph_int_t k,
|
||||
igraph_bool_t offset,
|
||||
igraph_bool_t normalize);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2021-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#if defined(VECTOR_LIST)
|
||||
/* It was indicated that every item in a list is a vector of the base type
|
||||
* so let's define ITEM_TYPE appropriately */
|
||||
#define ITEM_TYPE BASE_VECTOR
|
||||
#elif defined(MATRIX_LIST)
|
||||
/* It was indicated that every item in a list is a matrix of the base type
|
||||
* so let's define ITEM_TYPE appropriately */
|
||||
#define ITEM_TYPE BASE_MATRIX
|
||||
#else
|
||||
#define ITEM_TYPE BASE
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Vector list, dealing with lists of typed vectors efficiently.
|
||||
* \ingroup types
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
ITEM_TYPE* stor_begin;
|
||||
ITEM_TYPE* stor_end;
|
||||
ITEM_TYPE* end;
|
||||
#ifdef EXTRA_TYPE_FIELDS
|
||||
EXTRA_TYPE_FIELDS
|
||||
#endif
|
||||
} TYPE;
|
||||
|
||||
/*--------------------*/
|
||||
/* Allocation */
|
||||
/*--------------------*/
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(init)(TYPE* v, igraph_int_t size);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(init_copy)(TYPE* to, const TYPE* from);
|
||||
IGRAPH_EXPORT void FUNCTION(destroy)(TYPE* v);
|
||||
|
||||
/*--------------------*/
|
||||
/* Accessing elements */
|
||||
/*--------------------*/
|
||||
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE ITEM_TYPE* FUNCTION(get_ptr)(const TYPE* v, igraph_int_t pos);
|
||||
IGRAPH_EXPORT void FUNCTION(set)(TYPE* v, igraph_int_t pos, ITEM_TYPE* e);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE ITEM_TYPE* FUNCTION(tail_ptr)(const TYPE *v);
|
||||
|
||||
/*-----------------*/
|
||||
/* List properties */
|
||||
/*-----------------*/
|
||||
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_int_t FUNCTION(capacity)(const TYPE* v);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_bool_t FUNCTION(empty)(const TYPE* v);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_int_t FUNCTION(size)(const TYPE* v);
|
||||
|
||||
/*------------------------*/
|
||||
/* Resizing operations */
|
||||
/*------------------------*/
|
||||
|
||||
IGRAPH_EXPORT void FUNCTION(clear)(TYPE* v);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(reserve)(TYPE* v, igraph_int_t capacity);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(resize)(TYPE* v, igraph_int_t new_size);
|
||||
|
||||
/*------------------------*/
|
||||
/* Adding/removing items */
|
||||
/*------------------------*/
|
||||
|
||||
IGRAPH_EXPORT void FUNCTION(discard)(TYPE* v, igraph_int_t index);
|
||||
IGRAPH_EXPORT void FUNCTION(discard_back)(TYPE* v);
|
||||
IGRAPH_EXPORT void FUNCTION(discard_fast)(TYPE* v, igraph_int_t index);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(insert)(TYPE* v, igraph_int_t pos, ITEM_TYPE* e);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(insert_copy)(TYPE* v, igraph_int_t pos, const ITEM_TYPE* e);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(insert_new)(TYPE* v, igraph_int_t pos, ITEM_TYPE** result);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(push_back)(TYPE* v, ITEM_TYPE* e);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(push_back_copy)(TYPE* v, const ITEM_TYPE* e);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(push_back_new)(TYPE* v, ITEM_TYPE** result);
|
||||
IGRAPH_EXPORT ITEM_TYPE FUNCTION(pop_back)(TYPE* v);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(remove)(TYPE* v, igraph_int_t index, ITEM_TYPE* e);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(remove_fast)(TYPE* v, igraph_int_t index, ITEM_TYPE* e);
|
||||
IGRAPH_EXPORT void FUNCTION(replace)(TYPE* v, igraph_int_t pos, ITEM_TYPE* e);
|
||||
IGRAPH_EXPORT void FUNCTION(remove_consecutive_duplicates)(TYPE *v, igraph_bool_t (*eq)(const ITEM_TYPE*, const ITEM_TYPE*));
|
||||
|
||||
/*------------------*/
|
||||
/* Exchanging items */
|
||||
/*------------------*/
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(permute)(TYPE *v, const igraph_vector_int_t *index);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(reverse)(TYPE *v);
|
||||
IGRAPH_EXPORT void FUNCTION(swap)(TYPE *v1, TYPE *v2);
|
||||
IGRAPH_EXPORT void FUNCTION(swap_elements)(TYPE* v, igraph_int_t i, igraph_int_t j);
|
||||
|
||||
/*-----------*/
|
||||
/* Sorting */
|
||||
/*-----------*/
|
||||
|
||||
IGRAPH_EXPORT void FUNCTION(sort)(
|
||||
TYPE *v, int (*cmp)(const ITEM_TYPE*, const ITEM_TYPE*));
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(sort_ind)(
|
||||
TYPE *v, igraph_vector_int_t *ind,
|
||||
int (*cmp)(const ITEM_TYPE*, const ITEM_TYPE*)
|
||||
);
|
||||
|
||||
#undef ITEM_TYPE
|
||||
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2003-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_TYPES_H
|
||||
#define IGRAPH_TYPES_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define __STDC_FORMAT_MACROS /* needed for PRId32 and PRId64 from inttypes.h on Linux */
|
||||
#endif
|
||||
|
||||
#include "igraph_config.h"
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <math.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
#if !defined(IGRAPH_INTEGER_SIZE)
|
||||
# error "igraph integer size not defined; check the value of IGRAPH_INTEGER_SIZE when compiling"
|
||||
#elif IGRAPH_INTEGER_SIZE == 64
|
||||
typedef int64_t igraph_int_t;
|
||||
typedef uint64_t igraph_uint_t;
|
||||
#elif IGRAPH_INTEGER_SIZE == 32
|
||||
typedef int32_t igraph_int_t;
|
||||
typedef uint32_t igraph_uint_t;
|
||||
#else
|
||||
# error "Invalid igraph integer size; check the value of IGRAPH_INTEGER_SIZE when compiling"
|
||||
#endif
|
||||
|
||||
typedef igraph_int_t igraph_integer_t;
|
||||
|
||||
typedef double igraph_real_t;
|
||||
|
||||
/* IGRAPH_BOOL_TYPE is set to 'bool' by default, and it is not meant to be
|
||||
* overridden, except for the R interface where we know what we are doing.
|
||||
* See igraph_config.h for more info */
|
||||
typedef IGRAPH_BOOL_TYPE igraph_bool_t;
|
||||
|
||||
/* printf format specifier for igraph_int_t */
|
||||
#if IGRAPH_INTEGER_SIZE == 64
|
||||
# define IGRAPH_PRId PRId64
|
||||
# define IGRAPH_PRIu PRIu64
|
||||
#else
|
||||
# define IGRAPH_PRId PRId32
|
||||
# define IGRAPH_PRIu PRIu32
|
||||
#endif
|
||||
|
||||
/* maximum and minimum allowed values for igraph_int_t */
|
||||
#if IGRAPH_INTEGER_SIZE == 64
|
||||
# define IGRAPH_INTEGER_MAX INT64_MAX
|
||||
# define IGRAPH_INTEGER_MIN INT64_MIN
|
||||
#else
|
||||
# define IGRAPH_INTEGER_MAX INT32_MAX
|
||||
# define IGRAPH_INTEGER_MIN INT32_MIN
|
||||
#endif
|
||||
|
||||
/* maximum and minimum allowed values for igraph_uint_t */
|
||||
#if IGRAPH_INTEGER_SIZE == 64
|
||||
# define IGRAPH_UINT_MAX UINT64_MAX
|
||||
# define IGRAPH_UINT_MIN UINT64_MIN
|
||||
#else
|
||||
# define IGRAPH_UINT_MAX UINT32_MAX
|
||||
# define IGRAPH_UINT_MIN UINT32_MIN
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* \define IGRAPH_VCOUNT_MAX
|
||||
* \brief The maximum number of vertices supported in igraph graphs.
|
||||
*
|
||||
* The value of this constant is one less than \c IGRAPH_INTEGER_MAX .
|
||||
* When igraph is compiled in 32-bit mode, this means that you are limited
|
||||
* to 2<superscript>31</superscript> – 2 (about 2.1 billion) vertices. In
|
||||
* 64-bit mode, the limit is 2<superscript>63</superscript> – 2 so you are much
|
||||
* more likely to hit out-of-memory issues due to other reasons before reaching
|
||||
* this limit.
|
||||
*/
|
||||
#define IGRAPH_VCOUNT_MAX (IGRAPH_INTEGER_MAX-1)
|
||||
/* The 'os' and 'is' vectors in igraph_t have vcount+1 elements,
|
||||
* thus this cannot currently be larger than IGRAPH_INTEGER_MAX-1.
|
||||
* Several functions rely on this value not exceeding IGRAPH_INTEGER_MAX-1
|
||||
* to avoid overflow.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \define IGRAPH_ECOUNT_MAX
|
||||
* \brief The maximum number of edges supported in igraph graphs.
|
||||
*
|
||||
* The value of this constant is half of \c IGRAPH_INTEGER_MAX .
|
||||
* When igraph is compiled in 32-bit mode, this means that you are limited
|
||||
* to approximately 2<superscript>30</superscript> (about 1.07 billion)
|
||||
* vertices. In 64-bit mode, the limit is approximately
|
||||
* 2<superscript>62</superscript> so you are much more likely to hit
|
||||
* out-of-memory issues due to other reasons before reaching this limit.
|
||||
*/
|
||||
#define IGRAPH_ECOUNT_MAX (IGRAPH_INTEGER_MAX/2)
|
||||
/* The endpoints of edges are often stored in a vector twice the length
|
||||
* of the edge count, thus this cannot be larger than IGRAPH_INTEGER_MAX/2.
|
||||
* Some of the overflow checking code relies on this. */
|
||||
|
||||
/* Replacements for printf that print doubles in the same way on all platforms
|
||||
* (even for NaN and infinities) */
|
||||
IGRAPH_EXPORT int igraph_real_printf(igraph_real_t val);
|
||||
IGRAPH_EXPORT int igraph_real_fprintf(FILE *file, igraph_real_t val);
|
||||
IGRAPH_EXPORT int igraph_real_printf_aligned(int width, igraph_real_t val);
|
||||
IGRAPH_EXPORT int igraph_real_fprintf_aligned(FILE *file, int width, igraph_real_t val);
|
||||
IGRAPH_EXPORT int igraph_real_snprintf(char *str, size_t size, igraph_real_t val);
|
||||
|
||||
/* Replacements for printf that print doubles in the same way on all platforms
|
||||
* (even for NaN and infinities) with the largest possible precision */
|
||||
IGRAPH_EXPORT int igraph_real_printf_precise(igraph_real_t val);
|
||||
IGRAPH_EXPORT int igraph_real_fprintf_precise(FILE *file, igraph_real_t val);
|
||||
IGRAPH_EXPORT int igraph_real_snprintf_precise(char *str, size_t size, igraph_real_t val);
|
||||
|
||||
#define IGRAPH_INFINITY ((double)INFINITY)
|
||||
#define IGRAPH_NAN ((double)NAN)
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,158 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2009-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_VECTOR_H
|
||||
#define IGRAPH_VECTOR_H
|
||||
|
||||
#include "igraph_complex.h"
|
||||
#include "igraph_constants.h"
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_types.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* Flexible vector */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
#define BASE_IGRAPH_REAL
|
||||
#include "igraph_pmt.h"
|
||||
#include "igraph_vector_type.h"
|
||||
#include "igraph_pmt_off.h"
|
||||
#undef BASE_IGRAPH_REAL
|
||||
|
||||
#define BASE_CHAR
|
||||
#include "igraph_pmt.h"
|
||||
#include "igraph_vector_type.h"
|
||||
#include "igraph_pmt_off.h"
|
||||
#undef BASE_CHAR
|
||||
|
||||
#define BASE_BOOL
|
||||
#include "igraph_pmt.h"
|
||||
#include "igraph_vector_type.h"
|
||||
#include "igraph_pmt_off.h"
|
||||
#undef BASE_BOOL
|
||||
|
||||
#define BASE_INT
|
||||
#include "igraph_pmt.h"
|
||||
#include "igraph_vector_type.h"
|
||||
#include "igraph_pmt_off.h"
|
||||
#undef BASE_INT
|
||||
|
||||
#define BASE_COMPLEX
|
||||
#include "igraph_pmt.h"
|
||||
#include "igraph_vector_type.h"
|
||||
#include "igraph_pmt_off.h"
|
||||
#undef BASE_COMPLEX
|
||||
|
||||
#define BASE_IGRAPH_REAL
|
||||
#include "igraph_pmt.h"
|
||||
#include "igraph_vector_pmt.h"
|
||||
#include "igraph_pmt_off.h"
|
||||
#undef BASE_IGRAPH_REAL
|
||||
|
||||
#define BASE_CHAR
|
||||
#include "igraph_pmt.h"
|
||||
#include "igraph_vector_pmt.h"
|
||||
#include "igraph_pmt_off.h"
|
||||
#undef BASE_CHAR
|
||||
|
||||
#define BASE_BOOL
|
||||
#include "igraph_pmt.h"
|
||||
#include "igraph_vector_pmt.h"
|
||||
#include "igraph_pmt_off.h"
|
||||
#undef BASE_BOOL
|
||||
|
||||
#define BASE_INT
|
||||
#include "igraph_pmt.h"
|
||||
#include "igraph_vector_pmt.h"
|
||||
#include "igraph_pmt_off.h"
|
||||
#undef BASE_INT
|
||||
|
||||
#define BASE_COMPLEX
|
||||
#include "igraph_pmt.h"
|
||||
#include "igraph_vector_pmt.h"
|
||||
#include "igraph_pmt_off.h"
|
||||
#undef BASE_COMPLEX
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* Helper macros */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
#ifndef IGRAPH_VECTOR_NULL
|
||||
#define IGRAPH_VECTOR_NULL { 0,0,0 }
|
||||
#endif
|
||||
|
||||
#ifndef IGRAPH_VECTOR_INIT_FINALLY
|
||||
#define IGRAPH_VECTOR_INIT_FINALLY(v, size) \
|
||||
do { IGRAPH_CHECK(igraph_vector_init(v, size)); \
|
||||
IGRAPH_FINALLY(igraph_vector_destroy, v); } while (0)
|
||||
#endif
|
||||
#ifndef IGRAPH_VECTOR_BOOL_INIT_FINALLY
|
||||
#define IGRAPH_VECTOR_BOOL_INIT_FINALLY(v, size) \
|
||||
do { IGRAPH_CHECK(igraph_vector_bool_init(v, size)); \
|
||||
IGRAPH_FINALLY(igraph_vector_bool_destroy, v); } while (0)
|
||||
#endif
|
||||
#ifndef IGRAPH_VECTOR_CHAR_INIT_FINALLY
|
||||
#define IGRAPH_VECTOR_CHAR_INIT_FINALLY(v, size) \
|
||||
do { IGRAPH_CHECK(igraph_vector_char_init(v, size)); \
|
||||
IGRAPH_FINALLY(igraph_vector_char_destroy, v); } while (0)
|
||||
#endif
|
||||
#ifndef IGRAPH_VECTOR_INT_INIT_FINALLY
|
||||
#define IGRAPH_VECTOR_INT_INIT_FINALLY(v, size) \
|
||||
do { IGRAPH_CHECK(igraph_vector_int_init(v, size)); \
|
||||
IGRAPH_FINALLY(igraph_vector_int_destroy, v); } while (0)
|
||||
#endif
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* Type-specific vector functions */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_vector_floor(const igraph_vector_t *from, igraph_vector_int_t *to);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_vector_round(const igraph_vector_t *from, igraph_vector_int_t *to);
|
||||
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_bool_t igraph_vector_all_almost_e(const igraph_vector_t *lhs,
|
||||
const igraph_vector_t *rhs,
|
||||
igraph_real_t eps);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_vector_zapsmall(igraph_vector_t *v, igraph_real_t tol);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_vector_complex_zapsmall(igraph_vector_complex_t *v, igraph_real_t tol) ;
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_vector_is_nan(const igraph_vector_t *v,
|
||||
igraph_vector_bool_t *is_nan);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_bool_t igraph_vector_is_any_nan(const igraph_vector_t *v);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_bool_t igraph_vector_is_all_finite(const igraph_vector_t *v);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_vector_int_pair_order(const igraph_vector_int_t* v, const igraph_vector_int_t *v2,
|
||||
igraph_vector_int_t* res, igraph_int_t maxval);
|
||||
|
||||
/* For internal use only: */
|
||||
|
||||
IGRAPH_PRIVATE_EXPORT igraph_error_t igraph_i_vector_int_order(
|
||||
const igraph_vector_int_t* v,
|
||||
igraph_vector_int_t* res,
|
||||
igraph_int_t maxval);
|
||||
IGRAPH_PRIVATE_EXPORT igraph_error_t igraph_i_vector_int_rank(
|
||||
const igraph_vector_int_t *v,
|
||||
igraph_vector_int_t *res,
|
||||
igraph_int_t maxval);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2022-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_VECTOR_LIST_H
|
||||
#define IGRAPH_VECTOR_LIST_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_types.h"
|
||||
#include "igraph_vector.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* Flexible list of vectors */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
/* Indicate to igraph_typed_list_pmt.h that we are going to work with _vectors_
|
||||
* of the base type, not the base type directly */
|
||||
#define VECTOR_LIST
|
||||
|
||||
#define BASE_IGRAPH_REAL
|
||||
#include "igraph_pmt.h"
|
||||
#include "igraph_typed_list_pmt.h"
|
||||
#include "igraph_pmt_off.h"
|
||||
#undef BASE_IGRAPH_REAL
|
||||
|
||||
#define BASE_INT
|
||||
#include "igraph_pmt.h"
|
||||
#include "igraph_typed_list_pmt.h"
|
||||
#include "igraph_pmt_off.h"
|
||||
#undef BASE_INT
|
||||
|
||||
#undef VECTOR_LIST
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* Helper macros */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
#define IGRAPH_VECTOR_LIST_INIT_FINALLY(v, size) \
|
||||
do { IGRAPH_CHECK(igraph_vector_list_init(v, size)); \
|
||||
IGRAPH_FINALLY(igraph_vector_list_destroy, v); } while (0)
|
||||
#define IGRAPH_VECTOR_INT_LIST_INIT_FINALLY(v, size) \
|
||||
do { IGRAPH_CHECK(igraph_vector_int_list_init(v, size)); \
|
||||
IGRAPH_FINALLY(igraph_vector_int_list_destroy, v); } while (0)
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,313 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2007-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*--------------------*/
|
||||
/* Allocation */
|
||||
/*--------------------*/
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_vector, init)(
|
||||
TYPE(igraph_vector) *v, igraph_int_t size);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_vector, init_array)(
|
||||
TYPE(igraph_vector) *v, const BASE *data, igraph_int_t length);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_vector, init_copy)(
|
||||
TYPE(igraph_vector) *to, const TYPE(igraph_vector) *from);
|
||||
|
||||
#ifndef NOTORDERED
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_vector, init_range)(TYPE(igraph_vector)*v, BASE start, BASE end);
|
||||
#endif
|
||||
|
||||
IGRAPH_EXPORT void FUNCTION(igraph_vector, destroy)(TYPE(igraph_vector) *v);
|
||||
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_int_t FUNCTION(igraph_vector, capacity)(const TYPE(igraph_vector)*v);
|
||||
|
||||
/*--------------------*/
|
||||
/* Accessing elements */
|
||||
/*--------------------*/
|
||||
|
||||
#ifndef VECTOR
|
||||
/**
|
||||
* \ingroup vector
|
||||
* \define VECTOR
|
||||
* \brief Accessing an element of a vector.
|
||||
*
|
||||
* Usage:
|
||||
* \verbatim VECTOR(v)[0] \endverbatim
|
||||
* to access the first element of the vector, you can also use this in
|
||||
* assignments, like:
|
||||
* \verbatim VECTOR(v)[10] = 5; \endverbatim
|
||||
*
|
||||
* Note that there are no range checks right now.
|
||||
*
|
||||
* \param v The vector object.
|
||||
*
|
||||
* Time complexity: O(1).
|
||||
*/
|
||||
#define VECTOR(v) ((v).stor_begin)
|
||||
#endif
|
||||
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE BASE FUNCTION(igraph_vector, get)(const TYPE(igraph_vector) *v, igraph_int_t pos);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE BASE* FUNCTION(igraph_vector, get_ptr)(const TYPE(igraph_vector) *v, igraph_int_t pos);
|
||||
IGRAPH_EXPORT void FUNCTION(igraph_vector, set)(TYPE(igraph_vector) *v, igraph_int_t pos, BASE value);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE BASE FUNCTION(igraph_vector, tail)(const TYPE(igraph_vector) *v);
|
||||
|
||||
/*-----------------------*/
|
||||
/* Initializing elements */
|
||||
/*-----------------------*/
|
||||
|
||||
IGRAPH_EXPORT void FUNCTION(igraph_vector, null)(TYPE(igraph_vector) *v);
|
||||
IGRAPH_EXPORT void FUNCTION(igraph_vector, fill)(TYPE(igraph_vector) *v, BASE e);
|
||||
|
||||
#ifndef NOTORDERED
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_vector, range)(TYPE(igraph_vector) *v, BASE start, BASE end);
|
||||
#endif
|
||||
|
||||
/*-----------------------*/
|
||||
/* Vector views */
|
||||
/*-----------------------*/
|
||||
|
||||
IGRAPH_EXPORT TYPE(igraph_vector) FUNCTION(igraph_vector, view)(const BASE *data,
|
||||
igraph_int_t length);
|
||||
|
||||
/*-----------------------*/
|
||||
/* Copying vectors */
|
||||
/*-----------------------*/
|
||||
|
||||
IGRAPH_EXPORT void FUNCTION(igraph_vector, copy_to)(const TYPE(igraph_vector) *v, BASE *to);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_vector, update)(TYPE(igraph_vector) *to,
|
||||
const TYPE(igraph_vector) *from);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_vector, append)(TYPE(igraph_vector) *to,
|
||||
const TYPE(igraph_vector) *from);
|
||||
IGRAPH_EXPORT void FUNCTION(igraph_vector, swap)(TYPE(igraph_vector) *v1, TYPE(igraph_vector) *v2);
|
||||
|
||||
/*-----------------------*/
|
||||
/* Exchanging elements */
|
||||
/*-----------------------*/
|
||||
|
||||
IGRAPH_EXPORT void FUNCTION(igraph_vector, swap_elements)(
|
||||
TYPE(igraph_vector) *v, igraph_int_t i, igraph_int_t j);
|
||||
IGRAPH_EXPORT void FUNCTION(igraph_vector, reverse)(TYPE(igraph_vector) *v);
|
||||
IGRAPH_EXPORT void FUNCTION(igraph_vector, reverse_section)(
|
||||
TYPE(igraph_vector) *v, igraph_int_t from, igraph_int_t to);
|
||||
IGRAPH_EXPORT void FUNCTION(igraph_vector, rotate_left)(
|
||||
TYPE(igraph_vector) *v, igraph_int_t n);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_vector, permute)(TYPE(igraph_vector) *v,
|
||||
const igraph_vector_int_t *ind);
|
||||
IGRAPH_EXPORT void FUNCTION(igraph_vector, shuffle)(TYPE(igraph_vector) *v);
|
||||
|
||||
/*-----------------------*/
|
||||
/* Vector operations */
|
||||
/*-----------------------*/
|
||||
|
||||
IGRAPH_EXPORT void FUNCTION(igraph_vector, add_constant)(TYPE(igraph_vector) *v, BASE plus);
|
||||
IGRAPH_EXPORT void FUNCTION(igraph_vector, scale)(TYPE(igraph_vector) *v, BASE by);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_vector, add)(TYPE(igraph_vector) *v1,
|
||||
const TYPE(igraph_vector) *v2);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_vector, sub)(TYPE(igraph_vector) *v1,
|
||||
const TYPE(igraph_vector) *v2);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_vector, mul)(TYPE(igraph_vector) *v1,
|
||||
const TYPE(igraph_vector) *v2);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_vector, div)(TYPE(igraph_vector) *v1,
|
||||
const TYPE(igraph_vector) *v2);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_vector, cumsum)(TYPE(igraph_vector) *to,
|
||||
const TYPE(igraph_vector) *from);
|
||||
|
||||
#ifndef NOABS
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_vector, abs)(TYPE(igraph_vector) *v);
|
||||
#endif
|
||||
|
||||
/*------------------------------*/
|
||||
/* Comparison */
|
||||
/*------------------------------*/
|
||||
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_bool_t FUNCTION(igraph_vector, all_e)(const TYPE(igraph_vector) *lhs,
|
||||
const TYPE(igraph_vector) *rhs);
|
||||
#ifndef NOTORDERED
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_bool_t FUNCTION(igraph_vector, all_l)(const TYPE(igraph_vector) *lhs,
|
||||
const TYPE(igraph_vector) *rhs);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_bool_t FUNCTION(igraph_vector, all_g)(const TYPE(igraph_vector) *lhs,
|
||||
const TYPE(igraph_vector) *rhs);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_bool_t FUNCTION(igraph_vector, all_le)(const TYPE(igraph_vector) *lhs,
|
||||
const TYPE(igraph_vector) *rhs);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_bool_t FUNCTION(igraph_vector, all_ge)(const TYPE(igraph_vector) *lhs,
|
||||
const TYPE(igraph_vector) *rhs);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE int FUNCTION(igraph_vector, lex_cmp)(
|
||||
const TYPE(igraph_vector) *lhs, const TYPE(igraph_vector) *rhs);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE int FUNCTION(igraph_vector, colex_cmp)(
|
||||
const TYPE(igraph_vector) *lhs, const TYPE(igraph_vector) *rhs);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE int FUNCTION(igraph_vector, lex_cmp_untyped)(const void *lhs, const void *rhs);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE int FUNCTION(igraph_vector, colex_cmp_untyped)(const void *lhs, const void *rhs);
|
||||
#endif
|
||||
|
||||
/*------------------------------*/
|
||||
/* Finding minimum and maximum */
|
||||
/*------------------------------*/
|
||||
|
||||
#ifndef NOTORDERED
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE BASE FUNCTION(igraph_vector, min)(const TYPE(igraph_vector)* v);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE BASE FUNCTION(igraph_vector, max)(const TYPE(igraph_vector)* v);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_int_t FUNCTION(igraph_vector, which_min)(const TYPE(igraph_vector)* v);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_int_t FUNCTION(igraph_vector, which_max)(const TYPE(igraph_vector)* v);
|
||||
IGRAPH_EXPORT void FUNCTION(igraph_vector, minmax)(
|
||||
const TYPE(igraph_vector) *v, BASE *min, BASE *max);
|
||||
IGRAPH_EXPORT void FUNCTION(igraph_vector, which_minmax)(
|
||||
const TYPE(igraph_vector) *v, igraph_int_t *which_min, igraph_int_t *which_max);
|
||||
#endif
|
||||
|
||||
/*-------------------*/
|
||||
/* Vector properties */
|
||||
/*-------------------*/
|
||||
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_bool_t FUNCTION(igraph_vector, empty)(const TYPE(igraph_vector)* v);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_int_t FUNCTION(igraph_vector, size)(const TYPE(igraph_vector)* v);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_bool_t FUNCTION(igraph_vector, isnull)(const TYPE(igraph_vector) *v);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE BASE FUNCTION(igraph_vector, sum)(const TYPE(igraph_vector) *v);
|
||||
IGRAPH_DEPRECATED IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_real_t FUNCTION(igraph_vector, sumsq)(const TYPE(igraph_vector) *v);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE BASE FUNCTION(igraph_vector, prod)(const TYPE(igraph_vector) *v);
|
||||
#ifndef NOTORDERED
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_bool_t FUNCTION(igraph_vector, isininterval)(const TYPE(igraph_vector) *v,
|
||||
BASE low, BASE high);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_bool_t FUNCTION(igraph_vector, any_smaller)(const TYPE(igraph_vector) *v,
|
||||
BASE limit);
|
||||
#endif
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_bool_t FUNCTION(igraph_vector, is_equal)(const TYPE(igraph_vector) *lhs,
|
||||
const TYPE(igraph_vector) *rhs);
|
||||
#ifndef NOTORDERED
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_real_t FUNCTION(igraph_vector, maxdifference)(const TYPE(igraph_vector) *m1,
|
||||
const TYPE(igraph_vector) *m2);
|
||||
#endif
|
||||
|
||||
/*------------------------*/
|
||||
/* Searching for elements */
|
||||
/*------------------------*/
|
||||
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_bool_t FUNCTION(igraph_vector, contains)(const TYPE(igraph_vector) *v, BASE e);
|
||||
IGRAPH_EXPORT igraph_bool_t FUNCTION(igraph_vector, search)(
|
||||
const TYPE(igraph_vector) *v, igraph_int_t from, BASE what, igraph_int_t *pos);
|
||||
#ifndef NOTORDERED
|
||||
IGRAPH_EXPORT igraph_bool_t FUNCTION(igraph_vector, binsearch_slice)(
|
||||
const TYPE(igraph_vector) *v, BASE what, igraph_int_t *pos,
|
||||
igraph_int_t start, igraph_int_t end);
|
||||
IGRAPH_EXPORT igraph_bool_t FUNCTION(igraph_vector, binsearch)(
|
||||
const TYPE(igraph_vector) *v, BASE what, igraph_int_t *pos);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_bool_t FUNCTION(igraph_vector, contains_sorted)(
|
||||
const TYPE(igraph_vector) *v, BASE what);
|
||||
#endif
|
||||
|
||||
/*------------------------*/
|
||||
/* Resizing operations */
|
||||
/*------------------------*/
|
||||
|
||||
IGRAPH_EXPORT void FUNCTION(igraph_vector, clear)(TYPE(igraph_vector)* v);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_vector, resize)(
|
||||
TYPE(igraph_vector)* v, igraph_int_t new_size);
|
||||
IGRAPH_EXPORT void FUNCTION(igraph_vector, resize_min)(TYPE(igraph_vector)*v);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_vector, reserve)(
|
||||
TYPE(igraph_vector)* v, igraph_int_t capacity);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_vector, push_back)(TYPE(igraph_vector)* v, BASE e);
|
||||
IGRAPH_EXPORT BASE FUNCTION(igraph_vector, pop_back)(TYPE(igraph_vector)* v);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_vector, insert)(
|
||||
TYPE(igraph_vector) *v, igraph_int_t pos, BASE value);
|
||||
IGRAPH_EXPORT void FUNCTION(igraph_vector, remove)(
|
||||
TYPE(igraph_vector) *v, igraph_int_t elem);
|
||||
IGRAPH_EXPORT void FUNCTION(igraph_vector, remove_fast)(
|
||||
TYPE(igraph_vector) *v, igraph_int_t elem);
|
||||
IGRAPH_EXPORT void FUNCTION(igraph_vector, remove_section)(
|
||||
TYPE(igraph_vector) *v, igraph_int_t from, igraph_int_t to);
|
||||
|
||||
/*-----------*/
|
||||
/* Sorting */
|
||||
/*-----------*/
|
||||
|
||||
#ifndef NOTORDERED
|
||||
|
||||
IGRAPH_EXPORT void FUNCTION(igraph_vector, sort)(TYPE(igraph_vector) *v);
|
||||
IGRAPH_EXPORT void FUNCTION(igraph_vector, reverse_sort)(TYPE(igraph_vector) *v);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_vector, sort_ind)(
|
||||
const TYPE(igraph_vector) *v, igraph_vector_int_t *inds, igraph_order_t order);
|
||||
|
||||
#endif
|
||||
|
||||
/*-----------*/
|
||||
/* Printing */
|
||||
/*-----------*/
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_vector, print)(const TYPE(igraph_vector) *v);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_vector, fprint)(const TYPE(igraph_vector) *v, FILE *file);
|
||||
|
||||
#ifdef OUT_FORMAT
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_vector, printf)(const TYPE(igraph_vector) *v, const char *format);
|
||||
#endif /* OUT_FORMAT */
|
||||
|
||||
/*----------------------------------------*/
|
||||
/* Operations specific to complex vectors */
|
||||
/*----------------------------------------*/
|
||||
|
||||
#ifdef BASE_COMPLEX
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_vector_complex_real(const igraph_vector_complex_t *v,
|
||||
igraph_vector_t *real);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_vector_complex_imag(const igraph_vector_complex_t *v,
|
||||
igraph_vector_t *imag);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_vector_complex_realimag(const igraph_vector_complex_t *v,
|
||||
igraph_vector_t *real,
|
||||
igraph_vector_t *imag);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_vector_complex_create(igraph_vector_complex_t *v,
|
||||
const igraph_vector_t *real,
|
||||
const igraph_vector_t *imag);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_vector_complex_create_polar(igraph_vector_complex_t *v,
|
||||
const igraph_vector_t *r,
|
||||
const igraph_vector_t *theta);
|
||||
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_bool_t igraph_vector_complex_all_almost_e(const igraph_vector_complex_t *lhs,
|
||||
const igraph_vector_complex_t *rhs,
|
||||
igraph_real_t eps);
|
||||
|
||||
#endif /* BASE_COMPLEX */
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_vector, init_real)(TYPE(igraph_vector)*v, int no, ...);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_vector, init_int)(TYPE(igraph_vector)*v, int no, ...);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_vector, init_real_end)(TYPE(igraph_vector)*v, double endmark, ...);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_vector, init_int_end)(TYPE(igraph_vector)*v, int endmark, ...);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_vector, move_interval)(
|
||||
TYPE(igraph_vector) *v, igraph_int_t begin, igraph_int_t end,
|
||||
igraph_int_t to);
|
||||
#ifndef NOTORDERED
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_vector, filter_smaller)(TYPE(igraph_vector) *v, BASE elem);
|
||||
#endif
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_vector, get_interval)(
|
||||
const TYPE(igraph_vector) *v, TYPE(igraph_vector) *res,
|
||||
igraph_int_t from, igraph_int_t to);
|
||||
#ifndef NOTORDERED
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_vector, difference_sorted)(const TYPE(igraph_vector) *v1,
|
||||
const TYPE(igraph_vector) *v2, TYPE(igraph_vector) *result);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_vector, difference_and_intersection_sorted)(
|
||||
const TYPE(igraph_vector) *v1, const TYPE(igraph_vector) *v2,
|
||||
TYPE(igraph_vector) *vdiff12, TYPE(igraph_vector) *vdiff21,
|
||||
TYPE(igraph_vector) *vinter);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_vector, intersect_sorted)(const TYPE(igraph_vector) *v1,
|
||||
const TYPE(igraph_vector) *v2, TYPE(igraph_vector) *result);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_int_t FUNCTION(igraph_vector, intersection_size_sorted)(
|
||||
const TYPE(igraph_vector) *v1,
|
||||
const TYPE(igraph_vector) *v2);
|
||||
#endif
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_vector, index)(const TYPE(igraph_vector) *v,
|
||||
TYPE(igraph_vector) *newv,
|
||||
const igraph_vector_int_t *idx);
|
||||
IGRAPH_EXPORT igraph_error_t FUNCTION(igraph_vector, index_in_place)(TYPE(igraph_vector) *v,
|
||||
const igraph_vector_int_t *idx);
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2009-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_VECTOR_PTR_H
|
||||
#define IGRAPH_VECTOR_PTR_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_vector.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* Flexible vector, storing pointers */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Vector, storing pointers efficiently
|
||||
* \ingroup internal
|
||||
*
|
||||
*/
|
||||
typedef struct s_vector_ptr {
|
||||
void** stor_begin;
|
||||
void** stor_end;
|
||||
void** end;
|
||||
igraph_finally_func_t* item_destructor;
|
||||
} igraph_vector_ptr_t;
|
||||
|
||||
#define IGRAPH_VECTOR_PTR_NULL { 0,0,0,0 }
|
||||
#define IGRAPH_VECTOR_PTR_INIT_FINALLY(v, size) \
|
||||
do { IGRAPH_CHECK(igraph_vector_ptr_init(v, size)); \
|
||||
IGRAPH_FINALLY(igraph_vector_ptr_destroy, v); } while (0)
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_vector_ptr_init(igraph_vector_ptr_t* v, igraph_int_t size);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_vector_ptr_init_array(igraph_vector_ptr_t* v, void *const *data, igraph_int_t length);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_vector_ptr_init_copy(igraph_vector_ptr_t *to, const igraph_vector_ptr_t *from);
|
||||
IGRAPH_EXPORT igraph_vector_ptr_t igraph_vector_ptr_view (void *const *data, igraph_int_t length);
|
||||
IGRAPH_EXPORT void igraph_vector_ptr_destroy(igraph_vector_ptr_t* v);
|
||||
IGRAPH_EXPORT void igraph_vector_ptr_free_all(igraph_vector_ptr_t* v);
|
||||
IGRAPH_EXPORT void igraph_vector_ptr_destroy_all(igraph_vector_ptr_t* v);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_vector_ptr_reserve(igraph_vector_ptr_t* v, igraph_int_t capacity);
|
||||
IGRAPH_EXPORT void igraph_vector_ptr_resize_min(igraph_vector_ptr_t* v);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_bool_t igraph_vector_ptr_empty(const igraph_vector_ptr_t* v);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_int_t igraph_vector_ptr_size(const igraph_vector_ptr_t* v);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_int_t igraph_vector_ptr_capacity(const igraph_vector_ptr_t* v);
|
||||
IGRAPH_EXPORT void igraph_vector_ptr_clear(igraph_vector_ptr_t* v);
|
||||
IGRAPH_EXPORT void igraph_vector_ptr_null(igraph_vector_ptr_t* v);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_vector_ptr_push_back(igraph_vector_ptr_t* v, void* e);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_vector_ptr_append(igraph_vector_ptr_t *to,
|
||||
const igraph_vector_ptr_t *from);
|
||||
IGRAPH_EXPORT void *igraph_vector_ptr_pop_back(igraph_vector_ptr_t *v);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_vector_ptr_insert(igraph_vector_ptr_t *v, igraph_int_t pos, void* e);
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE void *igraph_vector_ptr_get(const igraph_vector_ptr_t* v, igraph_int_t pos);
|
||||
IGRAPH_EXPORT void igraph_vector_ptr_set(igraph_vector_ptr_t* v, igraph_int_t pos, void* value);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_vector_ptr_resize(igraph_vector_ptr_t* v, igraph_int_t newsize);
|
||||
IGRAPH_EXPORT void igraph_vector_ptr_copy_to(const igraph_vector_ptr_t *v, void** to);
|
||||
IGRAPH_EXPORT igraph_error_t igraph_vector_ptr_permute(igraph_vector_ptr_t* v, const igraph_vector_int_t* index);
|
||||
IGRAPH_EXPORT void igraph_vector_ptr_remove(igraph_vector_ptr_t *v, igraph_int_t pos);
|
||||
IGRAPH_EXPORT void igraph_vector_ptr_sort(igraph_vector_ptr_t *v, int(*compar)(const void*, const void*));
|
||||
IGRAPH_EXPORT igraph_error_t igraph_vector_ptr_sort_ind(
|
||||
igraph_vector_ptr_t *v, igraph_vector_int_t *inds, int(*compar)(const void*, const void*));
|
||||
|
||||
IGRAPH_EXPORT IGRAPH_FUNCATTR_PURE igraph_finally_func_t* igraph_vector_ptr_get_item_destructor(const igraph_vector_ptr_t *v);
|
||||
IGRAPH_EXPORT igraph_finally_func_t* igraph_vector_ptr_set_item_destructor(igraph_vector_ptr_t *v,
|
||||
igraph_finally_func_t *func);
|
||||
|
||||
/**
|
||||
* \define IGRAPH_VECTOR_PTR_SET_ITEM_DESTRUCTOR
|
||||
* \brief Sets the item destructor for this pointer vector (macro version).
|
||||
*
|
||||
* This macro is expanded to \ref igraph_vector_ptr_set_item_destructor(), the
|
||||
* only difference is that the second argument is automatically cast to an
|
||||
* \c igraph_finally_func_t*. The cast is necessary in most cases as the
|
||||
* destructor functions we use (such as \ref igraph_vector_destroy()) take a
|
||||
* pointer to some concrete igraph data type, while \c igraph_finally_func_t
|
||||
* expects \c void*
|
||||
*/
|
||||
#define IGRAPH_VECTOR_PTR_SET_ITEM_DESTRUCTOR(v, func) \
|
||||
igraph_vector_ptr_set_item_destructor((v), (igraph_finally_func_t*)(func))
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2013-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Vector, dealing with arrays efficiently.
|
||||
* \ingroup types
|
||||
*/
|
||||
|
||||
typedef struct TYPE(igraph_vector) {
|
||||
BASE* stor_begin;
|
||||
BASE* stor_end;
|
||||
BASE* end;
|
||||
} TYPE(igraph_vector);
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2010-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_VERSION_H
|
||||
#define IGRAPH_VERSION_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
#define IGRAPH_VERSION "@PACKAGE_VERSION@"
|
||||
#define IGRAPH_VERSION_MAJOR @PACKAGE_VERSION_MAJOR@
|
||||
#define IGRAPH_VERSION_MINOR @PACKAGE_VERSION_MINOR@
|
||||
#define IGRAPH_VERSION_PATCH @PACKAGE_VERSION_PATCH@
|
||||
#define IGRAPH_VERSION_PRERELEASE "@PACKAGE_VERSION_PRERELEASE@"
|
||||
|
||||
IGRAPH_EXPORT void igraph_version(const char **version_string,
|
||||
int *major,
|
||||
int *minor,
|
||||
int *patch);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2009-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IGRAPH_VISITOR_H
|
||||
#define IGRAPH_VISITOR_H
|
||||
|
||||
#include "igraph_decls.h"
|
||||
#include "igraph_constants.h"
|
||||
#include "igraph_error.h"
|
||||
#include "igraph_types.h"
|
||||
#include "igraph_datatype.h"
|
||||
|
||||
IGRAPH_BEGIN_C_DECLS
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* Visitor-like functions */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* \typedef igraph_bfshandler_t
|
||||
* \brief Callback type for BFS function.
|
||||
*
|
||||
* \ref igraph_bfs() is able to call a callback function, whenever a
|
||||
* new vertex is found, while doing the breadth-first search. This
|
||||
* callback function must be of type \c igraph_bfshandler_t. It has
|
||||
* the following arguments:
|
||||
*
|
||||
* \param graph The graph that the algorithm is working on. Of course
|
||||
* this must not be modified.
|
||||
* \param vid The id of the vertex just found by the breadth-first
|
||||
* search.
|
||||
* \param pred The id of the previous vertex visited. It is -1 if
|
||||
* there is no previous vertex, because the current vertex is the root
|
||||
* is a search tree.
|
||||
* \param succ The id of the next vertex that will be visited. It is
|
||||
* -1 if there is no next vertex, because the current vertex is the
|
||||
* last one in a search tree.
|
||||
* \param rank The rank of the current vertex, it starts with zero.
|
||||
* \param dist The distance (number of hops) of the current vertex
|
||||
* from the root of the current search tree.
|
||||
* \param extra The extra argument that was passed to \ref
|
||||
* igraph_bfs().
|
||||
* \return \c IGRAPH_SUCCESS if the BFS should continue, \c IGRAPH_STOP
|
||||
* if the BFS should stop and return to the caller normally. Any other
|
||||
* value is treated as an igraph error code, terminating the search and
|
||||
* returning to the caller with the same error code. If a BFS is
|
||||
* is terminated prematurely, then all elements of the result vectors
|
||||
* that were not yet calculated at the point of the termination
|
||||
* contain negative values.
|
||||
*
|
||||
* \sa \ref igraph_bfs()
|
||||
*/
|
||||
|
||||
typedef igraph_error_t igraph_bfshandler_t(const igraph_t *graph,
|
||||
igraph_int_t vid,
|
||||
igraph_int_t pred,
|
||||
igraph_int_t succ,
|
||||
igraph_int_t rank,
|
||||
igraph_int_t dist,
|
||||
void *extra);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_bfs(const igraph_t *graph,
|
||||
igraph_int_t root, const igraph_vector_int_t *roots,
|
||||
igraph_neimode_t mode, igraph_bool_t unreachable,
|
||||
const igraph_vector_int_t *restricted,
|
||||
igraph_vector_int_t *order, igraph_vector_int_t *rank,
|
||||
igraph_vector_int_t *parents,
|
||||
igraph_vector_int_t *pred, igraph_vector_int_t *succ,
|
||||
igraph_vector_int_t *dist, igraph_bfshandler_t *callback,
|
||||
void *extra);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_bfs_simple(const igraph_t *graph, igraph_int_t root, igraph_neimode_t mode,
|
||||
igraph_vector_int_t *order, igraph_vector_int_t *layers,
|
||||
igraph_vector_int_t *parents);
|
||||
|
||||
/**
|
||||
* \function igraph_dfshandler_t
|
||||
* \brief Callback type for the DFS function.
|
||||
*
|
||||
* \ref igraph_dfs() is able to call a callback function, whenever a
|
||||
* new vertex is discovered, and/or whenever a subtree is
|
||||
* completed. These callbacks must be of type \c
|
||||
* igraph_dfshandler_t. They have the following arguments:
|
||||
*
|
||||
* \param graph The graph that the algorithm is working on. Of course
|
||||
* this must not be modified.
|
||||
* \param vid The id of the vertex just found by the depth-first
|
||||
* search.
|
||||
* \param dist The distance (number of hops) of the current vertex
|
||||
* from the root of the current search tree.
|
||||
* \param extra The extra argument that was passed to \ref
|
||||
* igraph_dfs().
|
||||
* \return \c IGRAPH_SUCCESS if the DFS should continue, \c IGRAPH_STOP
|
||||
* if the DFS should stop and return to the caller normally. Any other
|
||||
* value is treated as an igraph error code, terminating the search and
|
||||
* returning to the caller with the same error code. If a DFS is
|
||||
* is terminated prematurely, then all elements of the result vectors
|
||||
* that were not yet calculated at the point of the termination
|
||||
* contain negative values.
|
||||
*
|
||||
* \sa \ref igraph_dfs()
|
||||
*/
|
||||
|
||||
typedef igraph_error_t igraph_dfshandler_t(const igraph_t *graph,
|
||||
igraph_int_t vid,
|
||||
igraph_int_t dist,
|
||||
void *extra);
|
||||
|
||||
IGRAPH_EXPORT igraph_error_t igraph_dfs(const igraph_t *graph, igraph_int_t root,
|
||||
igraph_neimode_t mode, igraph_bool_t unreachable,
|
||||
igraph_vector_int_t *order,
|
||||
igraph_vector_int_t *order_out, igraph_vector_int_t *parents,
|
||||
igraph_vector_int_t *dist, igraph_dfshandler_t *in_callback,
|
||||
igraph_dfshandler_t *out_callback,
|
||||
void *extra);
|
||||
|
||||
IGRAPH_END_C_DECLS
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user