... | ... | @@ -59,12 +59,25 @@ NDL model defines structure of the constraint programming problem and is compile |
|
|
## Query
|
|
|
|
|
|
NDL query is a Prolog like program, containing rules, with bodies consisting of goals from a predefined set of clauses:
|
|
|
* NDL model clauses: `constraint/2`, `constraint_range/2`, `variable/2`, `new_value/2`, `constraint/3`, `is_satisfied/3`
|
|
|
* binary arithmetic operations: +, -, /, *, div, mod
|
|
|
* binary arithmetic comparisons: =, >=, >, <, <=
|
|
|
* heads of the rules defined in the query itself (allows recursion)
|
|
|
* NDL model clauses: `constant/2`, `variable/(2..6)`, `constraint/3`, `range_element/2`
|
|
|
* binary arithmetic operations: `+/2`, `//2`, `-/2`, `*/2`, `mod/2`, `min/2`, `max/2`, `abs/1`
|
|
|
* uses Prolog `is` notation
|
|
|
* only binary and unary expressions are allowed
|
|
|
* dividing by `0` gives `0`
|
|
|
* at least one of the arguments has to be of type `range`, constants are promoted to `ranges` automatically
|
|
|
* binary arithmetic comparisons: `=/2`, `>=/2`, `>/2`, `</2`, `<=/2`
|
|
|
* loops in form of `for_each(+Generator:model_clause, +Query:query)`
|
|
|
* first argument is a non-deterministic model clause, i.e. `variable/(2..6)`, `constraint/3`, `range_element/2`
|
|
|
* `Generator`'s variables are available in the `Query`
|
|
|
* queries are run in order, independently, it the query fails on the specific variable assignment, it continues with the next assignment
|
|
|
* conditions `if(+Condition:query,+Then:query)` and `if(+Condition:test,+Then:query,+Else:query)`
|
|
|
* `Condition` contains only one term
|
|
|
* if `Condition` succeeds, `Then` query is evaluated
|
|
|
* if `Condition` fails and `Else` query is provided, then `Else` is evaluated
|
|
|
* if `Condition` fails and `Else` query is not provided, then nothing happens and expression succeeds (non-standard in the Prolog world)
|
|
|
* operation operating on the current solution:
|
|
|
* `get_value(+Index:variable_index, -Value:integer)` - gets the variable's current value
|
|
|
* `set_value(+Index:variable_index, +Value:integer)` - set the variable's value to `Value`
|
|
|
* `swap_values(+Index1:variable_index, +Index2:variable_index)` - swap values of two variables
|
|
|
* `flip_variable(+Index:variable_index, +HeadsValue:integer, +TailsValue:integer)` - if variable has value `HeadsValue` or `TailsValue`, sets the value to the other one. Otherwise fails.
|
|
|
|