1

I have an optimization problem which I'm trying to solve with lpSolve.

Imagine you have 17 machines. On some of these machines you can produce product i, on some of them not (here the objective function is 0, on the others it has a certain value with is the runtime). These machines have a different runtime to produce this product, so I want to find out which machine to choose by minimizing the runtime.

So the formula looks like this: enter image description here s.d.: enter image description here -> r defines the runtime of product i on machine j, which should be smaller than 20 and greater than 10 in this example. -> d defines product i on machine j

My code looked like this, but I guess I'm on the wrong path:

f_obj <- c(29.1, 29.1,  0.0, 15.0, 15.0, 15.0,  0.0,  0.0,  0.0,  0.0,  0.0,  0.0,  0.0,  0.0 15.0,  0.0,  0.0)
f_con <- matrix(c(1,1,0,1,1,1,0,0,0,0,0,0,0,0,1,0,0), ncol=17, byrow=TRUE)
f_rhs <- c(20) 
f_dir <- c("<=")
solution2 <- lp("min",f_obj2,f_con,f_dir,f_rhs)

The solution should look like this:

solution2$solution
 [1] 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Where the "1" is telling on which machine the product should be produced.

Can anyone help? Thank you!


Okay I tried to code it with some smaller data (17x2 matrix) for 2 products. My constraint looks like this: constraint

with 5000 as a large number (here the actual value is 0).

My objective fct looks like this (not sure if right?):

obt_fct

Additionally the constraints:

f_rhs <- rep(c(5700), times=17) #(because actually time constraint is smaller than 5700 per machine)
f_dir <- rep(c("<="), times=17)

But my solution looks like this:

    solution2$solution
 [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Do you know where is the error?

Makyen
  • 31,849
  • 12
  • 86
  • 121
Chocolino
  • 31
  • 3
  • How many products do you have? Your input needs to be matrix, 17 rows for each machine, and n columns for each product. Your problem is an integer lp problem then, answering which product will be produced on which machine, such that it satisfies your time constraints. – user2974951 Jul 04 '22 at 11:10
  • Yes, thats exactly what I need! In total, I have 17 machines and 245 products. Do I need 4165 columns then? Does the f_obj function needs to be the possibility of production (1,0) and the constraints define the runtime? – Chocolino Jul 04 '22 at 11:32
  • No, you need a 17 x 245 matrix, where each element tells the runtime on machine i for product j. If a machine cannot produce a product then the runtime can be for ex. a very large number (roughly). The optimization has to assign a machine to each product then. – user2974951 Jul 04 '22 at 11:43
  • Okay, I made an sample with some smaller data (17x2 matrix). My objection function is a 17x2 matrix with the runtime per machine and product. My constraints are the possibilities if producible of not (1 fo yes, 0 for no). Also one contraint for the sum of all runtimes per machine needs to be greater than 10 and smaller than 20. But my solutions doesnt fit. The algotrithm only chooses one machine for both, so result looks like this: `solution2$solution [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0`. Do you know where is the error? – Chocolino Jul 05 '22 at 05:59
  • Here is the entire code: `f_obj <- matrix([1:34], nrow=17, byrow=TRUE) f_obj[f_obj == 0] <- 5000, f_con <- matrix(c(rep(1,17), rep(3,17)), ncol=2) f_con <- rbind(f_con,f_con), f_rhs <- c(rep(c(10), times=17),rep(c(20), times=17)), f_dir <- c(rep(c(">="), times=17),rep(c("<="), times=17))` – Chocolino Jul 05 '22 at 06:04
  • This is typical scheduling problem (https://en.wikipedia.org/wiki/Unrelated-machines_scheduling). You should provide some useful data. – det Jul 05 '22 at 12:50
  • I know about the problem, just don't know how to fix it. I posted all the code I have. – Chocolino Jul 06 '22 at 05:38

0 Answers0