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