Operators and bipartite graphs
Bipartite graphs, unions, intersections and differences, subgraphs, and products and other transformations.
36 entries: 34 functions and 2 types. Part of the Open Graph reference; All functions lists every entry on one page, with a filter. The badges say how each entry is checked.
Types
subgraph_implementation_ttype#
Unit tests
How induced_subgraph builds its result.
typedef enum og_subgraph_implementation_t {
OG_SUBGRAPH_AUTO = 0, /* choose by the share of vertices kept */
OG_SUBGRAPH_COPY_AND_DELETE = 1, /* copy the graph, delete the other vertices */
OG_SUBGRAPH_CREATE_FROM_SCRATCH = 2 /* build a new graph from the kept vertices */
} og_subgraph_implementation_t;
Both methods give the same graph; they differ in speed and in edge order. Other values give OG_EINVAL.
- Parameters
OG_SUBGRAPH_AUTO0: COPY_AND_DELETE when more than half of the vertices are selected, else CREATE_FROM_SCRATCH.OG_SUBGRAPH_COPY_AND_DELETE1: copy the graph and delete the other vertices.OG_SUBGRAPH_CREATE_FROM_SCRATCH2: build a new graph from the kept vertices.
- Checked
- Enum; every value is tested through
induced_subgraphagainst python-igraph. - C name
og_subgraph_implementation_t- In notebooks
Og.SubgraphImplementation- igraph 1.0
igraph_subgraph_implementation_t- See also
induced_subgraph,induced_subgraph_map
product_ttype#
Unit tests
The graph products of product.
typedef enum og_product_t {
OG_PRODUCT_CARTESIAN = 0,
OG_PRODUCT_LEXICOGRAPHIC = 1,
OG_PRODUCT_STRONG = 2,
OG_PRODUCT_TENSOR = 3,
OG_PRODUCT_MODULAR = 4
} og_product_t;
Definitions under product. Other values give OG_EINVAL.
- Parameters
OG_PRODUCT_CARTESIAN0: Cartesian product.OG_PRODUCT_LEXICOGRAPHIC1: lexicographic product.OG_PRODUCT_STRONG2: strong product.OG_PRODUCT_TENSOR3: tensor (direct) product.OG_PRODUCT_MODULAR4: modular product (simple graphs only).
- Checked
- Enum; every value is tested through
productagainst networkx. - C name
og_product_t- In notebooks
Og.ProductType- igraph 1.0
igraph_product_t- See also
product
Bipartite graphs
create_bipartite#
Exact
Builds a graph from vertex kinds and an edge list, checking that every edge joins the two kinds.
og_error_t og_create_bipartite(
og_t *graph,
const og_vector_bool_t *types,
const og_vector_int_t *edges,
og_bool_t directed
);
types has one entry per vertex (false and true are the two kinds); its length sets the vertex count. edges lists the two endpoints of every edge in turn, and the edge order is kept. Every edge must join a false vertex and a true one.
- Parameters
graphOutput: an uninitialisedog_t. The function creates the result graph; free it withdestroy.typesThe kind of every vertex.edgesEndpoints of the edges, two entries per edge.directedtrue for a directed graph.
- Returns
OG_SUCCESS, or the error code of the failure (see errors).- Errors
OG_EINVALedges has an odd number of entries, or an edge joins two vertices of the same kind.OG_EINVVIDedges names a vertex id outside 0 .. size of types - 1.OG_ENOMEMMemory runs out.
- Complexity
- O(|V| + |E|).
- Checked
- 220 random bipartite graphs rebuilt from python-igraph's types and edges; the error codes as python-igraph reports them.
- C name
og_create_bipartite- In notebooks
Og.CreateBipartite- igraph 1.0
igraph_create_bipartite- See also
full_bipartite,is_bipartite,biadjacency
full_bipartite#
Exact
Complete bipartite graph K(n1, n2).
og_error_t og_full_bipartite(
og_t *graph,
og_vector_bool_t *types,
og_int_t n1,
og_int_t n2,
og_bool_t directed,
og_neimode_t mode
);
Vertices 0 .. n1-1 are the first kind (type false), n1 .. n1+n2-1 the second (type true), and every vertex of the first kind is joined to every vertex of the second. A directed graph takes its directions from mode; with OG_ALL each pair gets two edges, first to second kind first. Edges are listed by first-kind vertex, then by second-kind vertex.
- Parameters
graphOutput: an uninitialisedog_t. The function creates the result graph; free it withdestroy.typesOutput (may be NULL): the kind of every vertex, false for the first n1, true for the rest.n1Number of first-kind vertices.n2Number of second-kind vertices.directedtrue for a directed graph; mode then sets the edge directions.modeDirected graphs only:OG_OUTfor edges from the first kind to the second,OG_INthe other way,OG_ALLfor both.
- Returns
OG_SUCCESS, or the error code of the failure (see errors).- Errors
OG_EINVALn1 or n2 is negative.OG_EINVMODEThe graph is directed and mode is notOG_OUT,OG_INorOG_ALL.OG_ERANGEThe result would have more vertices or edges than Open Graph supports.OG_ENOMEMMemory runs out.
- Complexity
- O(n1 n2).
- Checked
- python-igraph's Full_Bipartite on 420 cases (sizes up to 40x40, every directedness and mode); edge order and types identical.
- C name
og_full_bipartite- In notebooks
Og.FullBipartite- igraph 1.0
igraph_full_bipartite- See also
create_bipartite,bipartite_game_gnm
bipartite_game_gnm#
Same quality
Random bipartite graph with exactly m edges, G(n1, n2, m).
og_error_t og_bipartite_game_gnm(
og_t *graph,
og_vector_bool_t *types,
og_int_t n1,
og_int_t n2,
og_int_t m,
og_bool_t directed,
og_neimode_t mode,
og_edge_type_sw_t allowed_edge_types,
og_bool_t edge_labeled
);
Vertices as in full_bipartite, edge directions as there. The m edges are drawn uniformly among the possible first-kind/second-kind pairs. allowed_edge_types decides whether parallel edges are allowed (OG_MULTI_SW); self-loops cannot occur in a bipartite graph. With edge_labeled = true the order of the edges is part of the random outcome; with false the edge list is a set (or a multiset).
Without parallel edges a uniform m-subset of the possible edges is drawn (Vitter's sampling methods) and listed in a fixed order (unlabeled) or a uniformly random order (labeled). With parallel edges, unlabeled draws a uniform multiset and lists it in random order, and labeled draws m independent uniform edges. Asking for every possible edge without parallel edges gives full_bipartite's graph. Random numbers come from rng_default().
- Parameters
graphOutput: an uninitialisedog_t. The function creates the result graph; free it withdestroy.typesOutput (may be NULL): the kind of every vertex, false for the first n1, true for the rest.n1Number of first-kind vertices.n2Number of second-kind vertices.mNumber of edges.directedtrue for a directed graph; mode then sets the edge directions.modeDirected graphs only:OG_OUTfor edges from the first kind to the second,OG_INthe other way,OG_ALLfor both.allowed_edge_typesOG_MULTI_SWallows parallel edges;OG_SIMPLE_SWdoes not.edge_labeledtrue: edge order is part of the outcome; false: the edges form a set.
- Returns
OG_SUCCESS, or the error code of the failure (see errors).- Errors
OG_EINVALn1, n2 or m is negative; m exceeds the number of possible edges without parallel edges; or m > 0 with no possible edge.OG_EINVMODEThe graph is directed and mode is notOG_OUT,OG_INorOG_ALL.OG_ERANGEThe result would have more vertices or edges than Open Graph supports.OG_ENOMEMMemory runs out.
- Complexity
- O(n1 + n2 + m).
- Checked
- Open Graph's own random stream, so one seed gives another graph than igraph. Outcome distributions match python-igraph's Random_Bipartite(m=...) by chi-square (20,000 draws per configuration) and the exact uniform law; unlabeled samples list their edges in python-igraph's order.
- C name
og_bipartite_game_gnm- In notebooks
Og.BipartiteGameGnm- igraph 1.0
igraph_bipartite_game_gnm- See also
bipartite_game_gnp,bipartite_iea_game,full_bipartite
bipartite_game_gnp#
Same quality
Random bipartite graph in which each possible edge appears with probability p, G(n1, n2, p).
og_error_t og_bipartite_game_gnp(
og_t *graph,
og_vector_bool_t *types,
og_int_t n1,
og_int_t n2,
og_real_t p,
og_bool_t directed,
og_neimode_t mode,
og_edge_type_sw_t allowed_edge_types,
og_bool_t edge_labeled
);
Vertices and directions as bipartite_game_gnm. Without parallel edges each possible first-kind/second-kind edge is present independently with probability p (0 <= p <= 1), found by geometric skipping (Batagelj and Brandes 2005); p = 1 gives full_bipartite's graph.
With parallel edges (OG_MULTI_SW) p is the expected number of edges per possible pair and may exceed 1. Unlabeled: every pair gets a geometric number of edges with mean p. Labeled: a geometric total with mean p times the number of pairs, placed uniformly. The labeled model without parallel edges is not available (OG_UNIMPLEMENTED), as in igraph. Random numbers come from rng_default().
- Parameters
graphOutput: an uninitialisedog_t. The function creates the result graph; free it withdestroy.typesOutput (may be NULL): the kind of every vertex, false for the first n1, true for the rest.n1Number of first-kind vertices.n2Number of second-kind vertices.pEdge probability, or the expected multiplicity with parallel edges.directedtrue for a directed graph; mode then sets the edge directions.modeDirected graphs only:OG_OUTfor edges from the first kind to the second,OG_INthe other way,OG_ALLfor both.allowed_edge_typesOG_MULTI_SWallows parallel edges;OG_SIMPLE_SWdoes not.edge_labeledtrue: edge order is part of the outcome (parallel edges only).
- Returns
OG_SUCCESS, or the error code of the failure (see errors).- Errors
OG_EINVALn1 or n2 is negative, or p is NaN, negative, infinite, or above 1 without parallel edges.OG_UNIMPLEMENTEDedge_labeled is true without parallel edges.OG_EINVMODEThe graph is directed and mode is notOG_OUT,OG_INorOG_ALL.OG_ERANGEThe result would have more vertices or edges than Open Graph supports.OG_ENOMEMMemory runs out.
- Complexity
- O(n1 + n2 + number of edges drawn).
- Checked
- Open Graph's own random stream. Outcome and edge-count histograms match python-igraph's Random_Bipartite(p=...), plus the exact law on 2x2 and the mean p N for multigraphs; edge order as python-igraph's.
- C name
og_bipartite_game_gnp- In notebooks
Og.BipartiteGameGnp- igraph 1.0
igraph_bipartite_game_gnp- See also
bipartite_game_gnm,bipartite_iea_game
bipartite_iea_game#
Same quality
Random bipartite multigraph from m independently placed edges.
og_error_t og_bipartite_iea_game(
og_t *graph,
og_vector_bool_t *types,
og_int_t n1,
og_int_t n2,
og_int_t m,
og_bool_t directed,
og_neimode_t mode
);
Each of the m edges joins a uniformly chosen first-kind/second-kind pair, independently of the others (independent edge assignment), so parallel edges can occur. Vertices and directions as bipartite_game_gnm. Random numbers come from rng_default().
- Parameters
graphOutput: an uninitialisedog_t. The function creates the result graph; free it withdestroy.typesOutput (may be NULL): the kind of every vertex, false for the first n1, true for the rest.n1Number of first-kind vertices.n2Number of second-kind vertices.mNumber of edges.directedtrue for a directed graph; mode then sets the edge directions.modeDirected graphs only:OG_OUTfor edges from the first kind to the second,OG_INthe other way,OG_ALLfor both.
- Returns
OG_SUCCESS, or the error code of the failure (see errors).- Errors
OG_EINVALn1, n2 or m is negative, or m > 0 with no possible edge.OG_EINVMODEThe graph is directed and mode is notOG_OUT,OG_INorOG_ALL.OG_ERANGEThe result would have more vertices or edges than Open Graph supports.OG_ENOMEMMemory runs out.
- Complexity
- O(n1 + n2 + m).
- Checked
- python-igraph has no bipartite IEA model: uniformity over ordered edge lists by goodness of fit. It is the same model as the edge-labeled multigraph G(n1, n2, m), which is compared with python-igraph.
- C name
og_bipartite_iea_game- In notebooks
Og.BipartiteIeaGame- igraph 1.0
igraph_bipartite_iea_game- See also
bipartite_game_gnm,bipartite_game_gnp
biadjacency#
Exact
Builds a bipartite graph from its biadjacency matrix.
og_error_t og_biadjacency(
og_t *graph,
og_vector_bool_t *types,
const og_matrix_t *biadjmatrix,
og_bool_t directed,
og_neimode_t mode,
og_bool_t multiple
);
Row i of the matrix is first-kind vertex i (type false), column j is second-kind vertex rows + j (type true). With multiple = false every nonzero entry (NaN included) gives one edge; with multiple = true an entry is a count, its integer part giving that many parallel edges, and must be finite and not negative. Entries are read column by column, which sets the edge order. directed and mode as in full_bipartite.
- Parameters
graphOutput: an uninitialisedog_t. The function creates the result graph; free it withdestroy.typesOutput (may be NULL): the kind of every vertex.biadjmatrixThe biadjacency matrix: rows are first-kind vertices, columns second-kind ones.directedtrue for a directed graph; mode then sets the edge directions.modeDirected graphs only:OG_OUTfor edges from the first kind to the second,OG_INthe other way,OG_ALLfor both.multipletrue: entries are edge counts; false: any nonzero entry is one edge.
- Returns
OG_SUCCESS, or the error code of the failure (see errors).- Errors
OG_EINVALmultiple is true and an entry is negative, NaN or infinite.OG_ERANGEAn entry asks for more edges than Open Graph supports.OG_EINVMODEThe graph is directed and mode is notOG_OUT,OG_INorOG_ALL.OG_ENOMEMMemory runs out.
- Complexity
- O(rows x cols + |E|).
- Checked
- 220 random matrices for every directedness, mode and multiple, edge order identical to python-igraph's Biadjacency. Deliberate difference: with multiple, NaN and +inf entries are refused (python-igraph makes no edge for them).
- C name
og_biadjacency- In notebooks
Og.Biadjacency- igraph 1.0
igraph_biadjacency- See also
weighted_biadjacency,get_biadjacency,create_bipartite
weighted_biadjacency#
Exact
Builds a weighted bipartite graph from a biadjacency matrix.
og_error_t og_weighted_biadjacency(
og_t *graph,
og_vector_bool_t *types,
og_vector_t *weights,
const og_matrix_t *biadjmatrix,
og_bool_t directed,
og_neimode_t mode
);
As biadjacency without counts: every nonzero entry gives one edge, and weights receives the entry as that edge's weight (in a directed graph with OG_ALL both edges get it).
- Parameters
graphOutput: an uninitialisedog_t. The function creates the result graph; free it withdestroy.typesOutput (may be NULL): the kind of every vertex.weightsOutput (may be NULL): the weight of every edge, in edge order.biadjmatrixThe biadjacency matrix: rows are first-kind vertices, columns second-kind ones.directedtrue for a directed graph; mode then sets the edge directions.modeDirected graphs only:OG_OUTfor edges from the first kind to the second,OG_INthe other way,OG_ALLfor both.
- Returns
OG_SUCCESS, or the error code of the failure (see errors).- Errors
OG_EINVMODEThe graph is directed and mode is notOG_OUT,OG_INorOG_ALL.OG_ENOMEMMemory runs out.
- Complexity
- O(rows x cols + |E|).
- Checked
- The same 220 matrices against python-igraph's Biadjacency(weighted=True): edges and weights identical for every directedness and mode.
- C name
og_weighted_biadjacency- In notebooks
Og.WeightedBiadjacency- igraph 1.0
igraph_weighted_biadjacency- See also
biadjacency,get_biadjacency
get_biadjacency#
Exact
Biadjacency matrix of a bipartite graph.
og_error_t og_get_biadjacency(
const og_t *graph,
const og_vector_bool_t *types,
const og_vector_t *weights,
og_matrix_t *res,
og_vector_int_t *row_ids,
og_vector_int_t *col_ids
);
Rows are the vertices of type false and columns those of type true, each in increasing id; row_ids and col_ids give the vertex behind every row and column. Entry (i, j) counts the edges between the two vertices, or sums their weights when weights is given. Edge directions are ignored. Edges joining two vertices of the same kind are left out, with a warning.
- Parameters
graphThe input graph.typesThe kind of every vertex.weightsEdge weights to sum (may be NULL: count the edges).resOutput: the matrix, resized to (number of false vertices) x (number of true vertices).row_idsOutput (may be NULL): vertex id of every row.col_idsOutput (may be NULL): vertex id of every column.
- Returns
OG_SUCCESS, or the error code of the failure (see errors).- Errors
OG_EINVALtypes does not have one entry per vertex, or weights one entry per edge.OG_ENOMEMMemory runs out.
- Complexity
- O(n1 n2 + |V| + |E|), n1 and n2 the sizes of the two kinds.
- Checked
- 220 random bipartite graphs (parallel edges, both orientations) against python-igraph's get_biadjacency: matrix, row and column ids identical.
- C name
og_get_biadjacency- In notebooks
Og.GetBiadjacency- igraph 1.0
igraph_get_biadjacency- See also
biadjacency,weighted_biadjacency
bipartite_projection_size#
Exact
Vertex and edge counts of the two one-mode projections, without building them.
og_error_t og_bipartite_projection_size(
const og_t *graph,
const og_vector_bool_t *types,
og_int_t *vcount1,
og_int_t *ecount1,
og_int_t *vcount2,
og_int_t *ecount2
);
The projection onto one kind joins two vertices of that kind when they share a neighbour (Borgatti and Everett 1997); each joined pair counts once. vcount1 and ecount1 describe the projection onto the type-false vertices, vcount2 and ecount2 the one onto the type-true vertices; each output may be NULL.
- Parameters
graphThe input graph.typesThe kind of every vertex.vcount1Output (may be NULL): vertices of the first projection.ecount1Output (may be NULL): edges of the first projection.vcount2Output (may be NULL): vertices of the second projection.ecount2Output (may be NULL): edges of the second projection.
- Returns
OG_SUCCESS, or the error code of the failure (see errors).- Errors
OG_EINVALtypes does not have one entry per vertex, or an edge joins two vertices of the same kind.OG_ENOMEMMemory runs out.
- Complexity
- O(sum over the vertices of degree squared).
- Checked
- 220 random bipartite graphs against python-igraph's bipartite_projection_size; error codes as python-igraph's.
- C name
og_bipartite_projection_size- In notebooks
Og.BipartiteProjectionSize- igraph 1.0
igraph_bipartite_projection_size- See also
bipartite_projection
bipartite_projection#
Exact
The two one-mode projections of a bipartite graph.
og_error_t og_bipartite_projection(
const og_t *graph,
const og_vector_bool_t *types,
og_t *proj1,
og_t *proj2,
og_vector_int_t *multiplicity1,
og_vector_int_t *multiplicity2,
og_int_t probe1
);
Each projection is an undirected simple graph with one vertex per vertex of its kind, in increasing original id, and an edge between two vertices that share at least one neighbour. Edges are listed by their smaller vertex, partners in the order first met. multiplicity1 and multiplicity2 give, per projected edge, the number of shared neighbours.
proj1 is the projection onto the type-false vertices, proj2 onto the type-true ones. With probe1 >= 0, proj1 is instead the projection onto the kind of vertex probe1; a negative probe1 keeps the default. Each projection keeps the graph attributes and those of its own vertices.
- Parameters
graphThe input graph.typesThe kind of every vertex.proj1Output (may be NULL): an uninitialisedog_t. The function creates the result graph; free it withdestroy.proj2Output (may be NULL): an uninitialisedog_t. The function creates the result graph; free it withdestroy.multiplicity1Output (may be NULL): shared-neighbour count of every edge of proj1.multiplicity2Output (may be NULL): shared-neighbour count of every edge of proj2.probe1A vertex whose kind proj1 should hold, or a negative number for the default.
- Returns
OG_SUCCESS, or the error code of the failure (see errors).- Errors
OG_EINVALtypes does not have one entry per vertex, or an edge joins two vertices of the same kind.OG_EINVALprobe1 is not a vertex of the graph, or probe1 is given while proj1 is NULL.OG_ENOMEMMemory runs out.
- Complexity
- O(sum over the vertices of degree squared).
- Checked
- 220 random bipartite graphs against python-igraph's bipartite_projection: both projections' edges in order and their multiplicities identical; attributes as python-igraph keeps them (120 cases).
- C name
og_bipartite_projection- In notebooks
Og.BipartiteProjection- igraph 1.0
igraph_bipartite_projection- See also
bipartite_projection_size,is_bipartite
is_bipartite#
Exact
Tests whether the vertices split into two kinds with every edge between the kinds, and returns such a split.
og_error_t og_is_bipartite(
const og_t *graph,
og_bool_t *res,
og_vector_bool_t *types
);
Each connected component is two-coloured by breadth-first search, edge directions ignored. An odd cycle or a self-loop makes the graph non-bipartite. When it is bipartite, types receives the colouring, with the lowest vertex of each component on the false side. The null graph is bipartite.
- Parameters
graphThe input graph.resOutput (may be NULL): true when the graph is bipartite.typesOutput (may be NULL): the kind of every vertex; only written when the graph is bipartite.
- Returns
OG_SUCCESS, or the error code of the failure (see errors).- Errors
OG_ENOMEMMemory runs out.
- Complexity
- O(|V| + |E|).
- Checked
- Result and colouring identical to python-igraph's is_bipartite(return_types=True) on 440 graphs (220 random, and the same with one extra edge).
- C name
og_is_bipartite- In notebooks
Og.IsBipartite- igraph 1.0
igraph_is_bipartite- See also
is_bipartite_coloring,bipartite_projection,create_bipartite
og_t g;
og_bool_t bip;
og_vector_bool_t types;
og_ring(&g, 6, OG_UNDIRECTED, false, true); /* an even cycle */
og_vector_bool_init(&types, 0);
og_is_bipartite(&g, &bip, &types);
/* bip is true; types false true false true false true */
og_vector_bool_destroy(&types);
og_destroy(&g);
Unions, intersections and differences
disjoint_union#
Exact
Puts two graphs side by side in one graph.
og_error_t og_disjoint_union(
og_t *res,
const og_t *left,
const og_t *right
);
The result has the vertices of left with their ids, then those of right with ids shifted by left's vertex count; the edges of left come first, then those of right, each in their original order. Both graphs must be directed or both undirected. Attributes are not carried over.
- Parameters
resOutput: an uninitialisedog_t. The function creates the result graph; free it withdestroy.leftThe first graph.rightThe second graph.
- Returns
OG_SUCCESS, or the error code of the failure (see errors).- Errors
OG_EINVALThe operands are not all directed or all undirected.OG_ERANGEThe result would have more vertices or edges than Open Graph supports.OG_ENOMEMMemory runs out.
- Complexity
- O(|V| + |E|) of both graphs together.
- Checked
- 240 random cases against python-igraph's disjoint_union (null graph, single vertex, isolated vertices, loops, multi-edges, both directednesses).
- C name
og_disjoint_union- In notebooks
Og.DisjointUnion- igraph 1.0
igraph_disjoint_union- See also
disjoint_union_many,join,union
disjoint_union_many#
Exact
Puts any number of graphs side by side in one graph.
og_error_t og_disjoint_union_many(og_t *res, const og_vector_ptr_t *graphs);
As disjoint_union for a vector of graph pointers: each graph's vertex ids are shifted by the vertex counts of the graphs before it, and the edges follow graph by graph. An empty vector gives the directed null graph. Attributes are not carried over.
- Parameters
resOutput: an uninitialisedog_t. The function creates the result graph; free it withdestroy.graphsVector of pointers to the graphs (constog_t*).
- Returns
OG_SUCCESS, or the error code of the failure (see errors).- Errors
OG_EINVALThe operands are not all directed or all undirected.OG_ERANGEThe result would have more vertices or edges than Open Graph supports.OG_ENOMEMMemory runs out.
- Complexity
- O(|V| + |E|) of all graphs together.
- Checked
- The same 240 cases with 2-4 operands against python-igraph's disjoint_union.
- C name
og_disjoint_union_many- In notebooks
Og.DisjointUnionMany- igraph 1.0
igraph_disjoint_union_many- See also
disjoint_union,union_many
join#
Unit tests
Disjoint union of two graphs plus every edge between them.
og_error_t og_join(og_t *res, const og_t *left, const og_t *right);
The join (Harary 1969) is the disjoint union with every vertex of left joined to every vertex of right; in a directed graph both directions are added. The new edges come after the original ones, grouped by left vertex, right vertices in increasing order (directed: u -> v, then v -> u). Both graphs must be directed or both undirected. Attributes are not carried over.
- Parameters
resOutput: an uninitialisedog_t. The function creates the result graph; free it withdestroy.leftThe first graph.rightThe second graph.
- Returns
OG_SUCCESS, or the error code of the failure (see errors).- Errors
OG_EINVALThe operands are not all directed or all undirected.OG_ERANGEThe result would have more vertices or edges than Open Graph supports.OG_ENOMEMMemory runs out.
- Complexity
- O(|V1| + |V2| + |E1| + |E2| + |V1| |V2|).
- Checked
- python-igraph has no join: checked against the definition (numbering, edge counts, directions, empty operands). The order of the added edges is Open Graph's reading of the definition and was not compared with igraph.
- C name
og_join- In notebooks
Og.Join- igraph 1.0
igraph_join- See also
disjoint_union,full_bipartite
union#
Exact
Union of two graphs on shared vertex ids.
og_error_t og_union(
og_t *res,
const og_t *left,
const og_t *right,
og_vector_int_t *edge_map1,
og_vector_int_t *edge_map2
);
Vertices with the same id are the same vertex, so the result has as many vertices as the larger graph. An edge (u, v) appears as often as in the operand that has it most often; in undirected graphs (u, v) and (v, u) are the same edge. Result edges are listed in decreasing (from, to) order. edge_map1 and edge_map2 give, for every edge of left and of right, the id of the result edge it became; among parallel edges the pairing is the one igraph reports. Both graphs must be directed or both undirected. Attributes are not carried over.
- Parameters
resOutput: an uninitialisedog_t. The function creates the result graph; free it withdestroy.leftThe first graph.rightThe second graph.edge_map1Output (may be NULL): result edge id of every edge of left.edge_map2Output (may be NULL): result edge id of every edge of right.
- Returns
OG_SUCCESS, or the error code of the failure (see errors).- Errors
OG_EINVALThe operands are not all directed or all undirected.OG_ENOMEMMemory runs out.
- Complexity
- O(|V| + |E|) when no operand has parallel edges; O(|E| log |E|) for an operand that has them (it is sorted by comparisons).
- Checked
- 240 random cases with shared edges, multi-edges and loops against python-igraph's union: edge order and both edge maps identical. 7.2 ms against python-igraph's 8.2 ms on 2 x 50k directed edges.
- C name
og_union- In notebooks
Og.Union- igraph 1.0
igraph_union- See also
union_many,intersection,disjoint_union,difference
og_t a, b, u;
og_vector_int_t map1, map2;
og_small(&a, 3, OG_UNDIRECTED, 0,1, 1,2, -1);
og_small(&b, 4, OG_UNDIRECTED, 1,2, 2,3, -1);
og_vector_int_init(&map1, 0);
og_vector_int_init(&map2, 0);
og_union(&u, &a, &b, &map1, &map2);
/* u: 4 vertices, edges 2-3, 1-2, 0-1 (in that order); map1 2 1; map2 1 0 */
og_vector_int_destroy(&map2);
og_vector_int_destroy(&map1);
og_destroy(&u);
og_destroy(&b);
og_destroy(&a);
union_many#
Exact
Union of any number of graphs on shared vertex ids.
og_error_t og_union_many(
og_t *res,
const og_vector_ptr_t *graphs,
og_vector_int_list_t *edgemaps
);
As union for a vector of graph pointers: the result has as many vertices as the largest graph, and every edge its largest multiplicity over the graphs. edgemaps receives one vector per graph, mapping its edges to result edge ids. With more than two graphs the merge uses a heap, O(|E| log k) for k graphs. An empty vector gives the directed null graph. Attributes are not carried over.
- Parameters
resOutput: an uninitialisedog_t. The function creates the result graph; free it withdestroy.graphsVector of pointers to the graphs (constog_t*).edgemapsOutput (may be NULL): one edge map per graph; resized to the number of graphs.
- Returns
OG_SUCCESS, or the error code of the failure (see errors).- Errors
OG_EINVALThe operands are not all directed or all undirected.OG_ENOMEMMemory runs out.
- Complexity
- O(|V| + |E| log k) for k graphs without parallel edges; graphs with parallel edges are sorted first.
- Checked
- As
unionwith 2-4 operands, and 3 to 150 operands with edge maps in the independent check. - C name
og_union_many- In notebooks
Og.UnionMany- igraph 1.0
igraph_union_many- See also
union,intersection_many
intersection#
Exact
Intersection of two graphs on shared vertex ids.
og_error_t og_intersection(
og_t *res,
const og_t *left,
const og_t *right,
og_vector_int_t *edge_map1,
og_vector_int_t *edge_map2
);
An edge (u, v) is kept as often as the operand that has it least often; the result has as many vertices as the larger graph. Edges are listed in decreasing (from, to) order. edge_map1 and edge_map2 give, for every edge of left and of right, the result edge it became, or -1 when it is not in the intersection. Both graphs must be directed or both undirected. Attributes are not carried over.
- Parameters
resOutput: an uninitialisedog_t. The function creates the result graph; free it withdestroy.leftThe first graph.rightThe second graph.edge_map1Output (may be NULL): result edge id of every edge of left, -1 if dropped.edge_map2Output (may be NULL): result edge id of every edge of right, -1 if dropped.
- Returns
OG_SUCCESS, or the error code of the failure (see errors).- Errors
OG_EINVALThe operands are not all directed or all undirected.OG_ENOMEMMemory runs out.
- Complexity
- As
union. - Checked
- 240 random cases against python-igraph's intersection: edges in order and edge maps identical.
- C name
og_intersection- In notebooks
Og.Intersection- igraph 1.0
igraph_intersection- See also
intersection_many,union,difference
intersection_many#
Exact
Intersection of any number of graphs on shared vertex ids.
og_error_t og_intersection_many(
og_t *res,
const og_vector_ptr_t *graphs,
og_vector_int_list_t *edgemaps
);
As intersection for a vector of graph pointers: every edge is kept with its smallest multiplicity over the graphs, and edgemaps gives one map per graph (-1 for edges not kept). With more than two graphs the merge uses a heap. An empty vector gives the directed null graph. Attributes are not carried over.
- Parameters
resOutput: an uninitialisedog_t. The function creates the result graph; free it withdestroy.graphsVector of pointers to the graphs (constog_t*).edgemapsOutput (may be NULL): one edge map per graph; resized to the number of graphs.
- Returns
OG_SUCCESS, or the error code of the failure (see errors).- Errors
OG_EINVALThe operands are not all directed or all undirected.OG_ENOMEMMemory runs out.
- Complexity
- As
union_many. - Checked
- As
intersectionwith 2-4 operands, and 3 to 150 operands with edge maps in the independent check. - C name
og_intersection_many- In notebooks
Og.IntersectionMany- igraph 1.0
igraph_intersection_many- See also
intersection,union_many
difference#
Exact
Edges of one graph that are not in another, on shared vertex ids.
og_error_t og_difference(og_t *res, const og_t *orig, const og_t *sub);
The result has the vertices of orig. Each edge of sub removes one matching copy from orig, so parallel edges subtract by count; vertices of sub beyond orig's count play no role. The treatment of undirected self-loops and the order of the kept edges reproduce igraph's. The result keeps the graph and vertex attributes of orig, and every kept edge the attributes of the orig edge it comes from. Both graphs must be directed or both undirected.
- Parameters
resOutput: an uninitialisedog_t. The function creates the result graph; free it withdestroy.origThe graph to subtract from.subThe graph whose edges are removed.
- Returns
OG_SUCCESS, or the error code of the failure (see errors).- Errors
OG_EINVALThe operands are not all directed or all undirected.OG_ENOMEMMemory runs out.
- Complexity
- O(|V| + |E|) of both graphs together.
- Checked
- 240 random cases against python-igraph's difference (edge order, multi-edges, loops) and 220 attribute cases through a recording handler.
- C name
og_difference- In notebooks
Og.Difference- igraph 1.0
igraph_difference- See also
complementer,intersection
complementer#
Exact
Complement graph: the vertex pairs that are not joined.
og_error_t og_complementer(og_t *res, const og_t *graph, og_bool_t loops);
The result has the same vertices and an edge for every pair (ordered pair in a directed graph) that is not an edge of graph. With loops = true a vertex without a self-loop gets one. For every vertex the new edges are listed from the largest partner down. On a multigraph each extra copy of an edge also hides the next smaller partner, which is what igraph does. The graph and vertex attributes are kept.
- Parameters
resOutput: an uninitialisedog_t. The function creates the result graph; free it withdestroy.graphThe input graph.loopstrue: add self-loops where the graph has none.
- Returns
OG_SUCCESS, or the error code of the failure (see errors).- Errors
OG_ERANGEThe complement would have more edges than Open Graph supports.OG_ENOMEMMemory runs out.
- Complexity
- O(|V|^2).
- Checked
- 240 graphs up to 60 vertices, with and without loops, against python-igraph's complementer: edge order identical, multi-edge behaviour included; attributes as python-igraph keeps them.
- C name
og_complementer- In notebooks
Og.Complementer- igraph 1.0
igraph_complementer- See also
difference
Subgraphs
induced_subgraph#
Exact
Subgraph made of the selected vertices and every edge between them.
og_error_t og_induced_subgraph(
const og_t *graph,
og_t *res,
const og_vs_t vids,
og_subgraph_implementation_t impl
);
The kept vertices are renumbered 0, 1, ... in increasing original id; repeated ids count once. Attributes of the graph, of the kept vertices and of the kept edges are carried over.
impl chooses the method. OG_SUBGRAPH_COPY_AND_DELETE copies the graph and deletes the other vertices, keeping the surviving edges in their original order. OG_SUBGRAPH_CREATE_FROM_SCRATCH builds a new graph, listing for every kept vertex its kept edges in adjacency order. OG_SUBGRAPH_AUTO takes COPY_AND_DELETE when the selector names more than half as many vertices as the graph has, otherwise CREATE_FROM_SCRATCH. Both orders equal igraph's.
- Parameters
graphThe input graph.resOutput: an uninitialisedog_t. The function creates the result graph; free it withdestroy.vidsVertex selector with the vertices to keep.implOG_SUBGRAPH_AUTO,OG_SUBGRAPH_COPY_AND_DELETEorOG_SUBGRAPH_CREATE_FROM_SCRATCH.
- Returns
OG_SUCCESS, or the error code of the failure (see errors).- Errors
OG_EINVVIDvids names a vertex that is not in the graph.OG_EINVALimpl is not a known value.OG_ENOMEMMemory runs out.
- Complexity
- COPY_AND_DELETE: O(|V| + |E|). CREATE_FROM_SCRATCH: O(|V| + the degrees of the kept vertices).
- Checked
- 240 random graphs against python-igraph's induced_subgraph for all three methods: edge order and the source of every result edge identical. One deliberate difference: with an even number of self-loops at a vertex, CREATE_FROM_SCRATCH maps each loop's attributes once where igraph maps one twice and another not at all.
- C name
og_induced_subgraph- In notebooks
Og.InducedSubgraph- igraph 1.0
igraph_induced_subgraph- See also
induced_subgraph_map,induced_subgraph_edges,subgraph_from_edges,subgraph_implementation_t
og_t g, sub;
og_vector_int_t keep;
og_ring(&g, 6, OG_UNDIRECTED, false, true); /* the cycle 0-1-2-3-4-5-0 */
og_vector_int_init_int(&keep, 3, 0, 1, 2);
og_induced_subgraph(&g, &sub, og_vss_vector(&keep), OG_SUBGRAPH_AUTO);
/* sub: 3 vertices, edges 0-1 and 1-2 */
og_vector_int_destroy(&keep);
og_destroy(&sub);
og_destroy(&g);
induced_subgraph_map#
Exact
Induced subgraph, also returning how vertex ids map between the graph and the result.
og_error_t og_induced_subgraph_map(
const og_t *graph,
og_t *res,
const og_vs_t vids,
og_subgraph_implementation_t impl,
og_vector_int_t *map,
og_vector_int_t *invmap
);
Builds the same subgraph as induced_subgraph. map has one entry per vertex of graph: its id in the result, or -1 when it was not kept. invmap has one entry per vertex of the result: its original id. Either may be NULL.
- Parameters
graphThe input graph.resOutput: an uninitialisedog_t. The function creates the result graph; free it withdestroy.vidsVertex selector with the vertices to keep.implOG_SUBGRAPH_AUTO,OG_SUBGRAPH_COPY_AND_DELETEorOG_SUBGRAPH_CREATE_FROM_SCRATCH.mapOutput (may be NULL): result id of every original vertex, -1 if dropped.invmapOutput (may be NULL): original id of every result vertex.
- Returns
OG_SUCCESS, or the error code of the failure (see errors).- Errors
OG_EINVVIDvids names a vertex that is not in the graph.OG_EINVALimpl is not a known value.OG_ENOMEMMemory runs out.
- Complexity
- As
induced_subgraph. - Checked
- The same 240 cases as
induced_subgraph, with map and invmap checked for every method. - C name
og_induced_subgraph_map- In notebooks
Og.InducedSubgraphMap- igraph 1.0
igraph_induced_subgraph_map- See also
induced_subgraph
induced_subgraph_edges#
Exact
Ids of the edges whose two endpoints are both selected.
og_error_t og_induced_subgraph_edges(
const og_t *graph,
og_vs_t vids,
og_vector_int_t *edges
);
Lists, in increasing order, every edge with both ends among the selected vertices; self-loops at a selected vertex count. Repeated ids in the selector count once. No graph is built.
- Parameters
graphThe input graph.vidsVertex selector.edgesOutput: the edge ids, increasing; cleared first.
- Returns
OG_SUCCESS, or the error code of the failure (see errors).- Errors
OG_EINVVIDvids names a vertex that is not in the graph.OG_ENOMEMMemory runs out.
- Complexity
- O(k log k + d log k), k the number of selected vertices and d the sum of their degrees.
- Checked
- 240 random selections: the edge ids python-igraph's induced subgraph keeps, increasing.
- C name
og_induced_subgraph_edges- In notebooks
Og.InducedSubgraphEdges- igraph 1.0
igraph_induced_subgraph_edges- See also
induced_subgraph,subgraph_from_edges
subgraph_from_edges#
Exact
Subgraph made of the selected edges.
og_error_t og_subgraph_from_edges(
const og_t *graph,
og_t *res,
const og_es_t eids,
og_bool_t delete_vertices
);
Keeps the selected edges in their original order. With delete_vertices = true, vertices not touched by any selected edge are removed and the rest renumbered in increasing order; with false all vertices stay. Attributes of the graph and of the kept vertices and edges are carried over. Repeated edge ids count once.
- Parameters
graphThe input graph.resOutput: an uninitialisedog_t. The function creates the result graph; free it withdestroy.eidsEdge selector with the edges to keep.delete_verticesRemove the vertices no kept edge touches.
- Returns
OG_SUCCESS, or the error code of the failure (see errors).- Errors
OG_EINVEIDeids names an edge that is not in the graph.OG_ENOMEMMemory runs out.
- Complexity
- O(|V| + |E|).
- Checked
- 240 random edge selections (with repeats) for both values of delete_vertices against python-igraph's subgraph_edges, edge order identical.
- C name
og_subgraph_from_edges- In notebooks
Og.SubgraphFromEdges- igraph 1.0
igraph_subgraph_from_edges- See also
induced_subgraph,induced_subgraph_edges
Products and transformations
compose#
Exact
Relational composition of two graphs.
og_error_t og_compose(
og_t *res,
const og_t *g1,
const og_t *g2,
og_vector_int_t *edge_map1,
og_vector_int_t *edge_map2
);
For every edge i -> k of g1 and every edge k -> j of g2 the result gets one edge i -> j, so parallel edges and loops multiply. In undirected graphs each edge can be walked either way. The result has the larger vertex count of the two. edge_map1 and edge_map2 give, for every result edge, the g1 edge and the g2 edge it came from. Both graphs must be directed or both undirected. Attributes are not carried over.
- Parameters
resOutput: an uninitialisedog_t. The function creates the result graph; free it withdestroy.g1The first graph (edges i -> k).g2The second graph (edges k -> j).edge_map1Output (may be NULL): the g1 edge of every result edge.edge_map2Output (may be NULL): the g2 edge of every result edge.
- Returns
OG_SUCCESS, or the error code of the failure (see errors).- Errors
OG_EINVALThe operands are not all directed or all undirected.OG_ENOMEMMemory runs out.
- Complexity
- O(|V1| + |V2| + |E1| + size of the result).
- Checked
- 240 random cases against python-igraph's compose, edge order identical; the edge maps are checked by hand (python-igraph does not return them).
- C name
og_compose- In notebooks
Og.Compose- igraph 1.0
igraph_compose- See also
graph_power,product
connect_neighborhood#
Exact
Joins every vertex to all vertices within a given distance, in place.
og_error_t og_connect_neighborhood(
og_t *graph,
og_int_t order,
og_neimode_t mode
);
For each vertex i in increasing order a breadth-first search (neighbours in increasing id) finds the vertices within order steps; i gets a new edge to each one at distance 2 or more, in the order found. Undirected graphs, and OG_ALL, add each pair once, from the smaller id. OG_OUT follows edges forward and adds i -> j; OG_IN follows them backward and also adds i -> j. An order below 2 changes nothing (with a warning). Existing edges stay as they are.
- Parameters
graphThe graph to change in place.orderLargest distance to connect.modeOG_OUT,OG_INorOG_ALL; undirected graphs always useOG_ALL.
- Returns
OG_SUCCESS, or the error code of the failure (see errors).- Errors
OG_EINVMODEmode is notOG_OUT,OG_INorOG_ALL.OG_EINVALorder is negative.OG_ENOMEMMemory runs out.
- Complexity
- O(|V| (|V| + |E|)) in the worst case: one breadth-first search of depth order per vertex.
- Checked
- Edge order identical to python-igraph's Lattice(nei=2,3) on 48 lattices, which add their edges through this function; 220 random graphs for orders 0-3 and every mode as edge sets. The direction of the edges added with
OG_INhas no oracle and is not tested against igraph. - C name
og_connect_neighborhood- In notebooks
Og.ConnectNeighborhood- igraph 1.0
igraph_connect_neighborhood- See also
graph_power
contract_vertices#
Exact
Merges vertices according to a mapping, in place.
og_error_t og_contract_vertices(
og_t *graph,
const og_vector_int_t *mapping,
const og_attribute_combination_t *vertex_comb
);
mapping[v] is the new id of vertex v; vertices with the same new id become one. The graph ends with (largest new id + 1) vertices, and every edge keeps its id with its endpoints renamed, so loops and parallel edges can appear. Graph and edge attributes are kept. With vertex_comb the vertex attributes of each merged group are combined (original ids in increasing order); with NULL they are dropped. The new structure is built aside and swapped in only when complete, so a failure leaves the graph unchanged.
- Parameters
graphThe graph to change in place.mappingNew id of every vertex.vertex_combHow to combine vertex attributes (may be NULL: drop them).
- Returns
OG_SUCCESS, or the error code of the failure (see errors).- Errors
OG_EINVALmapping does not have one entry per vertex.OG_EINVVIDmapping holds a negative id or one that is too large.OG_ENOMEMMemory runs out.
- Complexity
- O(|V| + |E|), plus the attribute combination.
- Checked
- Structure identical to python-igraph's contract_vertices on 240 cases; attribute combination checked against python-igraph on 210 cases with the attributes area's handler.
- C name
og_contract_vertices- In notebooks
Og.ContractVertices- igraph 1.0
igraph_contract_vertices- See also
simplify,induced_subgraph
graph_power#
Exact
Graph power: joins every pair of vertices at most k steps apart.
og_error_t og_graph_power(
const og_t *graph,
og_t *res,
og_int_t order,
og_bool_t directed
);
The result has the same vertices. Its edges are first one edge per adjacent pair, without loops or duplicates, in increasing (from, to) order, then the pairs at distance 2 to order, found as in connect_neighborhood. With directed = true on a directed graph distances follow the edge directions and the result is directed; otherwise it is undirected. order 0 gives no edges. The graph and vertex attributes are kept, the edge attributes are not.
- Parameters
graphThe input graph.resOutput: an uninitialisedog_t. The function creates the result graph; free it withdestroy.orderThe power k (not negative).directedDirected graphs: keep directions (true) or ignore them (false).
- Returns
OG_SUCCESS, or the error code of the failure (see errors).- Errors
OG_EINVALorder is negative.OG_ENOMEMMemory runs out.
- Complexity
- O(|V| (|V| + |E|)) in the worst case: one bounded breadth-first search per vertex.
- Checked
- 220 random graphs for orders 0-3, both values of directed, as edge sets against python-igraph's neighborhood() (python-igraph has no graph power); the edge order is Open Graph's own.
- C name
og_graph_power- In notebooks
Og.GraphPower- igraph 1.0
igraph_graph_power- See also
connect_neighborhood,compose
product#
Exact
Cartesian, lexicographic, strong, tensor or modular product of two graphs.
og_error_t og_product(
og_t *res,
const og_t *g1,
const og_t *g2,
og_product_t type
);
Vertex (u, v) of the product, u from g1 and v from g2, gets id u |V2| + v. Two product vertices are joined following the definitions in Hammack, Imrich and Klavžar (2011):
Cartesian: u = u' and v ~ v', or u ~ u' and v = v'. Lexicographic: u ~ u', or u = u' and v ~ v'. Strong: the Cartesian edges plus the tensor edges. Tensor: u ~ u' and v ~ v'. Modular: the tensor edges plus the pairs non-adjacent in both graphs (u != u', v != v').
The definitions are applied edge by edge, so parallel edges and loops of the operands carry over. The modular product needs simple graphs. Both graphs must be directed or both undirected. The edge order is Open Graph's own and was not compared with igraph. Attributes are not carried over.
- Parameters
- Returns
OG_SUCCESS, or the error code of the failure (see errors).- Errors
OG_EINVALThe operands are not all directed or all undirected.OG_EINVALtype is unknown, or the modular product gets a graph with loops or parallel edges.OG_ERANGEThe product would have more vertices than Open Graph supports.OG_ENOMEMMemory runs out.
- Complexity
- O(|V1| |V2| + size of the result); the modular product O(|V1|^2 |V2|^2) for the complement part.
- Checked
- python-igraph has no product: 220 pairs of simple graphs as edge sets against networkx (BSD, used as a black box) for all five types; directed modular products and multigraph operands checked against the edge-count formulas. Edge order not compared.
- C name
og_product- In notebooks
Og.Product- igraph 1.0
igraph_product- See also
product_t,rooted_product
rooted_product#
Exact
Rooted product: a copy of g2 hung on every vertex of g1 by its root.
og_error_t og_rooted_product(
og_t *res,
const og_t *g1,
const og_t *g2,
og_int_t root
);
Vertex (u, v), u from g1 and v from g2, gets id u |V2| + v. For every vertex u of g1 the result holds a copy of g2 on the vertices (u, *); then every edge (a, b) of g1 joins the root copies (a, root) and (b, root) (Godsil and McKay 1978). Both graphs must be directed or both undirected. The edge order is Open Graph's own: the copies of g2 first, then g1's edges. Attributes are not carried over.
- Parameters
resOutput: an uninitialisedog_t. The function creates the result graph; free it withdestroy.g1The graph whose vertices carry the copies.g2The graph that is copied.rootThe vertex of g2 used to attach each copy.
- Returns
OG_SUCCESS, or the error code of the failure (see errors).- Errors
OG_EINVALThe operands are not all directed or all undirected.OG_EINVVIDroot is not a vertex of g2.OG_ERANGEThe product would have more vertices than Open Graph supports.OG_ENOMEMMemory runs out.
- Complexity
- O(|V1| |V2| + |V1| |E2| + |E1|).
- Checked
- Undirected cases as edge sets against networkx's rooted_product (220 pairs, random roots); directed and multigraph operands by the edge count |V1| |E2| + |E1|. Edge order not compared.
- C name
og_rooted_product- In notebooks
Og.RootedProduct- igraph 1.0
igraph_rooted_product- See also
product
linegraph#
Exact
Line graph: one vertex per edge, joined when the edges meet.
og_error_t og_linegraph(const og_t *graph, og_t *linegraph);
Vertex i of the result is edge i of the graph. Directed graphs (Harary and Norman 1960): an edge j -> i for every edge j that ends where edge i starts; a self-loop thus gets one loop. Undirected graphs: two edges are joined once for every endpoint they share (a self-loop has two), so edges sharing both ends are joined twice, and every self-loop also gets one loop of its own. Edge order equals igraph's. Attributes are not carried over.
- Parameters
graphThe input graph.linegraphOutput: an uninitialisedog_t. The function creates the result graph; free it withdestroy.
- Returns
OG_SUCCESS, or the error code of the failure (see errors).- Errors
OG_ENOMEMMemory runs out.
- Complexity
- O(|V| + |E| + size of the result); the result has about the sum of the squared degrees in edges.
- Checked
- 240 random graphs (loops, multi-edges, both directednesses) against python-igraph's linegraph, edge order identical.
- C name
og_linegraph- In notebooks
Og.Linegraph- igraph 1.0
igraph_linegraph- See also
induced_subgraph_edges
mycielskian#
Exact
Applies the Mycielski construction k times.
og_error_t og_mycielskian(const og_t *graph, og_t *res, og_int_t k);
One step on a graph with n vertices v_0 .. v_(n-1) adds a shadow u_i = n + i for every vertex and a hub w = 2n. Edges: the original ones, then for every edge (v_a, v_b) the edges (v_a, u_b) and (u_a, v_b), then (u_i, w) for every i. Each step raises the chromatic number by one and keeps a triangle-free graph triangle-free (Mycielski 1955). Special cases: the null graph becomes one vertex, a single vertex becomes one edge. The size is checked before anything is built. Directed graphs follow the same rules. Attributes are not carried over.
- Parameters
graphThe input graph.resOutput: an uninitialisedog_t. The function creates the result graph; free it withdestroy.kNumber of steps (not negative); 0 copies the graph.
- Returns
OG_SUCCESS, or the error code of the failure (see errors).- Errors
OG_EINVALk is negative.OG_ERANGEThe result would have more vertices or edges than Open Graph supports.OG_ENOMEMMemory runs out.
- Complexity
- O(size of the result): each step maps n vertices and m edges to 2n + 1 vertices and 3m + n edges.
- Checked
- python-igraph has no Mycielskian: 220 simple undirected graphs for 0-2 steps as edge sets against networkx's mycielskian, and the Mycielski graphs from the null graph against networkx's mycielski_graph(1..5); edge order as igraph lists its Mycielski graphs (up to order 6).
- C name
og_mycielskian- In notebooks
Og.Mycielskian- igraph 1.0
igraph_mycielskian- See also
vertex_coloring_greedy,clique_number
simplify#
Exact
Removes parallel edges, self-loops or both, in place.
og_error_t og_simplify(
og_t *graph,
og_bool_t remove_multiple,
og_bool_t remove_loops,
const og_attribute_combination_t *edge_comb
);
With remove_multiple the graph keeps one edge per (from, to) pair, listed in increasing (from, to) order (undirected: smaller end first). With remove_loops self-loops go. When only loops are removed the other edges keep their order and ids shift down. If the graph is already known to have no parallel edges (or no loops) it is not touched for them.
Graph and vertex attributes are kept. With edge_comb the attributes of merged edges are combined (the merged edges in increasing id); with NULL edge attributes are dropped when parallel edges are merged, and kept when only loops go. The new structure is built aside and swapped in only when complete, so a failure leaves the graph unchanged.
- Parameters
graphThe graph to change in place.remove_multipleMerge parallel edges into one.remove_loopsDelete self-loops.edge_combHow to combine the attributes of merged edges (may be NULL).
- Returns
OG_SUCCESS, or the error code of the failure (see errors).- Errors
OG_ENOMEMMemory runs out.
- Complexity
- O(|V| + |E|), plus the attribute combination.
- Checked
- 240 random graphs for every flag combination plus heavy multigraphs against python-igraph's simplify: edge order and the ids merged into each edge identical; attribute combination checked against python-igraph on 210 cases.
- C name
og_simplify- In notebooks
Og.Simplify- igraph 1.0
igraph_simplify- See also
contract_vertices
og_t g;
og_small(&g, 3, OG_UNDIRECTED, 0,1, 1,0, 1,1, 1,2, -1);
og_simplify(&g, true, true, NULL); /* merge parallel edges, drop loops */
/* g now has the edges 0-1 and 1-2 */
og_destroy(&g);
reverse_edges#
Exact
Reverses the direction of the selected edges, in place.
og_error_t og_reverse_edges(og_t *graph, const og_es_t eids);
Each occurrence of an edge in the selector reverses it once, so an edge listed twice ends as it was. Edge ids and all attributes stay. Undirected graphs are left unchanged. Selecting all edges takes a constant-time path: the stored tail and head columns and the in- and out-adjacency tables trade places. Otherwise the new structure is built aside and swapped in only when complete, so a failure leaves the graph unchanged.
- Parameters
graphThe graph to change in place.eidsEdge selector with the edges to reverse.
- Returns
OG_SUCCESS, or the error code of the failure (see errors).- Errors
OG_EINVEIDeids names an edge that is not in the graph.OG_ENOMEMMemory runs out.
- Complexity
- O(1) for all edges; O(|V| + |E|) otherwise.
- Checked
- 240 random graphs with random edge lists against python-igraph's reverse_edges; the all-edges path checked equal to reversing the explicit list of every edge.
- C name
og_reverse_edges- In notebooks
Og.ReverseEdges- igraph 1.0
igraph_reverse_edges- See also
simplify