File: equality_test.R

package info (click to toggle)
r-cran-linprog 0.9-4-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 204 kB
  • sloc: sh: 13; makefile: 2
file content (23 lines) | stat: -rw-r--r-- 618 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
library( "linprog" )

# min x1 + x2, s.t. x1 + 0.5 * x2 = 2
cvec <- c( 1, 1 )
Amat <- matrix( c( 1, 0.5 ), nrow = 1 )
bvec <- 2
a1 <- solveLP( cvec, bvec, Amat, const.dir = "=" )
print( a1 )

a2 <- solveLP( cvec, bvec, Amat, const.dir = "=", lpSolve = TRUE )
print( a2 )

# max 27 * x1 + 9 * x2
# s.t. x1 - x2 = 8  &  x1 + x2 <= 74
cvec <- c( 27, 9 )
bvec <- c( 8, 74 )
Amat <- matrix( c( 1, 1, -1, 1 ), nrow = 2 ) 
b1 <- solveLP( cvec, bvec, Amat, maximum = TRUE, const.dir = c( "==", "<=" ) )
print( b1 )

b2 <- solveLP( cvec, bvec, Amat, maximum = TRUE, const.dir = c( "==", "<=" ),
   lpSolve = TRUE )
print( b2 )