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!Method
add_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)
source
Erdos.add_vertex_property!Method
add_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.

source
Erdos.edge_propertyMethod
edge_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.

source
Erdos.graph_propertyMethod
graph_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.

source
Erdos.has_edge_propertyMethod
has_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.

source
Erdos.has_vertex_propertyMethod
has_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.

source
Erdos.set_graph_property!Method
set_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")
source
Erdos.vertex_propertyMethod
vertex_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.

source

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