R:lpSolve崩溃了R

时间:2018-08-11 20:52:59

标签: r linear-programming lpsolve

我正在尝试使用lpSolve解决R中的线性优化问题。问题的详细信息在此处的上一个问题中进行了描述:https://math.stackexchange.com/questions/2813747/need-some-help-implementing-a-linear-program-with-a-parameter-and-deviational-va

我编写了以下R脚本以读取我的数据集并构造lpSolve的输入(故意编辑的路径)。最终,我将循环求解与每个观察值相对应的百分位数,但现在,我只是尝试在一个特定的百分位数上进行尝试。

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)

“国内”数据集中有862个观测值和9个约束。

不幸的是,当我开始运行lp函数时,R只是死了,没有警告,没有错误,它只是停止了。如果我使用的是RStudio,它将启动一个新会话,如果我仅使用R本身,则整个程序将消失。

如果使用R 3.5.1 64位,那会有所不同。

有什么想法吗?难道我做错了什么?还有什么我可以尝试的吗?

谢谢

0 个答案:

没有答案