lp_parse modeling language features separation of data from the model, multidimensional tables, mathematical expressions and three constructs for writing constraints: If, ForAll and Sum.
Each declaration and constraint must be written on one line in the input. A line can be continued by ending it with ``\''.
Everything after ``#'' on a line is ignored as a comment. Note that the comment can actually span to many lines if the line ends in ``\''.
(a|b) means a and b are alternatives
[a] means a is optional
{a} means a is repeated zero or more times
{ ("index:" | "const:" | "var:" | "input:") {declaration} } ("min:" | "max:") expression { "s.t." {expression ("=" | "<" | ">") expression} }
declaration declares an index, constant, variable or defines the data source.
symbol ["=" expression " .. " expression]
Symbols are case sensitive, they must contain only alphanumeric characters and they can't begin with number or similarly as reserved words. Reserved words are section names and function names.
The first expression is the default minimum value of the index and the second one is the default maximum value. Expressions are rounded to integers after evaluation.
(scalar | number | "(" expression ")") \ {("+" | "-" | "*" | "/") (scalar | number | \ "(" expression ")")} where scalar -- is a scalar constant or a single element of a multidimensional constant and is defined as symbol ["[" expression ("," expression) "]"]
An unevaluatable expression is defined as
{(scalar | number | "+" | "-" | "*" | "/" | ";" | \ "(" expression ")" | function)}
symbol["[" index' {"," index'} "]"] \ ["=" (expression | "{" expression {"," expression} "}")] where index' -- is defined as (index | expression [" .. " expression] | \ index "=" expression [" .. " expression])
If a constant is not initialized in the model, lp_parse expects to get a value for it next time it reads from the current input source. lp_parse reads data each time declaration mode changes. A table must be initialized completely within the model or with external data.
Data source should have a values separated with whitespace for each so far declared but uninitialized data variable. Constants are initialized with values read from the data source in the order of declaration. Tables are initialized by looping the rightmost index as the innermost loop. Datafiles can have comment lines.
{expression ("=" | "<" | ">") expression} where expression -- is either evaluatable or unevaluatable.
["If" | "ForAll" | "Sum"] \ "(" first_argument ";" expression ")"
where the syntax and meaning of the first argument depends on the function.
The first argument of an If-function is an expression, whose value is evaluated and the expression is output only if the evaluation rounds to an non-zero integer.
The first argument of ForAll and Sum -functions is a list of indexes
index'' {"," index''} where index'' is defined as {index | index "=" expression [" .. " expression]}
The expression part of the function is parsed possibly several times with looping the values of the indexes, the rightmost index defining the innermost loop.
Ari Jolma Helsinki University of Technology Laboratory of Water Resources Engineering Building W 02150 Espoo Finland E-mail: ajolma@ahti.hut.fi