Chapter 12. Graph, vertex and edge attributes

1. The Attribute Handler Interface
2. Handling attribute combination lists
3. Accessing attributes from C

Attributes are numbers or strings (or basically any kind of data) associated with the vertices or edges of a graph, or with the graph itself. Eg. you may label vertices with symbolic names or attach numeric weights to the edges of a graph.

igraph attributes are designed to be flexible and extensible. In igraph attributes are implemented via an interface abstraction: any type implementing the functions in the interface, can be used for storing vertex, edge and graph attributes. This means that different attribute implementations can be used together with igraph. This is reasonable: if igraph is used from Python attributes can be of any Python type, from GNU R all R types are allowed. There is an experimental attribute implementation to be used when programming in C, but by default it is currently turned off.

First we briefly look over how attribute handlers can be implemented. This is not something a user does every day. It is rather typically the job of the high level interface writers. (But it is possible to write an interface without implementing attributes.) Then we show the experimental C attribute handler.

1. The Attribute Handler Interface

It is possible to attach an attribute handling interface to igraph. This is simply a table of functions, of type igraph_attribute_table_t. These functions are invoked to notify the attribute handling code about the structural changes in a graph. See the documentation of this type for details.

By default there is no attribute interface attached to igraph, to attach one, call igraph_set_attribute_table with your new table.

1.1. igraph_attribute_table_t — Table of functions to perform operations on attributes

typedef struct igraph_attribute_table_t {
    int (*init)(igraph_t *graph, igraph_vector_ptr_t *attr);
    void (*destroy)(igraph_t *graph);
    int (*copy)(igraph_t *to, const igraph_t *from, igraph_bool_t ga,
                igraph_bool_t va, igraph_bool_t ea);
    int (*add_vertices)(igraph_t *graph, long int nv, igraph_vector_ptr_t *attr);
    int (*permute_vertices)(const igraph_t *graph,
                            igraph_t *newgraph,
                            const igraph_vector_t *idx);
    int (*combine_vertices)(const igraph_t *graph,
                            igraph_t *newgraph,
                            const igraph_vector_ptr_t *merges,
                            const igraph_attribute_combination_t *comb);
    int (*add_edges)(igraph_t *graph, const igraph_vector_t *edges,
                     igraph_vector_ptr_t *attr);
    int (*permute_edges)(const igraph_t *graph,
                         igraph_t *newgraph, const igraph_vector_t *idx);
    int (*combine_edges)(const igraph_t *graph,
                         igraph_t *newgraph,
                         const igraph_vector_ptr_t *merges,
                         const igraph_attribute_combination_t *comb);
    int (*get_info)(const igraph_t *graph,
                    igraph_strvector_t *gnames, igraph_vector_t *gtypes,
                    igraph_strvector_t *vnames, igraph_vector_t *vtypes,
                    igraph_strvector_t *enames, igraph_vector_t *etypes);
    igraph_bool_t (*has_attr)(const igraph_t *graph, igraph_attribute_elemtype_t type,
                              const char *name);
    int (*gettype)(const igraph_t *graph, igraph_attribute_type_t *type,
                   igraph_attribute_elemtype_t elemtype, const char *name);
    int (*get_numeric_graph_attr)(const igraph_t *graph, const char *name,
                                  igraph_vector_t *value);
    int (*get_string_graph_attr)(const igraph_t *graph, const char *name,
                                 igraph_strvector_t *value);
    int (*get_bool_graph_attr)(const igraph_t *igraph, const char *name,
                               igraph_vector_bool_t *value);
    int (*get_numeric_vertex_attr)(const igraph_t *graph, const char *name,
                                   igraph_vs_t vs,
                                   igraph_vector_t *value);
    int (*get_string_vertex_attr)(const igraph_t *graph, const char *name,
                                  igraph_vs_t vs,
                                  igraph_strvector_t *value);
    int (*get_bool_vertex_attr)(const igraph_t *graph, const char *name,
                                igraph_vs_t vs,
                                igraph_vector_bool_t *value);
    int (*get_numeric_edge_attr)(const igraph_t *graph, const char *name,
                                 igraph_es_t es,
                                 igraph_vector_t *value);
    int (*get_string_edge_attr)(const igraph_t *graph, const char *name,
                                igraph_es_t es,
                                igraph_strvector_t *value);
    int (*get_bool_edge_attr)(const igraph_t *graph, const char *name,
                              igraph_es_t es,
                              igraph_vector_bool_t *value);
} igraph_attribute_table_t;

This type collects the functions defining an attribute handler. It has the following members:

Values: 

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 attr member of the igraph_t object. It is expected to return an error code.

destroy:

This function is called whenever the graph object is destroyed, right before freeing the allocated memory.

copy:

This function is called when copying a graph with igraph_copy, after the structure of the graph has been already copied. It is expected to return an error code.

add_vertices:

Called when vertices are added to a graph, before adding the vertices themselves. The number of vertices to add is supplied as an argument. Expected to return an error code.

permute_vertices:

Typically called when a new graph is created based on an existing one, e.g. if vertices are removed from a graph. The supplied index vector defines which old vertex a new vertex corresponds to. Its length must be the same as the number of vertices in the new graph.

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 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.

add_edges:

Called when new edges have been added. The number of new edges are supplied as well. It is expected to return an error code.

permute_edges:

Typically called when a new graph is created and some of the new edges should carry the attributes of some of the old edges. The idx vector shows the mapping between the old edges and the new ones. Its length is the same as the number of edges in the new graph, and for each edge it gives the id of the old edge (the edge in the old graph).

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.

get_info:

Query the attributes of a graph, the names and types should be returned.

has_attr:

Check whether a graph has the named graph/vertex/edge attribute.

gettype:

Query the type of a graph/vertex/edge attribute.

get_numeric_graph_attr:

Query a numeric graph attribute. The value should be placed as the first element of the value vector.

get_string_graph_attr:

Query a string graph attribute. The value should be placed as the first element of the value string vector.

get_bool_graph_attr:

Query a boolean graph attribute. The value should be placed as the first element of the value boolean vector.

get_numeric_vertex_attr:

Query a numeric vertex attribute, for the vertices included in vs.

get_string_vertex_attr:

Query a string vertex attribute, for the vertices included in vs.

get_bool_vertex_attr:

Query a boolean vertex attribute, for the vertices included in vs.

get_numeric_edge_attr:

Query a numeric edge attribute, for the edges included in es.

get_string_edge_attr:

Query a string edge attribute, for the edges included in es.

get_bool_edge_attr:

Query a boolean edge attribute, for the edges included in es.

Note that the get_*_*_attr are allowed to convert the attributes to numeric or string. E.g. if a vertex attribute is a GNU R complex data type, then get_string_vertex_attribute may serialize it into a string, but this probably makes sense only if add_vertices is able to deserialize it.

1.2. igraph_set_attribute_table — Attach an attribute table.

igraph_attribute_table_t *
igraph_set_attribute_table(const igraph_attribute_table_t * table);

This function attaches attribute handling code to the igraph library. Note that the attribute handler table is not thread-local even if igraph is compiled in thread-local mode. In the vast majority of cases, this is not a significant restriction.

Arguments: 

table:

Pointer to an igraph_attribute_table_t object containing the functions for attribute manipulation. Supply NULL here if you don't want attributes.

Returns: 

Pointer to the old attribute handling table.

Time complexity: O(1).

1.3. igraph_attribute_type_t — The possible types of the attributes.

typedef enum { IGRAPH_ATTRIBUTE_DEFAULT = 0,
               IGRAPH_ATTRIBUTE_NUMERIC = 1,
               IGRAPH_ATTRIBUTE_BOOLEAN = 5,
               IGRAPH_ATTRIBUTE_STRING = 2,
               IGRAPH_ATTRIBUTE_R_OBJECT = 3,
               IGRAPH_ATTRIBUTE_PY_OBJECT = 4
             } igraph_attribute_type_t;

Note that this is only the type communicated by the attribute interface towards igraph functions. Eg. in the GNU R attribute handler, it is safe to say that all complex R object attributes are strings, as long as this interface is able to serialize them into strings. See also igraph_attribute_table_t.

Values: 

IGRAPH_ATTRIBUTE_DEFAULT:

Currently not used for anything.

IGRAPH_ATTRIBUTE_NUMERIC:

Numeric attribute.

IGRAPH_ATTRIBUTE_BOOLEAN:

Logical values, true or false.

IGRAPH_ATTRIBUTE_STRING:

Attribute that can be converted to a string.

IGRAPH_ATTRIBUTE_R_OBJECT:

An R object. This is usually ignored by the igraph functions.

IGRAPH_ATTRIBUTE_PY_OBJECT:

A Python object. Usually ignored by the igraph functions.

2. Handling attribute combination lists

Several graph operations may collapse multiple vertices or edges into a single one. Attribute combination lists are used to indicate to the attribute handler how to combine the attributes of the original vertices or edges and how to derive the final attribute value that is to be assigned to the collapsed vertex or edge. For example, igraph_simplify() removes loops and combines multiple edges into a single one; in case of a graph with an edge attribute named weight the attribute combination list can tell the attribute handler whether the weight of a collapsed edge should be the sum, the mean or some other function of the weights of the original edges that were collapsed into one.

One attribute combination list may contain several attribute combination records, one for each vertex or edge attribute that is to be handled during the operation.

2.1. igraph_attribute_combination_init — Initialize attribute combination list.

