-1

We trying to solve the next linear optimization problem:

We have:

  • Pij, i=1÷3, j=1÷30, Pij are positive
  • Bi, i=1÷3, integer positive

The searching result is matrix of 3 x 30 of binary values Xij with next conditions:

Constraints:

  • For each j =1÷30, Sum (by index of i=1÷3)Xij=1
  • For each i =1÷3, Sum by index of (j=1÷3o)Xij≤Bi

Objective: Optimize:

  • Maximize (Sum (by index of i=1÷3) Sum (by index of j=1÷30) Pij *Xij)

Haw we can solve the problem in the R?

I tried to do with lpsolve package. The received values is not correct.

Is there are limitation in linear programing solutions for number of constraints in R?

In real situation our cases are more than 25000 (the j index is 1÷30000)

Thank you in advance,

Boriana

lrnzcig
  • 3,868
  • 4
  • 36
  • 50
Boriana
  • 1
  • 6
  • 4
    If you didn't get the "correct" solution then either there are multiple solutions, or you used lpsolve incorrectly. However, you didn't provide your code, so it's hard to help you further. – pkofod Mar 21 '17 at 10:51
  • 1
    http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – takje Mar 21 '17 at 11:57
  • I manage to set the correct solution. What are the limitation of the number of constraints? Is it come only from the matrix size limitation? – Boriana Mar 21 '17 at 15:47

2 Answers2

0

The decision was to reduce this task to linear programing task. This way of decision construct one matrix with 3 x 3*j dimension for the Bi constraints and one matrix j x 3*j dimension for the Xij constrains. Than two matrixes should be combined vertically as constraint of task – the received matrix is 3+j x 3*j dimensional. The object vector is constructed by Pij but as vector 90 x 1. The rhs constraint is combination between Bi (1 x 3) and vector of 1 (1 x j) – vector is 1 x 3 + j. It is worked with lp or Rglpk_solve_LP. I checked this with several combination. It is worked for j=5000, but it doesn’t worked for j=10000. We should use it for 30000 cases. The matrixes became too large. Is it possible to solve this in another way? What are the limitation for the linear programing procedure? Are they come only by RAM of computer and size of matrixes?

Boriana
  • 1
  • 6
0
# read file 
    pd30 = read.csv("b3ovd30.csv")  # read csv file
# objective function 
    P <- t(pd30)
    c <- as.vector(t(P))
# linear constraints
    S <- matrix(rep(1),1, ncol(P))
    S0 <- matrix(rep(0),1, ncol(P))
#constraint that sum across row <= B[i] 
    A1 <- rbind ( cbind(S,S0,S0),cbind(S0,S,S0),cbind(S0,S0,S) )
    rm(S0)
    A0 <- matrix(rep(0),nrow(P),1)
    Ad <- diag(1, ncol(P), ncol(P))
# constraint that sum of rows is 1
    A2 <- cbind(Ad, Ad, Ad)
# both constraints
    A <- rbind (A1, A2)
    rm(A0)
    rm(Ad)
    rm(A1)
    rm(A2)
# RHS of constraint for A1
    b1 <- matrix(c(8,19,30), ncol=1)
# RHS of constraint for A2
    b2 <- t(S)
# both RHS
    b <- rbind (b1, b2)
    rm(b1)
    rm(b2)
#specify symbols for constraints:
    LEG1 <- matrix(rep("<="), nrow(P),1)
    LEG2 <- matrix(rep("=="), ncol(P),1)
    LEG <- rbind (LEG1, LEG2)
    rm(LEG1)
    rm(LEG2)
    types <- matrix(rep("B"), nrow(P)*ncol(P),1)
# Run
    install.packages("Rglpk")
    library(Rglpk)
    result <- Rglpk_solve_LP(c, A, LEG, b, types , max = TRUE)
    print(result$status)
    print(result$solution)
    solution3 <- matrix(result$solution, ncol=3, byrow = F)
Boriana
  • 1
  • 6
  • Is this a solution or just code you didn't put in the Question itself? Could you elaborate on it? – LW001 Jan 31 '18 at 13:48
  • @LW001 This is solution in code for the problem described in question. In case of 30 cases. The size of cases that can be used depend by computer. – Boriana Jan 31 '18 at 14:09