for-loopmatrixamplstochastic

How to improve my AMPL SP model with more dimensions


I have a problem with AMPL to do a stochastic programming,

currently I have three scenarios and assign probabilities before each solution.

for { t in 1..SIZE-1 by 2} {

    let Demand := DemandSeq[t];
    let Resources := ResourcesSeq[t];

    # change probability of each stage
    if StateSequence[t] = 1 # N
        then {
            let P[1]:= 0.7;
            let P[2]:= 0.2;
            let P[3]:= 0.1;
        }
    else if StateSequence[t] = 2 # A
        then {
            let P[1]:= 0.6;
            let P[2]:= 0.3;
            let P[3]:= 0.1;
        }
    else if StateSequence[t] = 3 # M
        then {
            let P[1]:= 0.5;
            let P[2]:= 0.4;
            let P[3]:= 0.1;
        };
  solve;
  ...
}

Now what if I change this three scenarios problem into a 10 scenarios problem. I already have a 10*10 probability matrix, but I don't know how to assign prob.


Solution

  • As I replied on the AMPL Google Group, you can define a two-dimensional parameter to store probabilities:

    param Probs{1..10, 1..10};
    

    define it in the data in a compact form (or read from a database or a spreadsheet), for example:

    data;
    param Probs :
       1   2   3   ...  10 :=
    1 0.1 0.2 0.05 ... 0.1
    ...
    

    and use an iterated form of let to assign the data to P:

    let {i in 1..10} P[i] := Prob[StateSequence[t], i];