int igraph_attribute_combination_init(igraph_attribute_combination_t *comb);

Arguments: 

comb:

The uninitialized attribute combination list.

Returns: 

Error code.

Time complexity: O(1)

2.2. igraph_attribute_combination_add — Add combination record to attribute combination list.

int igraph_attribute_combination_add(igraph_attribute_combination_t *comb,
                                     const char *name,
                                     igraph_attribute_combination_type_t type,
                                     igraph_function_pointer_t func);

Arguments: 

comb:

The attribute combination list.

name:

The name of the attribute. If the name already exists the attribute combination record will be replaced. Use NULL to add a default combination record for all atributes not in the list.

type:

The type of the attribute combination. See igraph_attribute_combination_type_t for the options.

func:

Function to be used if type is IGRAPH_ATTRIBUTE_COMBINE_FUNCTION.

Returns: 

Error code.

Time complexity: O(n), where n is the number of current attribute combinations.

2.3. igraph_attribute_combination_remove — Remove a record from an attribute combination list.

int igraph_attribute_combination_remove(igraph_attribute_combination_t *comb,
                                        const char *name);

Arguments: 

comb:

The attribute combination list.

name:

The attribute name of the attribute combination record to remove. It will be ignored if the named attribute does not exist. It can be NULL to remove the default combination record.

Returns: 

Error code. This currently always returns IGRAPH_SUCCESS.

Time complexity: O(n), where n is the number of records in the attribute combination list.

2.4. igraph_attribute_combination_destroy — Destroy attribute combination list.

void igraph_attribute_combination_destroy(igraph_attribute_combination_t *comb);

Arguments: 

comb:

The attribute combination list.

Time complexity: O(n), where n is the number of records in the attribute combination list.

2.5. igraph_attribute_combination_type_t — The possible types of attribute combinations.

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;

Values: 

IGRAPH_ATTRIBUTE_COMBINE_IGNORE:

Ignore old attributes, use an empty value.

IGRAPH_ATTRIBUTE_COMBINE_DEFAULT:

Use the default way to combine attributes (decided by the attribute handler implementation).

IGRAPH_ATTRIBUTE_COMBINE_FUNCTION:

Supply your own function to combine attributes.

IGRAPH_ATTRIBUTE_COMBINE_SUM:

Take the sum of the attributes.

IGRAPH_ATTRIBUTE_COMBINE_PROD:

Take the product of the attributes.

IGRAPH_ATTRIBUTE_COMBINE_MIN:

Take the minimum attribute.

IGRAPH_ATTRIBUTE_COMBINE_MAX:

Take the maximum attribute.

IGRAPH_ATTRIBUTE_COMBINE_RANDOM:

Take a random attribute.

IGRAPH_ATTRIBUTE_COMBINE_FIRST:

Take the first attribute.

IGRAPH_ATTRIBUTE_COMBINE_LAST:

Take the last attribute.

IGRAPH_ATTRIBUTE_COMBINE_MEAN:

Take the mean of the attributes.

IGRAPH_ATTRIBUTE_COMBINE_MEDIAN:

Take the median of the attributes.

IGRAPH_ATTRIBUTE_COMBINE_CONCAT:

Concatenate the attributes.

3. Accessing attributes from C

There is an experimental attribute handler that can be used from C code. In this section we show how this works. This attribute handler is by default not attached (the default is no attribute handler), so we first need to attach it:

igraph_set_attribute_table(&igraph_cattribute_table);

Now the attribute functions are available. Please note that the attribute handler must be attached before you call any other igraph functions, otherwise you might end up with graphs without attributes and an active attribute handler, which might cause unexpected program behaviour. The rule is that you attach the attribute handler in the beginning of your main() and never touch it again. Detaching the attribute handler might lead to memory leaks.

It is not currently possible to have attribute handlers on a per-graph basis. All graphs in an application must be managed with the same attribute handler. This also applies to the default case when there is no attribute handler at all.

The C attribute handler supports attaching real numbers, boolean values and character strings as attributes. No vector values are allowed. For example, vertices have a name attribute holding a single string value for each vertex, but it is not possible to have a coords attribute which is a vector of numbers per vertex.

The functions documented in this section are specific to the C attribute handler. Code using these functions will not function when a different attribute handler is attached.

Example 12.1.  File examples/simple/cattributes.c

/* -*- mode: C -*-  */
/*
   IGraph library.
   Copyright (C) 2007-2012  Gabor Csardi <csardi.gabor@gmail.com>
   334 Harvard street, Cambridge, MA 02139 USA

   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, write to the Free Software
   Foundation, Inc.,  51 Franklin Street, Fifth Floor, Boston, MA
   02110-1301 USA

*/

#include <igraph.h>
#include <string.h>
#include <stdlib.h>

int print_attributes(const igraph_t *g) {

    igraph_vector_t gtypes, vtypes, etypes;
    igraph_strvector_t gnames, vnames, enames;
    long int i;

    igraph_vector_t vec;
    igraph_strvector_t svec;
    long int j;

    igraph_vector_init(&gtypes, 0);
    igraph_vector_init(&vtypes, 0);
    igraph_vector_init(&etypes, 0);
    igraph_strvector_init(&gnames, 0);
    igraph_strvector_init(&vnames, 0);
    igraph_strvector_init(&enames, 0);

    igraph_cattribute_list(g, &gnames, &gtypes, &vnames, &vtypes,
                           &enames, &etypes);

    /* Graph attributes */
    for (i = 0; i < igraph_strvector_size(&gnames); i++) {
        printf("%s=", STR(gnames, i));
        if (VECTOR(gtypes)[i] == IGRAPH_ATTRIBUTE_NUMERIC) {
            igraph_real_printf(GAN(g, STR(gnames, i)));
            putchar(' ');
        } else {
            printf("\"%s\" ", GAS(g, STR(gnames, i)));
        }
    }
    printf("\n");

    for (i = 0; i < igraph_vcount(g); i++) {
        long int j;
        printf("Vertex %li: ", i);
        for (j = 0; j < igraph_strvector_size(&vnames); j++) {
            printf("%s=", STR(vnames, j));
            if (VECTOR(vtypes)[j] == IGRAPH_ATTRIBUTE_NUMERIC) {
                igraph_real_printf(VAN(g, STR(vnames, j), i));
                putchar(' ');
            } else {
                printf("\"%s\" ", VAS(g, STR(vnames, j), i));
            }
        }
        printf("\n");
    }

    for (i = 0; i < igraph_ecount(g); i++) {
        long int j;
        printf("Edge %li (%i-%i): ", i, (int)IGRAPH_FROM(g, i), (int)IGRAPH_TO(g, i));
        for (j = 0; j < igraph_strvector_size(&enames); j++) {
            printf("%s=", STR(enames, j));
            if (VECTOR(etypes)[j] == IGRAPH_ATTRIBUTE_NUMERIC) {
                igraph_real_printf(EAN(g, STR(enames, j), i));
                putchar(' ');
            } else {
                printf("\"%s\" ", EAS(g, STR(enames, j), i));
            }
        }
        printf("\n");
    }

    /* Check vector-based query functions */
    igraph_vector_init(&vec, 0);
    igraph_strvector_init(&svec, 0);

    for (j = 0; j < igraph_strvector_size(&vnames); j++) {
        if (VECTOR(vtypes)[j] == IGRAPH_ATTRIBUTE_NUMERIC) {
            igraph_cattribute_VANV(g, STR(vnames, j), igraph_vss_all(), &vec);
            for (i = 0; i < igraph_vcount(g); i++) {
                igraph_real_t num = VAN(g, STR(vnames, j), i);
                if (num != VECTOR(vec)[i] &&
                    (!isnan(num) || !isnan(VECTOR(vec)[i]))) {
                    exit(51);
                }
            }
        } else {
            igraph_cattribute_VASV(g, STR(vnames, j), igraph_vss_all(), &svec);
            for (i = 0; i < igraph_vcount(g); i++) {
                const char *str = VAS(g, STR(vnames, j), i);
                if (strcmp(str, STR(svec, i))) {
                    exit(52);
                }
            }
        }
    }

    for (j = 0; j < igraph_strvector_size(&enames); j++) {
        if (VECTOR(etypes)[j] == IGRAPH_ATTRIBUTE_NUMERIC) {
            igraph_cattribute_EANV(g, STR(enames, j),
                                   igraph_ess_all(IGRAPH_EDGEORDER_ID), &vec);
            for (i = 0; i < igraph_ecount(g); i++) {
                igraph_real_t num = EAN(g, STR(enames, j), i);
                if (num != VECTOR(vec)[i] &&
                    (!isnan(num) || !isnan(VECTOR(vec)[i]))) {
                    exit(53);
                }
            }
        } else {
            igraph_cattribute_EASV(g, STR(enames, j),
                                   igraph_ess_all(IGRAPH_EDGEORDER_ID), &svec);
            for (i = 0; i < igraph_ecount(g); i++) {
                const char *str = EAS(g, STR(enames, j), i);
                if (strcmp(str, STR(svec, i))) {
                    exit(54);
                }
            }
        }
    }

    igraph_strvector_destroy(&svec);
    igraph_vector_destroy(&vec);

    igraph_strvector_destroy(&enames);
    igraph_strvector_destroy(&vnames);
    igraph_strvector_destroy(&gnames);
    igraph_vector_destroy(&etypes);
    igraph_vector_destroy(&vtypes);
    igraph_vector_destroy(&gtypes);

    return 0;
}

