k3: a fluent API for kiwi constraints
kiwi solves systems of linear constraints. k3 adds a bit of syntactic sugar to make working with them easier.
var k3 = K3(),
v = k3.variable,
a = v("a"),
b = v("b"),
c = v("c"),
d = v("d");
// make some constraints
k3.ge(b, [a]) // b > a
.le(b, [c]) // b < c
.eq(d, [a, c.mul(2)]); // d = a + 2*c
// suggest some values
k3.eq(a, 2)
.eq(d, 11);
// solve!
k3();
// get the values back out
console.log(a(), b(), c(), d());
Create a system of constraints.
Optimize a system of constraints.
Get/create a named variable.
Get the value of a variable.
Get the kiwi variable.
Get the name of the variable.
Return [coefficient, variable]
, suitable for passing to kiwi.
Constrain leftHand
to be equal to rightHand
.
rightHand
can be a number, or an array of variables (or multiples of variables). If a number, this value will be suggested to the solver,
rather than constrained.
If name
is provided, any constraints previously created with that
name
will be removed before adding this constraint.
Constrain leftHand
to be greater than or equal to rightHand
.
rightHand
must be an array of variables (or multiples of variables).
If name
is provided, any constraints previously created with that
name
will be removed before adding this constraint.
Constrain leftHand
to be greater than or equal to rightHand
.
rightHand
must be an array of variables (or multiples of variables).
If name
is provided, any constraints previously created with that
name
will be removed before adding this constraint.