gtopt/pampl_parser.hpp file

Parser for pseudo-AMPL (.pampl) user constraint files.

This module provides PamplParser::parse_file(), which reads a .pampl file and converts it to a vector of UserConstraint objects ready to be merged into a System::user_constraint_array.

PAMPL file format

A .pampl file contains a sequence of constraint definitions, each terminated by a semicolon. Blank lines and # / // comments are ignored everywhere.

Formal grammar (pseudo-BNF):

pampl_file      := constraint_stmt*

constraint_stmt := constraint_hdr? constraint_expr ';'

constraint_hdr  := ['inactive'] 'constraint' IDENT [STRING] ':'

constraint_expr := <same syntax as UserConstraint::expression>
                   e.g. generator('G1').generation + ... <= 300,
                        for(stage in {1,2})

STRING          := '"' ... '"'  |  '\'' ... '\''
IDENT           := [A-Za-z_][A-Za-z0-9_]*

Examples

# System peak capacity limit
constraint gen_pair_limit "Combined generation limit for G1 and G2":
  generator('G1').generation + generator('G2').generation <= 300,
  for(stage in {1,2,3}, block in 1..24);

# Inactive during tuning
inactive constraint flow_check:
  line('L1').flow <= 200;

# No header — uid is auto-assigned
sum(generator(all).generation) <= 1000;

UID assignment

If the file is merged into a system that already has constraints with UIDs 1–N, pass start_uid = N + 1 so there are no collisions. When no header is present the name is auto-generated as "uc_<uid>".

Namespaces

namespace gtopt

Classes

class gtopt::PamplParser
Parser for pseudo-AMPL constraint files (.pampl)
struct gtopt::PamplParseResult
Result of parsing a PAMPL file or string.