int main() {

    igraph_t g, g2;
    FILE *ifile;
    igraph_vector_t gtypes, vtypes, etypes;
    igraph_strvector_t gnames, vnames, enames;
    long int i;
    igraph_vector_t y;
    igraph_strvector_t id;
    igraph_vector_bool_t type;
    char str[21];

    /* turn on attribute handling */
    igraph_set_attribute_table(&igraph_cattribute_table);

    ifile = fopen("links.net", "r");
    if (ifile == 0) {
        return 10;
    }
    igraph_read_graph_pajek(&g, ifile);
    fclose(ifile);

    igraph_vector_init(&gtypes, 0);
    igraph_vector_init(&vtypes, 0);
    igraph_vector_init(&etypes, 0);
    igraph_strvector_init(&gnames, 0);
    igraph_strvector_init(&vnames, 0);
    igraph_strvector_init(&enames, 0);

    igraph_cattribute_list(&g, &gnames, &gtypes, &vnames, &vtypes,
                           &enames, &etypes);

    /* List attribute names and types */
    printf("Graph attributes: ");
    for (i = 0; i < igraph_strvector_size(&gnames); i++) {
        printf("%s (%i) ", STR(gnames, i), (int)VECTOR(gtypes)[i]);
    }
    printf("\n");
    printf("Vertex attributes: ");
    for (i = 0; i < igraph_strvector_size(&vnames); i++) {
        printf("%s (%i) ", STR(vnames, i), (int)VECTOR(vtypes)[i]);
    }
    printf("\n");
    printf("Edge attributes: ");
    for (i = 0; i < igraph_strvector_size(&enames); i++) {
        printf("%s (%i) ", STR(enames, i), (int)VECTOR(etypes)[i]);
    }
    printf("\n");

    print_attributes(&g);

    /* Copying a graph */
    igraph_copy(&g2, &g);
    print_attributes(&g2);
    igraph_destroy(&g2);

    /* Adding vertices */
    igraph_add_vertices(&g, 3, 0);
    print_attributes(&g);

    /* Adding edges */
    igraph_add_edge(&g, 1, 1);
    igraph_add_edge(&g, 2, 5);
    igraph_add_edge(&g, 3, 6);
    print_attributes(&g);

    /* Deleting vertices */
    igraph_delete_vertices(&g, igraph_vss_1(1));
    igraph_delete_vertices(&g, igraph_vss_1(4));
    print_attributes(&g);

    /* Deleting edges */
    igraph_delete_edges(&g, igraph_ess_1(igraph_ecount(&g) - 1));
    igraph_delete_edges(&g, igraph_ess_1(0));
    print_attributes(&g);

    /* Set graph attributes */
    SETGAN(&g, "id", 10);
    if (GAN(&g, "id") != 10) {
        return 11;
    }
    SETGAS(&g, "name", "toy");
    if (strcmp(GAS(&g, "name"), "toy")) {
        return 12;
    }
    SETGAB(&g, "is_regular", 0);
    if (GAB(&g, "is_regular") != 0) {
        return 13;
    }

    /* Delete graph attributes */
    DELGA(&g, "id");
    DELGA(&g, "name");
    DELGA(&g, "is_regular");
    igraph_cattribute_list(&g, &gnames, 0, 0, 0, 0, 0);
    if (igraph_strvector_size(&gnames) != 0) {
        return 14;
    }

    /* Delete vertex attributes */
    DELVA(&g, "x");
    DELVA(&g, "shape");
    DELVA(&g, "xfact");
    DELVA(&g, "yfact");
    igraph_cattribute_list(&g, 0, 0, &vnames, 0, 0, 0);
    if (igraph_strvector_size(&vnames) != 3) {
        return 15;
    }

    /* Delete edge attributes */
    igraph_cattribute_list(&g, 0, 0, 0, 0, &enames, 0);
    i = igraph_strvector_size(&enames);
    DELEA(&g, "hook1");
    DELEA(&g, "hook2");
    DELEA(&g, "label");
    igraph_cattribute_list(&g, 0, 0, 0, 0, &enames, 0);
    if (igraph_strvector_size(&enames) != i - 3) {
        return 16;
    }

    /* Set vertex attributes */
    SETVAN(&g, "y", 0, -1);
    SETVAN(&g, "y", 1, 2.1);
    if (VAN(&g, "y", 0) != -1 ||
        VAN(&g, "y", 1) != 2.1) {
        return 17;
    }
    SETVAS(&g, "id", 0, "foo");
    SETVAS(&g, "id", 1, "bar");
    if (strcmp(VAS(&g, "id", 0), "foo") ||
        strcmp(VAS(&g, "id", 1), "bar")) {
        return 18;
    }
    SETVAB(&g, "type", 0, 1);
    SETVAB(&g, "type", 1, 0);
    if (!VAB(&g, "type", 0) || VAB(&g, "type", 1)) {
        return 26;
    }

    /* Set edge attributes */
    SETEAN(&g, "weight", 2, 100.0);
    SETEAN(&g, "weight", 0, -100.1);
    if (EAN(&g, "weight", 2) != 100.0 ||
        EAN(&g, "weight", 0) != -100.1) {
        return 19;
    }
    SETEAS(&g, "color", 2, "RED");
    SETEAS(&g, "color", 0, "Blue");
    if (strcmp(EAS(&g, "color", 2), "RED") ||
        strcmp(EAS(&g, "color", 0), "Blue")) {
        return 20;
    }
    SETEAB(&g, "type", 0, 1);
    SETEAB(&g, "type", 2, 0);
    if (!EAB(&g, "type", 0) || EAB(&g, "type", 2)) {
        return 27;
    }

    /* Set vertex attributes as vector */
    igraph_vector_init(&y, igraph_vcount(&g));
    igraph_vector_fill(&y, 1.23);
    SETVANV(&g, "y", &y);
    igraph_vector_destroy(&y);
    for (i = 0; i < igraph_vcount(&g); i++) {
        if (VAN(&g, "y", i) != 1.23) {
            return 21;
        }
    }
    igraph_vector_init_seq(&y, 0, igraph_vcount(&g) - 1);
    SETVANV(&g, "foobar", &y);
    igraph_vector_destroy(&y);
    for (i = 0; i < igraph_vcount(&g); i++) {
        if (VAN(&g, "foobar", i) != i) {
            return 22;
        }
    }

    igraph_vector_bool_init(&type, igraph_vcount(&g));
    for (i = 0; i < igraph_vcount(&g); i++) {
        VECTOR(type)[i] = (i % 2 == 1);
    }
    SETVABV(&g, "type", &type);
    igraph_vector_bool_destroy(&type);
    for (i = 0; i < igraph_vcount(&g); i++) {
        if (VAB(&g, "type", i) != (i % 2 == 1)) {
            return 28;
        }
    }

    igraph_strvector_init(&id, igraph_vcount(&g));
    for (i = 0; i < igraph_vcount(&g); i++) {
        snprintf(str, sizeof(str) - 1, "%li", i);
        igraph_strvector_set(&id, i, str);
    }
    SETVASV(&g, "foo", &id);
    igraph_strvector_destroy(&id);
    for (i = 0; i < igraph_vcount(&g); i++) {
        printf("%s ", VAS(&g, "foo", i));
    }
    printf("\n");
    igraph_strvector_init(&id, igraph_vcount(&g));
    for (i = 0; i < igraph_vcount(&g); i++) {
        snprintf(str, sizeof(str) - 1, "%li", i);
        igraph_strvector_set(&id, i, str);
    }
    SETVASV(&g, "id", &id);
    igraph_strvector_destroy(&id);
    for (i = 0; i < igraph_vcount(&g); i++) {
        printf("%s ", VAS(&g, "id", i));
    }
    printf("\n");

    /* Set edge attributes as vector */
    igraph_vector_init(&y, igraph_ecount(&g));
    igraph_vector_fill(&y, 12.3);
    SETEANV(&g, "weight", &y);
    igraph_vector_destroy(&y);
    for (i = 0; i < igraph_ecount(&g); i++) {
        if (EAN(&g, "weight", i) != 12.3) {
            return 23;
        }
    }
    igraph_vector_init_seq(&y, 0, igraph_ecount(&g) - 1);
    SETEANV(&g, "foobar", &y);
    igraph_vector_destroy(&y);
    for (i = 0; i < igraph_ecount(&g); i++) {
        if (VAN(&g, "foobar", i) != i) {
            return 24;
        }
    }

    igraph_vector_bool_init(&type, igraph_ecount(&g));
    for (i = 0; i < igraph_ecount(&g); i++) {
        VECTOR(type)[i] = (i % 2 == 1);
    }
    SETEABV(&g, "type", &type);
    igraph_vector_bool_destroy(&type);
    for (i = 0; i < igraph_ecount(&g); i++) {
        if (EAB(&g, "type", i) != (i % 2 == 1)) {
            return 29;
        }
    }

    igraph_strvector_init(&id, igraph_ecount(&g));
    for (i = 0; i < igraph_ecount(&g); i++) {
        snprintf(str, sizeof(str) - 1, "%li", i);
        igraph_strvector_set(&id, i, str);
    }
    SETEASV(&g, "foo", &id);
    igraph_strvector_destroy(&id);
    for (i = 0; i < igraph_ecount(&g); i++) {
        printf("%s ", EAS(&g, "foo", i));
    }
    printf("\n");
    igraph_strvector_init(&id, igraph_ecount(&g));
    for (i = 0; i < igraph_ecount(&g); i++) {
        snprintf(str, sizeof(str) - 1, "%li", i);
        igraph_strvector_set(&id, i, str);
    }
    SETEASV(&g, "color", &id);
    igraph_strvector_destroy(&id);
    for (i = 0; i < igraph_ecount(&g); i++) {
        printf("%s ", EAS(&g, "color", i));
    }
    printf("\n");

    /* Delete all remaining attributes */
    DELALL(&g);
    igraph_cattribute_list(&g, &gnames, &gtypes, &vnames, &vtypes, &enames, &etypes);
    if (igraph_strvector_size(&gnames) != 0 ||
        igraph_strvector_size(&vnames) != 0 ||
        igraph_strvector_size(&enames) != 0) {
        return 25;
    }

    /* Destroy */
    igraph_vector_destroy(&gtypes);
    igraph_vector_destroy(&vtypes);
    igraph_vector_destroy(&etypes);
    igraph_strvector_destroy(&gnames);
    igraph_strvector_destroy(&vnames);
    igraph_strvector_destroy(&enames);

    igraph_destroy(&g);

    return 0;
}


