Skip to content

ZarahShibli/Markdown-Linear-Programming-R

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

Linear Programming for Soda company


linear-regression

import library

library(lpSolve)

Objective Function

  • Max(13X1 + 23X2 + 30X3)

Subject to (Constraints)

  • 5X1 + 15X2 + 4X3 <= 480 (CO2)
  • 4X1 + 4X2 + 10X3 <= 160 (Water)
  • 35X1 + 20X2 + 15X3 <= 1190 (Flavor)
  • 5X1 + 10X2 + 20X3 <= 200 (number of worker * work hours * 5 days)
  • X1, X2, X3 >= 0 (We don't want a negative amount of batches)

create Objective coeffation

obj_coeff <- c(13,23,30)

constraints matrix

constraints <- matrix(
  c(
    5,15,4,
    4,4,10,
    35,20,15,
    5,10,20
  ), nrow =4, byrow= TRUE
)

rename column and row names

colnames(constraints) = c("Strwaberry" , "Orange" , "Grape")
rownames(constraints) = c("CO2" , "Water" , "Flavor" , "Production Time")
View(constraints)

create direction vector

direction_c <- c("<=","<=","<=","<=") 

create resources vectore

resources <- c(480,160,1190,200) # 200 = number of employee * work hours * work day

create linear programming object

solve_lp <- lp(
  "max", # find max result
  obj_coeff,
  constraints,
  direction_c,
  resources
)
solve_lp$objval # Objective value
solve_lp$solution # solution 

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published