代码之家  ›  专栏  ›  技术社区  ›  XerXes

为各种n运行SCIMP

  •  0
  • XerXes  · 技术社区  · 9 年前

    我有一个线性程序,我可以为n输入数字,它给我这个特定n的LP输出。我现在想为n=10…1000的各种情况做这个。有没有一种技术,我不必对每个n手动执行,而是自动执行,并在文件中输出每个n的LP解?我喜欢稍后绘制图表。

    这是我的线性程序:

    #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;
    
    1 回复  |  直到 9 年前
        1
  •  2
  •   mueldgog    9 年前

    您可以通过控制台提供参数:

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

    然后,您可以通过使用shell脚本(例如。,

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