[英]How to augment lpsolve R optimization solution to run on a hadoop cluster?
我正在使用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解決它? 我的意思是讓我說我有類似的問題,但是有大量的變量和約束,那么有沒有辦法實現更快的處理?
簡而言之,您希望大規模地進行線性編程(lp),並且您對求解器的性能不滿意。
我建議采用以下方法。
你需要使用這個求解器嗎? 以下是一些替代方案:
- Gurobi
- Mosek
- CPlex
實現並行處理的弱方法是並行運行流程。 你能一次推出幾個最佳選擇嗎? (在這里,你可以在Hadoop中編寫一個簡單的exectuion任務)
如果你相應地提交數據,求解器可以表現得更好(稀疏矩陣......)
在您的代碼中,您使用lpSolve::lp
。 根據lpSolver 5.6.7的CRAN頁面及其PDF ,運輸問題lpSolve:lp.transport
有一種特殊模式。 (我沒有和R一起工作,我不熟悉語法。我是一個Matlab“愛好者”。)
也許在學術界花了一些時間。 您可能會在sciencedirect.com上找到一篇論文(花費一些錢)。
CPU越快,獲得解決方案的速度就越快(答案)。 您介意給我們一些關於您的環境(操作系統,CPU)的見解嗎?
您是否曾嘗試在quant.stackexchange.com中提出您的問題,因為數值優化與數學密切相關並且“不涉及那么多編程”。
我們使用CLP 。 根據一些同事的說法,您可以設置一個標志或使用不同的實現來並行運行求解器(在許多核心上執行1個問題)。 看看SYMPHONY吧。
讓我們發布,您介意給我們一些關於您的環境(操作系統,CPU)的見解嗎?
在Quora上,您可以找到答案,Hadoop在數據處理方面表現出色,I / O速度快,不是專為優化或計算而設計的: Quora
如果您不想獎勵我,請告訴我。
即使我做了一些研究,我還沒有收到任何賞金......這個帖子到了你沒有給我們必要細節的地步,我們應該為你解決它 - 這永遠不會成功!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.