furlong v0.2.0 Furlong.Solver View Source
Elixir-port of the Kiwisolver; usage example below adapted from Kiwisolver docs.
Variables are represented by refs.
# create variables
x1 = make_ref()
x2 = make_ref()
xm = make_ref()
import Furlong.Solver
import Furlong.Constraint
# create system of in-/equalities
system =
new()
|> add_constraint(constraint(x1 >= 0))
|> add_constraint(constraint(x2 <= 100))
|> add_constraint(constraint(x2 >= x1 + 10))
|> add_constraint(constraint(xm == (x1 + x2) / 2))
|> add_constraint(constraint(x1 == 40), :weak)
|> add_edit_variable(xm, :strong)
|> suggest_value(xm, 60)
# query sytem for values assigned to variables
value?(system, x1)
value?(system, x2)
value?(system, xm)
# update edit variable value
system =
system |>
suggest_value(xm, 90)
# query values -- as above
value?(system, x1)
value?(system, x2)
value?(system, xm)
For further information, see overconstrained.io.
Link to this section Summary
Functions
Creates a new solver instance by adding a constraint to the given solver instance with :required
strength.
Creates a new solver instance by adding a constraint to the given solver instance. Default constraint strength is :required
.
:required
, :strong
, :medium
, :weak
can be passed as the second argument.
Returns a new solver instance, where the given variable is editable. Strength can be :strong
, :medium
, :weak
.
Creates a new, empty, solver instance, i.e. a system of in-/equalities.
Creates a new solver instance by removing the given constraint from the given solver instance.
Returns a new solver instance where the given variable is no longer editable.
Returns a new solver instance in which the given value is suggested for the given edit variable.
Looks up the value of the given variable in the given solver instance. Default value is 0.
Link to this section Functions
Creates a new solver instance by adding a constraint to the given solver instance with :required
strength.
Creates a new solver instance by adding a constraint to the given solver instance. Default constraint strength is :required
.
:required
, :strong
, :medium
, :weak
can be passed as the second argument.
Returns a new solver instance, where the given variable is editable. Strength can be :strong
, :medium
, :weak
.
Creates a new, empty, solver instance, i.e. a system of in-/equalities.
Creates a new solver instance by removing the given constraint from the given solver instance.
Returns a new solver instance where the given variable is no longer editable.
Returns a new solver instance in which the given value is suggested for the given edit variable.
Looks up the value of the given variable in the given solver instance. Default value is 0.