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

Link to this type

constraint()

@type constraint() :: :< | :<= | :== | :>= | :> | :"abs==" | :"all!=" | :no_overlap
@type t() :: %Exhort.SAT.Constraint{defn: term(), res: term()}

Link to this section Functions

Link to this function

all_different(list, opts \\ [])

@spec all_different(list(), Keyword.t()) :: t()

Create a constraint that ensures each item in the list is different in the solution.

@spec bool_and(list()) :: t()

Create longical and constraint on the list of booleans.

@spec bool_or(list()) :: t()

Create a constraint that requires one of the booleans in the list to be true.

Link to this function

implication(bool1, bool2)

Add an implication constraint where bool1 implies bool2.

Link to this macro

new(expr, opts \\ [])

(macro)

Define a bounded constraint.

Link to this function

no_overlap(list, opts \\ [])

@spec no_overlap(list(), Keyword.t()) :: t()

Create a constraint that ensures no overlap among the variables.