Example 12.2.  File examples/simple/cattributes2.c

/* -*- mode: C -*-  */
/*
   IGraph library.
   Copyright (C) 2007-2012  Gabor Csardi <csardi.gabor@gmail.com>
   334 Harvard street, Cambridge, MA 02139 USA

   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, write to the Free Software
   Foundation, Inc.,  51 Franklin Street, Fifth Floor, Boston, MA
   02110-1301 USA

*/

#include <igraph.h>

void null_warning_handler (const char *reason, const char *file,
                           int line, int igraph_errno) {
}

int main() {

    igraph_t g;
    igraph_vector_t y;
    igraph_warning_handler_t* oldwarnhandler;

    /* turn on attribute handling */
    igraph_set_attribute_table(&igraph_cattribute_table);

    /* Create a graph, add some attributes and save it as a GraphML file */
    igraph_famous(&g, "Petersen");
    SETGAS(&g, "name", "Petersen's graph");
    SETGAN(&g, "vertices", igraph_vcount(&g));
    SETGAN(&g, "edges", igraph_ecount(&g));
    SETGAB(&g, "famous", 1);

    igraph_vector_init_seq(&y, 1, igraph_vcount(&g));
    SETVANV(&g, "id", &y);
    igraph_vector_destroy(&y);

    SETVAS(&g, "name", 0, "foo");
    SETVAS(&g, "name", 1, "foobar");

    SETVAB(&g, "is_first", 0, 1);

    igraph_vector_init_seq(&y, 1, igraph_ecount(&g));
    SETEANV(&g, "id", &y);
    igraph_vector_destroy(&y);

    SETEAS(&g, "name", 0, "FOO");
    SETEAS(&g, "name", 1, "FOOBAR");

    SETEAB(&g, "is_first", 0, 1);

    /* Turn off the warning handler temporarily because the GML writer will
     * print warnings about boolean attributes being converted to numbers, and
     * we don't care about these */
    oldwarnhandler = igraph_set_warning_handler(null_warning_handler);
    igraph_write_graph_gml(&g, stdout, 0, "");
    igraph_set_warning_handler(oldwarnhandler);

    /* Back to business */
    igraph_write_graph_graphml(&g, stdout, /*prefixattr=*/ 1);

    igraph_destroy(&g);

    return 0;
}


Example 12.3.  File examples/simple/cattributes3.c

/* -*- mode: C -*-  */
/*
   IGraph library.
   Copyright (C) 2010-2012  Gabor Csardi <csardi.gabor@gmail.com>
   334 Harvard street, Cambridge, MA 02139 USA

   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, write to the Free Software
   Foundation, Inc.,  51 Franklin Street, Fifth Floor, Boston, MA
   02110-1301 USA

*/

#include <igraph.h>

int mf(const igraph_vector_t *input, igraph_real_t *output) {
    *output = 0.0;
    return 0;
}

int main() {

    igraph_t g, g2;
    igraph_vector_t weight;
    igraph_attribute_combination_t comb;

    igraph_set_attribute_table(&igraph_cattribute_table);

    igraph_small(&g, 4, IGRAPH_DIRECTED,
                 0, 1, 0, 1, 0, 1,
                 1, 2, 2, 3,
                 -1);

    igraph_vector_init_seq(&weight, 1, igraph_ecount(&g));
    SETEANV(&g, "weight", &weight);
    igraph_vector_destroy(&weight);

    /* ****************************************************** */
    igraph_copy(&g2, &g);
    igraph_attribute_combination(&comb,
                                 "weight", IGRAPH_ATTRIBUTE_COMBINE_SUM,
                                 "",       IGRAPH_ATTRIBUTE_COMBINE_IGNORE,
                                 IGRAPH_NO_MORE_ATTRIBUTES);
    igraph_simplify(&g2, /*multiple=*/ 1, /*loops=*/ 1, &comb);
    igraph_attribute_combination_destroy(&comb);
    igraph_write_graph_graphml(&g2, stdout, /*prefixattr=*/ 1);
    igraph_destroy(&g2);
    /* ****************************************************** */

    /* ****************************************************** */
    igraph_copy(&g2, &g);
    igraph_attribute_combination(&comb,
                                 "weight", IGRAPH_ATTRIBUTE_COMBINE_PROD,
                                 "",       IGRAPH_ATTRIBUTE_COMBINE_IGNORE,
                                 IGRAPH_NO_MORE_ATTRIBUTES);
    igraph_simplify(&g2, /*multiple=*/ 1, /*loops=*/ 1, &comb);
    igraph_attribute_combination_destroy(&comb);
    igraph_write_graph_graphml(&g2, stdout, /*prefixattr=*/ 1);
    igraph_destroy(&g2);
    /* ****************************************************** */

    /* ****************************************************** */
    igraph_copy(&g2, &g);
    igraph_attribute_combination(&comb,
                                 "weight", IGRAPH_ATTRIBUTE_COMBINE_MIN,
                                 "",       IGRAPH_ATTRIBUTE_COMBINE_IGNORE,
                                 IGRAPH_NO_MORE_ATTRIBUTES);
    igraph_simplify(&g2, /*multiple=*/ 1, /*loops=*/ 1, &comb);
    igraph_attribute_combination_destroy(&comb);
    igraph_write_graph_graphml(&g2, stdout, /*prefixattr=*/ 1);
    igraph_destroy(&g2);
    /* ****************************************************** */

    /* ****************************************************** */
    igraph_copy(&g2, &g);
    igraph_attribute_combination(&comb,
                                 "weight", IGRAPH_ATTRIBUTE_COMBINE_MAX,
                                 "",       IGRAPH_ATTRIBUTE_COMBINE_IGNORE,
                                 IGRAPH_NO_MORE_ATTRIBUTES);
    igraph_simplify(&g2, /*multiple=*/ 1, /*loops=*/ 1, &comb);
    igraph_attribute_combination_destroy(&comb);
    igraph_write_graph_graphml(&g2, stdout, /*prefixattr=*/ 1);
    igraph_destroy(&g2);
    /* ****************************************************** */

    /* ****************************************************** */
    igraph_copy(&g2, &g);
    igraph_attribute_combination(&comb,
                                 "weight", IGRAPH_ATTRIBUTE_COMBINE_FIRST,
                                 "",       IGRAPH_ATTRIBUTE_COMBINE_IGNORE,
                                 IGRAPH_NO_MORE_ATTRIBUTES);
    igraph_simplify(&g2, /*multiple=*/ 1, /*loops=*/ 1, &comb);
    igraph_attribute_combination_destroy(&comb);
    igraph_write_graph_graphml(&g2, stdout, /*prefixattr=*/ 1);
    igraph_destroy(&g2);
    /* ****************************************************** */

    /* ****************************************************** */
    igraph_copy(&g2, &g);
    igraph_attribute_combination(&comb,
                                 "weight", IGRAPH_ATTRIBUTE_COMBINE_LAST,
                                 "",       IGRAPH_ATTRIBUTE_COMBINE_IGNORE,
                                 IGRAPH_NO_MORE_ATTRIBUTES);
    igraph_simplify(&g2, /*multiple=*/ 1, /*loops=*/ 1, &comb);
    igraph_attribute_combination_destroy(&comb);
    igraph_write_graph_graphml(&g2, stdout, /*prefixattr=*/ 1);
    igraph_destroy(&g2);
    /* ****************************************************** */

    /* ****************************************************** */
    igraph_copy(&g2, &g);
    igraph_attribute_combination(&comb,
                                 "weight", IGRAPH_ATTRIBUTE_COMBINE_MEAN,
                                 "",       IGRAPH_ATTRIBUTE_COMBINE_IGNORE,
                                 IGRAPH_NO_MORE_ATTRIBUTES);
    igraph_simplify(&g2, /*multiple=*/ 1, /*loops=*/ 1, &comb);
    igraph_attribute_combination_destroy(&comb);
    igraph_write_graph_graphml(&g2, stdout, /*prefixattr=*/ 1);
    igraph_destroy(&g2);
    /* ****************************************************** */

    /* ****************************************************** */
    igraph_copy(&g2, &g);
    igraph_attribute_combination(&comb,
                                 "weight", IGRAPH_ATTRIBUTE_COMBINE_FUNCTION, mf,
                                 "",       IGRAPH_ATTRIBUTE_COMBINE_IGNORE,
                                 IGRAPH_NO_MORE_ATTRIBUTES);
    igraph_simplify(&g2, /*multiple=*/ 1, /*loops=*/ 1, &comb);
    igraph_attribute_combination_destroy(&comb);
    igraph_write_graph_graphml(&g2, stdout, /*prefixattr=*/ 1);
    igraph_destroy(&g2);
    /* ****************************************************** */

    /* ****************************************************** */
    igraph_copy(&g2, &g);
    igraph_attribute_combination(&comb,
                                 "",       IGRAPH_ATTRIBUTE_COMBINE_MEAN,
                                 IGRAPH_NO_MORE_ATTRIBUTES);
    igraph_simplify(&g2, /*multiple=*/ 1, /*loops=*/ 1, &comb);
    igraph_attribute_combination_destroy(&comb);
    igraph_write_graph_graphml(&g2, stdout, /*prefixattr=*/ 1);
    igraph_destroy(&g2);
    /* ****************************************************** */

    igraph_destroy(&g);

    return 0;
}


