5

我正在使用 R lpsolve 包来优化我的运输模型。我的代码运行良好,但运行需要很长时间,因为我有大量的节点和路径。我打算在 hadoop 集群上运行我的代码。

请指导我有关我需要对我的代码进行的更改。我认为在 hadoop 集群上运行优化可能是不可能的,因为我们最终可能会得到局部最小值而不是全局最小值。

我在互联网上搜索“lpsolve hadoop”之类的术语,但没有得到任何有用的信息。

请指导我查看我应该查看的材料或示例。======================================更新1=========== =========================== 我原来的问题就在这里

我进一步简化了问题,我正在解决的当前问题如下。

附上我使用 excel 构建的 R 代码和输入数据文件。在实际场景中,输入数据文件将使用 SQL 生成,长度超过 30,000 行。

在此处输入图像描述

我的输入excel文件:

startlink   endlink link_dsc    lnk_type    cons_type   cost    equality_const  fpc_const   max_const
"source","-","-","0"    "vmi1","MM1","VMI","1"  source_to_VMI   supply  equality supply 0   100 null    null
"vmi1","MM1","VMI","0"  "cust1","MM1","SHIP_CUST_1d_AIR","1"    vmi_to_shipcust flow    null    5   null    null    null
"vmi1","MM1","VMI","1"  "cust1","MM1","SHIP_CUST_1d_AIR","2"    vmi_to_shipcust flow    null    5   null    null    null
"vmi1","MM1","VMI","2"  "cust1","MM1","SHIP_CUST_1d_AIR","3"    vmi_to_shipcust flow    null    5   null    null    null
"vmi1","MM1","VMI","3"  "cust1","MM1","SHIP_CUST_1d_AIR","4"    vmi_to_shipcust flow    null    5   null    null    null
"vmi1","MM1","VMI","4"  "cust1","MM1","SHIP_CUST_1d_AIR","5"    vmi_to_shipcust flow    null    5   null    null    null
"vmi1","MM1","VMI","5"  "cust1","MM1","SHIP_CUST_1d_AIR","6"    vmi_to_shipcust flow    null    5   null    null    null
"vmi1","MM1","VMI","6"  "cust1","MM1","SHIP_CUST_1d_AIR","7"    vmi_to_shipcust flow    null    5   null    null    null
"vmi1","MM1","VMI","7"  "cust1","MM1","SHIP_CUST_1d_AIR","8"    vmi_to_shipcust flow    null    5   null    null    null
"vmi1","MM1","VMI","8"  "cust1","MM1","SHIP_CUST_1d_AIR","9"    vmi_to_shipcust flow    null    5   null    null    null
"vmi1","MM1","VMI","9"  "cust1","MM1","SHIP_CUST_1d_AIR","10"   vmi_to_shipcust flow    null    5   null    null    null
"vmi1","MM1","VMI","0"  "vmi1","MM1","VMI","1"  vmi_to_vmi_inv  flow    null    0   null    null    null
"vmi1","MM1","VMI","1"  "vmi1","MM1","VMI","2"  vmi_to_vmi_inv  flow    null    0   null    null    null
"vmi1","MM1","VMI","2"  "vmi1","MM1","VMI","3"  vmi_to_vmi_inv  flow    null    0   null    null    null
"vmi1","MM1","VMI","3"  "vmi1","MM1","VMI","4"  vmi_to_vmi_inv  flow    null    0   null    null    null
"vmi1","MM1","VMI","4"  "vmi1","MM1","VMI","5"  vmi_to_vmi_inv  flow    null    0   null    null    null
"vmi1","MM1","VMI","5"  "vmi1","MM1","VMI","6"  vmi_to_vmi_inv  flow    null    0   null    null    null
"vmi1","MM1","VMI","6"  "vmi1","MM1","VMI","7"  vmi_to_vmi_inv  flow    null    0   null    null    null
"vmi1","MM1","VMI","7"  "vmi1","MM1","VMI","8"  vmi_to_vmi_inv  flow    null    0   null    null    null
"vmi1","MM1","VMI","8"  "vmi1","MM1","VMI","9"  vmi_to_vmi_inv  flow    null    0   null    null    null
"vmi1","MM1","VMI","9"  "vmi1","MM1","VMI","10" vmi_to_vmi_inv  flow    null    0   null    null    null
"vmi1","MM1","VMI","10" "SINK","-","-","100"    vmi_to_sink esacpe  null    100 null    null    null
"cust1","MM1","SHIP_CUST_1d_AIR","1"    "cust1","MM1","CUST","1"    shipcust_to_cust    flow    null    0   null    null    null
"cust1","MM1","SHIP_CUST_1d_AIR","2"    "cust1","MM1","CUST","2"    shipcust_to_cust    flow    null    0   null    null    null
"cust1","MM1","SHIP_CUST_1d_AIR","3"    "cust1","MM1","CUST","3"    shipcust_to_cust    flow    null    0   null    null    null
"cust1","MM1","SHIP_CUST_1d_AIR","4"    "cust1","MM1","CUST","4"    shipcust_to_cust    flow    null    0   null    null    null
"cust1","MM1","SHIP_CUST_1d_AIR","5"    "cust1","MM1","CUST","5"    shipcust_to_cust    flow    null    0   null    null    null
"cust1","MM1","SHIP_CUST_1d_AIR","6"    "cust1","MM1","CUST","6"    shipcust_to_cust    flow    null    0   null    null    null
"cust1","MM1","SHIP_CUST_1d_AIR","7"    "cust1","MM1","CUST","7"    shipcust_to_cust    flow    null    0   null    null    null
"cust1","MM1","SHIP_CUST_1d_AIR","8"    "cust1","MM1","CUST","8"    shipcust_to_cust    flow    null    0   null    null    null
"cust1","MM1","SHIP_CUST_1d_AIR","9"    "cust1","MM1","CUST","9"    shipcust_to_cust    flow    null    0   null    null    null
"cust1","MM1","SHIP_CUST_1d_AIR","10"   "cust1","MM1","CUST","10"   shipcust_to_cust    flow    null    0   null    null    null
"cust1","MM1","CUST","4"    "SINK","-","-","100"    cust_to_sink    flow    demand  0   null    null    50
"vmi1","MM1","VMI","0"  "cust1","MM1","SHIP_CUST_2d_AIR","2"    vmi_to_shipcust flow    null    5   null    null    null
"vmi1","MM1","VMI","1"  "cust1","MM1","SHIP_CUST_2d_AIR","3"    vmi_to_shipcust flow    null    5   null    null    null
"vmi1","MM1","VMI","2"  "cust1","MM1","SHIP_CUST_2d_AIR","4"    vmi_to_shipcust flow    null    5   null    null    null
"vmi1","MM1","VMI","3"  "cust1","MM1","SHIP_CUST_2d_AIR","5"    vmi_to_shipcust flow    null    5   null    null    null
"vmi1","MM1","VMI","4"  "cust1","MM1","SHIP_CUST_2d_AIR","6"    vmi_to_shipcust flow    null    5   null    null    null
"vmi1","MM1","VMI","5"  "cust1","MM1","SHIP_CUST_2d_AIR","7"    vmi_to_shipcust flow    null    5   null    null    null
"vmi1","MM1","VMI","6"  "cust1","MM1","SHIP_CUST_2d_AIR","8"    vmi_to_shipcust flow    null    5   null    null    null
"vmi1","MM1","VMI","7"  "cust1","MM1","SHIP_CUST_2d_AIR","9"    vmi_to_shipcust flow    null    5   null    null    null
"vmi1","MM1","VMI","8"  "cust1","MM1","SHIP_CUST_2d_AIR","10"   vmi_to_shipcust flow    null    5   null    null    null
"cust1","MM1","SHIP_CUST_2d_AIR","2"    "cust1","MM1","CUST","2"    shipcust_to_cust    flow    null    0   null    null    null
"cust1","MM1","SHIP_CUST_2d_AIR","3"    "cust1","MM1","CUST","3"    shipcust_to_cust    flow    null    0   null    null    null
"cust1","MM1","SHIP_CUST_2d_AIR","4"    "cust1","MM1","CUST","4"    shipcust_to_cust    flow    null    0   null    null    null
"cust1","MM1","SHIP_CUST_2d_AIR","5"    "cust1","MM1","CUST","5"    shipcust_to_cust    flow    null    0   null    null    null
"cust1","MM1","SHIP_CUST_2d_AIR","6"    "cust1","MM1","CUST","6"    shipcust_to_cust    flow    null    0   null    null    null
"cust1","MM1","SHIP_CUST_2d_AIR","7"    "cust1","MM1","CUST","7"    shipcust_to_cust    flow    null    0   null    null    null
"cust1","MM1","SHIP_CUST_2d_AIR","8"    "cust1","MM1","CUST","8"    shipcust_to_cust    flow    null    0   null    null    null
"cust1","MM1","SHIP_CUST_2d_AIR","9"    "cust1","MM1","CUST","9"    shipcust_to_cust    flow    null    0   null    null    null
"cust1","MM1","SHIP_CUST_2d_AIR","10"   "cust1","MM1","CUST","10"   shipcust_to_cust    flow    null    0   null    null    null
"source","-","-","0"    "vmi2","MM2","VMI","2"  source_to_VMI   supply  equality supply 0   50  null    null
"vmi2","MM2","VMI","0"  "cust1","MM2","SHIP_CUST_1d_AIR","1"    vmi_to_shipcust flow    null    1.4 null    null    null
"vmi2","MM2","VMI","1"  "cust1","MM2","SHIP_CUST_1d_AIR","2"    vmi_to_shipcust flow    null    1.4 null    null    null
"vmi2","MM2","VMI","2"  "cust1","MM2","SHIP_CUST_1d_AIR","3"    vmi_to_shipcust flow    null    1.4 null    null    null
"vmi2","MM2","VMI","3"  "cust1","MM2","SHIP_CUST_1d_AIR","4"    vmi_to_shipcust flow    null    1.4 null    null    null
"vmi2","MM2","VMI","4"  "cust1","MM2","SHIP_CUST_1d_AIR","5"    vmi_to_shipcust flow    null    1.4 null    null    null
"vmi2","MM2","VMI","5"  "cust1","MM2","SHIP_CUST_1d_AIR","6"    vmi_to_shipcust flow    null    1.4 null    null    null
"vmi2","MM2","VMI","6"  "cust1","MM2","SHIP_CUST_1d_AIR","7"    vmi_to_shipcust flow    null    1.4 null    null    null
"vmi2","MM2","VMI","7"  "cust1","MM2","SHIP_CUST_1d_AIR","8"    vmi_to_shipcust flow    null    1.4 null    null    null
"vmi2","MM2","VMI","8"  "cust1","MM2","SHIP_CUST_1d_AIR","9"    vmi_to_shipcust flow    null    1.4 null    null    null
"vmi2","MM2","VMI","9"  "cust1","MM2","SHIP_CUST_1d_AIR","10"   vmi_to_shipcust flow    null    1.4 null    null    null
"vmi2","MM2","VMI","0"  "vmi2","MM2","VMI","1"  vmi_to_vmi_inv  flow    null    0   null    null    null
"vmi2","MM2","VMI","1"  "vmi2","MM2","VMI","2"  vmi_to_vmi_inv  flow    null    0   null    null    null
"vmi2","MM2","VMI","2"  "vmi2","MM2","VMI","3"  vmi_to_vmi_inv  flow    null    0   null    null    null
"vmi2","MM2","VMI","3"  "vmi2","MM2","VMI","4"  vmi_to_vmi_inv  flow    null    0   null    null    null
"vmi2","MM2","VMI","4"  "vmi2","MM2","VMI","5"  vmi_to_vmi_inv  flow    null    0   null    null    null
"vmi2","MM2","VMI","5"  "vmi2","MM2","VMI","6"  vmi_to_vmi_inv  flow    null    0   null    null    null
"vmi2","MM2","VMI","6"  "vmi2","MM2","VMI","7"  vmi_to_vmi_inv  flow    null    0   null    null    null
"vmi2","MM2","VMI","7"  "vmi2","MM2","VMI","8"  vmi_to_vmi_inv  flow    null    0   null    null    null
"vmi2","MM2","VMI","8"  "vmi2","MM2","VMI","9"  vmi_to_vmi_inv  flow    null    0   null    null    null
"vmi2","MM2","VMI","9"  "vmi2","MM2","VMI","10" vmi_to_vmi_inv  flow    null    0   null    null    null
"vmi2","MM2","VMI","10" "SINK","-","-","100"    vmi_to_sink esacpe  null    100 null    null    null
"cust1","MM2","SHIP_CUST_1d_AIR","1"    "cust1","MM2","CUST","1"    shipcust_to_cust    flow    null    0   null    null    null
"cust1","MM2","SHIP_CUST_1d_AIR","2"    "cust1","MM2","CUST","2"    shipcust_to_cust    flow    null    0   null    null    null
"cust1","MM2","SHIP_CUST_1d_AIR","3"    "cust1","MM2","CUST","3"    shipcust_to_cust    flow    null    0   null    null    null
"cust1","MM2","SHIP_CUST_1d_AIR","4"    "cust1","MM2","CUST","4"    shipcust_to_cust    flow    null    0   null    null    null
"cust1","MM2","SHIP_CUST_1d_AIR","5"    "cust1","MM2","CUST","5"    shipcust_to_cust    flow    null    0   null    null    null
"cust1","MM2","SHIP_CUST_1d_AIR","6"    "cust1","MM2","CUST","6"    shipcust_to_cust    flow    null    0   null    null    null
"cust1","MM2","SHIP_CUST_1d_AIR","7"    "cust1","MM2","CUST","7"    shipcust_to_cust    flow    null    0   null    null    null
"cust1","MM2","SHIP_CUST_1d_AIR","8"    "cust1","MM2","CUST","8"    shipcust_to_cust    flow    null    0   null    null    null
"cust1","MM2","SHIP_CUST_1d_AIR","9"    "cust1","MM2","CUST","9"    shipcust_to_cust    flow    null    0   null    null    null
"cust1","MM2","SHIP_CUST_1d_AIR","10"   "cust1","MM2","CUST","10"   shipcust_to_cust    flow    null    0   null    null    null
"cust1","MM2","CUST","9"    "SINK","-","-","100"    cust_to_sink    flow    demand  0   null    null    10
"vmi2","MM2","VMI","0"  "cust1","MM2","SHIP_CUST_2d_AIR","2"    vmi_to_shipcust flow    null    1.4 null    null    null
"vmi2","MM2","VMI","1"  "cust1","MM2","SHIP_CUST_2d_AIR","3"    vmi_to_shipcust flow    null    1.4 null    null    null
"vmi2","MM2","VMI","2"  "cust1","MM2","SHIP_CUST_2d_AIR","4"    vmi_to_shipcust flow    null    1.4 null    null    null
"vmi2","MM2","VMI","3"  "cust1","MM2","SHIP_CUST_2d_AIR","5"    vmi_to_shipcust flow    null    1.4 null    null    null
"vmi2","MM2","VMI","4"  "cust1","MM2","SHIP_CUST_2d_AIR","6"    vmi_to_shipcust flow    null    1.4 null    null    null
"vmi2","MM2","VMI","5"  "cust1","MM2","SHIP_CUST_2d_AIR","7"    vmi_to_shipcust flow    null    1.4 null    null    null
"vmi2","MM2","VMI","6"  "cust1","MM2","SHIP_CUST_2d_AIR","8"    vmi_to_shipcust flow    null    1.4 null    null    null
"vmi2","MM2","VMI","7"  "cust1","MM2","SHIP_CUST_2d_AIR","9"    vmi_to_shipcust flow    null    1.4 null    null    null
"vmi2","MM2","VMI","8"  "cust1","MM2","SHIP_CUST_2d_AIR","10"   vmi_to_shipcust flow    null    1.4 null    null    null
"cust1","MM2","SHIP_CUST_2d_AIR","2"    "cust1","MM2","CUST","2"    shipcust_to_cust    flow    null    0   null    null    null
"cust1","MM2","SHIP_CUST_2d_AIR","3"    "cust1","MM2","CUST","3"    shipcust_to_cust    flow    null    0   null    null    null
"cust1","MM2","SHIP_CUST_2d_AIR","4"    "cust1","MM2","CUST","4"    shipcust_to_cust    flow    null    0   null    null    null
"cust1","MM2","SHIP_CUST_2d_AIR","5"    "cust1","MM2","CUST","5"    shipcust_to_cust    flow    null    0   null    null    null
"cust1","MM2","SHIP_CUST_2d_AIR","6"    "cust1","MM2","CUST","6"    shipcust_to_cust    flow    null    0   null    null    null
"cust1","MM2","SHIP_CUST_2d_AIR","7"    "cust1","MM2","CUST","7"    shipcust_to_cust    flow    null    0   null    null    null
"cust1","MM2","SHIP_CUST_2d_AIR","8"    "cust1","MM2","CUST","8"    shipcust_to_cust    flow    null    0   null    null    null
"cust1","MM2","SHIP_CUST_2d_AIR","9"    "cust1","MM2","CUST","9"    shipcust_to_cust    flow    null    0   null    null    null
"cust1","MM2","SHIP_CUST_2d_AIR","10"   "cust1","MM2","CUST","10"   shipcust_to_cust    flow    null    0   null    null    null
"vmi1","MM1","VMI","0"  "cust3","MM1","SHIP_CUST_1d_AIR","1"    vmi_to_shipcust flow    null    15  null    null    null
"vmi1","MM1","VMI","1"  "cust3","MM1","SHIP_CUST_1d_AIR","2"    vmi_to_shipcust flow    null    15  null    null    null
"vmi1","MM1","VMI","2"  "cust3","MM1","SHIP_CUST_1d_AIR","3"    vmi_to_shipcust flow    null    15  null    null    null
"vmi1","MM1","VMI","3"  "cust3","MM1","SHIP_CUST_1d_AIR","4"    vmi_to_shipcust flow    null    15  null    null    null
"vmi1","MM1","VMI","4"  "cust3","MM1","SHIP_CUST_1d_AIR","5"    vmi_to_shipcust flow    null    15  null    null    null
"vmi1","MM1","VMI","5"  "cust3","MM1","SHIP_CUST_1d_AIR","6"    vmi_to_shipcust flow    null    15  null    null    null
"vmi1","MM1","VMI","6"  "cust3","MM1","SHIP_CUST_1d_AIR","7"    vmi_to_shipcust flow    null    15  null    null    null
"vmi1","MM1","VMI","7"  "cust3","MM1","SHIP_CUST_1d_AIR","8"    vmi_to_shipcust flow    null    15  null    null    null
"vmi1","MM1","VMI","8"  "cust3","MM1","SHIP_CUST_1d_AIR","9"    vmi_to_shipcust flow    null    15  null    null    null
"vmi1","MM1","VMI","9"  "cust3","MM1","SHIP_CUST_1d_AIR","10"   vmi_to_shipcust flow    null    15  null    null    null
"cust3","MM1","SHIP_CUST_1d_AIR","1"    "cust3","MM1","CUST","1"    shipcust_to_cust    flow    null    0   null    null    null
"cust3","MM1","SHIP_CUST_1d_AIR","2"    "cust3","MM1","CUST","2"    shipcust_to_cust    flow    null    0   null    null    null
"cust3","MM1","SHIP_CUST_1d_AIR","3"    "cust3","MM1","CUST","3"    shipcust_to_cust    flow    null    0   null    null    null
"cust3","MM1","SHIP_CUST_1d_AIR","4"    "cust3","MM1","CUST","4"    shipcust_to_cust    flow    null    0   null    null    null
"cust3","MM1","SHIP_CUST_1d_AIR","5"    "cust3","MM1","CUST","5"    shipcust_to_cust    flow    null    0   null    null    null
"cust3","MM1","SHIP_CUST_1d_AIR","6"    "cust3","MM1","CUST","6"    shipcust_to_cust    flow    null    0   null    null    null
"cust3","MM1","SHIP_CUST_1d_AIR","7"    "cust3","MM1","CUST","7"    shipcust_to_cust    flow    null    0   null    null    null
"cust3","MM1","SHIP_CUST_1d_AIR","8"    "cust3","MM1","CUST","8"    shipcust_to_cust    flow    null    0   null    null    null
"cust3","MM1","SHIP_CUST_1d_AIR","9"    "cust3","MM1","CUST","9"    shipcust_to_cust    flow    null    0   null    null    null
"cust3","MM1","SHIP_CUST_1d_AIR","10"   "cust3","MM1","CUST","10"   shipcust_to_cust    flow    null    0   null    null    null
"cust3","MM1","CUST","6"    "SINK","-","-","100"    cust_to_sink    flow    demand  0   null    null    5
"vmi1","MM1","VMI","0"  "cust3","MM1","SHIP_CUST_2d_AIR","2"    vmi_to_shipcust flow    null    15  null    null    null
"vmi1","MM1","VMI","1"  "cust3","MM1","SHIP_CUST_2d_AIR","3"    vmi_to_shipcust flow    null    15  null    null    null
"vmi1","MM1","VMI","2"  "cust3","MM1","SHIP_CUST_2d_AIR","4"    vmi_to_shipcust flow    null    15  null    null    null
"vmi1","MM1","VMI","3"  "cust3","MM1","SHIP_CUST_2d_AIR","5"    vmi_to_shipcust flow    null    15  null    null    null
"vmi1","MM1","VMI","4"  "cust3","MM1","SHIP_CUST_2d_AIR","6"    vmi_to_shipcust flow    null    15  null    null    null
"vmi1","MM1","VMI","5"  "cust3","MM1","SHIP_CUST_2d_AIR","7"    vmi_to_shipcust flow    null    15  null    null    null
"vmi1","MM1","VMI","6"  "cust3","MM1","SHIP_CUST_2d_AIR","8"    vmi_to_shipcust flow    null    15  null    null    null
"vmi1","MM1","VMI","7"  "cust3","MM1","SHIP_CUST_2d_AIR","9"    vmi_to_shipcust flow    null    15  null    null    null
"vmi1","MM1","VMI","8"  "cust3","MM1","SHIP_CUST_2d_AIR","10"   vmi_to_shipcust flow    null    15  null    null    null
"cust3","MM1","SHIP_CUST_2d_AIR","2"    "cust3","MM1","CUST","2"    shipcust_to_cust    flow    null    0   null    null    null
"cust3","MM1","SHIP_CUST_2d_AIR","3"    "cust3","MM1","CUST","3"    shipcust_to_cust    flow    null    0   null    null    null
"cust3","MM1","SHIP_CUST_2d_AIR","4"    "cust3","MM1","CUST","4"    shipcust_to_cust    flow    null    0   null    null    null
"cust3","MM1","SHIP_CUST_2d_AIR","5"    "cust3","MM1","CUST","5"    shipcust_to_cust    flow    null    0   null    null    null
"cust3","MM1","SHIP_CUST_2d_AIR","6"    "cust3","MM1","CUST","6"    shipcust_to_cust    flow    null    0   null    null    null
"cust3","MM1","SHIP_CUST_2d_AIR","7"    "cust3","MM1","CUST","7"    shipcust_to_cust    flow    null    0   null    null    null
"cust3","MM1","SHIP_CUST_2d_AIR","8"    "cust3","MM1","CUST","8"    shipcust_to_cust    flow    null    0   null    null    null
"cust3","MM1","SHIP_CUST_2d_AIR","9"    "cust3","MM1","CUST","9"    shipcust_to_cust    flow    null    0   null    null    null
"cust3","MM1","SHIP_CUST_2d_AIR","10"   "cust3","MM1","CUST","10"   shipcust_to_cust    flow    null    0   null    null    null
"vmi2","MM2","VMI","0"  "cust3","MM2","SHIP_CUST_1d_AIR","1"    vmi_to_shipcust flow    null    1.8 null    null    null
"vmi2","MM2","VMI","1"  "cust3","MM2","SHIP_CUST_1d_AIR","2"    vmi_to_shipcust flow    null    1.8 null    null    null
"vmi2","MM2","VMI","2"  "cust3","MM2","SHIP_CUST_1d_AIR","3"    vmi_to_shipcust flow    null    1.8 null    null    null
"vmi2","MM2","VMI","3"  "cust3","MM2","SHIP_CUST_1d_AIR","4"    vmi_to_shipcust flow    null    1.8 null    null    null
"vmi2","MM2","VMI","4"  "cust3","MM2","SHIP_CUST_1d_AIR","5"    vmi_to_shipcust flow    null    1.8 null    null    null
"vmi2","MM2","VMI","5"  "cust3","MM2","SHIP_CUST_1d_AIR","6"    vmi_to_shipcust flow    null    1.8 null    null    null
"vmi2","MM2","VMI","6"  "cust3","MM2","SHIP_CUST_1d_AIR","7"    vmi_to_shipcust flow    null    1.8 null    null    null
"vmi2","MM2","VMI","7"  "cust3","MM2","SHIP_CUST_1d_AIR","8"    vmi_to_shipcust flow    null    1.8 null    null    null
"vmi2","MM2","VMI","8"  "cust3","MM2","SHIP_CUST_1d_AIR","9"    vmi_to_shipcust flow    null    1.8 null    null    null
"vmi2","MM2","VMI","9"  "cust3","MM2","SHIP_CUST_1d_AIR","10"   vmi_to_shipcust flow    null    1.8 null    null    null
"cust3","MM2","SHIP_CUST_1d_AIR","1"    "cust3","MM2","CUST","1"    shipcust_to_cust    flow    null    0   null    null    null
"cust3","MM2","SHIP_CUST_1d_AIR","2"    "cust3","MM2","CUST","2"    shipcust_to_cust    flow    null    0   null    null    null
"cust3","MM2","SHIP_CUST_1d_AIR","3"    "cust3","MM2","CUST","3"    shipcust_to_cust    flow    null    0   null    null    null
"cust3","MM2","SHIP_CUST_1d_AIR","4"    "cust3","MM2","CUST","4"    shipcust_to_cust    flow    null    0   null    null    null
"cust3","MM2","SHIP_CUST_1d_AIR","5"    "cust3","MM2","CUST","5"    shipcust_to_cust    flow    null    0   null    null    null
"cust3","MM2","SHIP_CUST_1d_AIR","6"    "cust3","MM2","CUST","6"    shipcust_to_cust    flow    null    0   null    null    null
"cust3","MM2","SHIP_CUST_1d_AIR","7"    "cust3","MM2","CUST","7"    shipcust_to_cust    flow    null    0   null    null    null
"cust3","MM2","SHIP_CUST_1d_AIR","8"    "cust3","MM2","CUST","8"    shipcust_to_cust    flow    null    0   null    null    null
"cust3","MM2","SHIP_CUST_1d_AIR","9"    "cust3","MM2","CUST","9"    shipcust_to_cust    flow    null    0   null    null    null
"cust3","MM2","SHIP_CUST_1d_AIR","10"   "cust3","MM2","CUST","10"   shipcust_to_cust    flow    null    0   null    null    null
"cust3","MM2","CUST","8"    "SINK","-","-","100"    cust_to_sink    flow    demand  0   null    null    7
"vmi2","MM2","VMI","0"  "cust3","MM2","SHIP_CUST_2d_AIR","2"    vmi_to_shipcust flow    null    1.8 null    null    null
"vmi2","MM2","VMI","1"  "cust3","MM2","SHIP_CUST_2d_AIR","3"    vmi_to_shipcust flow    null    1.8 null    null    null
"vmi2","MM2","VMI","2"  "cust3","MM2","SHIP_CUST_2d_AIR","4"    vmi_to_shipcust flow    null    1.8 null    null    null
"vmi2","MM2","VMI","3"  "cust3","MM2","SHIP_CUST_2d_AIR","5"    vmi_to_shipcust flow    null    1.8 null    null    null
"vmi2","MM2","VMI","4"  "cust3","MM2","SHIP_CUST_2d_AIR","6"    vmi_to_shipcust flow    null    1.8 null    null    null
"vmi2","MM2","VMI","5"  "cust3","MM2","SHIP_CUST_2d_AIR","7"    vmi_to_shipcust flow    null    1.8 null    null    null
"vmi2","MM2","VMI","6"  "cust3","MM2","SHIP_CUST_2d_AIR","8"    vmi_to_shipcust flow    null    1.8 null    null    null
"vmi2","MM2","VMI","7"  "cust3","MM2","SHIP_CUST_2d_AIR","9"    vmi_to_shipcust flow    null    1.8 null    null    null
"vmi2","MM2","VMI","8"  "cust3","MM2","SHIP_CUST_2d_AIR","10"   vmi_to_shipcust flow    null    1.8 null    null    null
"cust3","MM2","SHIP_CUST_2d_AIR","2"    "cust3","MM2","CUST","2"    shipcust_to_cust    flow    null    0   null    null    null
"cust3","MM2","SHIP_CUST_2d_AIR","3"    "cust3","MM2","CUST","3"    shipcust_to_cust    flow    null    0   null    null    null
"cust3","MM2","SHIP_CUST_2d_AIR","4"    "cust3","MM2","CUST","4"    shipcust_to_cust    flow    null    0   null    null    null
"cust3","MM2","SHIP_CUST_2d_AIR","5"    "cust3","MM2","CUST","5"    shipcust_to_cust    flow    null    0   null    null    null
"cust3","MM2","SHIP_CUST_2d_AIR","6"    "cust3","MM2","CUST","6"    shipcust_to_cust    flow    null    0   null    null    null
"cust3","MM2","SHIP_CUST_2d_AIR","7"    "cust3","MM2","CUST","7"    shipcust_to_cust    flow    null    0   null    null    null
"cust3","MM2","SHIP_CUST_2d_AIR","8"    "cust3","MM2","CUST","8"    shipcust_to_cust    flow    null    0   null    null    null
"cust3","MM2","SHIP_CUST_2d_AIR","9"    "cust3","MM2","CUST","9"    shipcust_to_cust    flow    null    0   null    null    null
"cust3","MM2","SHIP_CUST_2d_AIR","10"   "cust3","MM2","CUST","10"   shipcust_to_cust    flow    null    0   null    null    null
"SINK","-","-","100"    "source","-","-","0"    closed_loop flow    null    0   null    null    null

