2015-05-04 73 views
0

我目前正在使用IBM ILOG CPLEX Optimization Studio編程CPLEX/OPL模型。 我有一個使用包含子集並取決於另一個參數/變量的總和或索引的問題,例如,檢查以下約束:NB 2,3,4,8)。CPLEX/OPL模型 - 子集索引的約束條件

任何人都可以幫我正確地合併這些限制嗎?

請找到源代碼附:

//Parameter 

int maxblock=...;     //number of blocks (I) 
int maxprodfam=...;    //number of product families (J) 
int maxprod=...;     //number of products (P) 
int maxdemand=...;     //number of demand elements (K) 

range blocks=1..maxblock; 
range prodfam=1..maxprodfam; 
range products=1..maxprod; 
range demandelements=1..maxdemand; 

int startalpha[blocks]=...;  //earliest start time of block i 
int endalpha[blocks]=...;  //latest completion time of block i 
int prodtime[products]=...;  //unit production time for product p (a) 
int minorsetup[products]=...; //minor setup time per sub-lot of product p (s) 
int majorsetup[prodfam]=...;  //major setup time for product family j (S) 
int demand[products]=...;   //demand elements (d) 

//Variablen 

dvar int+ x[blocks][demandelements]; //quantity of demand element k satisfied from production in block i (x) 
dvar boolean y[blocks][prodfam];  //product family assessment to blocks (y) 
dvar boolean q[blocks][products];  //product assessment to blocks 
dvar boolean o[blocks];    //activation of blocks (e.g. if a prodfam is assignes to it) 
dvar int+ alpha[blocks];    //start time block 
dvar int+ duration[blocks];   //duration of block 

//Modell 

minimize 
alpha[maxblock]+duration[maxblock]; //objective function (minimize the makespan) 

subject to { 
forall(i in blocks) 
    NB1: //one product family assigned to each block 
    sum(j in prodfam) 
     y[i][j]==o[i]; 

forall(i in blocks, j in prodfam) 
    NB2: //production sub-lots 
    sum(p in products(j))q[i][p]<=y[i][j]*abs(products(j)); 

forall(i in blocks, k in demandelements(i)) 
    NB3: //product flow from block i into demand element k 
    x[i][k]<=demand[k]*q[i][p(k)]; 

forall(i in blocks) 
    NB4: //block schedule 
    duration[i]==sum(j in prodfam)majorsetup[j]*y[i][j] 
    +sum(p in products)minorsetup[p]*q[i][p] 
    +sum(k in demandelements(i))alpha[p(k)]*x[i][k]; 

forall(i in 2..maxblock) 
    NB5: //block starts when other block finished 
    alpha[i]>=alpha[i-1]+duration[i-1]; 

forall(i in blocks) 
    NB6: //time window earliest start 
    alpha[i]>=startalpha[i]*o[i]; 

forall(i in blocks) 
    NB7: //time window latest completion 
    alpha[i]+duration[i]<=endalpha[i]; 

forall(k in demandelements) 
    NB8: //matching output and demand 
    sum(i in blocks(k))x[i][k]==demand[k]; 
} 

回答

0

目前尚不清楚你的問題是什麼,但我猜你的問題是使用約束2.嘗試與造型之類的產品(j)辦理爲這些設置 - 因此在每個產品系列中創建一系列產品。作爲安裝的一部分提供的OPL示例中有這樣的例子。例如,在示例\ opl \ models \ AssemblySequencing \ Sequence模型中,我們有

{string} computer[AllComputers] = ...; 

因此,您可以做類似於例如

{int} productsInFamily[prodfam] = ...; 

編輯:採用新型結構...嘗試類似:

forall(i in blocks, j in prodfam) 
    NB2: //production sub-lots 
    sum(p in productsInFamily[j])q[i][p]<=y[i][j]*abs(products(j)); 

還有很多其他的方法可以做到這種數據結構的,有的可能是更有效的,有些人可能會賺更多從商業角度來看。我個人喜歡使用一組東西,特別是使用元組集合。瞭解數據結構類型以及如何將它們結合到OPL中,因爲擁有正確的數據結構總是有助於您的建模。

+0

如何在模型中使用創建的數組? NB2://生產子批 sum(產品(j)中的p)q [i] [p] <= y [i] [j] * ABS(製品(J)); –

+0

看我上面的編輯。 – TimChippingtonDerrick

+0

它不起作用..也許是由於分配給產品系列和所有產品的產品之間的缺失鏈接? –