Example 12.4.  File examples/simple/cattributes4.c

/* -*- mode: C -*-  */
/*
   IGraph library.
   Copyright (C) 2010-2021  The igraph development team

   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, write to the Free Software
   Foundation, Inc.,  51 Franklin Street, Fifth Floor, Boston, MA
   02110-1301 USA

*/

#include <igraph.h>

int main() {

    igraph_t g, g2;
    igraph_attribute_combination_t comb;

    igraph_set_attribute_table(&igraph_cattribute_table);

    igraph_small(&g, 4, IGRAPH_DIRECTED,
                 0, 1, 0, 1, 0, 1,
                 1, 2, 2, 3,
                 -1);

    SETEAS(&g, "color", 0, "green");
    SETEAS(&g, "color", 1, "red");
    SETEAS(&g, "color", 2, "blue");
    SETEAS(&g, "color", 3, "white");
    SETEAS(&g, "color", 4, "black");

    /* ****************************************************** */
    igraph_copy(&g2, &g);
    igraph_attribute_combination(&comb,
                                 "weight", IGRAPH_ATTRIBUTE_COMBINE_SUM,
                                 "color",  IGRAPH_ATTRIBUTE_COMBINE_FIRST,
                                 "",       IGRAPH_ATTRIBUTE_COMBINE_IGNORE,
                                 IGRAPH_NO_MORE_ATTRIBUTES);
    igraph_simplify(&g2, /*multiple=*/ 1, /*loops=*/ 1, &comb);
    igraph_attribute_combination_destroy(&comb);
    igraph_write_graph_graphml(&g2, stdout, /*prefixattr=*/ 1);
    igraph_destroy(&g2);
    /* ****************************************************** */

    /* ****************************************************** */
    igraph_copy(&g2, &g);
    igraph_attribute_combination(&comb,
                                 "",       IGRAPH_ATTRIBUTE_COMBINE_LAST,
                                 IGRAPH_NO_MORE_ATTRIBUTES);
    igraph_simplify(&g2, /*multiple=*/ 1, /*loops=*/ 1, &comb);
    igraph_attribute_combination_destroy(&comb);
    igraph_write_graph_graphml(&g2, stdout, /*prefixattr=*/ 1);
    igraph_destroy(&g2);
    /* ****************************************************** */

    /* ****************************************************** */
    igraph_copy(&g2, &g);
    igraph_attribute_combination(&comb,
                                 "",       IGRAPH_ATTRIBUTE_COMBINE_IGNORE,
                                 "color",  IGRAPH_ATTRIBUTE_COMBINE_CONCAT,
                                 IGRAPH_NO_MORE_ATTRIBUTES);
    igraph_simplify(&g2, /*multiple=*/ 1, /*loops=*/ 1, &comb);
    igraph_attribute_combination_destroy(&comb);
    igraph_write_graph_graphml(&g2, stdout, /*prefixattr=*/ 1);
    igraph_destroy(&g2);
    /* ****************************************************** */

    igraph_destroy(&g);

    return 0;
}


3.1. Query attributes

3.1.1. igraph_cattribute_list — List all attributes
3.1.2. igraph_cattribute_has_attr — Checks whether a (graph, vertex or edge) attribute exists
3.1.3. igraph_cattribute_GAN — Query a numeric graph attribute.
3.1.4. GAN — Query a numeric graph attribute.
3.1.5. igraph_cattribute_GAB — Query a boolean graph attribute.
3.1.6. GAB — Query a boolean graph attribute.
3.1.7. igraph_cattribute_GAS — Query a string graph attribute.
3.1.8. GAS — Query a string graph attribute.
3.1.9. igraph_cattribute_VAN — Query a numeric vertex attribute.
3.1.10. VAN — Query a numeric vertex attribute.
3.1.11. igraph_cattribute_VANV — Query a numeric vertex attribute for many vertices
3.1.12. VANV — Query a numeric vertex attribute for all vertices.
3.1.13. igraph_cattribute_VAB — Query a boolean vertex attribute.
3.1.14. VAB — Query a boolean vertex attribute.
3.1.15. igraph_cattribute_VABV — Query a boolean vertex attribute for many vertices
3.1.16. VABV — Query a boolean vertex attribute for all vertices.
3.1.17. igraph_cattribute_VAS — Query a string vertex attribute.
3.1.18. VAS — Query a string vertex attribute.
3.1.19. igraph_cattribute_VASV — Query a string vertex attribute for many vertices
3.1.20. VASV — Query a string vertex attribute for all vertices.
3.1.21. igraph_cattribute_EAN — Query a numeric edge attribute.
3.1.22. EAN — Query a numeric edge attribute.
3.1.23. igraph_cattribute_EANV — Query a numeric edge attribute for many edges
3.1.24. EANV — Query a numeric edge attribute for all edges.
3.1.25. igraph_cattribute_EAB — Query a boolean edge attribute.
3.1.26. EAB — Query a boolean edge attribute.
3.1.27. igraph_cattribute_EABV — Query a boolean edge attribute for many edges
3.1.28. EABV — Query a boolean edge attribute for all edges.
3.1.29. igraph_cattribute_EAS — Query a string edge attribute.
3.1.30. EAS — Query a string edge attribute.
3.1.31. igraph_cattribute_EASV — Query a string edge attribute for many edges
3.1.32. EASV — Query a string edge attribute for all edges.

3.1.1. igraph_cattribute_list — List all attributes

int igraph_cattribute_list(const igraph_t *graph,
                           igraph_strvector_t *gnames, igraph_vector_t *gtypes,
                           igraph_strvector_t *vnames, igraph_vector_t *vtypes,
                           igraph_strvector_t *enames, igraph_vector_t *etypes);

See igraph_attribute_type_t for the various attribute types.

Arguments: 

graph:

The input graph.

gnames:

String vector, the names of the graph attributes.

gtypes:

Numeric vector, the types of the graph attributes.

vnames:

String vector, the names of the vertex attributes.

vtypes:

Numeric vector, the types of the vertex attributes.

enames:

String vector, the names of the edge attributes.

etypes:

Numeric vector, the types of the edge attributes.

Returns: 

Error code.

Naturally, the string vector with the attribute names and the numeric vector with the attribute types are in the right order, i.e. the first name corresponds to the first type, etc. Time complexity: O(Ag+Av+Ae), the number of all attributes.

3.1.2. igraph_cattribute_has_attr — Checks whether a (graph, vertex or edge) attribute exists

igraph_bool_t igraph_cattribute_has_attr(const igraph_t *graph,
        igraph_attribute_elemtype_t type,
        const char *name);

Arguments: 

graph:

The graph.

type:

The type of the attribute, IGRAPH_ATTRIBUTE_GRAPH, IGRAPH_ATTRIBUTE_VERTEX or IGRAPH_ATTRIBUTE_EDGE.

name:

Character constant, the name of the attribute.

Returns: 

Logical value, TRUE if the attribute exists, FALSE otherwise.

Time complexity: O(A), the number of (graph, vertex or edge) attributes, assuming attribute names are not too long.

3.1.3. igraph_cattribute_GAN — Query a numeric graph attribute.

igraph_real_t igraph_cattribute_GAN(const igraph_t *graph, const char *name);

Returns the value of the given numeric graph attribute. The attribute must exist, otherwise an error is triggered.

Arguments: 

graph:

The input graph.

name:

The name of the attribute to query.

Returns: 

The value of the attribute.

See also: 

GAN for a simpler interface.

Time complexity: O(Ag), the number of graph attributes.

3.1.4. GAN — Query a numeric graph attribute.

#define GAN(graph,n)

This is shorthand for igraph_cattribute_GAN().

Arguments: 

graph:

The graph.

n:

The name of the attribute.

Returns: 

The value of the attribute.

3.1.5. igraph_cattribute_GAB — Query a boolean graph attribute.

igraph_bool_t igraph_cattribute_GAB(const igraph_t *graph, const char *name);

Returns the value of the given numeric graph attribute. The attribute must exist, otherwise an error is triggered.

Arguments: 

graph:

The input graph.

name:

The name of the attribute to query.

Returns: 

The value of the attribute.

See also: 

GAB for a simpler interface.

Time complexity: O(Ag), the number of graph attributes.

3.1.6. GAB — Query a boolean graph attribute.

#define GAB(graph,n)

This is shorthand for igraph_cattribute_GAB().

Arguments: 

graph:

The graph.

n:

The name of the attribute.

Returns: 

The value of the attribute.

3.1.7. igraph_cattribute_GAS — Query a string graph attribute.