我的 R 代码如下:您必须获取上述 csv 数据并将其粘贴到文件 C:/dumy_network.csv 中。

我的 R 代码可能效率不高,但它可以达到目的!

library("lpSolve", lib.loc="C:/Users/njog/Documents/R/win-library/3.0")

#get the data from CSV file
mydata <- read.csv("C:/dumy_network.csv", header=TRUE)

#build list of nodes (no repetition)
nodes=unique(c(as.character(mydata$startlink),as.character(mydata$endlink)))
#list of all links
links=mydata[,1:2]
#cost of moving material on each link - optimization problem objective coefficients
cost=mydata$cost

#decision variable is flow on each link. Objective is to minimize product of (cost on each link*flow on the link). Therefore, count of decision variable is equal to count of links.

#constraints matrix: for each node in nodes, incoming quantity should be equal to outgoing quantity. 

constraints=matrix(0,sum(mydata$max_const!='null')+sum(mydata$equality_const!='null')+length(nodes),length(mydata$endlink))

for (i in 1:length(nodes) ) {
  constraints[i,]=t(1*(nodes[i]==links[,1])-1*(nodes[i]==links[,2]))
}

#get constraints for equality constraints- in some cases we have to ship material exactly same as this quanity.
constraint1=matrix(mydata$equality_const,1,length(mydata$equality_const))
constraint1[constraint1=="null"]=0
constraint1=as.numeric(constraint1)
constraint1_length=which(constraint1!=0)

