0

I'm trying to solve a linear optimization problem in R using lpSolve. The details of what the problem is are described in a previous question here: https://math.stackexchange.com/questions/2813747/need-some-help-implementing-a-linear-program-with-a-parameter-and-deviational-va

I've written the following R script to read in my datasets and construct the inputs for lpSolve (paths deliberately redacted). Ultimately I'll loop through solving for the percentile that corresponds to each observation but for now I'm just trying to try it out on one particular percentile.

library(readr)
library(dplyr)
library(magrittr)
library(lpSolve)

# Define percentile rank function
perc.rank <- function(x) trunc(rank(x))/length(x)

# Read in domestic and nondomestic datasets
domestic <- read_csv("D:/ ... /QuantileRegression/MSOAs_Areas_Volumes_ExcludedRemoved_Domestic.csv")
nondomestic <- read_csv("D:/ ... /QuantileRegression/MSOAs_Areas_Volumes_ExcludedRemoved_NonDomestic.csv")

# Add percentile rank columns to domestic and nondomestic datasets
domestic$percentile <- perc.rank(domestic$DomesticConsumption)
nondomestic$percentile <- perc.rank(nondomestic$NonDomesticConsumption)

domestic.const.mat <- select(domestic, Area_C1:Area_Mixed) 
domestic.const.mat %<>% mutate(underestimation=1) %<>% mutate(overestimation=-1)

domestic.const.dir <- rep("==", length.out=nrow(domestic.const.mat))

domestic.const.rhs <- domestic$DomesticConsumption

domestic.const.rhs <- as.numeric(domestic.const.rhs)

domestic.obj <- rep(c(0.9020071, 1-0.9020071), times=nrow(domestic))
domestic.const.mat <- as.matrix(domestic.const.mat)

lp ("min", domestic.obj, domestic.const.mat, domestic.const.dir, domestic.const.rhs)

There are 862 observations in the 'domestic' dataset and 9 constraints.

Unfortunately, when I get to running the lp function, R just dies, no warning, no errors, it just stops. If I'm using RStudio it starts a new session, and if I just use R itself the whole program just disappears.

I'm using R 3.5.1 64-bit if that makes a difference.

Any ideas? Am I doing something wrong? Is there something else I can try?

Thanks

  • Can you edit this to include the actual data that goes into `domestic` and `nondomestic`? As the question is currently written, we cant test this on our own machines, and therefore it is very difficult to help you – Conor Neilson Aug 11 '18 at 23:38
  • They're quite big datasets, domestic is 862 observations with 29 variables. Also, some of the values are derived from a commercial dataset so I'm not sure if it's OK to share them. – Dan Evans Aug 12 '18 at 12:54
  • Try using the package `lpSolveAPI` which in my opinion can be more robust. – Karsten W. Aug 20 '18 at 14:30
  • Thanks all. I ended up using lpSolveAPI instead and then discovered I was formulating the problem incorrectly anyway. This stuff is NOT very user friendly or intuitive! Got there in the end though. – Dan Evans Aug 20 '18 at 15:04

0 Answers0