Skip to content

indegree

Syntax

indegree(network, node_id)

Parameters

network
The network to act upon.
node_id
The ID of node to get the indegree for.

Returns

Returns the indegree of the node.

Description

Finds and returns the indegree of the specified node in a network.

Examples

simulation {
    start_date = 2020-Jan-01
    end_date = 2020-Jan-01
    locations = none
    default_model = none
}

network my_network {
    is_directed = 1
}

condition TestCondition {
    start_state = Excluded
    meta_start_state = MetaStart

    state MetaStart {
        # Make complete triangular graph
        add_edge(my_network, 1, 2)
        add_edge(my_network, 2, 1)

        add_edge(my_network, 2, 3)
        add_edge(my_network, 3, 2)

        add_edge(my_network, 3, 1)
        add_edge(my_network, 1, 3)

        # Add an extra edge hanging off the triangle
        add_edge(my_network, 1, 4)

        wait(0)
        default(PrintDegrees)
    }

    state PrintDegrees {
        print("2 == ", indegree(my_network, 1))
        print("2 == ", indegree(my_network, 2))
        print("2 == ", indegree(my_network, 3))
        print("1 == ", indegree(my_network, 4))

        wait(0)
        default(Excluded)
    }
}

See Also