const char* igraph_cattribute_GAS(const igraph_t *graph, const char *name);

Returns a const pointer to the string graph attribute specified in name. The attribute must exist, otherwise an error is triggered.

Arguments: 

graph:

The input graph.

name:

The name of the attribute to query.

Returns: 

The value of the attribute.

See also: 

GAS for a simpler interface.

Time complexity: O(Ag), the number of graph attributes.

3.1.8. GAS — Query a string graph attribute.

#define GAS(graph,n)

This is shorthand for igraph_cattribute_GAS().

Arguments: 

graph:

The graph.

n:

The name of the attribute.

Returns: 

The value of the attribute.

3.1.9. igraph_cattribute_VAN — Query a numeric vertex attribute.

igraph_real_t igraph_cattribute_VAN(const igraph_t *graph, const char *name,
                                    igraph_integer_t vid);

The attribute must exist, otherwise an error is triggered.

Arguments: 

graph:

The input graph.

name:

The name of the attribute.

vid:

The id of the queried vertex.

Returns: 

The value of the attribute.

See also: 

VAN macro for a simpler interface.

Time complexity: O(Av), the number of vertex attributes.

3.1.10. VAN — Query a numeric vertex attribute.

#define VAN(graph,n,v)

This is shorthand for igraph_cattribute_VAN().

Arguments: 

graph:

The graph.

n:

The name of the attribute.

v:

The id of the vertex.

Returns: 

The value of the attribute.

3.1.11. igraph_cattribute_VANV — Query a numeric vertex attribute for many vertices

int igraph_cattribute_VANV(const igraph_t *graph, const char *name,
                           igraph_vs_t vids, igraph_vector_t *result);

Arguments: 

graph:

The input graph.

name:

The name of the attribute.

vids:

The vertices to query.

result:

Pointer to an initialized vector, the result is stored here. It will be resized, if needed.

Returns: 

Error code.

Time complexity: O(v), where v is the number of vertices in 'vids'.

3.1.12. VANV — Query a numeric vertex attribute for all vertices.

#define VANV(graph,n,vec)

This is a shorthand for igraph_cattribute_VANV().

Arguments: 

graph:

The graph.

n:

The name of the attribute.

vec:

Pointer to an initialized vector, the result is stored here. It will be resized, if needed.

Returns: 

Error code.

3.1.13. igraph_cattribute_VAB — Query a boolean vertex attribute.

igraph_bool_t igraph_cattribute_VAB(const igraph_t *graph, const char *name,
                                    igraph_integer_t vid);

The attribute must exist, otherwise an error is triggered.

Arguments: 

graph:

The input graph.

name:

The name of the attribute.

vid:

The id of the queried vertex.

Returns: 

The value of the attribute.

See also: 

VAB macro for a simpler interface.

Time complexity: O(Av), the number of vertex attributes.

3.1.14. VAB — Query a boolean vertex attribute.

#define VAB(graph,n,v)

This is shorthand for igraph_cattribute_VAB().

Arguments: 

graph:

The graph.

n:

The name of the attribute.

v:

The id of the vertex.

Returns: 

The value of the attribute.

3.1.15. igraph_cattribute_VABV — Query a boolean vertex attribute for many vertices

int igraph_cattribute_VABV(const igraph_t *graph, const char *name,
                           igraph_vs_t vids, igraph_vector_bool_t *result);

Arguments: 

graph:

The input graph.

name:

The name of the attribute.

vids:

The vertices to query.

result:

Pointer to an initialized boolean vector, the result is stored here. It will be resized, if needed.

Returns: 

Error code.

Time complexity: O(v), where v is the number of vertices in 'vids'.

3.1.16. VABV — Query a boolean vertex attribute for all vertices.

#define VABV(graph,n,vec)

This is a shorthand for igraph_cattribute_VABV().

Arguments: 

graph:

The graph.

n:

The name of the attribute.

vec:

Pointer to an initialized boolean vector, the result is stored here. It will be resized, if needed.

Returns: 

Error code.

3.1.17. igraph_cattribute_VAS — Query a string vertex attribute.

const char* igraph_cattribute_VAS(const igraph_t *graph, const char *name,
                                  igraph_integer_t vid);

The attribute must exist, otherwise an error is triggered.

Arguments: 

graph:

The input graph.

name:

The name of the attribute.

vid:

The id of the queried vertex.

Returns: 

The value of the attribute.

See also: 

The macro VAS for a simpler interface.

Time complexity: O(Av), the number of vertex attributes.

3.1.18. VAS — Query a string vertex attribute.

#define VAS(graph,n,v)

This is shorthand for igraph_cattribute_VAS().

Arguments: 

graph:

The graph.

n:

The name of the attribute.

v:

The id of the vertex.

Returns: 

The value of the attribute.

3.1.19. igraph_cattribute_VASV — Query a string vertex attribute for many vertices

int igraph_cattribute_VASV(const igraph_t *graph, const char *name,
                           igraph_vs_t vids, igraph_strvector_t *result);

Arguments: 

graph:

The input graph.

name:

The name of the attribute.

vids:

The vertices to query.

result:

Pointer to an initialized string vector, the result is stored here. It will be resized, if needed.

Returns: 

Error code.

Time complexity: O(v), where v is the number of vertices in 'vids'. (We assume that the string attributes have a bounded length.)

3.1.20. VASV — Query a string vertex attribute for all vertices.

#define VASV(graph,n,vec)

This is a shorthand for igraph_cattribute_VASV().

Arguments: 

graph:

The graph.

n:

The name of the attribute.

vec:

Pointer to an initialized string vector, the result is stored here. It will be resized, if needed.

Returns: 

Error code.

3.1.21. igraph_cattribute_EAN — Query a numeric edge attribute.

igraph_real_t igraph_cattribute_EAN(const igraph_t *graph, const char *name,
                                    igraph_integer_t eid);

The attribute must exist, otherwise an error is triggered.

Arguments: 

graph:

The input graph.

name:

The name of the attribute.

eid:

The id of the queried edge.

Returns: 

The value of the attribute.

See also: 

EAN for an easier interface.

Time complexity: O(Ae), the number of edge attributes.

3.1.22. EAN — Query a numeric edge attribute.

#define EAN(graph,n,e)

This is shorthand for igraph_cattribute_EAN().

Arguments: 

graph:

The graph.

n:

The name of the attribute.

e:

The id of the edge.

Returns: 

The value of the attribute.

3.1.23. igraph_cattribute_EANV — Query a numeric edge attribute for many edges

int igraph_cattribute_EANV(const igraph_t *graph, const char *name,
                           igraph_es_t eids, igraph_vector_t *result);

Arguments: 

graph:

The input graph.

name:

The name of the attribute.

eids:

The edges to query.

result:

Pointer to an initialized vector, the result is stored here. It will be resized, if needed.

Returns: 

Error code.

Time complexity: O(e), where e is the number of edges in 'eids'.

3.1.24. EANV — Query a numeric edge attribute for all edges.

#define EANV(graph,n,vec)

This is a shorthand for igraph_cattribute_EANV().

Arguments: 

graph:

The graph.

n:

The name of the attribute.

vec:

Pointer to an initialized vector, the result is stored here. It will be resized, if needed.

Returns: 

Error code.

3.1.25. igraph_cattribute_EAB — Query a boolean edge attribute.

igraph_bool_t igraph_cattribute_EAB(const igraph_t *graph, const char *name,
                                    igraph_integer_t eid);

The attribute must exist, otherwise an error is triggered.

Arguments: 

graph:

The input graph.

name:

The name of the attribute.

eid:

The id of the queried edge.

Returns: 

The value of the attribute.

See also: 

EAB for an easier interface.

Time complexity: O(Ae), the number of edge attributes.

3.1.26. EAB — Query a boolean edge attribute.

#define EAB(graph,n,e)

This is shorthand for igraph_cattribute_EAB().

Arguments: 

graph:

The graph.

n:

The name of the attribute.

e:

The id of the edge.

Returns: 

The value of the attribute.

3.1.27. igraph_cattribute_EABV — Query a boolean edge attribute for many edges

int igraph_cattribute_EABV(const igraph_t *graph, const char *name,
                           igraph_es_t eids, igraph_vector_bool_t *result);

Arguments: 

graph:

The input graph.

name:

The name of the attribute.

eids:

The edges to query.

result:

Pointer to an initialized boolean vector, the result is stored here. It will be resized, if needed.

Returns: 

Error code.

Time complexity: O(e), where e is the number of edges in 'eids'.

3.1.28. EABV — Query a boolean edge attribute for all edges.

#define EABV(graph,n,vec)

This is a shorthand for igraph_cattribute_EABV().

Arguments: 

graph:

The graph.

n:

The name of the attribute.

vec:

Pointer to an initialized vector, the result is stored here. It will be resized, if needed.

Returns: 

Error code.

3.1.29. igraph_cattribute_EAS — Query a string edge attribute.

const char* igraph_cattribute_EAS(const igraph_t *graph, const char *name,
                                  igraph_integer_t eid);

The attribute must exist, otherwise an error is triggered.

Arguments: 

graph:

The input graph.

name:

The name of the attribute.

eid:

The id of the queried edge.

Returns: 

The value of the attribute.

\se EAS if you want to type less. Time complexity: O(Ae), the number of edge attributes.

3.1.30. EAS — Query a string edge attribute.

#define EAS(graph,n,e)

This is shorthand for igraph_cattribute_EAS().

