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.
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.
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:
|
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 |
|
This function is called whenever the graph object is destroyed, right before freeing the allocated memory. |
|
This function is called when copying a graph with |
|
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. |
|
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. |
|
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. |
|
Called when new edges have been added. The number of new edges are supplied as well. It is expected to return an error code. |
|
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). |
|
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. |
|
Query the attributes of a graph, the names and types should be returned. |
|
Check whether a graph has the named graph/vertex/edge attribute. |
|
Query the type of a graph/vertex/edge attribute. |
|
Query a numeric graph attribute. The
value should be placed as the first element of the |
|
Query a string graph attribute. The
value should be placed as the first element of the |
|
Query a boolean graph attribute. The
value should be placed as the first element of the |
|
Query a numeric vertex attribute,
for the vertices included in |
|
Query a string vertex attribute,
for the vertices included in |
|
Query a boolean vertex attribute,
for the vertices included in |
|
Query a numeric edge attribute, for
the edges included in |
|
Query a string edge attribute, for the
edges included in |
|
Query a boolean edge attribute, for the
edges included in |
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.
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:
|
Pointer to an |
Returns:
Pointer to the old attribute handling table. |
Time complexity: O(1).
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:
|
Currently not used for anything. |
|
Numeric attribute. |
|
Logical values, true or false. |
|
Attribute that can be converted to a string. |
|
An R object. This is usually ignored by the igraph functions. |
|
A Python object. Usually ignored by the igraph functions. |
igraph_attribute_combination_init
— Initialize attribute combination list.igraph_attribute_combination_add
— Add combination record to attribute combination list.igraph_attribute_combination_remove
— Remove a record from an attribute combination list.igraph_attribute_combination_destroy
— Destroy attribute combination list.igraph_attribute_combination_type_t
— The possible types of attribute combinations.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.
int igraph_attribute_combination_init(igraph_attribute_combination_t *comb);
Arguments:
|
The uninitialized attribute combination list. |
Returns:
Error code. |
Time complexity: O(1)
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:
|
The attribute combination list. |
|
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. |
|
The type of the attribute combination. See |
|
Function to be used if |
Returns:
Error code. |
Time complexity: O(n), where n is the number of current attribute combinations.
int igraph_attribute_combination_remove(igraph_attribute_combination_t *comb, const char *name);
Arguments:
|
The attribute combination list. |
|
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.
void igraph_attribute_combination_destroy(igraph_attribute_combination_t *comb);
Arguments:
|
The attribute combination list. |
Time complexity: O(n), where n is the number of records in the attribute combination list.
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:
|
Ignore old attributes, use an empty value. |
|
Use the default way to combine attributes (decided by the attribute handler implementation). |
|
Supply your own function to combine attributes. |
|
Take the sum of the attributes. |
|
Take the product of the attributes. |
|
Take the minimum attribute. |
|
Take the maximum attribute. |
|
Take a random attribute. |
|
Take the first attribute. |
|
Take the last attribute. |
|
Take the mean of the attributes. |
|
Take the median of the attributes. |
|
Concatenate the attributes. |
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(>ypes, 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, >ypes, &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(>ypes); 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(>ypes, 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, >ypes, &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, >ypes, &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(>ypes); 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; }
igraph_cattribute_list
— List all attributesigraph_cattribute_has_attr
— Checks whether a (graph, vertex or edge) attribute existsigraph_cattribute_GAN
— Query a numeric graph attribute.GAN
— Query a numeric graph attribute.igraph_cattribute_GAB
— Query a boolean graph attribute.GAB
— Query a boolean graph attribute.igraph_cattribute_GAS
— Query a string graph attribute.GAS
— Query a string graph attribute.igraph_cattribute_VAN
— Query a numeric vertex attribute.VAN
— Query a numeric vertex attribute.igraph_cattribute_VANV
— Query a numeric vertex attribute for many verticesVANV
— Query a numeric vertex attribute for all vertices.igraph_cattribute_VAB
— Query a boolean vertex attribute.VAB
— Query a boolean vertex attribute.igraph_cattribute_VABV
— Query a boolean vertex attribute for many verticesVABV
— Query a boolean vertex attribute for all vertices.igraph_cattribute_VAS
— Query a string vertex attribute.VAS
— Query a string vertex attribute.igraph_cattribute_VASV
— Query a string vertex attribute for many verticesVASV
— Query a string vertex attribute for all vertices.igraph_cattribute_EAN
— Query a numeric edge attribute.EAN
— Query a numeric edge attribute.igraph_cattribute_EANV
— Query a numeric edge attribute for many edgesEANV
— Query a numeric edge attribute for all edges.igraph_cattribute_EAB
— Query a boolean edge attribute.EAB
— Query a boolean edge attribute.igraph_cattribute_EABV
— Query a boolean edge attribute for many edgesEABV
— Query a boolean edge attribute for all edges.igraph_cattribute_EAS
— Query a string edge attribute.EAS
— Query a string edge attribute.igraph_cattribute_EASV
— Query a string edge attribute for many edgesEASV
— Query a string edge attribute for all edges.
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:
|
The input graph. |
|
String vector, the names of the graph attributes. |
|
Numeric vector, the types of the graph attributes. |
|
String vector, the names of the vertex attributes. |
|
Numeric vector, the types of the vertex attributes. |
|
String vector, the names of the edge attributes. |
|
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.
igraph_bool_t igraph_cattribute_has_attr(const igraph_t *graph, igraph_attribute_elemtype_t type, const char *name);
Arguments:
|
The graph. |
|
The type of the attribute, |
|
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.
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:
|
The input graph. |
|
The name of the attribute to query. |
Returns:
The value of the attribute. |
See also:
|
Time complexity: O(Ag), the number of graph attributes.
#define GAN(graph,n)
This is shorthand for igraph_cattribute_GAN()
.
Arguments:
|
The graph. |
|
The name of the attribute. |
Returns:
The value of the 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:
|
The input graph. |
|
The name of the attribute to query. |
Returns:
The value of the attribute. |
See also:
|
Time complexity: O(Ag), the number of graph attributes.
#define GAB(graph,n)
This is shorthand for igraph_cattribute_GAB()
.
Arguments:
|
The graph. |
|
The name of the attribute. |
Returns:
The value of the 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:
|
The input graph. |
|
The name of the attribute to query. |
Returns:
The value of the attribute. |
See also:
|
Time complexity: O(Ag), the number of graph attributes.
#define GAS(graph,n)
This is shorthand for igraph_cattribute_GAS()
.
Arguments:
|
The graph. |
|
The name of the attribute. |
Returns:
The value of the 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:
|
The input graph. |
|
The name of the attribute. |
|
The id of the queried vertex. |
Returns:
The value of the attribute. |
See also:
|
Time complexity: O(Av), the number of vertex attributes.
#define VAN(graph,n,v)
This is shorthand for igraph_cattribute_VAN()
.
Arguments:
|
The graph. |
|
The name of the attribute. |
|
The id of the vertex. |
Returns:
The value of the attribute. |
int igraph_cattribute_VANV(const igraph_t *graph, const char *name, igraph_vs_t vids, igraph_vector_t *result);
Arguments:
|
The input graph. |
|
The name of the attribute. |
|
The vertices to query. |
|
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'.
#define VANV(graph,n,vec)
This is a shorthand for igraph_cattribute_VANV()
.
Arguments:
|
The graph. |
|
The name of the attribute. |
|
Pointer to an initialized vector, the result is stored here. It will be resized, if needed. |
Returns:
Error code. |
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:
|
The input graph. |
|
The name of the attribute. |
|
The id of the queried vertex. |
Returns:
The value of the attribute. |
See also:
|
Time complexity: O(Av), the number of vertex attributes.
#define VAB(graph,n,v)
This is shorthand for igraph_cattribute_VAB()
.
Arguments:
|
The graph. |
|
The name of the attribute. |
|
The id of the vertex. |
Returns:
The value of the attribute. |
int igraph_cattribute_VABV(const igraph_t *graph, const char *name, igraph_vs_t vids, igraph_vector_bool_t *result);
Arguments:
|
The input graph. |
|
The name of the attribute. |
|
The vertices to query. |
|
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'.
#define VABV(graph,n,vec)
This is a shorthand for igraph_cattribute_VABV()
.
Arguments:
|
The graph. |
|
The name of the attribute. |
|
Pointer to an initialized boolean vector, the result is stored here. It will be resized, if needed. |
Returns:
Error code. |
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:
|
The input graph. |
|
The name of the attribute. |
|
The id of the queried vertex. |
Returns:
The value of the attribute. |
See also:
The macro |
Time complexity: O(Av), the number of vertex attributes.
#define VAS(graph,n,v)
This is shorthand for igraph_cattribute_VAS()
.
Arguments:
|
The graph. |
|
The name of the attribute. |
|
The id of the vertex. |
Returns:
The value of the attribute. |
int igraph_cattribute_VASV(const igraph_t *graph, const char *name, igraph_vs_t vids, igraph_strvector_t *result);
Arguments:
|
The input graph. |
|
The name of the attribute. |
|
The vertices to query. |
|
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.)
#define VASV(graph,n,vec)
This is a shorthand for igraph_cattribute_VASV()
.
Arguments:
|
The graph. |
|
The name of the attribute. |
|
Pointer to an initialized string vector, the result is stored here. It will be resized, if needed. |
Returns:
Error code. |
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:
|
The input graph. |
|
The name of the attribute. |
|
The id of the queried edge. |
Returns:
The value of the attribute. |
See also:
|
Time complexity: O(Ae), the number of edge attributes.
#define EAN(graph,n,e)
This is shorthand for igraph_cattribute_EAN()
.
Arguments:
|
The graph. |
|
The name of the attribute. |
|
The id of the edge. |
Returns:
The value of the attribute. |
int igraph_cattribute_EANV(const igraph_t *graph, const char *name, igraph_es_t eids, igraph_vector_t *result);
Arguments:
|
The input graph. |
|
The name of the attribute. |
|
The edges to query. |
|
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'.
#define EANV(graph,n,vec)
This is a shorthand for igraph_cattribute_EANV()
.
Arguments:
|
The graph. |
|
The name of the attribute. |
|
Pointer to an initialized vector, the result is stored here. It will be resized, if needed. |
Returns:
Error code. |
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:
|
The input graph. |
|
The name of the attribute. |
|
The id of the queried edge. |
Returns:
The value of the attribute. |
See also:
|
Time complexity: O(Ae), the number of edge attributes.
#define EAB(graph,n,e)
This is shorthand for igraph_cattribute_EAB()
.
Arguments:
|
The graph. |
|
The name of the attribute. |
|
The id of the edge. |
Returns:
The value of the attribute. |
int igraph_cattribute_EABV(const igraph_t *graph, const char *name, igraph_es_t eids, igraph_vector_bool_t *result);
Arguments:
|
The input graph. |
|
The name of the attribute. |
|
The edges to query. |
|
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'.
#define EABV(graph,n,vec)
This is a shorthand for igraph_cattribute_EABV()
.
Arguments:
|
The graph. |
|
The name of the attribute. |
|
Pointer to an initialized vector, the result is stored here. It will be resized, if needed. |
Returns:
Error code. |
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:
|
The input graph. |
|
The name of the attribute. |
|
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.
#define EAS(graph,n,e)
This is shorthand for igraph_cattribute_EAS()
.
Arguments:
|
The graph. |
|
The name of the attribute. |
|
The id of the edge. |
Returns:
The value of the attribute. |
int igraph_cattribute_EASV(const igraph_t *graph, const char *name, igraph_es_t eids, igraph_strvector_t *result);
Arguments:
|
The input graph. |
|
The name of the attribute. |
|
The edges to query. |
|
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.)
#define EASV(graph,n,vec)
This is a shorthand for igraph_cattribute_EASV()
.
Arguments:
|
The graph. |
|
The name of the attribute. |
|
Pointer to an initialized string vector, the result is stored here. It will be resized, if needed. |
Returns:
Error code. |
igraph_cattribute_GAN_set
— Set a numeric graph attributeSETGAN
— Set a numeric graph attributeigraph_cattribute_GAB_set
— Set a boolean graph attributeSETGAB
— Set a boolean graph attributeigraph_cattribute_GAS_set
— Set a string graph attribute.SETGAS
— Set a string graph attributeigraph_cattribute_VAN_set
— Set a numeric vertex attributeSETVAN
— Set a numeric vertex attributeigraph_cattribute_VAB_set
— Set a boolean vertex attributeSETVAB
— Set a boolean vertex attributeigraph_cattribute_VAS_set
— Set a string vertex attributeSETVAS
— Set a string vertex attributeigraph_cattribute_EAN_set
— Set a numeric edge attributeSETEAN
— Set a numeric edge attributeigraph_cattribute_EAB_set
— Set a boolean edge attributeSETEAB
— Set a boolean edge attributeigraph_cattribute_EAS_set
— Set a string edge attributeSETEAS
— Set a string edge attributeigraph_cattribute_VAN_setv
— Set a numeric vertex attribute for all vertices.SETVANV
— Set a numeric vertex attribute for all verticesigraph_cattribute_VAB_setv
— Set a boolean vertex attribute for all vertices.SETVABV
— Set a boolean vertex attribute for all verticesigraph_cattribute_VAS_setv
— Set a string vertex attribute for all vertices.SETVASV
— Set a string vertex attribute for all verticesigraph_cattribute_EAN_setv
— Set a numeric edge attribute for all edges.SETEANV
— Set a numeric edge attribute for all edgesigraph_cattribute_EAB_setv
— Set a boolean edge attribute for all edges.SETEABV
— Set a boolean edge attribute for all edgesigraph_cattribute_EAS_setv
— Set a string edge attribute for all edges.SETEASV
— Set a string edge attribute for all edges
int igraph_cattribute_GAN_set(igraph_t *graph, const char *name, igraph_real_t value);
Arguments:
|
The graph. |
|
Name of the graph attribute. If there is no such attribute yet, then it will be added. |
|
The (new) value of the graph attribute. |
Returns:
Error code. |
\se SETGAN
if you want to type less.
Time complexity: O(1).
#define SETGAN(graph,n,value)
This is a shorthand for igraph_cattribute_GAN_set()
.
Arguments:
|
The graph. |
|
The name of the attribute. |
|
The new value of the attribute. |
Returns:
Error code. |
int igraph_cattribute_GAB_set(igraph_t *graph, const char *name, igraph_bool_t value);
Arguments:
|
The graph. |
|
Name of the graph attribute. If there is no such attribute yet, then it will be added. |
|
The (new) value of the graph attribute. |
Returns:
Error code. |
\se SETGAN
if you want to type less.
Time complexity: O(1).
#define SETGAB(graph,n,value)
This is a shorthand for igraph_cattribute_GAB_set()
.
Arguments:
|
The graph. |
|
The name of the attribute. |
|
The new value of the attribute. |
Returns:
Error code. |
int igraph_cattribute_GAS_set(igraph_t *graph, const char *name, const char *value);
Arguments:
|
The graph. |
|
Name of the graph attribute. If there is no such attribute yet, then it will be added. |
|
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).
#define SETGAS(graph,n,value)
This is a shorthand for igraph_cattribute_GAS_set()
.
Arguments:
|
The graph. |
|
The name of the attribute. |
|
The new value of the attribute. |
Returns:
Error code. |
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:
|
The graph. |
|
Name of the attribute. |
|
Vertices for which to set the attribute. |
|
The (new) value of the attribute. |
Returns:
Error code. |
See also:
|
Time complexity: O(n), the number of vertices if the attribute is new, O(|vid|) otherwise.
#define SETVAN(graph,n,vid,value)
This is a shorthand for igraph_cattribute_VAN_set()
.
Arguments:
|
The graph. |
|
The name of the attribute. |
|
Ids of the vertices to set. |
|
The new value of the attribute. |
Returns:
Error code. |
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:
|
The graph. |
|
Name of the attribute. |
|
Vertices for which to set the attribute. |
|
The (new) value of the attribute. |
Returns:
Error code. |
See also:
|
Time complexity: O(n), the number of vertices if the attribute is new, O(|vid|) otherwise.
#define SETVAB(graph,n,vid,value)
This is a shorthand for igraph_cattribute_VAB_set()
.
Arguments:
|
The graph. |
|
The name of the attribute. |
|
Ids of the vertices to set. |
|
The new value of the attribute. |
Returns:
Error code. |
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:
|
The graph. |
|
Name of the attribute. |
|
Vertices for which to set the attribute. |
|
The (new) value of the attribute. |
Returns:
Error code. |
See also:
|
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).
#define SETVAS(graph,n,vid,value)
This is a shorthand for igraph_cattribute_VAS_set()
.
Arguments:
|
The graph. |
|
The name of the attribute. |
|
Ids of the vertices to set. |
|
The new value of the attribute. |
Returns:
Error code. |
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:
|
The graph. |
|
Name of the attribute. |
|
Edges for which to set the attribute. |
|
The (new) value of the attribute. |
Returns:
Error code. |
See also:
|
Time complexity: O(e), the number of edges if the attribute is new, O(|eid|) otherwise.
#define SETEAN(graph,n,eid,value)
This is a shorthand for igraph_cattribute_EAN_set()
.
Arguments:
|
The graph. |
|
The name of the attribute. |
|
Ids of the edges to set. |
|
The new value of the attribute. |
Returns:
Error code. |
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:
|
The graph. |
|
Name of the attribute. |
|
Edges for which to set the attribute. |
|
The (new) value of the attribute. |
Returns:
Error code. |
See also:
|
Time complexity: O(e), the number of edges if the attribute is new, O(|eid|) otherwise.
#define SETEAB(graph,n,eid,value)
This is a shorthand for igraph_cattribute_EAB_set()
.
Arguments:
|
The graph. |
|
The name of the attribute. |
|
Ids of the edges to set. |
|
The new value of the attribute. |
Returns:
Error code. |
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:
|
The graph. |
|
Name of the attribute. |
|
Edges for which to set the attribute. |
|
The (new) value of the attribute. |
Returns:
Error code. |
See also:
|
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).
#define SETEAS(graph,n,eid,value)
This is a shorthand for igraph_cattribute_EAS_set()
.
Arguments:
|
The graph. |
|
The name of the attribute. |
|
Ids of the edges to set. |
|
The new value of the attribute. |
Returns:
Error code. |
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:
|
The graph. |
|
Name of the attribute. |
|
The new attribute values. The length of this vector must match the number of vertices. |
Returns:
Error code. |
See also:
|
Time complexity: O(n), the number of vertices.
#define SETVANV(graph,n,v)
This is a shorthand for igraph_cattribute_VAN_setv()
.
Arguments:
|
The graph. |
|
The name of the attribute. |
|
Vector containing the new values of the attributes. |
Returns:
Error code. |
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:
|
The graph. |
|
Name of the attribute. |
|
The new attribute values. The length of this boolean vector must match the number of vertices. |
Returns:
Error code. |
See also:
|
Time complexity: O(n), the number of vertices.
#define SETVABV(graph,n,v)
This is a shorthand for igraph_cattribute_VAB_setv()
.
Arguments:
|
The graph. |
|
The name of the attribute. |
|
Vector containing the new values of the attributes. |
Returns:
Error code. |
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:
|
The graph. |
|
Name of the attribute. |
|
String vector, the new attribute values. The length of this vector must match the number of vertices. |
Returns:
Error code. |
See also:
|
Time complexity: O(n+l), n is the number of vertices, l is the total length of the strings.
#define SETVASV(graph,n,v)
This is a shorthand for igraph_cattribute_VAS_setv()
.
Arguments:
|
The graph. |
|
The name of the attribute. |
|
Vector containing the new values of the attributes. |
Returns:
Error code. |
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:
|
The graph. |
|
Name of the attribute. |
|
The new attribute values. The length of this vector must match the number of edges. |
Returns:
Error code. |
See also:
|
Time complexity: O(e), the number of edges.
#define SETEANV(graph,n,v)
This is a shorthand for igraph_cattribute_EAN_setv()
.
Arguments:
|
The graph. |
|
The name of the attribute. |
|
Vector containing the new values of the attributes. |
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:
|
The graph. |
|
Name of the attribute. |
|
The new attribute values. The length of this vector must match the number of edges. |
Returns:
Error code. |
See also:
|
Time complexity: O(e), the number of edges.
#define SETEABV(graph,n,v)
This is a shorthand for igraph_cattribute_EAB_setv()
.
Arguments:
|
The graph. |
|
The name of the attribute. |
|
Vector containing the new values of the attributes. |
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:
|
The graph. |
|
Name of the attribute. |
|
String vector, the new attribute values. The length of this vector must match the number of edges. |
Returns:
Error code. |
See also:
|
Time complexity: O(e+l), e is the number of edges, l is the total length of the strings.
#define SETEASV(graph,n,v)
This is a shorthand for igraph_cattribute_EAS_setv()
.
Arguments:
|
The graph. |
|
The name of the attribute. |
|
Vector containing the new values of the attributes. |
igraph_cattribute_remove_g
— Remove a graph attributeDELGA
— Remove a graph attribute.igraph_cattribute_remove_v
— Remove a vertex attributeDELVA
— Remove a vertex attribute.igraph_cattribute_remove_e
— Remove an edge attributeDELEA
— Remove an edge attribute.igraph_cattribute_remove_all
— Remove all graph/vertex/edge attributesDELGAS
— Remove all graph attributes.DELVAS
— Remove all vertex attributes.DELEAS
— Remove all edge attributes.DELALL
— Remove all attributes.
void igraph_cattribute_remove_g(igraph_t *graph, const char *name);
Arguments:
|
The graph object. |
|
Name of the graph attribute to remove. |
See also:
|
#define DELGA(graph,n)
A shorthand for igraph_cattribute_remove_g()
.
Arguments:
|
The graph. |
|
The name of the attribute to remove. |
void igraph_cattribute_remove_v(igraph_t *graph, const char *name);
Arguments:
|
The graph object. |
|
Name of the vertex attribute to remove. |
See also:
|
#define DELVA(graph,n)
A shorthand for igraph_cattribute_remove_v()
.
Arguments:
|
The graph. |
|
The name of the attribute to remove. |
void igraph_cattribute_remove_e(igraph_t *graph, const char *name);
Arguments:
|
The graph object. |
|
Name of the edge attribute to remove. |
See also:
|
#define DELEA(graph,n)
A shorthand for igraph_cattribute_remove_e()
.
Arguments:
|
The graph. |
|
The name of the attribute to remove. |
void igraph_cattribute_remove_all(igraph_t *graph, igraph_bool_t g, igraph_bool_t v, igraph_bool_t e);
Arguments:
|
The graph object. |
|
Boolean, whether to remove graph attributes. |
|
Boolean, whether to remove vertex attributes. |
|
Boolean, whether to remove edge attributes. |
See also:
#define DELALL(graph)
All graph, vertex and edges attributes will be removed.
Calls igraph_cattribute_remove_all()
.
Arguments:
|
The graph. |
← Chapter 11. Vertex and edge selectors and sequences, iterators | Chapter 13. Structural properties of graphs → |