list_table
Declares one or more list_table variables for use in the FRED program
Synopsis
list_table <variable1> <variable2> ...
Description
A list_table
statement declares one or more list_tables. List_tables must be defined within
a variables block.
Like dictionaries in python, list_tables are mutable associative arrays consisting of key-value pairs that can be accessed via the key of each pair. Each key is paired with a single value.
Keys are real numbers, and values are lists.
A list_table variable is global and may be accessed or changed by any agent.
List_table variables are always initialized as empty lists.
List_table items can be set using the action set
or by an assignment statement:
set(list_table_name, key, list-value)
list_table_name[key] = list-value
List_table items can be accessed using the function lookup_list
or by using
the notation shown:
my_list = lookup_list(list_table_name, key)
my_list = list_table_name[key]
When looking up list-values in a table, an error occurs if the key does not exist.
List_table items can be erased using the action erase
:
erase(list_table_name, key)
All list_table items can be erased using the action clear
:
clear(list_table_name)
Options
Table variables are declared with a variables
block and may include
optional properties output
and output_interval
.
variables {
list_table <table_name>
<list_table_name>.output = 0/1
<list_table_name>.output_interval = <N_days>
}
If the output
property is defined, the list_table is output to a
file named
<path-to-job-results>/RUN<n>/LIST/<list_table_name>.txt
(same as global lists).
If the output_interval
property is defined, the list_table is output
every N
simulation days to a file named
<path-to-job-results>/RUN<n>/LIST/<list_table_name>-<day>.txt
List_table output files have one value per line and follow the format:
KEY_1
LENGTH_1
LIST_ITEM_11
...
LIST_ITEM_1(LENGTH_1)
KEY_2
LENGTH_2
LIST_ITEM_21
...
LIST_ITEM_2(LENGTH_2)
...
The keys are sorted in ascending order.
List_table output files can be retrieved using the fred_get_list
command.
Examples
The following declares a list_table variable called lookup_table1
.
The table is output to a file at the end of a run.
variables {
list_table lookup_table1
lookup_table1.output = 1
}
See Also
clear(), default_value, erase(), global, global_list, lookup_list(), set(), table