constraint1_final=matrix(0,length(constraint1_length),length(mydata$equality_const))

for (i in 1:length(constraint1_length) ) {
  constraint1_final[i,constraint1_length[i]]=1
}
start=length(nodes)+1
end=length(nodes)+length(constraint1_length)
constraints[start:end,]=constraint1_final

#get constraints for maxconstraints - in some cases we cannot ship material exceeding this quanity.
constraint2=matrix(mydata$max_const,1,length(mydata$max_const))
constraint2[constraint2=="null"]=0
constraint2=as.numeric(constraint2)
constraint2_length=which(constraint2!=0)

constraint2_final=matrix(0,length(constraint2_length),length(mydata$max_const))

for (i in 1:length(constraint2_length) ) {
  constraint2_final[i,constraint2_length[i]]=1
}
start=end+1
end=end+length(constraint2_length)
constraints[start:end,]=constraint2_final


#building direction of constraints
direction=c(rep("=",length(nodes)),rep("=",sum(mydata$equality_const!='null')),rep("<=",sum(mydata$max_const!='null')))

#building right hand side of constraints
b1=as.numeric(as.character(mydata$equality_const[constraint1_length]))
b2=as.numeric(as.character(mydata$max_const[constraint2_length]))
b=c(rep(0,length(nodes)),b1,b2)

