🎩
wilmerags 🌱
  • Home
  • Social
  • Cloud
    • Aws
  • Stats
  • Code
    • Scrum
    • Ssh
    • Vim
    • Dvc
    • Postgresql
    • Tmux
    • Terraform
    • Web tools
    • Sql
    • Rest api
    • Mongo
    • Docker
    • Octave
    • Elasticsearch
    • Kubernetes
    • Bash
    • Rabbitmq
    • Databases
      • Mongo
      • Elasticsearch
      • Sql
        • Postgresql
    • Devops
      • Terraform
      • Docker
      • Kubernetes
      • Rabbitmq
    • Python
      • Airflow
      • Keras
      • Spark
      • Azure
      • Matplotlib
      • Jupyter
      • Numpy
      • Databases
      • Sklearn
      • Requests
      • Pandas
      • Elasticsearch
      • Tensorflow
    • Git
      • Gitflow
    • R
      • Lpsolve
  • Indie-hacker
  • Macos
  • Interesting
  • Thoughts
    • Health
    • Work
    • Relationships
    • On the need of expressiveness
    • On organizing knowledge
    • On the importance of questions
  • Linux
    • Vim
    • Tmux
  • Webdev
    • Vue
  • Readings
    • Psychology
    • Habits
    • Projects management
    • Quotes
    • Dopamine detox
  • Ai
    • Ml
      • Xgboost
      • Performance evaluation
      • Community detection
      • Cloud_platforms
        • Ai platform
        • Sagemaker
      • Unsupervised_learning
    • Nlp
    • DS
Powered by GitBook
On this page
  1. Code
  2. R

Lpsolve

PreviousRNextIndie-hacker

Last updated 4 years ago

Was this helpful?

CtrlK

Was this helpful?

Recipes

Load balancing R example

install.packages('lpSolve')
library('lpSolve')

## Set the coefficients of the decision variables -> C
capacities.leads <- c(170,165,120,140,175,165,140,105,55)
capacities.positions <- ceiling(capacities.leads / 10)
coeff <- (capacities.positions ** -1) * (length(capacities.leads)**-1)
n.teams <- length(capacities.positions)
# Create constraint martix B
A <- matrix(c(diag(n.teams) * (capacities.positions**-1 ),
         diag(n.teams) * (capacities.positions**-1),
         rep(1,n.teams)),ncol = n.teams,byrow = T)

# Right hand side for the constraints
B <- c(rep(0.82,n.teams),
       rep(0.92,n.teams),
       110
)

# Direction of the constraints
constranints_direction  <- c(rep(">",n.teams),
                             rep("<",n.teams),
                             "==")

# Find the optimal solution
optimum <-  lp(direction="min",
               objective.in = coeff,
               const.mat = A,
               const.dir = constranints_direction,
               const.rhs = B,
               all.int = T)

# Print status: 0 = success, 2 = no feasible solution
print(optimum$status)

# Display the optimum values for x_4p, x_3p and x_w
best_sol <- optimum$solution
names(best_sol) <- c("Augusto","Alexander","Josmayry","Carlina","Gabriela","Maria Carolina","Tiziana","Gustavo","Jhem") 
print(best_sol)

# Check the value of objective function at optimal point
print(paste("Total cost: ", optimum$objval, sep=""))