Table of contents
- Objective function
- Constraints
- Variables and compound variables
- Data
- Blocks
- Domains
- Functions and tuples
- Other things
Objective function
The objective function can be one of either "min" or "max", after the keyword, you can define whichever
expression
you wish to optimize.
Once the model is compiled, it will be ran through the solver and find the optimal
solution
which fits the constraints.
Some solvers allow you to also work on finding a satisfiable solution, which is a solution that fits the
constraints, not caring about the objective function. in that case, instead of writing the min/max keyword and objective function,
you can use the "solve" keyword.
Constraints
The formal model can follow a list of constraints, you can use one of <=, >=, =, <, > comparisons.
Some solvers like the simplex, do not allow for strict inequalities <, >.
The special keyword "for" can be used at the end of a constraint to create a constraint for each element that
you iterate over.
Variables and compound variables
The language has "two runtimes", the formal model and the compiled model. In the formal model you can define
variables whose name is
determined after the model is compiled (compound variables), variables whose value is replaced during
compilation
(for example a number), or normal variables which will be kept after the compilation is finished.
A compound variable is any variable with an underscore in it's name, the first part of the variable will be used
as
a prefix name, and the rest of the variable (split by the underscore) will be treated as an expression, and
evaluated as a string or number
You can omit the curly braces if the index is a number or a variable name, for other kind of expressions, they
are
needed.
Sometimes you might need to manually write a name of a variable which looks like a compound variable, in that
case
you can escape the name with a backslash. Example: "\x_hello"
Data
After the constraints, inside the "where" section you can define the data of the model, this data will be used
inside the constraints and
objective functions.
The ROOC language supports arrays, matrices, graphs, strings, numbers and boolean values.
To define a data constant, you can use the "let" keyword followed by the name of the constant and the value.
Expansion blocks
Expansion blocks are a special kind of "expression" that can be used to preprocess an expression, an example is the average block which, given a comma separated list of expressions, it will expand it to the average of all the expressions.
will be compiled to
There are different expansion blocks that can be used to expand the expressions, you can find them in the documentation.
Scoped expansion blocks
Another type of expansion blocks are the ones that have a scope connected to it, inside the scope, the action of
the
expansion block
will be applied to all the iterations that the scope has.
You can put more than one scope and it will behave like if they were nested inside each other.
will be compiled to
there are different scoped expansion blocks that can be used to expand the expressions, you can find them in the documentation.
Domains
After the data you can define in which domain each variable will be part of, those variables are the ones that
will
remain after the compilation is finished.
Every variable that will end up in the compiled model must be defined, you can use the "for" iteration like in
the
constraints to define compound variables.
The domains are "Real", "NonNegativeReal", "Boolean" and "IntegerRange".
You can define a minimum and maximum value for each domain except for the "Boolean" domain.
They are required for the "IntegerRange" domain, and optional for Real (which defaults to -inf and inf) and NonNegativeReal (which defaults to 0 and inf).
Functions and tuples
The ROOC langage has a set of builtin functions that can be used to manipulate data.
Those functions can be run anywhere in the model or data section.
The language also has support for tuples and tuples destructuring, you can destructure a tuple or array by
writing the name of the variables inside a parenthesis "(a,b,c)". Some builtin values are destructurable, like
arrays, tuples and graph edges.
will be compiled to
Other things
You can write comments in the model by using the "//" or "/* */" syntax, a model is structured (in this order) by the objective function, constraints, data and domains.