Commit 26073e37 authored by Erkka Rinne's avatar Erkka Rinne
Browse files

Scenario reduction using SCENRED2

Activate this feature using active('scenRed') and setting mSettings parameters 'red_num_leaves' or 'red_percentage'.
parent 94ceea53
......@@ -72,6 +72,8 @@ files log /''/, gdx, f_info /'output\info.txt'/;
* Include options file to control the solver
$include 'input\1_options.gms';
* === Libraries ===============================================================
$libinclude scenred2
* === Definitions, sets, parameters and input data=============================
$include 'inc\1a_definitions.gms' // Definitions for possible model settings
......
......@@ -54,7 +54,9 @@ Sets
// Features
t_trajectoryHorizon, // Length of the horizon when start-up and shutdown trajectories are considered (in time steps)
t_initializationPeriod, // Number of time steps in the beginning of the simulation which are solved but the results of which are not stored
dataLength // The maximum number of time steps in any input data time series (recommended for correctly circulating data)
dataLength, // The maximum number of time steps in any input data time series (recommended for correctly circulating data)
red_num_leaves "desired number of preserved scenarios or leaves (SCENRED)"
red_percentage "Desired relative distance (accuracy) of scenario reduction (SCENRED)"
/
// Solve info
......@@ -143,6 +145,7 @@ Sets
addOn "Use StoSSch as a storage add-on to a larger model"
extraRes "Use extra tertiary reserves for error in elec. load during time step"
rampSched "Use power based scheduling"
scenRed "Reduce number of long-tem scenarios using GAMS SCENRED2"
/
* --- Set to declare time series that will be read between solves ------------------------------------------------------
......
......@@ -114,6 +114,8 @@ Sets
t_latestForecast(t) "t for the latest forecast that is available"
gnss_bound(grid, node, s, s) "Bound the samples so that the state at the last interval of the first sample equals the state at the first interval of the second sample"
s_parallel(s) "Samples which are treated as parallel"
ss(s, s) "Previous sample of sample"
s_prev(s) "Temporary set for previous sample"
* --- Sets used for the changing unit aggregation and efficiency approximations
uft(unit, f, t) "Active units on intervals, enables aggregation of units for later intervals"
......
......@@ -84,6 +84,7 @@ Parameters
Parameters
p_msWeight(mType, s) "Weight of sample"
p_msProbability(mType, s) "Probability to reach sample conditioned on anchestor samples"
p_msProbability_orig(mType, s) "Original probabilities of samples in model"
p_mfProbability(mType, f) "Probability of forecast"
p_msft_probability(mType, s, f, t) "Probability of forecast"
p_sProbability(s) "Probability of sample"
......
......@@ -69,6 +69,8 @@ $offtext
);
);
// Store original probabilities
p_msProbability_orig(m, s) = p_msProbability(m, s);
// Select forecasts in use for the models
if (not sum(f, mf(m, f)), // unless they have been provided as input
......
......@@ -448,6 +448,12 @@ loop(ms(mSolve, s),
= ds(s, t);
);
* --- Scenario reduction ------------------------------------------------------
if(active(mSolve, 'scenred'),
$$include 'inc/scenred.gms'
);
* --- Calculate statistics of time series data --------------------------------
loop(gn(grid, node)$sum(timeseries, p_autocorrelation(node, timeseries)),
......
* SCENRED2 command file
log_file sr.log
input_gdx output/srin.gdx
output_gdx output/srout.gdx
sr_option inc/scenred.opt
visual_init orig_tree
visual_red reduced_tree
* Ensure scenario reduction setting are given
if(mSettings(mSolve, 'red_num_leaves')
or mSettings(mSolve, 'red_percentage'),
* Get probabilitiesfor samples
p_sProbability(s)$ms(mSolve, s) = p_msProbability_orig(mSolve, s);
* SCENRED2 parameters
*ScenRedParms('num_time_steps') = 2;
*ScenRedParms('num_leaves') = card(s) - 1;
*ScenRedParms('num_nodes') = card(s);
*ScenRedParms('num_random') = card(grid) * card(node) * card(f) * mSettings('schedule', 't_horizon');
ScenRedParms('red_num_leaves') = mSettings(mSolve, 'red_num_leaves');
ScenRedParms('red_percentage') = mSettings(mSolve, 'red_percentage');
ScenRedParms('scen_red') = 1; // Reduce scenarios
ScenRedParms('tree_con') = 0; // No tree construction
*ScenRedParms('report_level') = 2;
ScenRedParms('run_time_limit') = 30;
$ifthen %debug% == 'yes'
ScenRedParms('visual_init') = 1;
ScenRedParms('visual_red') = 1;
$endif
* Data exchange and execute SCENRED2
execute_unload 'output/srin.gdx', ScenRedParms,
s, ss, p_sProbability,
ts_influx_;
execute 'scenred2 inc/scenred.cmd';
execute_load 'output/srout.gdx', ScenRedReport,
p_sProbability=red_prob;
* Update probabilities
p_msProbability(mSolve, s) = p_sProbability(s);
* Update sets
msft(mSolve, s, f, t)$msft(mSolve, s, f, t) = p_msProbability(mSolve, s);
sft(s, f, t)$sft(s, f, t) = p_msProbability(mSolve, s);
s_parallel(s)$s_parallel(s) = p_sProbability(s);
else
put log "!!! No scenario reduction setting given, skipping scenario reduction!"/;
);
* SCENRED2 option file
* 1 - Forward, 2 - Backward, 0 - Default
reduction_method 0
* 1 - Transport (default), 2 - Fortet-Mourier, 3 - Wasserstein
metric_type 1
* choice of norm (example: 0 - max, 1 - sum, 2 - Euclidian)
p_norm 1
* 0 - scaling off, 1 - scaling on (default)
scaling 1
* metric order (integer, default is 1)
order 1
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment