ob-lp_solve/README.org

105 lines
2.1 KiB
Org Mode

* ob-lp_solve
Evaluate Mixed Integer Linear Programming LP-format model with LP-solve
** Installation
The package is not (yet) available on MELPA, so it should be installed directly from the repository.
*** Dependencies
To be able to use =ob-lp_solve= you will need to install [[https://github.com/lp-solve/lp_solve][lp_solve]] and make sure it is on your =PATH=.
*** Installation with Doomemacs
In your =$DOOMDIR/packages.el= file, you might want to set up the following:
#+begin_src emacs-lisp
(package! ob-lp_solve
:recipe (:host github :repo "samuelortion/ob-lp_solve"))
#+end_src
*** Installation with Straight
#+begin_src emacs-lisp
(use-package ob-pasp
:straight (ob-pasp :type git :host github :repo "samuelortion/lp_solve"))
#+end_src
** Load for testing :noexport:
#+begin_src emacs-lisp
(load "~/Documents/projects/emacs/ob-lp_solve/ob-lp_solve.el")
(add-to-list 'org-babel-load-languages '(lp_solve . t))
#+end_src
#+RESULTS:
: ((lp-solve . t) (lp_solve . t) (emacs-lisp . t))
** Some basic examples
#+begin_src lp_solve :exports both
max: a + b;
r_1: a + b < 2;
#+end_src
#+RESULTS:
:
: Value of objective function: 2.00000000
:
: Actual values of the variables:
: a 1
: b 1
*** Linear programming Vertex cover problem relaxation
#+begin_src lp_solve :exports both
min: a + b + c + d + e;
r_1: a + c >= 1;
r_2: d + e >= 1;
r_3: c + b >= 1;
r_4: a + e >= 1;
r_5: a + d >= 1;
bin a;
bin b;
bin c;
bin d;
bin e;
#+end_src
#+RESULTS:
:
: Value of objective function: 3.00000000
:
: Actual values of the variables:
: a 1
: b 0
: c 1
: d 0
: e 1
#+begin_src dot :file vertex-cover-example.svg :results file graphics :exports output
graph G {
{
node [width=0.25 shape=circle style=filled]
a [fillcolor=yellow]
b
c [fillcolor=yellow]
d
e
}
a -- c
c -- b
d -- e
a -- e
a -- d
}
#+end_src
#+RESULTS:
[[file:vertex-cover-example.svg]]