[go: up one dir, main page]

0% found this document useful (0 votes)
21 views3 pages

Code Source

The document shows code for solving linear programming problems using R. It includes code to install packages, define matrices of coefficients, set constraint directions and bounds, and call the solveLP function. The output shows the initial simplex tableau, pivot steps, and optimal solution values found.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views3 pages

Code Source

The document shows code for solving linear programming problems using R. It includes code to install packages, define matrices of coefficients, set constraint directions and bounds, and call the solveLP function. The output shows the initial simplex tableau, pivot steps, and optimal solution values found.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

CODE SOURCE

install.packages("matlib")
library(matlib)
A matrix(c(2,4,3,-8), nrow= 2, ncol= 2, byrow= TRUE)
B <- c(7,-5)
A
B
solve(A,B)
plotEqn(A,B, xlim= c(0,20),ylim= c(0,10)), labels = TRUE,
solution= FALSE)
axis(side= 1, at= c(1,2,3,4,5), labels= c(1,2,3,4,5))
axis(side= 2,at= c(1,2,3), labels= c(1,2,3))
plotEqn3d(A,B)
AA<- matrix(c(2,4,6,4,5,6,3,1,-2), 3, 3, byrow = TRUE)
BN<- c(18,24,4)
solve(AA,BN)
plotEqn3d(AA,BN)
library(linprog)
install.packages("linprog")
library(linprog)
library(lpSolve)
library(linprog)
D<- matrix(c(1,0,0,2,3,2), nrow= 3, ncol= 2, byrow= TRUE)
Z<- c(3,5)
J<- c(4,12,18)
direction<- ("<=", "<=", "<=")
direction<- rep("<=",3)
solopt<- solveLP(Z,J,D, maximum = TRUE, direction,
verbose= 4)
solopt

CONSOLE

> solopt<- solveLP(Z,J,D, maximum = TRUE, direction,


verbose= 4)[1] "initial Tableau"
1 2 S 1 S 2 S 3 P0
1 1 0 1 0 0 4
2 0 2 0 1 0 12
3 3 2 0 0 1 18
Z-C -3 -5 0 0 0 0

Pivot Column: 2 ( 2 )
Pivot Row: 2 ( 2 )

1 2 S 1 S 2 S 3 P0
1 1 0 1 0.0 0 4
2 0 1 0 0.5 0 6
3 3 0 0 -1.0 1 6
Z-C -3 0 0 2.5 0 30

Pivot Column: 1 ( 1 )
Pivot Row: 3 ( 3 )
1 2 S 1 S 2 S 3 P0
1 0 0 1 0.3333333 -0.3333333 2
2 0 1 0 0.5000000 0.0000000 6
1 1 0 0 -0.3333333 0.3333333 2
Z-C 0 0 0 1.5000000 1.0000000 36> solopt

Results of Linear Programming / Linear Optimization

Objective function (Maximum): 36

Iterations in phase 1: 0
Iterations in phase 2: 2
Solution
opt
1 2
2 6

Basic Variables
opt
1 2
2 6
S 1 2

Constraints
actual dir bvec free dual dual.reg
1 2 <= 4 2 0.0 2
2 12 <= 12 0 1.5 6
3 18 <= 18 0 1.0 6

All Variables (including slack variables)


opt cvec min.c max.c marg marg.reg
1 2 3 0.0 7.5 NA NA
2 6 5 2.0 Inf NA NA
S 1 2 0 -4.5 3.0 0.0 NA
S 2 0 0 -Inf 1.5 -1.5 6
S 3 0 0 -Inf 1.0 -1.0 6

CODE SOURCE

M<- matrix(c(6,4,1,2,-1,1,0,1), nrow= 4, ncol= 2, byrow=


TRUE)
Z<- c(5,4)
N<- c(24,6,1,2)
#direction<- ("<=", "<=", "<=")
direction<- rep("<=",4)
solopt<- solveLP(Z,N,M, maximum = TRUE, direction,
verbose= 4)
solopt

CONSOLE
Results of Linear Programming / Linear Optimization

Objective function (Maximum): 21

Iterations in phase 1: 0
Iterations in phase 2: 2
Solution
opt
1 3.0
2 1.5

Basic Variables
opt
1 3.0
2 1.5
S 3 2.5
S 4 0.5

Constraints
actual dir bvec free dual dual.reg
1 24.0 <= 24 0.0 0.75 4.0
2 6.0 <= 6 0.0 0.50 2.0
3 -1.5 <= 1 2.5 0.00 2.5
4 1.5 <= 2 0.5 0.00 0.5

All Variables (including slack variables)


opt cvec min.c max.c marg marg.reg
1 3.0 5 2.00000 6.000000 NA NA
2 1.5 4 3.33333 10.000000 NA NA
S 1 0.0 0 -Inf 0.750000 -0.75 4
S 2 0.0 0 -Inf 0.500000 -0.50 2
S 3 2.5 0 -2.00000 0.400000 0.00 NA
S 4 0.5 0 -6.00000 0.666667 0.00 NA

You might also like