Network Types and Interface
Networks in Erdos are graphs with the additional capability of storing properties associated to vertices, edges, and to the graph itself. Edge and vertex properties are nothing else than edge and vertex maps with a name associated to them. Erdos defines some interface methods and their convenient short form equivalents to work with networks and properties.
julia> using Erdos
julia> g = Network(10, 20) # create erdos-renyi random network
julia> add_edge!(g, 1, 2); # add edge (1, 2) if it doesn't exists
julia> eprop!(g, "w", e -> rand()) # add edge property named "w"
Network(10, 20) with [] graph, [] vertex, ["w"] edge properties
julia> vprop!(g, "x", v -> [1,1]) # add vertex property named "x"
Network(10, 20) with [] graph, ["x"] vertex, ["w"] edge properties
julia> eprop(g, 1, 2, "w")
0.8959648919973169
julia> writenetwork("mygraph.graphml", g) # save graph and properties in .graphml format
Property Interface
Erdos.add_edge_property!
— Methodadd_edge_property!(g, name, T)
add_edge_property!(g, name, emap)
Add the edge property name
to g
.
If a type T
is given as an input, an edge map with valtype T
is created and stored into g
.
As an alternative, an existing edge map emap
can be stored into g
.
eprop!
is the short form of this function.
Example
g = random_regular_graph(10, 3, Network)
add_edge_property!(g, "weight", Float64)
# or equivalently
eprop!(g, "weight", Float64)
Erdos.add_vertex_property!
— Methodadd_vertex_property!(g, name, T)
add_vertex_property!(g, name, vmap)
Add the vertex property name
to g
.
If a type T
is given as an input, a vertex map with valtype T
is created and stored into g
.
As an alternative, an existing vertex map vmap
can be stored into g
.
vprop!
is the short form of this function.
Erdos.edge_property
— Methodedge_property(g, name)
Return an edge map corresponding to property name
of edges in g
.
edge_property(g)
Returns a dictionary with elements property_name => edge_map
.
edge_property(g, e)
edge_property(g, u, v)
Returns a dictionary of the form name => val
containing all the properties associated to edge e
.
edge_property(g, e, name)
edge_property(g, u, v, name)
Equivalent to edge_property(g, e)[name]
eprop
is the short form of this function.
Erdos.eprop
— FunctionSee edge_property
Erdos.eprop!
— FunctionErdos.gprop
— FunctionSee graph_property
Erdos.gprop!
— FunctionErdos.graph_property
— Methodgraph_property(g, name)
Return the property name
of g
.
graph_property(g)
Returns a dictionary with elements property_name => property_value
gprop
is the short form of this function.
Erdos.has_edge_property
— Methodhas_edge_property(g, name)
has_edge_property(g, name, e)
Check if network g
has an edge property named name
. The second method checks also if edge e
has an assigned value for that property.
has_eprop
is the short form of this function.
Erdos.has_eprop
— FunctionErdos.has_gprop
— FunctionErdos.has_graph_property
— Methodhas_graph_property(g, name)
Check if network g
has a graph property named name
.
has_gprop
is the short form of this function.
Erdos.has_vertex_property
— Methodhas_vertex_property(g, name, v)
Check if network g
has a vertex property named name
. The second method checks also if vertex v
has an assigned value for that property.
has_vprop
is the short form of this function.
Erdos.has_vprop
— FunctionErdos.idx
— Methodidx(e::AIndexedEdge)
Returns the index of edge e
.
Erdos.rem_edge_property!
— Methodrem_edge_property!(g, name)
Remove the edge property name
from g
.
rem_eprop!
is the short form of this function.
Erdos.rem_eprop!
— FunctionErdos.rem_gprop!
— FunctionErdos.rem_graph_property!
— Methodrem_graph_property!(g, name)
Remove the property name
from g
.
rem_gprop!
is the short form of this function.
Erdos.rem_vertex_property!
— Methodrem_vertex_property!(g, name)
Remove the vertex property name
from g
.
rem_vprop!
is the short form of this function.
Erdos.rem_vprop!
— FunctionErdos.set_graph_property!
— Methodset_graph_property!(g, name, x)
Set the property name
to value x
to g
. Creates the property if it doesn't exist. gprop!
can be conveniently used as a short form of this function.
Example
g = Network(10, 20)
set_graph_property!(g, "label", "My Network")
# or equivalently
gprop!(g, "label", "My Network")
Erdos.vertex_property
— Methodvertex_property(g, name)
Return an vertex map corresponding to property name
of vertices in g
.
vertex_property(g)
Returns a dictionary with elements property_name => vertex_map
.
vertex_property(g, v)
Returns a dictionary of the form name => val
containing all the properties associated to vertex v
.
vertex_property(g, v, name)
Equivalent to vertex_property(g, v)[name]
.
vprop
is the short form for this function.
Erdos.vprop
— FunctionSee vertex_property
Erdos.vprop!
— FunctionDefining new network types
In order to define a custom network type, e.g. MyNet <: ANetwork
, the corresponding interface methods have to be implemented. This is automatically done for custom network types having a props::PropertyStore
member. Take a look at src/factory/network.jl
and src/maps/property_store.jl
for an example.