scenred.gms 2.76 KB
Newer Older
1
2
3
4
5
* Ensure scenario reduction setting are given
if(mSettings(mSolve, 'red_num_leaves')
   or mSettings(mSolve, 'red_percentage'),

* Get probabilitiesfor samples
6
p_sProbability(s_active(s)) = p_msProbability(mSolve, s);
7
8

* SCENRED2 parameters
9
10
ScenRedParms('red_num_leaves') = min(mSettings(mSolve, 'red_num_leaves'),
                                     mSettings('schedule', 'scenarios'));
11
ScenRedParms('red_percentage') = mSettings(mSolve, 'red_percentage');
12
13
ScenRedParms('scen_red') = 1$mSettings(mSolve, 'red_num_leaves'); // Reduce scenarios
ScenRedParms('tree_con') = 1$mSettings(mSolve, 'red_percentage');  // Tree construction
14
15
*ScenRedParms('report_level') = 2;
ScenRedParms('run_time_limit') = 30;
16
$ifthene %debug%>1
17
18
19
20
ScenRedParms('visual_init') = 1;
ScenRedParms('visual_red') = 1;
$endif

Erkka Rinne's avatar
Erkka Rinne committed
21
* Export data
22
execute_unload 'srin.gdx', ScenRedParms,
23
24
                           s_active, ss, p_sProbability,
                           ts_influx_, ts_cf_;
Erkka Rinne's avatar
Erkka Rinne committed
25
26
27
28
29
* Choose right null device
$ifthen %system.filesys% == 'MSNT' $set nuldev NUL
$else $set nuldev /dev/null
$endif
* Execute SCENRED2 and load data
Erkka Rinne's avatar
Erkka Rinne committed
30
put log "Executing SCENRED2"/; putclose log;
Erkka Rinne's avatar
Erkka Rinne committed
31
execute 'scenred2 inc/scenred.cmd > %nuldev%';
32

33
34
35
36
37
38
39
40
41
42
43
44
if(errorLevel,
    put log "!!! Scenario reduction (SCENRED2) failed. ";
    put log "See file 'sr.log' for details."/;
    putclose;
    execError = execError + 1;
else
    execute_load 'srout.gdx', ScenRedReport,
                              ss=red_ancestor,
                              p_sProbability=red_prob;

    // Update probabilities
    p_msProbability(mSolve, s) = p_sProbability(s);
45

46
47
48
49
50
    // Update sets
    ms(mSolve, s)$ms(mSolve, s) = yes$p_msProbability(mSolve, s);
    msf(mSolve, s, f)$msf(mSolve, s, f) = ms(mSolve, s);
    msft(mSolve, s, f, t)$msft(mSolve, s, f, t) = msf(mSolve, s, f);
    sft(s, f, t)$sft(s, f, t) = yes$p_msProbability(mSolve, s);
51

52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
    // Update scenarios
    Option clear = s_scenario;
    count = 1;
    loop((mft_lastSteps(mSolve, f, t), msft(mSolve, s_, f, t)),  // Select each leaf sample
        Option clear = s_prev; s_prev(s_) = yes;
        loop(scenario$(ord(scenario) = count),
            s_scenario(s_, scenario) = yes;
            tmp = 0;
            repeat(
                loop(ss(s__, s)$s_prev(s__),
                    s_scenario(s, scenario) = yes;
                    Option clear = s_prev; s_prev(s) = yes;
                    tmp = ms_initial(mSolve, s);
                );
            until tmp);
        );
        count = count + 1;
    );
Erkka Rinne's avatar
Erkka Rinne committed
70

71
72
73
74
75
76
    // Clear data from removed samples
    ts_influx_(gn, ft, s_active(s))$(not p_sProbability(s)) = 0;
    ts_cf_(flowNode, ft, s_active(s))$(not p_sProbability(s)) = 0;

    s_active(s)$s_active(s) = yes$p_sProbability(s);
);
Erkka Rinne's avatar
Erkka Rinne committed
77

78
79
80
else
    put log "!!! No scenario reduction setting given, skipping scenario reduction!"/;
);