Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bollwyvl/k3
a fluent API for kiwi.js constraints
https://github.com/bollwyvl/k3
Last synced: 26 days ago
JSON representation
a fluent API for kiwi.js constraints
- Host: GitHub
- URL: https://github.com/bollwyvl/k3
- Owner: bollwyvl
- License: bsd-3-clause
- Created: 2015-08-24T03:36:54.000Z (over 9 years ago)
- Default Branch: gh-pages
- Last Pushed: 2015-08-24T03:44:31.000Z (over 9 years ago)
- Last Synced: 2024-10-15T16:11:00.932Z (about 2 months ago)
- Language: JavaScript
- Homepage: http://bollwyvl.github.io/k3/
- Size: 258 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-starred - bollwyvl/k3 - a fluent API for kiwi.js constraints (others)
README
# 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.```javascript
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());
```## API
### `k3 = K3()`
Create a system of constraints.### `k3()`
Optimize a system of constraints.### `variable = k3.variable("name")`
Get/create a named variable.#### `variable()`
Get the value of a variable.#### `variable.variable()`
Get the kiwi variable.#### `variable.named()`
Get the name of the variable.#### `variable.mul(coefficient)`
Return `[coefficient, variable]`, suitable for passing to kiwi.### `k3.eq([name], leftHand, rightHand)`
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.### `k3.ge([name], leftHand, rightHand)`
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.### `k3.le([name], leftHand, rightHand)`
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.[kiwi]: https://github.com/nucleic/kiwi/tree/feature-js