2017-06-21 130 views
0

我想爲我的設施位置問題使用大型數據集(3100個需求位置)。如何將多維數組模型轉換爲CPLEX中的元組結構?

其中一個約束是距離矩陣的大小。如果我使用二維數組來存儲位置之間的距離,我會存儲大量不必要的數據。 (像我不會在我的模型中使用長距離,所以我添加另一個約束,如< = maxdist)

而不是使用二維數組我試圖使用下面的元組,但是如果我不使用完整的距離矩陣(轉換爲元組)我沒有得到解決方案?

感謝您的建議...

{string} Supply = ...;  // Supply locations 
    {string} DC = ...;   // Candidate facility locations 
    {string} Demand = ...;  // Demand locations 

    tuple Dist_Tup{ 
    string FROM; 
    string TO; 
    float MILES; 
    }; 

    setof(Dist_Tup) DistanceTmp=...; 
    setof(Dist_Tup) Distance = { <FROM,TO,MILES> | <FROM,TO,MILES> in DistanceTmp : FROM in Supply || FROM in DC}; 

    dexpr float TransportCost1 = sum(i in Supply , a in Alt , j in DC , p in Period, BB in Distance : BB.TO==j && BB.FROM==i) X[i][a][j][p]*Dist[BB]*C[i][j]; 

    //dexpr float TransportCost1 = sum(i in Supply , a in Alt , j in DC , p in Period) X[i][a][j][p]*G[i][a][j]*C[i][j]; 
+0

是否與工作小例子問題,例如與3,4或5個位置來檢查邏輯和一致性 – TimChippingtonDerrick

+0

元組結構不適用於小尺寸,但我用陣列結構(行與//dexpr ...)的小問題,它工作正常... – KaanU

+0

該模型應該與這兩種實現類似或相同。我建議您嘗試使用兩個版本的小型實例,並將CPLEX中的模型作爲LP文件導出,以便您可以將它們進行比較。 – TimChippingtonDerrick

回答

0
從問題

感動的解決方案來回答:

我的新代碼作爲一種解決方案:

tuple Arc { 
string FROM; 
string TO; 
} 
tuple Dist_Tup{ 
string FROM; 
string TO; 
float MILES; 
}; 
setof(Dist_Tup) Distance=...; 
setof(Arc) SDC_Arcs = { <FROM,TO> | <FROM,TO,MILES> in Distance : FROM in Supply && TO in DC}; 
setof(Arc) SD_Arcs = { <FROM,TO> | <FROM,TO,MILES> in Distance : FROM in Supply && TO in Demand && MILES<=maxDist}; 
setof(Arc) DCD_Arcs = { <FROM,TO> | <FROM,TO,MILES> in Distance : FROM in DC && TO in Demand && MILES<=maxDist}; 

dexpr float TransportCost1 = sum(i in Supply , a in Alt , j in DC , p in Period, DIST in Distance : DIST.FROM==i && DIST.TO==j, ARC in SDC_Arcs : ARC.FROM==i && ARC.TO==j) X[ARC][a][p]*G2[DIST]*C[i][j];