Arguments: 

graph:

The graph.

n:

The name of the attribute.

e:

The id of the edge.

Returns: 

The value of the attribute.

3.1.31. igraph_cattribute_EASV — Query a string edge attribute for many edges

int igraph_cattribute_EASV(const igraph_t *graph, const char *name,
                           igraph_es_t eids, igraph_strvector_t *result);

Arguments: 

graph:

The input graph.

name:

The name of the attribute.

vids:

The edges to query.

result:

Pointer to an initialized string vector, the result is stored here. It will be resized, if needed.

Returns: 

Error code.

Time complexity: O(e), where e is the number of edges in 'eids'. (We assume that the string attributes have a bounded length.)

3.1.32. EASV — Query a string edge attribute for all edges.

#define EASV(graph,n,vec)

This is a shorthand for igraph_cattribute_EASV().

Arguments: 

graph:

The graph.

n:

The name of the attribute.

vec:

Pointer to an initialized string vector, the result is stored here. It will be resized, if needed.

Returns: 

Error code.

3.2. Set attributes

3.2.1. igraph_cattribute_GAN_set — Set a numeric graph attribute
3.2.2. SETGAN — Set a numeric graph attribute
3.2.3. igraph_cattribute_GAB_set — Set a boolean graph attribute
3.2.4. SETGAB — Set a boolean graph attribute
3.2.5. igraph_cattribute_GAS_set — Set a string graph attribute.
3.2.6. SETGAS — Set a string graph attribute
3.2.7. igraph_cattribute_VAN_set — Set a numeric vertex attribute
3.2.8. SETVAN — Set a numeric vertex attribute
3.2.9. igraph_cattribute_VAB_set — Set a boolean vertex attribute
3.2.10. SETVAB — Set a boolean vertex attribute
3.2.11. igraph_cattribute_VAS_set — Set a string vertex attribute
3.2.12. SETVAS — Set a string vertex attribute
3.2.13. igraph_cattribute_EAN_set — Set a numeric edge attribute
3.2.14. SETEAN — Set a numeric edge attribute
3.2.15. igraph_cattribute_EAB_set — Set a boolean edge attribute
3.2.16. SETEAB — Set a boolean edge attribute
3.2.17. igraph_cattribute_EAS_set — Set a string edge attribute
3.2.18. SETEAS — Set a string edge attribute
3.2.19. igraph_cattribute_VAN_setv — Set a numeric vertex attribute for all vertices.
3.2.20. SETVANV — Set a numeric vertex attribute for all vertices
3.2.21. igraph_cattribute_VAB_setv — Set a boolean vertex attribute for all vertices.
3.2.22. SETVABV — Set a boolean vertex attribute for all vertices
3.2.23. igraph_cattribute_VAS_setv — Set a string vertex attribute for all vertices.
3.2.24. SETVASV — Set a string vertex attribute for all vertices
3.2.25. igraph_cattribute_EAN_setv — Set a numeric edge attribute for all edges.
3.2.26. SETEANV — Set a numeric edge attribute for all edges
3.2.27. igraph_cattribute_EAB_setv — Set a boolean edge attribute for all edges.
3.2.28. SETEABV — Set a boolean edge attribute for all edges
3.2.29. igraph_cattribute_EAS_setv — Set a string edge attribute for all edges.
3.2.30. SETEASV — Set a string edge attribute for all edges

3.2.1. igraph_cattribute_GAN_set — Set a numeric graph attribute

int igraph_cattribute_GAN_set(igraph_t *graph, const char *name,
                              igraph_real_t value);

Arguments: 

graph:

The graph.

name:

Name of the graph attribute. If there is no such attribute yet, then it will be added.

value:

The (new) value of the graph attribute.

Returns: 

Error code.

\se SETGAN if you want to type less. Time complexity: O(1).

3.2.2. SETGAN — Set a numeric graph attribute

#define SETGAN(graph,n,value)

This is a shorthand for igraph_cattribute_GAN_set().

Arguments: 

graph:

The graph.

n:

The name of the attribute.

value:

The new value of the attribute.

Returns: 

Error code.

3.2.3. igraph_cattribute_GAB_set — Set a boolean graph attribute

int igraph_cattribute_GAB_set(igraph_t *graph, const char *name,
                              igraph_bool_t value);

Arguments: 

graph:

The graph.

name:

Name of the graph attribute. If there is no such attribute yet, then it will be added.

value:

The (new) value of the graph attribute.

Returns: 

Error code.

\se SETGAN if you want to type less. Time complexity: O(1).

3.2.4. SETGAB — Set a boolean graph attribute

#define SETGAB(graph,n,value)

This is a shorthand for igraph_cattribute_GAB_set().

Arguments: 

graph:

The graph.

n:

The name of the attribute.

value:

The new value of the attribute.

Returns: 

Error code.

3.2.5. igraph_cattribute_GAS_set — Set a string graph attribute.

int igraph_cattribute_GAS_set(igraph_t *graph, const char *name,
                              const char *value);

Arguments: 

graph:

The graph.

name:

Name of the graph attribute. If there is no such attribute yet, then it will be added.

value:

The (new) value of the graph attribute. It will be copied.

Returns: 

Error code.

\se SETGAS if you want to type less. Time complexity: O(1).

3.2.6. SETGAS — Set a string graph attribute

#define SETGAS(graph,n,value)

This is a shorthand for igraph_cattribute_GAS_set().

Arguments: 

graph:

The graph.

n:

The name of the attribute.

value:

The new value of the attribute.

Returns: 

Error code.

3.2.7. igraph_cattribute_VAN_set — Set a numeric vertex attribute

int igraph_cattribute_VAN_set(igraph_t *graph, const char *name,
                              igraph_integer_t vid, igraph_real_t value);

The attribute will be added if not present already. If present it will be overwritten. The same value is set for all vertices included in vid.

Arguments: 

graph:

The graph.

name:

Name of the attribute.

vid:

Vertices for which to set the attribute.

value:

The (new) value of the attribute.

Returns: 

Error code.

See also: 

SETVAN for a simpler way.

Time complexity: O(n), the number of vertices if the attribute is new, O(|vid|) otherwise.

3.2.8. SETVAN — Set a numeric vertex attribute

#define SETVAN(graph,n,vid,value)

This is a shorthand for igraph_cattribute_VAN_set().

Arguments: 

graph:

The graph.

n:

The name of the attribute.

vid:

Ids of the vertices to set.

value:

The new value of the attribute.

Returns: 

Error code.

3.2.9. igraph_cattribute_VAB_set — Set a boolean vertex attribute

int igraph_cattribute_VAB_set(igraph_t *graph, const char *name,
                              igraph_integer_t vid, igraph_bool_t value);

The attribute will be added if not present already. If present it will be overwritten. The same value is set for all vertices included in vid.

Arguments: 

graph:

The graph.

name:

Name of the attribute.

vid:

Vertices for which to set the attribute.

value:

The (new) value of the attribute.

Returns: 

Error code.

See also: 

SETVAB for a simpler way.

Time complexity: O(n), the number of vertices if the attribute is new, O(|vid|) otherwise.

3.2.10. SETVAB — Set a boolean vertex attribute

#define SETVAB(graph,n,vid,value)

This is a shorthand for igraph_cattribute_VAB_set().

Arguments: 

graph:

The graph.

n:

The name of the attribute.

vid:

Ids of the vertices to set.

value:

The new value of the attribute.

Returns: 

Error code.

3.2.11. igraph_cattribute_VAS_set — Set a string vertex attribute

int igraph_cattribute_VAS_set(igraph_t *graph, const char *name,
                              igraph_integer_t vid, const char *value);

The attribute will be added if not present already. If present it will be overwritten. The same value is set for all vertices included in vid.

Arguments: 

graph:

The graph.

name:

Name of the attribute.

vid:

Vertices for which to set the attribute.

value:

The (new) value of the attribute.

Returns: 

Error code.

See also: 

SETVAS for a simpler way.

Time complexity: O(n*l), n is the number of vertices, l is the length of the string to set. If the attribute if not new then only O(|vid|*l).

3.2.12. SETVAS — Set a string vertex attribute

#define SETVAS(graph,n,vid,value)

This is a shorthand for igraph_cattribute_VAS_set().

Arguments: 

graph:

The graph.

n:

The name of the attribute.

vid:

Ids of the vertices to set.

value:

The new value of the attribute.

Returns: 

Error code.

3.2.13. igraph_cattribute_EAN_set — Set a numeric edge attribute

int igraph_cattribute_EAN_set(igraph_t *graph, const char *name,
                              igraph_integer_t eid, igraph_real_t value);

The attribute will be added if not present already. If present it will be overwritten. The same value is set for all edges included in vid.

Arguments: 

graph:

The graph.

name:

Name of the attribute.

eid:

Edges for which to set the attribute.

value:

The (new) value of the attribute.

Returns: 

Error code.

See also: 

SETEAN for a simpler way.

Time complexity: O(e), the number of edges if the attribute is new, O(|eid|) otherwise.

3.2.14. SETEAN — Set a numeric edge attribute

#define SETEAN(graph,n,eid,value)

This is a shorthand for igraph_cattribute_EAN_set().

Arguments: 

graph:

The graph.

n:

The name of the attribute.

eid:

Ids of the edges to set.

value:

The new value of the attribute.

Returns: 

Error code.

3.2.15. igraph_cattribute_EAB_set — Set a boolean edge attribute

