2015-09-05 87 views
0

我有一個線性程序,我可以在n中輸入數字,它給了我對這個特定n的LP的輸出。我現在想爲各種n = 10 ... 1000做到這一點。有沒有一種技術,我不必手動做每個n,而是自動做到這一點,並輸出文件中每個n的LP的解決方案?我喜歡稍後繪製圖表。爲各種n運行SCIMP

這是我的線性規劃:

#Specify the number of n for the linear program. 
param n := 5000; 

#This is the set of probabilities of 
set N := {1 .. n}; 
#We specify the variables for the probabilities p_1,...p_n. 
var p[<i> in N] real >= 0; 

#These are the values of the vector c. It specifies a constant for each p_i. 
param c[<i> in N] := i/n ; 

#We define the entries a_{ij} of the Matrix A. 
defnumb a(i,j) := 
      if i < j then 0 
      else if i == j then i 
      else 1 end end; 

#The objective function. 
maximize prob: sum <i> in N : c[i] * p[i]; 

#The condition which needs to be fulfilled. 
subto condition: 
    forall <i> in N: 
     sum <j> in N: a(i,j) * p[j] <= 1; 

回答

2

您可以通過與控制檯給出的參數:

-D n=[number you want] -o [output file] 

然後,你可以通過只使用一個shell腳本重複數n表示,例如,

for i in {1..100} 
do 
zimpl -D n=$i -o 'output_'$i yourfile.zpl 
done