Liking cljdoc? Tell your friends :D

# clj-linear

A nice clojure api for doing linear programming. It uses Apache Commons Math under the covers. ## Usage

Put this in your lein depenencies:

``````[clj-linear "0.1.0-notyet"]
``````

``````  [clj-linear.core :as lp]
``````

Then you can use it like this:

``````(lp/minimize
(lp/expression (+ (* -2 :x) :y -5))
(lp/constraints
(<= (+ :x (* 2 :y)) 6)
(<= (+ (* 3 :x) (* 2 :y)) 12)
(>= :y 0)))

;; => {:x 4.0, :y 0.0}
``````

## Details

clj-linear uses two kinds of data under the covers.

### Expressions

An linear expression is a map of variables to coefficients. You can make it by hand, or with the `expression` macro. `clj-linear.expressions` has some useful code for manipulating linear expressions in this form.

### Constraints

Constraint equations are maps of the form `{:op :lhs :rhs}`, where `:op` is one of `:=`, `:>=`, or `:<=`. `:lhs` and `:rhs` are both linear expressions as described above. These are most easily created with the `constraint` and `constraints` macros, but may be manipulated by hand as well. NB: the macros will automatically normalize your constraints to put all the variables on the left-hand side and the constant on the right. The input to the minimize function must be in this form.

### Tips

You can you anything that's not a number or map as the variable in your linear systems. In particular, it's useful build up a system using vectors as variables and later merge the results into your own data using `assoc-in` . 