For using the igraph C library
Attributes are numbers, boolean values or strings associated with the vertices or edges of a graph, or with the graph itself. E.g. you may label vertices with symbolic names or attach numeric weights to the edges of a graph. In addition to these three basic types, a custom object type is supported as well.
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 R all R types are allowed. There is also 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. This is normally done on program startup, and is kept untouched
for the program's lifetime. It must be done before any graph object
is created, as graphs created with a given attribute handler
cannot be manipulated while a different attribute handler is
active.
typedef struct igraph_attribute_table_t { igraph_error_t (*init)(igraph_t *graph, igraph_vector_ptr_t *attr); void (*destroy)(igraph_t *graph); igraph_error_t (*copy)(igraph_t *to, const igraph_t *from, igraph_bool_t ga, igraph_bool_t va, igraph_bool_t ea); igraph_error_t (*add_vertices)(igraph_t *graph, igraph_integer_t nv, igraph_vector_ptr_t *attr); igraph_error_t (*permute_vertices)(const igraph_t *graph, igraph_t *newgraph, const igraph_vector_int_t *idx); igraph_error_t (*combine_vertices)(const igraph_t *graph, igraph_t *newgraph, const igraph_vector_int_list_t *merges, const igraph_attribute_combination_t *comb); igraph_error_t (*add_edges)(igraph_t *graph, const igraph_vector_int_t *edges, igraph_vector_ptr_t *attr); igraph_error_t (*permute_edges)(const igraph_t *graph, igraph_t *newgraph, const igraph_vector_int_t *idx); igraph_error_t (*combine_edges)(const igraph_t *graph, igraph_t *newgraph, const igraph_vector_int_list_t *merges, const igraph_attribute_combination_t *comb); igraph_error_t (*get_info)(const igraph_t *graph, igraph_strvector_t *gnames, igraph_vector_int_t *gtypes, igraph_strvector_t *vnames, igraph_vector_int_t *vtypes, igraph_strvector_t *enames, igraph_vector_int_t *etypes); igraph_bool_t (*has_attr)(const igraph_t *graph, igraph_attribute_elemtype_t type, const char *name); igraph_error_t (*gettype)(const igraph_t *graph, igraph_attribute_type_t *type, igraph_attribute_elemtype_t elemtype, const char *name); igraph_error_t (*get_numeric_graph_attr)(const igraph_t *graph, const char *name, igraph_vector_t *value); igraph_error_t (*get_string_graph_attr)(const igraph_t *graph, const char *name, igraph_strvector_t *value); igraph_error_t (*get_bool_graph_attr)(const igraph_t *igraph, const char *name, igraph_vector_bool_t *value); igraph_error_t (*get_numeric_vertex_attr)(const igraph_t *graph, const char *name, igraph_vs_t vs, igraph_vector_t *value); igraph_error_t (*get_string_vertex_attr)(const igraph_t *graph, const char *name, igraph_vs_t vs, igraph_strvector_t *value); igraph_error_t (*get_bool_vertex_attr)(const igraph_t *graph, const char *name, igraph_vs_t vs, igraph_vector_bool_t *value); igraph_error_t (*get_numeric_edge_attr)(const igraph_t *graph, const char *name, igraph_es_t es, igraph_vector_t *value); igraph_error_t (*get_string_edge_attr)(const igraph_t *graph, const char *name, igraph_es_t es, igraph_strvector_t *value); igraph_error_t (*get_bool_edge_attr)(const igraph_t *graph, const char *name, igraph_es_t es, igraph_vector_bool_t *value); } igraph_attribute_table_t;
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. It is supposed
to do any cleanup operations that are need to dispose of the |
|
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. |
|
Called when a new graph is created based on an existing one such that there is a mapping from the vertices of the new graph back to the vertices of the old graph (e.g. if vertices are removed from a graph). The supplied index vector defines which old vertex a new vertex corresponds to. Its length must be the same as the number of vertices in the new graph. Note that the old and the new graph may be the same. If the two graph instances are not the same, implementors may safely assume that the new graph has no vertex attributes yet (but it may already have graph or edge attributes by the time this function is called). |
|
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. It is guaranteed that the old and the new graph instances are different when this callback is called. Implementors may safely assume that the new graph has no vertex attributes yet (but it may already have graph or edge attributes by the time this function is called). |
|
Called when new edges have been added. The number of new edges are supplied as well. It is expected to return an error code. |
|
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). Note that the old and the new graph instances may be the same. If the two graph instances are not the same, implementors may safely assume that the new graph has no edge attributes yet (but it may already have graph or vertex attributes by the time this function is called). |
|
This function is called when the creation of a new graph involves a merge (contraction, etc.) of edges from another graph. The function is after the new graph was created. An argument specifies how several edges from the old graph map to a single edge in the new graph. It is guaranteed that the old and the new graph instances are different when this callback is called. Implementors may safely assume that the new graph has no edge attributes yet (but it may already have graph or vertex attributes by the time this function is called). |
|
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.
Attribute handlers are normally attached on program startup, and are left active for the program's lifetime. This is because a graph object created with a given attribute handler must not be manipulated while a different attribute handler is active.
Arguments:
|
Pointer to an |
Returns:
Pointer to the old attribute handling table. |
Time complexity: O(1).
typedef enum { IGRAPH_ATTRIBUTE_UNSPECIFIED = 0, IGRAPH_ATTRIBUTE_DEFAULT IGRAPH_DEPRECATED_ENUMVAL = IGRAPH_ATTRIBUTE_UNSPECIFIED, IGRAPH_ATTRIBUTE_NUMERIC = 1, IGRAPH_ATTRIBUTE_BOOLEAN = 2, IGRAPH_ATTRIBUTE_STRING = 3, IGRAPH_ATTRIBUTE_OBJECT = 127 } igraph_attribute_type_t;
Note that this is only the
type communicated by the attribute interface towards igraph
functions. E.g. in the 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 used internally as a "null value" or "placeholder value" in some algorithms. Attribute records with this type must not be passed to igraph functions. |
|
Numeric attribute. |
|
Logical values, true or false. |
|
Attribute that can be converted to a string. |
|
Custom attribute type, to be used for special data types by client applications. The R and Python interfaces use this for attributes that hold R or Python objects. Usually ignored by igraph functions. |
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.igraph_attribute_combination
— Initialize attribute combination list and add records.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.
igraph_error_t igraph_attribute_combination_init(igraph_attribute_combination_t *comb);
Arguments:
|
The uninitialized attribute combination list. |
Returns:
Error code. |
Time complexity: O(1)
igraph_error_t igraph_attribute_combination_add(igraph_attribute_combination_t *comb, const char *name, igraph_attribute_combination_type_t type, igraph_function_pointer_t func);
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.
igraph_error_t 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. |
igraph_error_t igraph_attribute_combination( igraph_attribute_combination_t *comb, ...);
Arguments:
|
The uninitialized attribute combination list. |
|
A list of 'name, type[, func]', where: |
|
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^2), where n is the number attribute combinations records to add.
Example 12.1. File examples/simple/igraph_attribute_combination.c
#include <igraph.h> int main(void) { igraph_t graph; igraph_attribute_combination_t comb; igraph_set_attribute_table(&igraph_cattribute_table); igraph_small(&graph, 2, IGRAPH_DIRECTED, 0,1, 0,1, -1); SETEAB(&graph, "type", 0, true); SETEAB(&graph, "type", 1, false); igraph_attribute_combination(&comb, "weight", IGRAPH_ATTRIBUTE_COMBINE_SUM, "type", IGRAPH_ATTRIBUTE_COMBINE_FIRST, "", IGRAPH_ATTRIBUTE_COMBINE_IGNORE, IGRAPH_NO_MORE_ATTRIBUTES); igraph_simplify(&graph, /*remove_multiple=*/ true, /*remove_loops=*/ true, &comb); igraph_write_graph_graphml(&graph, stdout, /*prefixattr=*/ true); igraph_destroy(&graph); igraph_attribute_combination_destroy(&comb); return 0; }
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.2. File examples/simple/cattributes.c
#include <igraph.h> #include <string.h> #include <stdlib.h> /* Prints graph, vertex and edge attributes stored in a graph. */ void print_attributes(const igraph_t *g) { igraph_vector_int_t gtypes, vtypes, etypes; igraph_strvector_t gnames, vnames, enames; igraph_integer_t i, j; igraph_vector_int_init(>ypes, 0); igraph_vector_int_init(&vtypes, 0); igraph_vector_int_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=", igraph_strvector_get(&gnames, i)); if (VECTOR(gtypes)[i] == IGRAPH_ATTRIBUTE_NUMERIC) { igraph_real_printf(GAN(g, igraph_strvector_get(&gnames, i))); putchar(' '); } else { printf("\"%s\" ", GAS(g, igraph_strvector_get(&gnames, i))); } } printf("\n"); /* vertex attributes */ for (i = 0; i < igraph_vcount(g); i++) { printf("Vertex %" IGRAPH_PRId ": ", i); for (j = 0; j < igraph_strvector_size(&vnames); j++) { printf("%s=", igraph_strvector_get(&vnames, j)); if (VECTOR(vtypes)[j] == IGRAPH_ATTRIBUTE_NUMERIC) { igraph_real_printf(VAN(g, igraph_strvector_get(&vnames, j), i)); putchar(' '); } else { printf("\"%s\" ", VAS(g, igraph_strvector_get(&vnames, j), i)); } } printf("\n"); } /* edge attributes */ for (i = 0; i < igraph_ecount(g); i++) { printf("Edge %" IGRAPH_PRId " (%" IGRAPH_PRId "-%" IGRAPH_PRId "): ", i, IGRAPH_FROM(g, i), IGRAPH_TO(g, i)); for (j = 0; j < igraph_strvector_size(&enames); j++) { printf("%s=", igraph_strvector_get(&enames, j)); if (VECTOR(etypes)[j] == IGRAPH_ATTRIBUTE_NUMERIC) { igraph_real_printf(EAN(g, igraph_strvector_get(&enames, j), i)); putchar(' '); } else { printf("\"%s\" ", EAS(g, igraph_strvector_get(&enames, j), i)); } } printf("\n"); } igraph_strvector_destroy(&enames); igraph_strvector_destroy(&vnames); igraph_strvector_destroy(&gnames); igraph_vector_int_destroy(&etypes); igraph_vector_int_destroy(&vtypes); igraph_vector_int_destroy(>ypes); } int main(void) { igraph_t graph; igraph_vector_t y; /* Turn on attribute handling. */ igraph_set_attribute_table(&igraph_cattribute_table); igraph_small(&graph, 3, IGRAPH_DIRECTED, 0,1, 1,2, -1); /* Set graph attributes. */ /* numeric */ SETGAN(&graph, "id", 10); /* string */ SETGAS(&graph, "name", "toy"); /* boolean */ SETGAB(&graph, "is_regular", false); /* Set edge string attribute. */ SETEAS(&graph, "color", 1, "RED"); /* Set vertex attributes as vector. */ igraph_vector_init(&y, igraph_vcount(&graph)); igraph_vector_fill(&y, 1.23); SETVANV(&graph, "y", &y); igraph_vector_destroy(&y); /* Set single vertex numeric attribute. */ SETVAN(&graph, "y", 0, -1); /* Delete graph attribute. */ DELGA(&graph, "is_regular"); /* Print the final result. */ print_attributes(&graph); /* Delete all remaining attributes. */ DELALL(&graph); /* Destroy the graph. */ igraph_destroy(&graph); return 0; }
Example 12.3. File examples/simple/cattributes2.c
#include <igraph.h> int main(void) { 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", true); igraph_vector_init_range(&y, 1, igraph_vcount(&g) + 1); SETVANV(&g, "id", &y); igraph_vector_destroy(&y); SETVAS(&g, "name", 0, "foo"); SETVAS(&g, "name", 1, "foobar"); SETVAB(&g, "is_first", 0, true); igraph_vector_init_range(&y, 1, igraph_ecount(&g) + 1); SETEANV(&g, "id", &y); igraph_vector_destroy(&y); SETEAS(&g, "name", 0, "FOO"); SETEAS(&g, "name", 1, "FOOBAR"); SETEAB(&g, "is_first", 0, true); /* 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(igraph_warning_handler_ignore); igraph_write_graph_gml(&g, stdout, IGRAPH_WRITE_GML_DEFAULT_SW, 0, ""); igraph_set_warning_handler(oldwarnhandler); /* Back to business. */ igraph_write_graph_graphml(&g, stdout, /*prefixattr=*/ true); igraph_destroy(&g); return 0; }
Example 12.4. File examples/simple/cattributes3.c
#include <igraph.h> igraph_error_t mf(const igraph_vector_t *input, igraph_real_t *output) { *output = 0.0; return IGRAPH_SUCCESS; } static void simplify_write_destroy(igraph_t *g, igraph_attribute_combination_t *comb) { igraph_simplify(g, /*remove_multiple=*/ true, /*remove_loops=*/ true, comb); igraph_write_graph_graphml(g, stdout, /*prefixattr=*/ true); igraph_attribute_combination_destroy(comb); igraph_destroy(g); } static void weight_test(igraph_t *g, igraph_attribute_combination_type_t weight_attr) { igraph_t g2; igraph_attribute_combination_t comb; igraph_copy(&g2, g); igraph_attribute_combination(&comb, "weight", weight_attr, "", IGRAPH_ATTRIBUTE_COMBINE_IGNORE, IGRAPH_NO_MORE_ATTRIBUTES); simplify_write_destroy(&g2, &comb); } int main(void) { 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_range(&weight, 1, igraph_ecount(&g) + 1); SETEANV(&g, "weight", &weight); igraph_vector_destroy(&weight); weight_test(&g, IGRAPH_ATTRIBUTE_COMBINE_SUM); weight_test(&g, IGRAPH_ATTRIBUTE_COMBINE_PROD); weight_test(&g, IGRAPH_ATTRIBUTE_COMBINE_MIN); weight_test(&g, IGRAPH_ATTRIBUTE_COMBINE_MAX); weight_test(&g, IGRAPH_ATTRIBUTE_COMBINE_FIRST); weight_test(&g, IGRAPH_ATTRIBUTE_COMBINE_LAST); weight_test(&g, IGRAPH_ATTRIBUTE_COMBINE_MEAN); /* ****************************************************** */ igraph_copy(&g2, &g); igraph_attribute_combination(&comb, "weight", IGRAPH_ATTRIBUTE_COMBINE_FUNCTION, mf, "", IGRAPH_ATTRIBUTE_COMBINE_IGNORE, IGRAPH_NO_MORE_ATTRIBUTES); simplify_write_destroy(&g2, &comb); /* ****************************************************** */ igraph_copy(&g2, &g); igraph_attribute_combination(&comb, "", IGRAPH_ATTRIBUTE_COMBINE_MEAN, IGRAPH_NO_MORE_ATTRIBUTES); simplify_write_destroy(&g2, &comb); /* ****************************************************** */ igraph_destroy(&g); return 0; }
Example 12.5. File examples/simple/cattributes4.c
#include <igraph.h> static void simplify_write_destroy(igraph_t *g, igraph_attribute_combination_t *comb) { igraph_simplify(g, /*remove_multiple=*/ true, /*remove_loops=*/ true, comb); igraph_write_graph_graphml(g, stdout, /*prefixattr=*/ true); igraph_attribute_combination_destroy(comb); igraph_destroy(g); } int main(void) { 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); simplify_write_destroy(&g2, &comb); /* ****************************************************** */ igraph_copy(&g2, &g); igraph_attribute_combination(&comb, "", IGRAPH_ATTRIBUTE_COMBINE_LAST, IGRAPH_NO_MORE_ATTRIBUTES); simplify_write_destroy(&g2, &comb); /* ****************************************************** */ igraph_copy(&g2, &g); igraph_attribute_combination(&comb, "", IGRAPH_ATTRIBUTE_COMBINE_IGNORE, "color", IGRAPH_ATTRIBUTE_COMBINE_CONCAT, IGRAPH_NO_MORE_ATTRIBUTES); simplify_write_destroy(&g2, &comb); /* ****************************************************** */ igraph_destroy(&g); return 0; }
igraph_cattribute_list
— List all attributes.igraph_cattribute_has_attr
— Checks whether a (graph, vertex or edge) attribute exists.igraph_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 vertices.VANV
— 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 vertices.VABV
— 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 vertices.VASV
— 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 edges.EANV
— 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 edges.EABV
— 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 edges.EASV
— Query a string edge attribute for all edges.
igraph_error_t igraph_cattribute_list(const igraph_t *graph, igraph_strvector_t *gnames, igraph_vector_int_t *gtypes, igraph_strvector_t *vnames, igraph_vector_int_t *vtypes, igraph_strvector_t *enames, igraph_vector_int_t *etypes);
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, |
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. If the attribute does not exist, a warning is issued and NaN is returned.
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 boolean graph attribute. If the attribute does not exist, a warning is issued and false is returned.
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 value must not be modified.
If the attribute does not exist, a warning is issued and
an empty string is returned.
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);
If the attribute does not exist, a warning is issued and
NaN is returned. See igraph_cattribute_VANV()
for
an error-checked version.
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. |
igraph_error_t 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);
If the vertex attribute does not exist, a warning is issued
and false is returned. See igraph_cattribute_VABV()
for
an error-checked version.
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. |
igraph_error_t 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);
Returns a const pointer to the string vertex attribute
specified in name
. The value must not be modified.
If the vertex attribute does not exist, a warning is issued and
an empty string is returned. See igraph_cattribute_VASV()
for an error-checked version.
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. |
igraph_error_t 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);
If the attribute does not exist, a warning is issued and
NaN is returned. See igraph_cattribute_EANV()
for
an error-checked version.
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. |
igraph_error_t 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);
If the edge attribute does not exist, a warning is issued and
false is returned. See igraph_cattribute_EABV()
for
an error-checked version.
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. |
igraph_error_t 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);
Returns a const pointer to the string edge attribute
specified in name
. The value must not be modified.
If the edge attribute does not exist, a warning is issued and
an empty string is returned. See igraph_cattribute_EASV()
for
an error-checked version.
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. |
igraph_error_t 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 attribute.SETGAN
— Set a numeric graph attributeigraph_cattribute_GAB_set
— Set a boolean graph attribute.SETGAB
— 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 attribute.SETVAN
— Set a numeric vertex attributeigraph_cattribute_VAB_set
— Set a boolean vertex attribute.SETVAB
— Set a boolean vertex attributeigraph_cattribute_VAS_set
— Set a string vertex attribute.SETVAS
— Set a string vertex attributeigraph_cattribute_EAN_set
— Set a numeric edge attribute.SETEAN
— Set a numeric edge attributeigraph_cattribute_EAB_set
— Set a boolean edge attribute.SETEAB
— Set a boolean edge attributeigraph_cattribute_EAS_set
— Set a string edge attribute.SETEAS
— 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
igraph_error_t 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. |
igraph_error_t 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. |
igraph_error_t 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. |
igraph_error_t 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. |
igraph_error_t 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. |
igraph_error_t 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. |
igraph_error_t 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. |
igraph_error_t 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. |
igraph_error_t 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. |
igraph_error_t 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. |
igraph_error_t 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. |
igraph_error_t 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. |
igraph_error_t 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. |
igraph_error_t 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. |
igraph_error_t 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 attribute.DELGA
— Remove a graph attribute.igraph_cattribute_remove_v
— Remove a vertex attribute.DELVA
— Remove a vertex attribute.igraph_cattribute_remove_e
— Remove an edge attribute.DELEA
— Remove an edge attribute.igraph_cattribute_remove_all
— Remove all graph/vertex/edge attributes.DELGAS
— 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. |
The C attribute handler supports combining the attributes of multiple
vertices of edges into a single attribute during a vertex or edge contraction
operation via a user-defined function. This is achieved by setting the
type of the attribute combination to IGRAPH_ATTRIBUTE_COMBINE_FUNCTION
and passing in a pointer to the custom combination function when specifying
attribute combinations in igraph_attribute_combination()
or
igraph_attribute_combination_add()
. For the C attribute handler, the
signature of the function depends on the type of the underlying attribute.
For numeric attributes, use:
igraph_error_t function(const igraph_vector_t *input, igraph_real_t *output);
where input
will receive a vector containing the value of the attribute
for all the vertices or edges being combined, and output
must be filled
by the function to the combined value. Similarly, for Boolean attributes, the
function takes a boolean vector in input
and must return the combined Boolean
value in output
:
igraph_error_t function(const igraph_vector_bool_t *input, igraph_bool_t *output);
For string attributes, the signature is slightly different:
igraph_error_t function(const igraph_strvector_t *input, char **output);
In case of strings, all strings in the input vector are owned by igraph
and must not be modified or freed in the combination handler. The string
returned to the caller in output
remains owned by the caller; igraph will
make a copy it and store the copy in the appropriate part of the data
structure holding the vertex or edge attributes.
← Chapter 11. Vertex and edge selectors and sequences, iterators | Chapter 13. Structural properties of graphs → |