Skip to content

numeric

Syntax

<scope> numeric <variable_name>
<scope> numeric <variable_name1> <variable_name2>...

Parameters

<scope>

The scope of the variable being declared. Valid values for scope are shared and agent.

Important

For agent-scoped variables, table and list_table variable types are currently disabled, as they would be extremely memory-intensive with fairly ordinary numbers of agents.

<variable_name>
A name to give the newly declared variable. If multiple are present, they must be separated by a space. Variable names must start with a letter and contain no symbols.

Description

Defines a variable that holds a double-precision, floating point value.

Examples

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

variables {
    agent numeric my_num

    shared numeric first_agent_id
    shared numeric second_agent_id
}

startup {
    my_num = 999

    # Spawn two agents for use in the simulation. Track their IDs so that we
    # can send them to different states in the condition.
    first_agent_id = spawn_agent()
    second_agent_id = spawn_agent()
}

condition TEST {
    start_state = Start

    state Start {
        next_if(FirstAgentState, id() == first_agent_id)

        wait(24)
        default(SecondAgentState)
    }

    state FirstAgentState {
        print("First agent has entered first agent state!")

        print("First agent my_num is: ", my_num)
        my_num = -1
        print("First agent my_num is now: ", my_num)

        wait(0)
        default(Excluded)
    }

    state SecondAgentState {
        print("Second agent has entered second agent state!")

        print("Second agent my_num is: ", my_num)
        my_num = -1.7
        print("Second agent my_num is now: ", my_num)

        wait(0)
        default(Excluded)
    }
}

Prints the following:

First agent has entered first agent state!
First agent my_num is: 999
First agent my_num is now: -1
Second agent has entered second agent state!
Second agent my_num is: 999
Second agent my_num is now: -1

See Also