Description Usage Arguments Value Author(s) See Also Examples
Solve a linear program (LP) or a mixed integer program (MIP). Find the values of the objective function and the associated variables using the specified solver.
1 |
p |
an object of class |
solver |
name of the solver to use: Rsymphony (default) |
... |
other parameters passed to the solver |
The object returned by the solver
Cyrille Szymanski <cnszym at gmail.com>
TODO
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | # create and solve the following linear program:
# Simple mixed integer linear program.
# max: 3 x1 + 1 x2 + 3 x3
# s.t.: -1 x1 + 2 x2 + x3 <= 4
# 4 x2 - 3 x3 <= 2
# x1 - 3 x2 + 2 x3 <= 3
# x1 >= 0 (integer)
# x2 >= 0 (real)
# x3 >= 0 (integer)
p <- newProblem()
p <- addVariable(p, "I", 3)
p <- addVariable(p, "C", 1)
p <- addVariable(p, "I", 3)
p <- addConstraint(p, "<=", 4, c(-1, 2, 1))
p <- addConstraint(p, "<=", 2, c(0, 4, -3))
p <- addConstraint(p, "<=", 3, c(1, -3, 2))
p <- addConstraint(p, ">=", 0, c(1, 0, 0))
p <- addConstraint(p, ">=", 0, c(0, 1, 0))
p <- addConstraint(p, ">=", 0, c(0, 0, 1))
if(require(Rsymphony))
mipSolve(p)
|
Loading required package: Rsymphony
Warning: Trying to use multiple processors with sequential build...
Starting Preprocessing...
Preprocessing finished...
constraints removed: 3
Solving...
****************************************************
* Optimal Solution Found *
****************************************************
Solution Found: Node 0, Level 0
Solution Cost: -26.7500000000
$solution
[1] 5.00 2.75 3.00
$objval
[1] 26.75
$status
TM_OPTIMAL_SOLUTION_FOUND
0
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.