NAME

lp_parse - A modeling language front-end for MILP solver lp_solve.


SYNOPSIS

lp_parse [options] [modelfile] [outputfile]


DESCRIPTION

lp_parse is a modeling language parser for MILP models. lp_parse does not solve the model, that is left for lp_solve to do. lp_solve is a MILP solver developed by M.R.C.M. Berkelaar at the Eindhoven University of Technology.

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.


OPTIONS

-? --help
Print some help and exit.

-d N --debug N
Set debug level to N. Level 1 gives warnings of undeclared variables.

-i file --input file
Read data from file. If file equals ``-'', read from standard input (no questions asked). If file does not begin with ``/'', the path of the model is prepended to it. The default is to ask from the user. Data source can be defined also in the model.

-v --version
Print version number and exit.

If outputfile is not given, lp_parse prints output to the standard output. If modelfile is not given, lp_parse reads the model from the standard input.


SYNTAX

A lp_parse MILP model consists of

  1. Declarations

  2. Target function

  3. Constraints

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

model
  {
    ("index:" | "const:" | "var:" | "input:")
    {declaration}
  }
  ("min:" | "max:") expression
  {
    "s.t."
    {expression ("=" | "<" | ">") expression}
  }

declaration declares an index, constant, variable or defines the data source.

index
An index is declared with statement

  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.

expression
An expression is either evaluatable or unevaluatable. Unevaluatable expressions can be used only in the target function or in constraints. An evaluatable expression is defined as

  (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)}

constant
A constant is declared with statement

  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.

variable
A variable declaration is similar to constant declaration except that a variable cannot be initialized.

data source
Data source declaration ``?'' means asking from the user, ``-'' means reading from the standard input, other strings are taken to define a file. If the string does not begin with ``/'', the path of the model is prepended to it.

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.

constraint
A constraint is defined as

  {expression ("=" | "<" | ">") expression}
 
 where expression -- is either evaluatable or unevaluatable. 

function
A function is defined as

  ["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.


EXAMPLE

An example is given in the accompanied files 4r.lps and 4r.dat.


BUGS


TODO

Define the syntax using the language of some parser generator.


SEE ALSO

lp_solve


ACKNOWLEDGEMENTS


CONTRIBUTED BY

 Ari Jolma
 Helsinki University of Technology
 Laboratory of Water Resources Engineering
 Building W
 02150 Espoo
 Finland
 E-mail: ajolma@ahti.hut.fi


STATUS

Use at own risk. Bug reports are welcome, as well as success stories.