Skip to content

has_edge_from

Syntax

has_edge_from(network, source_node_id, dest_node_id) 

Parameters

network
The network in which to look for an edge.
source_node_id
The ID of the source node to find an edge on.
dest_node_id
The ID of the destination node to find an edge on.

Returns

1 (true) if an edge is found, and 0 (false) otherwise.

Description

If there is an edge in a network between the node ID parameters, returns 1 (true). Otherwise, returns 0 (false).

Note

If the network is directed, and an edge is added from node A to node B, has_edge_from(network, A, B) will return true, and has_edge_from(network, B, A) will return false. If the network was undirected instead, both would return true. This is because an edge from B → A in a directed network is treated separately from an edge from A → B, but in an undirected network, they're the same.

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 {
        add_edge(my_network, 1, 2)
        print("1 == ", has_edge_from(my_network, 1, 2))
        print("0 == ", has_edge_from(my_network, 2, 1))

        add_edge(my_network, 2, 1)
        print("1 == ", has_edge_from(my_network, 1, 2))
        print("1 == ", has_edge_from(my_network, 2, 1))

        delete_edge(my_network, 1, 2)
        print("0 == ", has_edge_from(my_network, 1, 2))
        print("1 == ", has_edge_from(my_network, 2, 1))

        wait(0)
        default(Excluded)
    }
}

See Also