TABLES

From ASCEND
Revision as of 11:06, 17 February 2026 by Jpye (talk | contribs)
Jump to navigation Jump to search

This document captures the current v0.5 concept for tabular data syntax in ASCEND. It is a language design draft, not a complete implementation specification.

Goals

  • Keep ASCEND’s explicit, type-aware style.
  • Minimize repetitive boilerplate for indexed data.
  • Support both compact in-model data and external datasets.
  • Preserve dimensional/unit checking as a first-class feature.

New Declarations

1) TABLE

Intended for two-axis table data mapped to existing arrays.

TABLE <array_name>[<row_index_set>,<col_index_set>] [POSITIONAL] [DEFAULT <expr>];
...
END TABLE;

Rules:

  • Default (non-POSITIONAL) form:
 * first row contains column labels.
 * subsequent rows contain row label followed by row values.
 * : after row label is optional.
  • Sparse form:
 * no header row required.
 * each row uses <col_label>=<value> pairs.
 * DEFAULT <expr> indicates unspecified cells are filled with the default.
 * POSITIONAL form:
 * no row/column labels in body.
 * values are interpreted positionally from set ordering.
  • Row separator:
 * newline is the natural row separator.
 * ; immediately before newline joins lines, so one logical row can wrap across physical lines.

Examples:

Dense form, with row and column labels, as well as the central data array:

TABLE ship_cost[customer,facility];
      1 2 3
    1 2 4 5
    2 3 1 2
    3 4 2 1
    4 5 3 2
END TABLE;
TABLE ship_cost[customer,facility];
             Sydney 'New York' Rome
    Alan     2      4          5
    Bernhard 3      1          2
    Colin    4      2          1
    David    4      5          3
END TABLE;

Sparse form, as flagged via the DEFAULT value term:

TABLE ship_cost[customer,facility] DEFAULT 0;
    1: 1=2 2=4 3=5
    2: 1=3 2=1 3=2
    4 1=5 3=2
END TABLE;

'Positional' form, where row and column labels are implied (integer sequence):

TABLE c[city,city] POSITIONAL;
    0 89 22 11
    21 0 94 77
    11 19 0 35
    79 33 99 0
END TABLE;

2) VALUES

Intended for vectors and sparse ND assignments.

VALUES <array_name>[<index_set>, ...] [DEFAULT <expr>];
   <k1>[,<k2>...] = <value>;
   ...
END VALUES;

Example:

VALUES demand[customer] DEFAULT 0;
    1 = 45;
    2 = 30;
    3 = 40;
    4 = 35;
END VALUES;

3) DATASET

Intended for external files, especially large time-series and operational data.

DATASET <dataset_name> FROM "file.csv";
INDEX <set_name> FROM COLUMN <col_name> IS_A <type_name>;
<array_name>[<index_set>] FROM COLUMN <col_name> [{<units>}] [IS_A <type_name>];
...
END DATASET;

Example:

DATASET ops FROM "ops.csv";
    INDEX t FROM COLUMN timestamp IS_A time;
    load[t] FROM COLUMN load_MW {MW};
END DATASET;

Notes:

  • DATASET map targets must be indexed (name[...]).
  • If IS_A is omitted on a map line, a default type (planned: real_constant, dimensionless) can be assumed during compile/lowering.

Labels and Quoting

  • Identifier-like labels can be unquoted.
  • Labels with spaces/punctuation require symbol-constant quoting: 'New York'

Units Concept

  • Unit metadata may come from file metadata/rows (future data-handler behavior).
  • Inline units in DATASET mappings are allowed and should be checked for compatibility against declared type dimensions.