首页 > 解决方案 > R:lpSolve 崩溃 R

问题描述

我正在尝试使用 lpSolve 解决 R 中的线性优化问题。问题的详细信息在前面的问题中描述:https ://math.stackexchange.com/questions/2813747/need-some-help-implementing-a-linear-program-with-a-parameter-and -偏差-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 位。

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

谢谢

标签: rlinear-programminglpsolve

解决方案


推荐阅读