2

I have tried to use the R package LPSolve and in particular the lp.transport function to solve a optimisation problem. In my fictitious example below I have 5 office sites that I need to resource with a minimum number of employees and I have set up a cost matrix that determines the distance from each employees home to the office. I want to minimize the total distance traveled to work whilst meeting the minimum number of employees per office.

Initially this was working as I was treating all employees as equal (1). however problems have started to occur when I rate each employee by how efficient they are. For example I now want to say that officeX needs the equivalent of 2 engineers which might be made up of 4 engineers who are 50% efficient or 1 that is 200% efficient. When I do this however the solution found will split a employee across a number of offices, what I need is a additional constraint so impose that a employee can only be at 1 Office. Anyway hopefully that is enough background here is my example:

Employee <- c("Jim","John","Jonah","James","Jeremy","Jorge")
Office1 <- c(2.58321505105556, 5.13811249390279, 2.75943834864996, 
      6.73543614029559, 6.23080251653027, 9.00620341764497) 
Office2 <- c(24.1757667923894, 19.9990724784926, 24.3538456922105, 
      27.9532073293925, 26.3310994833106, 14.6856664813007) 
Office3 <- c(38.6957155251069, 37.9074293509861, 38.8271000719858, 
      40.3882569566947, 42.6658938732098, 34.2011184027657) 
Office4 <- c(28.8754359274453, 30.396841941228, 28.9595182970988, 
      29.2042274337124, 33.3933900645023, 28.6340025144932) 
Office5 <- c(49.8854888720157, 51.9164328512659, 49.948290261029, 
      49.4793138594302, 54.4908258333456, 50.1487397648236)

#create CostMatrix
costMat<-data.frame(Employee,Office1, Office2, Office3, Office4, Office5)

#efficiency is the worth of employees, eg if 1 they are working at 100% 
#so if for example I wanted 5 Employees
#working in a office then I could choose 5 at 100% or 10 working at 50% etc...
efficiency<-c(0.8416298, 0.8207991, 0.7129663, 1.1406839, 1.3868177, 1.1989748)

#Uncomment next line to see the working version based on headcount
#efficiency<-c(1,1,1,1,1,1)

#Minimum is the minimum number of Employees we want in each office
minimum<-c(1, 1, 2, 1, 1)

#solve problem
opSol <-lp.transport(cost.mat = as.matrix(costMat[,-1]),
                 direction = "min", 
                 col.signs = rep(">=",length(minimum)), 
                 col.rhs = minimum, 
                 row.signs = rep("==", length(efficiency)), 
                 row.rhs = efficiency,
                 integers=NULL)

#view solution
opSol$solution 

# My issue is one employee is being spread across multiple areas, 
#what I really want is a extra constraint that says that in a row there
# can only be 1 non 0 value.

1 Answer 1

1

I think this is no longer a transportation problem. However you still can solve it as a MIP model: enter image description here

Sign up to request clarification or add additional context in comments.

4 Comments

Hi Erwin, can you suggest a package in R I might want to look at to try and implement this?
You could use LpSolve.
Hi Erwin, I am struggling with the syntax. Are you able to provide a example? Thanks Tom
What syntax? The mathematical model or the call to the solver?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.