res = lpSolve::lp('min', cost, constraints, direction, b,  all.int = TRUE)
res$solution

answers1=data.frame(res$solution)
mydata=cbind(mydata,answers1)

======================================更新2=========== =========================== 没有得到任何答案,所以试图简化我的问题:

页面的示例部分给出了一个简单的问题。有谁知道如何使用 Mapreduce 解决它?我的意思是说我有一个类似的问题,但是有大量的变量和约束,那么有没有办法实现更快的处理?

4

1 回答 1

2

简而言之,您想做大规模的线性规划 (lp),但您对求解器的性能不满意。

方法

我建议以下方法。

求解器

你需要使用这个求解器吗?以下是一些替代方案:
- Gurobi
- Mosek
- CPlex

并行执行

实现并行处理的一个弱方法是并行运行进程。您可以一次启动多个优化吗?(在这里,您可以在 Hadoop 中编写一个简单的执行任务)

改进的输入

如果您相应地提交数据(稀疏矩阵,...),求解器的性能会更好

在您的代码中,您使用lpSolve::lp. 根据lpSolver 5.6.7 的 CRAN 页面及其PDF,传输问题有一个特殊的模式lpSolve:lp.transport。(我没有使用过 R,也不熟悉语法。我是 Matlab 的“爱好者”。)

最新研究

也许一些精力花在了学术界。您可能会在sciencedirect.com上找到一篇论文(花费一些美元)。

硬件

CPU 越快,您获得解决方案的速度就越快(答案)。您介意给我们一些关于您的环境(操作系统、CPU)的见解吗?

最后的想法

您是否尝试在quant.stackexchange.com中提出您的问题,因为数值优化与数学密切相关并且“不涉及那么多编程”。

并联模式

我们使用CLP。根据一些同事的说法,您可以设置一个标志或使用不同的实现来并行运行求解器(1 个问题在多个内核上执行)。看看交响乐。




随时向我们发布消息,您介意给我们一些关于您的环境(操作系统、CPU)的见解吗?

我的赏金

在 Quora 上,您会发现 Hadoop 擅长数据处理,I/O 速度快,不是专门为优化或计算而设计的:Quora

请让我知道,如果你不想用赏金奖励我。

缺少 +100 的赏金

即使我做了一些研究,我也没有收到任何赏金......这个帖子到了一个地步,你没有给我们必要的细节,我们应该为你解决它 - 这永远不会成功!

于 2014-04-13T13:05:15.610 回答