Igraph Reference Manual
Total Page:16
File Type:pdf, Size:1020Kb
igraph Reference Manual Gábor Csárdi, Department of Statistics, Harvard University Tamás Nepusz, Department of Biological Physics, Eötvös Loránd University Vincent Traag, Centre for Science and Technology Studies, Leiden University Szabolcs Horvát, Center for Systems Biology Dres- den, Max Planck Institute for Cell Biology and Genetics Fabio Zanini, Lowy Cancer Research Centre, University of New South Wales igraph Reference Manual by Gábor Csárdi, Tamás Nepusz, Vincent Traag, Szabolcs Horvát, and Fabio Zanini 0.9.4 This manual is for igraph, version 0.9.4. Copyright (C) 2005-2019 Gábor Csárdi and Tamás Nepusz. Copyright (C) 2020-2021 igraph development team. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled “GNU Free Documentation License”. Table of Contents 1. Introduction .............................................................................................................. 1 igraph is free software ........................................................................................... 1 Citing igraph ........................................................................................................ 2 2. Installation ................................................................................................................ 3 Prerequisites ......................................................................................................... 3 Installation ........................................................................................................... 3 General build instructions ............................................................................... 3 Specific instructions for Windows .................................................................... 4 Notable configuration options .......................................................................... 5 Building the documentation .................................................................................... 6 Notes for package maintainers ................................................................................. 6 Auto-detection of dependencies ....................................................................... 6 Shared and static builds .................................................................................. 7 Cross-compiling ............................................................................................ 7 Additional notes ............................................................................................ 7 3. Tutorial .................................................................................................................... 8 Compiling programs using igraph ............................................................................ 8 Compiling with CMake .................................................................................. 8 Compiling without CMake .............................................................................. 9 Running the program ..................................................................................... 9 Creating your first graphs ....................................................................................... 9 Calculating various properties of graphs .................................................................. 11 4. About igraph graphs, the basic interface ....................................................................... 13 The igraph data model .......................................................................................... 13 The basic interface ............................................................................................... 14 Graph constructors and destructors ................................................................. 14 Basic query operations ................................................................................. 16 Adding and deleting vertices and edges ........................................................... 24 5. Error handling ......................................................................................................... 27 Error handling basics .......................................................................................... 27 Error handlers .................................................................................................... 27 igraph_error_handler_t — The type of error handler functions. ................ 27 igraph_error_handler_abort — Abort program in case of error. .............. 28 igraph_error_handler_ignore — Ignore errors. ................................... 28 igraph_error_handler_printignore — Print and ignore errors. ............ 28 Error codes ........................................................................................................ 28 igraph_error_type_t — Error code type. ............................................... 28 igraph_strerror — Textual description of an error. ................................... 31 Warning messages .............................................................................................. 32 igraph_warning_handler_t — The type of igraph warning handler func- tions. ......................................................................................................... 32 igraph_set_warning_handler — Installs a warning handler. .................... 32 IGRAPH_WARNING — Triggers a warning. ..................................................... 32 IGRAPH_WARNINGF — Triggers a warning, with printf-like syntax. ................... 33 igraph_warning — Triggers a warning. ..................................................... 33 igraph_warningf — Triggers a warning, printf-like version. ......................... 33 igraph_warning_handler_ignore — Ignores all warnings. ..................... 34 igraph_warning_handler_print — Prints all warnings to the standard error. ......................................................................................................... 34 Advanced topics .................................................................................................. 35 Writing error handlers ................................................................................. 35 Error handling internals ............................................................................... 35 Deallocating memory .................................................................................. 37 Writing igraph functions with proper error handling ......................................... 38 Fatal errors ................................................................................................ 39 iii igraph Reference Manual Error handling and threads ........................................................................... 41 6. Memory (de)allocation .............................................................................................. 42 igraph_malloc — Allocate memory that can be safely deallocated by igraph func- tions. ................................................................................................................. 42 igraph_free — Deallocate memory that was allocated by igraph functions. ............... 42 7. Data structure library: vector, matrix, other data types .................................................... 44 About template types ........................................................................................... 44 Vectors .............................................................................................................. 45 About igraph_vector_t objects ...................................................................... 45 Constructors and Destructors ........................................................................ 45 Initializing elements ..................................................................................... 47 Accessing elements ..................................................................................... 48 Vector views ............................................................................................... 50 Copying vectors .......................................................................................... 50 Exchanging elements .................................................................................... 52 Vector operations ........................................................................................ 53 Vector comparisons ...................................................................................... 56 Finding minimum and maximum .................................................................... 59 Vector properties ......................................................................................... 61 Searching for elements ................................................................................. 65 Resizing operations ...................................................................................... 67 Sorting ....................................................................................................... 71 Set operations on sorted vectors ..................................................................... 71 Pointer vectors (igraph_vector_ptr_t) ............................................................. 72 Matrices ............................................................................................................