Igraph Reference Manual

Total Page:16

File Type:pdf, Size:1020Kb

Igraph Reference Manual igraph Reference Manual Gábor Csárdi Department of Biophysics, Research Institute for Nuclear and Particle Physics of the Hungarian Academy of Sciences 29-33 Konkoly-Thege Miklós road, Budapest H-1121, Hungary Center for Complex Systems Studies, Kalamazoo College 1200 Academy st, Kalamazoo, 49006, MI, USA Tamás Nepusz Department of Biophysics, Research Institute for Nuclear and Particle Physics of the Hungarian Academy of Sciences 29-33 Konkoly-Thege Miklós road, Budapest H-1121, Hungary igraph Reference Manual by Gábor Csárdi and Tamás Nepusz Copyright (C) 2005, 2006 Gábor Csárdi and Tamás Nepusz. 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 1.1. igraph is free software.................................................................................................................1 1.2. Citing igraph...............................................................................................................................2 2. Installation..............................................................................................................................................3 3. Tutorial...................................................................................................................................................5 3.1. Lesson 1. Compiling programs using igraph..............................................................................5 3.2. Lesson 2. Creating your first graphs...........................................................................................6 3.3. Lesson 3. Calculating various properties of graphs....................................................................8 4. About igraph graphs, the basic interface..........................................................................................10 4.1. The igraph data model...............................................................................................................10 4.2. The basic interface....................................................................................................................11 4.2.1. Graph Constructors and Destructors............................................................................11 4.2.2. Basic Query Operations................................................................................................14 4.2.3. Adding and Deleting Vertices and Edges.....................................................................20 5. Error Handling....................................................................................................................................25 5.1. Error handling basics................................................................................................................25 5.2. Error handlers............................................................................................................................25 5.2.1. igraph_error_handler_t — Type of error handler functions...............................25 5.2.2. igraph_error_handler_abort — Abort program in case of error.......................26 5.2.3. igraph_error_handler_ignore — Ignore errors.................................................26 5.2.4. igraph_error_handler_printignore — Print and ignore errors.......................27 5.3. Error codes................................................................................................................................27 5.3.1. igraph_error_type_t — Error code type..............................................................27 5.3.2. igraph_strerror — Textual description of an error...............................................30 5.4. Advanced topics........................................................................................................................31 5.4.1. Writing error handlers..................................................................................................31 5.4.2. Error handling internals................................................................................................32 5.4.3. Deallocating memory...................................................................................................34 5.4.4. Writing igraph functions with proper error handling..................................................35 5.4.5. Error handling and threads...........................................................................................36 6. Data structure library: vector, matrix, other data types..................................................................37 6.1. About template types................................................................................................................37 6.2. Vectors.......................................................................................................................................38 6.2.1. About igraph_vector_t objects......................................................................................38 6.2.2. Constructors and Destructors.......................................................................................39 6.2.3. Initializing elements.....................................................................................................42 6.2.4. Accessing elements......................................................................................................43 6.2.5. Vector views.................................................................................................................47 6.2.6. Copying vectors............................................................................................................48 6.2.7. Exchanging elements....................................................................................................50 6.2.8. Vector operations..........................................................................................................51 6.2.9. Finding minimum and maximum.................................................................................55 6.2.10. Vector properties.........................................................................................................59 6.2.11. Searching for elements...............................................................................................63 iii 6.2.12. Resizing operations....................................................................................................66 6.2.13. Sorting........................................................................................................................71 6.2.14. Pointer vectors (igraph_vector_ptr_t).........................................................................71 6.3. Matrices.....................................................................................................................................77 6.3.1. About igraph_matrix_t objects.....................................................................................77 6.3.2. Matrix constructors and destructors.............................................................................77 6.3.3. Initializing elements.....................................................................................................79 6.3.4. Copying matrices..........................................................................................................80 6.3.5. Accessing elements of a matrix....................................................................................82 6.3.6. Operations on rows and columns..................................................................................84 6.3.7. Matrix operations..........................................................................................................90 6.3.8. Combining matrices......................................................................................................96 6.3.9. Finding minimum and maximum.................................................................................97 6.3.10. Matrix properties......................................................................................................101 6.3.11. Searching for elements.............................................................................................105 6.3.12. Resizing operations..................................................................................................107 6.4. Sparse matrices.......................................................................................................................110 6.4.1. About igraph_spmatrix_t objects...............................................................................110 6.4.2. Sparse matrix constructors and destructors................................................................111 6.4.3. Accessing elements of a sparse matrix.......................................................................112 6.4.4. Matrix query operations.............................................................................................114 6.4.5. Matrix operations........................................................................................................117 6.5. Stacks......................................................................................................................................120
Recommended publications
  • Networkx: Network Analysis with Python
    NetworkX: Network Analysis with Python Salvatore Scellato Full tutorial presented at the XXX SunBelt Conference “NetworkX introduction: Hacking social networks using the Python programming language” by Aric Hagberg & Drew Conway Outline 1. Introduction to NetworkX 2. Getting started with Python and NetworkX 3. Basic network analysis 4. Writing your own code 5. You are ready for your project! 1. Introduction to NetworkX. Introduction to NetworkX - network analysis Vast amounts of network data are being generated and collected • Sociology: web pages, mobile phones, social networks • Technology: Internet routers, vehicular flows, power grids How can we analyze this networks? Introduction to NetworkX - Python awesomeness Introduction to NetworkX “Python package for the creation, manipulation and study of the structure, dynamics and functions of complex networks.” • Data structures for representing many types of networks, or graphs • Nodes can be any (hashable) Python object, edges can contain arbitrary data • Flexibility ideal for representing networks found in many different fields • Easy to install on multiple platforms • Online up-to-date documentation • First public release in April 2005 Introduction to NetworkX - design requirements • Tool to study the structure and dynamics of social, biological, and infrastructure networks • Ease-of-use and rapid development in a collaborative, multidisciplinary environment • Easy to learn, easy to teach • Open-source tool base that can easily grow in a multidisciplinary environment with non-expert users
    [Show full text]
  • Planar Hypohamiltonian Graphs on 40 Vertices
    Planar Hypohamiltonian Graphs on 40 Vertices Mohammadreza Jooyandeh, Brendan D. McKay Research School of Computer Science, Australian National University, ACT 2601, Australia Patric R. J. Osterg˚ard,¨ Ville H. Pettersson Department of Communications and Networking, Aalto University School of Electrical Engineering, P.O. Box 13000, 00076 Aalto, Finland Carol T. Zamfirescu Department of Applied Mathematics, Computer Science and Statistics, Ghent University, Krijgslaan 281 - S9, 9000 Ghent, Belgium Abstract A graph is hypohamiltonian if it is not Hamiltonian, but the deletion of any single vertex gives a Hamiltonian graph. Until now, the smallest known planar hypohamiltonian graph had 42 vertices, a result due to Araya and Wiener. That result is here improved upon by 25 planar hypohamiltonian graphs of order 40, which are found through computer-aided generation of certain families of planar graphs with girth 4 and a fixed number of 4-faces. It is further shown that planar hypohamiltonian graphs exist for all orders greater than or equal to 42. If Hamiltonian cycles are replaced by Hamilto- nian paths throughout the definition of hypohamiltonian graphs, we get the definition of hypotraceable graphs. It is shown that there is a planar hypo- traceable graph of order 154 and of all orders greater than or equal to 156. We also show that the smallest planar hypohamiltonian graph of girth 5 has 45 vertices. Email addresses: [email protected] (Mohammadreza Jooyandeh), [email protected] (Brendan D. McKay), [email protected] (Patric R. J. Osterg˚ard),¨ [email protected] (Ville H. Pettersson), [email protected] (Carol T. Zamfirescu) URL: http://www.jooyandeh.com (Mohammadreza Jooyandeh), http://cs.anu.edu.au/~bdm (Brendan D.
    [Show full text]
  • STATS 701 Data Analysis Using Python Lecture 27: Apis and Graph Processing Some Slides Adapted from C
    STATS 701 Data Analysis using Python Lecture 27: APIs and Graph Processing Some slides adapted from C. Budak Previously: Scraping Data from the Web We used BeautifulSoup to process HTML that we read directly We had to figure out where to find the data in the HTML This was okay for simple things like Wikipedia… ...but what about large, complicated data sets? E.g., Climate data from NOAA; Twitter/reddit/etc.; Google maps Many websites support APIs, which make these tasks simpler Instead of scraping for what we want, just ask! Example: ask Google Maps for a computer repair shop near a given address Three common API approaches Via a Python package Service (e.g., Google maps, ESRI*) provides library for querying DB Example: from arcgis.gis import GIS Via a command-line tool Ultimately, all three of these approaches end up submitting an Example: twurl https://developer.twitter.com/ HTTP request to a server, which returns information in the form of a Via HTTP requests JSON or XML file, typically. We submit an HTTP request to a server Supply additional parameters in URL to specify our query Example: https://www.yelp.com/developers/documentation/v3/business_search * ESRI is a GIS service, to which the university has a subscription: https://developers.arcgis.com/python/ Web service APIs Step 1: Create URL with query parameters Example (non-working): www.example.com/search?key1=val1&key2=val2 Step 2: Make an HTTP request Communicates to the server what kind of action we wish to perform https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Request_methods Step 3: Server returns a response to your request May be as simple as a code (e.g., 404 error)..
    [Show full text]
  • Every Graph Occurs As an Induced Subgraph of Some Hypohamiltonian Graph
    View metadata, citation and similar papers at core.ac.uk brought to you by CORE Received: 27 October 2016 Revised: 31 October 2017 Accepted: 20 November 2017 provided by Ghent University Academic Bibliography DOI: 10.1002/jgt.22228 ARTICLE Every graph occurs as an induced subgraph of some hypohamiltonian graph Carol T. Zamfirescu1 Tudor I. Zamfirescu2,3,4 1 Department of Applied Mathematics, Com- Abstract puter Science and Statistics, Ghent University, Krijgslaan 281 - S9, 9000 Ghent, Belgium We prove the titular statement. This settles a problem 2Fachbereich Mathematik, Universität of Chvátal from 1973 and encompasses earlier results Dortmund, 44221 Dortmund, Germany of Thomassen, who showed it for 3, and Collier and 3 “Simion Stoilow” Institute of Mathematics, Schmeichel, who proved it for bipartite graphs. We also Roumanian Academy, Bucharest, Roumania show that for every outerplanar graph there exists a pla- 4College of Mathematics and Information Science, Hebei Normal University, 050024 nar hypohamiltonian graph containing it as an induced Shijiazhuang, P.R. China subgraph. Correspondence Carol T. Zamfirescu, Department of KEYWORDS Applied Mathematics, Computer Sci- hypohamiltonian, induced subgraph ence and Statistics, Ghent University, Krijgslaan 281 - S9, 9000 Ghent, Belgium. MSC 2010. Email: czamfi[email protected] 05C10, 05C45, 05C60 Funding information Fonds Wetenschappelijk Onderzoek 1 INTRODUCTION Consider a non-hamiltonian graph . We call hypohamiltonian if for every vertex in , the graph − is hamiltonian. In similar spirit, is said to be almost hypohamiltonian if there exists a vertex in , which we will call exceptional, such that − is non-hamiltonian, and for any vertex ≠ in , the graph − is hamiltonian. For an overview of results on hypohamiltonicity till 1993, see the survey by Holton and Sheehan [7].
    [Show full text]
  • On Stable Cycles and Cycle Double Covers of Graphs with Large Circumference
    View metadata, citation and similar papers at core.ac.uk brought to you by CORE provided by Elsevier - Publisher Connector Discrete Mathematics 312 (2012) 2540–2544 Contents lists available at SciVerse ScienceDirect Discrete Mathematics journal homepage: www.elsevier.com/locate/disc On stable cycles and cycle double covers of graphs with large circumference Jonas Hägglund ∗, Klas Markström Department of Mathematics and Mathematical Statistics, Umeå University, SE-901 87 Umeå, Sweden article info a b s t r a c t Article history: A cycle C in a graph is called stable if there exists no other cycle D in the same graph such Received 11 October 2010 that V .C/ ⊆ V .D/. In this paper, we study stable cycles in snarks and we show that if a Accepted 16 August 2011 cubic graph G has a cycle of length at least jV .G/j − 9 then it has a cycle double cover. We Available online 23 September 2011 also give a construction for an infinite snark family with stable cycles of constant length and answer a question by Kochol by giving examples of cyclically 5-edge connected snarks Keywords: with stable cycles. Stable cycle ' 2011 Elsevier B.V. All rights reserved. Snark Cycle double cover Semiextension 1. Introduction In this paper, a cycle is a connected 2-regular subgraph. A cycle double cover (usually abbreviated CDC) is a multiset of cycles covering the edges of a graph such that each edge lies in exactly two cycles. The following is a famous open conjecture in graph theory. Conjecture 1.1 (CDCC).
    [Show full text]
  • Improved Bounds for Hypohamiltonian Graphs∗
    Also available at http://amc-journal.eu ISSN 1855-3966 (printed edn.), ISSN 1855-3974 (electronic edn.) ARS MATHEMATICA CONTEMPORANEA 13 (2017) 235–257 Improved bounds for hypohamiltonian graphs∗ Jan Goedgebeur , Carol T. Zamfirescu Department of Applied Mathematics, Computer Science & Statistics, Ghent University, Krijgslaan 281-S9, 9000 Ghent, Belgium In loving memory of Ella. Received 23 February 2016, accepted 16 January 2017, published online 6 March 2017 Abstract A graph G is hypohamiltonian if G is non-hamiltonian and G − v is hamiltonian for every v 2 V (G). In the following, every graph is assumed to be hypohamiltonian. Aldred, Wormald, and McKay gave a list of all graphs of order at most 17. In this article, we present an algorithm to generate all graphs of a given order and apply it to prove that there exist exactly 14 graphs of order 18 and 34 graphs of order 19. We also extend their results in the cubic case. Furthermore, we show that (i) the smallest graph of girth 6 has order 25, (ii) the smallest planar graph has order at least 23, (iii) the smallest cubic planar graph has order at least 54, and (iv) the smallest cubic planar graph of girth 5 with non-trivial automorphism group has order 78. Keywords: Hamiltonian, hypohamiltonian, planar, girth, cubic graph, exhaustive generation. Math. Subj. Class.: 05C10, 05C38, 05C45, 05C85 1 Introduction Throughout this paper all graphs are undirected, finite, connected, and neither contain loops nor multiple edges, unless explicitly stated otherwise. A graph is hamiltonian if it contains a cycle visiting every vertex of the graph.
    [Show full text]
  • Constructions and Enumeration Methods for Cubic Graphs and Trees
    Butler University Digital Commons @ Butler University Undergraduate Honors Thesis Collection Undergraduate Scholarship 2013 Constructions and Enumeration Methods for Cubic Graphs and Trees Erica R. Gilliland Butler University Follow this and additional works at: https://digitalcommons.butler.edu/ugtheses Part of the Discrete Mathematics and Combinatorics Commons Recommended Citation Gilliland, Erica R., "Constructions and Enumeration Methods for Cubic Graphs and Trees" (2013). Undergraduate Honors Thesis Collection. 360. https://digitalcommons.butler.edu/ugtheses/360 This Thesis is brought to you for free and open access by the Undergraduate Scholarship at Digital Commons @ Butler University. It has been accepted for inclusion in Undergraduate Honors Thesis Collection by an authorized administrator of Digital Commons @ Butler University. For more information, please contact [email protected]. BUTLER UNIVERSITY HONORS PROGRAM Honors Thesis Certification Please type all information in this section: Applicant Erica R. Gilliland (Name as it is to appear on diploma) Thesis title Constructions and Enumeration Methods for Cubic Graphs and Trees Intended date of commencement May 11, 2013 --~------------------------------ Read, approved, and signed by: tf -;t 'J,- J IJ Thesis adviser(s) D'rt/~ S// CWiV'-~ Date Date t.-t - 2. Z - 2.C?{3 Reader(s) Date Date Certified by Director, Honors Program Date For Honors Program use: Level of Honors conferred: University Departmental MtH1t£W1Ah"LS with ttijutt HoVJQ(5 ik1vrj,,1 r"U)U ",1-111 ttlStl HMbCS V(IIVet>i}\j HtlYlb6 froyrltm I Constructions and Enumeration Methods for Cubic Graphs and Trees Erica R. Gilliland A Thesis Presented to the Department of Mathematics College of Liberal Arts and Sciences and Honors Program of Butler University III Partial Fulfillment of the ncCIuirclllcnts for G rae! ua lion Honors Submitted: April 2:3, 2()1:3 Constructions and Enumeration Methods for Cubic Graphs and Trees Erica It Gilliland Under the supervision of Dr.
    [Show full text]
  • Empire Maps on Surfaces Arxiv:1106.4235V1 [Math.GT]
    University of Durham Final year project Empire Maps on Surfaces An exploration into colouring empire maps on the sphere and higher genus surfaces Author: Supervisor: Caspar de Haes Dr Vitaliy Kurlin D C 0 7 8 0 E 6 9 5 10 0 0 4 11 B 1' 3' F 3 5' 12 12' 0 7' 0 2 10' 2 A 13 9' A 1 1 8' 11' 0 0 0' 11 6' 4 4' 2' F 12 3 B 0 0 9 6 5 10 C E 0 7 8 0 arXiv:1106.4235v1 [math.GT] 21 Jun 2011 D April 28, 2011 Abstract This report is an introduction to mathematical map colouring and the problems posed by Heawood in his paper of 1890. There will be a brief discussion of the Map Colour Theorem; then we will move towards investigating empire maps in the plane and the recent contri- butions by Wessel. Finally we will conclude with a discussion of all known results for empire maps on higher genus surfaces and prove Heawoods Empire Conjecture in a previously unknown case. Contents 1 Introduction 3 1.1 Overview of the Problem . 3 1.2 History of the Problem . 3 1.3 Chapter Plan . 5 2 Graphs 6 2.1 Terminology and Notation . 6 2.2 Complete Graphs . 8 3 Surfaces 9 3.1 Surfaces and Embeddings . 9 3.2 Euler Characteristic . 10 3.3 Orientability . 11 3.4 Classification of surfaces . 11 4 Map Colouring 14 4.1 Maps and Colouring . 14 4.2 Dual Graphs . 15 4.3 Colouring Graphs .
    [Show full text]
  • Fastnet: an R Package for Fast Simulation and Analysis of Large-Scale Social Networks
    JSS Journal of Statistical Software November 2020, Volume 96, Issue 7. doi: 10.18637/jss.v096.i07 fastnet: An R Package for Fast Simulation and Analysis of Large-Scale Social Networks Xu Dong Luis Castro Nazrul Shaikh Tamr Inc. World Bank Cecareus Inc. Abstract Traditional tools and software for social network analysis are seldom scalable and/or fast. This paper provides an overview of an R package called fastnet, a tool for scaling and speeding up the simulation and analysis of large-scale social networks. fastnet uses multi-core processing and sub-graph sampling algorithms to achieve the desired scale-up and speed-up. Simple examples, usages, and comparisons of scale-up and speed-up as compared to other R packages, i.e., igraph and statnet, are presented. Keywords: social network analysis, network simulation, network metrics, multi-core process- ing, sampling. 1. Introduction It has been about twenty years since the introduction of social network analysis (SNA) soft- ware such as Pajek (Batagelj and Mrvar 1998) and UCINET (Borgatti, Everett, and Freeman 2002). Though these software packages are still existent, the last ten years have witnessed a significant change in the needs and aspiration of researchers working in the field. The growth of popular online social networks, such as Facebook, Twitter, LinkedIn, Snapchat, and the availability of data from large systems such as the telecommunication system and the inter- net of things (IoT) has ushered in the need to focus on computational and data management issues associated with SNA. During this period, several Python (Van Rossum et al. 2011) and Java based SNA tools, such as NetworkX (Hagberg, Schult, and Swart 2008) and SNAP (Leskovec and Sosič 2016), and R (R Core Team 2020) packages, such as statnet (Hunter, Handcock, Butts, Goodreau, and Morris 2008; Handcock et al.
    [Show full text]
  • Network Visualization with Igraph
    Using igraph for Visualisations Dr Jamsheed Shorish The Australian National University [email protected] 15 July 2013 - Beihang University Introduction I igraph is a network analysis and visualisation software package, currently for R and Python. I It can be found at igraph.sourceforge.net. I For our course, we will be using igraph for R . Screenshot from the igraph website, depicting an Erdős - Rényi graph and associated colour-coded components, or clusters. Installing igraph for R I Installation of igraph for R is very simple–the command is: > install.packages( 'igraph ') I You may need to specify a particular directory if e.g. you don’t have privileges to install to the system location for R : > install.packages( 'igraph ', lib='my/ package/location ') I To load the library, use > library( 'igraph ',lib) I or > library( 'igraph ', lib. loc='my/package/ location ') Loading a Dataset I The first thing to do is to get some data! I For consistency I’ll assume that all data is loaded in graphml format. I This can be exported by the Python networkx package. I To load a network dataset from a file, use: > G = read.graph( 'network.graphml ', format ='graphml ') I Confirm that your dataset is recognised by igraph : > G IGRAPHD-W- 560 1257 -- \ + attr: label (v/c), id (v/c), weight (e/n ), id (e/c) Layout of a Graph I To visualise a network well, use the layout function of igraph to specify the layout prior to plotting. I Different networks work best with different layouts–this is more art than science.
    [Show full text]
  • A Comparative Analysis of Large-Scale Network Visualization Tools
    A Comparative Analysis of Large-scale Network Visualization Tools Md Abdul Motaleb Faysal and Shaikh Arifuzzaman Department of Computer Science, University of New Orleans New Orleans, LA 70148, USA. Email: [email protected], [email protected] Abstract—Network (Graph) is a powerful abstraction for scalability for large network analysis. Such study will help a representing underlying relations and structures in large complex person to decide which tool to use for a specific case based systems. Network visualization provides a convenient way to ex- on his need. plore and study such structures and reveal useful insights. There exist several network visualization tools; however, these vary in One such study in [3] compares a couple of tools based on terms of scalability, analytics feature, and user-friendliness. Due scalability. Comparative studies on other visualization metrics to the huge growth of social, biological, and other scientific data, should be conducted to let end users have freedom in choosing the corresponding network data is also large. Visualizing such the specific tool he needs to use. In this paper, we have chosen large network poses another level of difficulty. In this paper, we five widely used visualization tools for an empirical and identify several popular network visualization tools and provide a comparative analysis based on the features and operations comparative analysis. Our comparisons are based on factors these tools support. We demonstrate empirically how those tools such as supported file formats, scalability in visualization scale to large networks. We also provide several case studies of and analysis, interacting capability with the drawn network, visual analytics on large network data and assess performances end user-friendliness (e.g., users with no programming back- of the tools.
    [Show full text]
  • The Nonorientable Genus of Complete Tripartite Graphs
    The nonorientable genus of complete tripartite graphs M. N. Ellingham∗ Department of Mathematics, 1326 Stevenson Center Vanderbilt University, Nashville, TN 37240, U. S. A. [email protected] Chris Stephensy Department of Mathematics, 1326 Stevenson Center Vanderbilt University, Nashville, TN 37240, U. S. A. [email protected] Xiaoya Zhaz Department of Mathematical Sciences Middle Tennessee State University, Murfreesboro, TN 37132, U.S.A. [email protected] October 6, 2003 Abstract In 1976, Stahl and White conjectured that the nonorientable genus of Kl;m;n, where l m (l 2)(m+n 2) ≥ ≥ n, is − − . The authors recently showed that the graphs K3;3;3 , K4;4;1, and K4;4;3 2 ¡ are counterexamples to this conjecture. Here we prove that apart from these three exceptions, the conjecture is true. In the course of the paper we introduce a construction called a transition graph, which is closely related to voltage graphs. 1 Introduction In this paper surfaces are compact 2-manifolds without boundary. The orientable surface of genus h, denoted S , is the sphere with h handles added, where h 0. The nonorientable surface of genus h ≥ k, denoted N , is the sphere with k crosscaps added, where k 1. A graph is said to be embeddable k ≥ on a surface if it can be drawn on that surface in such a way that no two edges cross. Such a drawing ∗Supported by NSF Grants DMS-0070613 and DMS-0215442 ySupported by NSF Grant DMS-0070613 and Vanderbilt University's College of Arts and Sciences Summer Re- search Award zSupported by NSF Grant DMS-0070430 1 is referred to as an embedding.
    [Show full text]