int igraph_cattribute_EAB_set(igraph_t *graph, const char *name,
                              igraph_integer_t eid, igraph_bool_t value);

The attribute will be added if not present already. If present it will be overwritten. The same value is set for all edges included in vid.

Arguments: 

graph:

The graph.

name:

Name of the attribute.

eid:

Edges for which to set the attribute.

value:

The (new) value of the attribute.

Returns: 

Error code.

See also: 

SETEAB for a simpler way.

Time complexity: O(e), the number of edges if the attribute is new, O(|eid|) otherwise.

3.2.16. SETEAB — Set a boolean edge attribute

#define SETEAB(graph,n,eid,value)

This is a shorthand for igraph_cattribute_EAB_set().

Arguments: 

graph:

The graph.

n:

The name of the attribute.

eid:

Ids of the edges to set.

value:

The new value of the attribute.

Returns: 

Error code.

3.2.17. igraph_cattribute_EAS_set — Set a string edge attribute

int igraph_cattribute_EAS_set(igraph_t *graph, const char *name,
                              igraph_integer_t eid, const char *value);

The attribute will be added if not present already. If present it will be overwritten. The same value is set for all edges included in vid.

Arguments: 

graph:

The graph.

name:

Name of the attribute.

eid:

Edges for which to set the attribute.

value:

The (new) value of the attribute.

Returns: 

Error code.

See also: 

SETEAS for a simpler way.

Time complexity: O(e*l), n is the number of edges, l is the length of the string to set. If the attribute if not new then only O(|eid|*l).

3.2.18. SETEAS — Set a string edge attribute

#define SETEAS(graph,n,eid,value)

This is a shorthand for igraph_cattribute_EAS_set().

Arguments: 

graph:

The graph.

n:

The name of the attribute.

eid:

Ids of the edges to set.

value:

The new value of the attribute.

Returns: 

Error code.

3.2.19. igraph_cattribute_VAN_setv — Set a numeric vertex attribute for all vertices.

int igraph_cattribute_VAN_setv(igraph_t *graph, const char *name,
                               const igraph_vector_t *v);

The attribute will be added if not present yet.

Arguments: 

graph:

The graph.

name:

Name of the attribute.

v:

The new attribute values. The length of this vector must match the number of vertices.

Returns: 

Error code.

See also: 

SETVANV for a simpler way.

Time complexity: O(n), the number of vertices.

3.2.20. SETVANV — Set a numeric vertex attribute for all vertices

#define SETVANV(graph,n,v)

This is a shorthand for igraph_cattribute_VAN_setv().

Arguments: 

graph:

The graph.

n:

The name of the attribute.

v:

Vector containing the new values of the attributes.

Returns: 

Error code.

3.2.21. igraph_cattribute_VAB_setv — Set a boolean vertex attribute for all vertices.

int igraph_cattribute_VAB_setv(igraph_t *graph, const char *name,
                               const igraph_vector_bool_t *v);

The attribute will be added if not present yet.

Arguments: 

graph:

The graph.

name:

Name of the attribute.

v:

The new attribute values. The length of this boolean vector must match the number of vertices.

Returns: 

Error code.

See also: 

SETVANV for a simpler way.

Time complexity: O(n), the number of vertices.

3.2.22. SETVABV — Set a boolean vertex attribute for all vertices

#define SETVABV(graph,n,v)

This is a shorthand for igraph_cattribute_VAB_setv().

Arguments: 

graph:

The graph.

n:

The name of the attribute.

v:

Vector containing the new values of the attributes.

Returns: 

Error code.

3.2.23. igraph_cattribute_VAS_setv — Set a string vertex attribute for all vertices.

int igraph_cattribute_VAS_setv(igraph_t *graph, const char *name,
                               const igraph_strvector_t *sv);

The attribute will be added if not present yet.

Arguments: 

graph:

The graph.

name:

Name of the attribute.

sv:

String vector, the new attribute values. The length of this vector must match the number of vertices.

Returns: 

Error code.

See also: 

SETVASV for a simpler way.

Time complexity: O(n+l), n is the number of vertices, l is the total length of the strings.

3.2.24. SETVASV — Set a string vertex attribute for all vertices

#define SETVASV(graph,n,v)

This is a shorthand for igraph_cattribute_VAS_setv().

Arguments: 

graph:

The graph.

n:

The name of the attribute.

v:

Vector containing the new values of the attributes.

Returns: 

Error code.

3.2.25. igraph_cattribute_EAN_setv — Set a numeric edge attribute for all edges.

int igraph_cattribute_EAN_setv(igraph_t *graph, const char *name,
                               const igraph_vector_t *v);

The attribute will be added if not present yet.

Arguments: 

graph:

The graph.

name:

Name of the attribute.

v:

The new attribute values. The length of this vector must match the number of edges.

Returns: 

Error code.

See also: 

SETEANV for a simpler way.

Time complexity: O(e), the number of edges.

3.2.26. SETEANV — Set a numeric edge attribute for all edges

#define SETEANV(graph,n,v)

This is a shorthand for igraph_cattribute_EAN_setv().

Arguments: 

graph:

The graph.

n:

The name of the attribute.

v:

Vector containing the new values of the attributes.

3.2.27. igraph_cattribute_EAB_setv — Set a boolean edge attribute for all edges.

int igraph_cattribute_EAB_setv(igraph_t *graph, const char *name,
                               const igraph_vector_bool_t *v);

The attribute will be added if not present yet.

Arguments: 

graph:

The graph.

name:

Name of the attribute.

v:

The new attribute values. The length of this vector must match the number of edges.

Returns: 

Error code.

See also: 

SETEABV for a simpler way.

Time complexity: O(e), the number of edges.

3.2.28. SETEABV — Set a boolean edge attribute for all edges

#define SETEABV(graph,n,v)

This is a shorthand for igraph_cattribute_EAB_setv().

Arguments: 

graph:

The graph.

n:

The name of the attribute.

v:

Vector containing the new values of the attributes.

3.2.29. igraph_cattribute_EAS_setv — Set a string edge attribute for all edges.

int igraph_cattribute_EAS_setv(igraph_t *graph, const char *name,
                               const igraph_strvector_t *sv);

The attribute will be added if not present yet.

Arguments: 

graph:

The graph.

name:

Name of the attribute.

sv:

String vector, the new attribute values. The length of this vector must match the number of edges.

Returns: 

Error code.

See also: 

SETEASV for a simpler way.

Time complexity: O(e+l), e is the number of edges, l is the total length of the strings.

3.2.30. SETEASV — Set a string edge attribute for all edges

#define SETEASV(graph,n,v)

This is a shorthand for igraph_cattribute_EAS_setv().

Arguments: 

graph:

The graph.

n:

The name of the attribute.

v:

Vector containing the new values of the attributes.

3.3. Remove attributes

3.3.1. igraph_cattribute_remove_g — Remove a graph attribute

void igraph_cattribute_remove_g(igraph_t *graph, const char *name);

Arguments: 

graph:

The graph object.

name:

Name of the graph attribute to remove.

See also: 

DELGA for a simpler way.

3.3.2. DELGA — Remove a graph attribute.

#define DELGA(graph,n)

A shorthand for igraph_cattribute_remove_g().

Arguments: 

graph:

The graph.

n:

The name of the attribute to remove.

3.3.3. igraph_cattribute_remove_v — Remove a vertex attribute

void igraph_cattribute_remove_v(igraph_t *graph, const char *name);

Arguments: 

graph:

The graph object.

name:

Name of the vertex attribute to remove.

See also: 

DELVA for a simpler way.

3.3.4. DELVA — Remove a vertex attribute.

#define DELVA(graph,n)

A shorthand for igraph_cattribute_remove_v().

Arguments: 

graph:

The graph.

n:

The name of the attribute to remove.

3.3.5. igraph_cattribute_remove_e — Remove an edge attribute

void igraph_cattribute_remove_e(igraph_t *graph, const char *name);

Arguments: 

graph:

The graph object.

name:

Name of the edge attribute to remove.

See also: 

DELEA for a simpler way.

3.3.6. DELEA — Remove an edge attribute.

#define DELEA(graph,n)

A shorthand for igraph_cattribute_remove_e().

Arguments: 

graph:

The graph.

n:

The name of the attribute to remove.

3.3.7. igraph_cattribute_remove_all — Remove all graph/vertex/edge attributes

void igraph_cattribute_remove_all(igraph_t *graph, igraph_bool_t g,
                                  igraph_bool_t v, igraph_bool_t e);

Arguments: 

graph:

The graph object.

g:

Boolean, whether to remove graph attributes.

v:

Boolean, whether to remove vertex attributes.

e:

Boolean, whether to remove edge attributes.

See also: 

DELGAS, DELVAS, DELEAS, DELALL for simpler ways.

3.3.8. DELGAS — Remove all graph attributes.

#define DELGAS(graph)

Calls igraph_cattribute_remove_all().

Arguments: 

graph:

The graph.

3.3.9. DELVAS — Remove all vertex attributes.

#define DELVAS(graph)

Calls igraph_cattribute_remove_all().

Arguments: 

graph:

The graph.

3.3.10. DELEAS — Remove all edge attributes.

#define DELEAS(graph)

Calls igraph_cattribute_remove_all().

Arguments: 

graph:

The graph.

3.3.11. DELALL — Remove all attributes.

#define DELALL(graph)

All graph, vertex and edges attributes will be removed. Calls igraph_cattribute_remove_all().

Arguments: 

graph:

The graph.