In previous posts I have demonstrated how to solve linear programs in R using lpSolve – or in Python using SciPy.optimize. In this coding example I want to show how to conduct simple linear optimization using the FuzzyLP package.
FuzzyLP is a package for “fuzzy” linear programming, i.e. linear optimization under uncertainty. In later posts I will show how to conduct fuzzy linear programming using FuzzyLP in R. This post focuses on a simple linear program that can be solved using the standard simplex algorithm.
The problem to solve is stated below in scalar syntax:
This problem can be solved by describing it in vector-matrix syntax, i.e. in the following form:
c is the coefficient vector of the objective function. x is the vector containing the optimization variables. A is the coefficient matrix of the linear constraints and b is the vector containing the constraint values.
In below coding example these vectors and matrices are defined in R and the problem is modelled and solved using crispLP, a function contained by FuzzyLP package. crispLP will solve the problem using the standard simplex algorithm.
# define vectors and matrices that describe the problem at hand c <- c(3,4) A <- matrix(c(1,1),nrow=1) dir <- c("<=") b <- c(1) # using crispLP from FuzzyLP to solve the problem; since it is a maximization problem "maximum" has to be TRUE solution <- crispLP(objective = c, A = A, dir = dir, b = b, maximum = TRUE)
##  "Solution is optimal."
# output solution solution
## x1 x2 objective ## [1,] 0 1 4
Data scientist focusing on simulation, optimization and modeling in R, SQL, VBA and Python
Leave a Reply