Exhort.SAT.Constraint (Exhort v0.1.1)
A constraint on the model.
Suggestion
Consider using
Exhort.SAT.Expr
instead of using this module directly.
The binary constraints are:
:< | :<= | :== | :>= | :> | :"abs=="
The list constraints are:
:"all!=" | :no_overlap
The expression must include a boundary: <
, <=
, ==
, >=
, >
.
"x" < "y"
The components of the expressoin may be simple mathematical expressions,
including the use of +
and *
:
"x" * "y" = "z"
The sum/1
function may be used to sum over a series of terms:
sum("x" + "y") == "z"
The variables in the expression may be model variables or Elixir variables.
For example, where "x"
is a model variable (e.g., def_int_var(x, {0, 3}
))
and y
is an Elixir variable (e.g., y = 2
):
"x" < y
A for
comprehension may be used to generate list values:
sum(for {x, y} <- list, do: "x" * "y") == "z"
As a larger example:
y = 20
z = [{0, 1}, {2, 3}, {4, 5}]
Builder.new()
|> Builder.def_int_var("x", {0, 3})
|> Builder.constrain(sum(for {a, b} <- z, do: a * b) < "y")
|> Builder.build()
...
Link to this section Summary
Functions
Create a constraint that ensures each item in the list is different in the solution.
Create longical and constraint on the list of booleans.
Create a constraint that requires one of the booleans in the list to be true.
Add an implication constraint where bool1
implies bool2
.
Define a bounded constraint.
Create a constraint that ensures no overlap among the variables.
Link to this section Types
constraint()
@type constraint() :: :< | :<= | :== | :>= | :> | :"abs==" | :"all!=" | :no_overlap
Link to this section Functions
all_different(list, opts \\ [])
Create a constraint that ensures each item in the list is different in the solution.
bool_and(list)
Create longical and constraint on the list of booleans.
bool_or(list)
Create a constraint that requires one of the booleans in the list to be true.
implication(bool1, bool2)
Add an implication constraint where bool1
implies bool2
.
Define a bounded constraint.
no_overlap(list, opts \\ [])
Create a constraint that ensures no overlap among the variables.