Commit 82ed6d06 authored by Erkka Rinne's avatar Erkka Rinne
Browse files

Fixed a bug with sample space calculation for long-term scenarios

Also a minor speedup for setting model dimension (set `msft` etc.)
parent cd6ab456
...@@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file. ...@@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file.
- Automated the calculation of sample start and end times if using long-term - Automated the calculation of sample start and end times if using long-term
scenarios. Also setting number of scenarios to one, instructs the model to use scenarios. Also setting number of scenarios to one, instructs the model to use
central forecast for the long-term. central forecast for the long-term.
- Speedup for model dimension calculation (set `msft` etc.)
## [1.0.6] - 2019-03-27 ## [1.0.6] - 2019-03-27
### Fixed ### Fixed
......
...@@ -68,10 +68,6 @@ $offtext ...@@ -68,10 +68,6 @@ $offtext
// Set previous samples for samples // Set previous samples for samples
ss(s, s_)$(msStart(m, s) = msEnd(m, s_)) = yes; ss(s, s_)$(msStart(m, s) = msEnd(m, s_)) = yes;
); );
if(mSettings(m, 'scenarios') and not ms_initial(m, s),
ms_central(mSolve, s) = yes;
p_msProbability(m, s) = 1;
);
); );
// Select forecasts in use for the models // Select forecasts in use for the models
......
...@@ -145,11 +145,12 @@ Option clear = p_stepLength; ...@@ -145,11 +145,12 @@ Option clear = p_stepLength;
Option clear = msft; Option clear = msft;
Option clear = mft; Option clear = mft;
Option clear = ft; Option clear = ft;
Option clear = sft; Option clear = sft, clear = fts;
Option clear = mst_start, clear = mst_end; Option clear = mst_start, clear = mst_end;
$ifthen declared scenario $ifthen declared scenario
if(mSettings(mSolve, 'scenarios'), // Only clear these if using long-term scenarios if(mSettings(mSolve, 'scenarios'), // Only clear these if using long-term scenarios
Options clear = s_active, clear = s_scenario, clear = ss; Options clear = s_active, clear = s_scenario, clear = ss,
clear = p_msProbability, clear = ms_central;
); );
$endif $endif
...@@ -230,7 +231,7 @@ loop(cc(counter), ...@@ -230,7 +231,7 @@ loop(cc(counter),
// Determine the combinations of forecasts and intervals // Determine the combinations of forecasts and intervals
// Include the t_jump for the realization // Include the t_jump for the realization
mft(mf(mSolve, f_solve), tt_interval(t)) ft(f_solve, tt_interval(t))
${ord(t) <= tSolveFirst + max(mSettings(mSolve, 't_jump'), ${ord(t) <= tSolveFirst + max(mSettings(mSolve, 't_jump'),
min(mSettings(mSolve, 't_perfectForesight'), min(mSettings(mSolve, 't_perfectForesight'),
currentForecastLength)) currentForecastLength))
...@@ -238,7 +239,7 @@ loop(cc(counter), ...@@ -238,7 +239,7 @@ loop(cc(counter),
} = yes; } = yes;
// Include the full horizon for the central forecast // Include the full horizon for the central forecast
mft(mf(mSolve, f_solve), tt_interval(t)) ft(f_solve, tt_interval(t))
${ord(t) > tSolveFirst + max(mSettings(mSolve, 't_jump'), ${ord(t) > tSolveFirst + max(mSettings(mSolve, 't_jump'),
min(mSettings(mSolve, 't_perfectForesight'), min(mSettings(mSolve, 't_perfectForesight'),
currentForecastLength)) currentForecastLength))
...@@ -247,7 +248,7 @@ loop(cc(counter), ...@@ -247,7 +248,7 @@ loop(cc(counter),
} = yes; } = yes;
// Include up to forecastLength for remaining forecasts // Include up to forecastLength for remaining forecasts
mft(mf(mSolve, f_solve), tt_interval(t)) ft(f_solve, tt_interval(t))
${not mf_central(mSolve, f_solve) ${not mf_central(mSolve, f_solve)
and not mf_realization(mSolve, f_solve) and not mf_realization(mSolve, f_solve)
and ord(t) > tSolveFirst + max(mSettings(mSolve, 't_jump'), and ord(t) > tSolveFirst + max(mSettings(mSolve, 't_jump'),
...@@ -261,67 +262,72 @@ loop(cc(counter), ...@@ -261,67 +262,72 @@ loop(cc(counter),
// Update tActive // Update tActive
t_active(tt_interval) = yes; t_active(tt_interval) = yes;
// Reset initial sample start and end times if using scenarios // Update tCounter for the next block of intervals
if(mSettings(mSolve, 'scenarios'), tCounter = mInterval(mSolve, 'lastStepInIntervalBlock', counter) + 1;
msStart(ms_initial) = 1;
msEnd(ms_initial) = currentForecastLength + 1; ); // END loop(counter)
);
// Reset initial sample start and end times if using scenarios
if(mSettings(mSolve, 'scenarios'),
Option clear = msStart, clear = msEnd;
msStart(ms_initial) = 1;
msEnd(ms_initial) = currentForecastLength + 1;
);
// Loop over defined samples // Loop over defined samples
msft(msf(mSolve, s, f_solve), tt_interval(t)) loop(msf(mSolve, s, f)$msStart(mSolve, s),
${ord(t) > msStart(mSolve, s) + tSolveFirst - 1 // Move the samples along with the dispatch // Move the samples along with the dispatch
and ord(t) < msEnd(mSolve, s) + tSolveFirst // Move the samples along with the dispatch sft(s, ft(f, t))${ord(t) > msStart(mSolve, s) + tSolveFirst - 1
} = mft(mSolve, f_solve, t); and ord(t) < msEnd(mSolve, s) + tSolveFirst
} = yes;
);
$ifthen defined scenario $ifthen defined scenario
// Create stochastic programming scenarios // Create stochastic programming scenarios
// Select root sample and central forecast // Select root sample and central forecast
loop((ms_initial(mSolve, s_), mf_central(mSolve, f_)), loop((ms_initial(mSolve, s_), mf_central(mSolve, f)),
s_active(s_) = yes; s_active(s_) = yes;
loop(scenario$(ord(scenario) <= mSettings(mSolve, 'scenarios')), p_msProbability(mSolve, s_) = 1;
s_scenario(s_, scenario) = yes; loop(scenario$(ord(scenario) <= mSettings(mSolve, 'scenarios')),
loop(tt_interval(t)$(ord(t) >= msEnd(mSolve, s_) + tSolveFirst), s_scenario(s_, scenario) = yes;
mft(mSolve, f_, t) = yes; if(mSettings(mSolve, 'scenarios') > 1,
if(mSettings(mSolve, 'scenarios') > 1, loop(ft(f, t)$(ord(t) >= msEnd(mSolve, s_) + tSolveFirst),
loop(s$(ord(s) = mSettings(mSolve, 'samples') + count_sample), loop(s$(ord(s) = mSettings(mSolve, 'samples') + count_sample),
s_active(s) = yes; s_active(s) = yes;
ms(mSolve, s) = yes; ms_central(mSolve, s) = yes;
ms_central(mSolve, s) = yes; sft(s, f, t) = yes;
msf(mSolve, s, f_) = yes; s_scenario(s, scenario) = yes;
msft(mSolve, s, f_, t) = yes; p_msProbability(mSolve, s) = p_scenProbability(scenario);
s_scenario(s, scenario) = yes; msStart(mSolve, s) = ord(t) - tSolveFirst;
p_msProbability(mSolve, s) = p_scenProbability(scenario); msEnd(mSolve, s) = ord(t) - tSolveFirst
msStart(mSolve, s) = ord(t) - tSolveFirst; + p_stepLength(mSolve, f, t);
msEnd(mSolve, s)
= ord(t) - tSolveFirst
+ mInterval(mSolve, 'stepsPerInterval', counter);
);
count_sample = count_sample + 1;
elseif mSettings(mSolve, 'scenarios') = 1,
loop(ms_central(mSolve, s),
s_scenario(s, scenario) = yes;
msStart(mSolve, s) = msEnd(mSolve, s_);
msEnd(mSolve, s) = msStart(mSolve, s_)
+ mSettings(mSolve, 't_horizon');
msft(mSolve, s, f_, t) = yes;
);
); );
count_sample = count_sample + 1;
);
elseif mSettings(mSolve, 'scenarios') = 1,
loop(ms(mSolve, s)$(not sameas(s, s_)),
s_active(s) = yes;
ms_central(mSolve, s) = yes;
p_msProbability(mSolve, s) = 1;
sft(s, ft(f, t)) = yes;
s_scenario(s, scenario) = yes;
msStart(mSolve, s) = msEnd(mSolve, s_);
msEnd(mSolve, s) = msStart(mSolve, s_)
+ mSettings(mSolve, 't_horizon');
); );
); );
); );
ms(ms_central(mSolve, s)) = yes;
msf(ms_central(mSolve, s), f) = yes;
);
$endif $endif
// Reduce the model dimension // Update the model specific sets and the reversed dimension set
ft(f_solve, tt_interval(t)) = mft(mSolve, f_solve, t); mft(mSolve, ft(f, t)) = yes;
ms(mSolve, s)$ms(mSolve, s) = s_active(s);
// Reduce the sample dimension msf(mSolve, s, f)$msf(mSolve, s, f) = s_active(s);
sft(s, f, t)$msft(mSolve, s, f, t) = ft(f, t); msft(mSolve, sft(s, f, t)) = yes;
fts(f, t, s)$sft(s, f, t) = ft(f, t); fts(ft(f, t), s)$sft(s, f, t) = yes;
// Update tCounter for the next block of intervals
tCounter = mInterval(mSolve, 'lastStepInIntervalBlock', counter) + 1;
); // END loop(counter)
* Build stochastic tree by definfing previous samples * Build stochastic tree by definfing previous samples
$ifthen defined scenario $ifthen defined scenario
......
...@@ -3,6 +3,7 @@ if(mSettings(mSolve, 'red_num_leaves') ...@@ -3,6 +3,7 @@ if(mSettings(mSolve, 'red_num_leaves')
or mSettings(mSolve, 'red_percentage'), or mSettings(mSolve, 'red_percentage'),
* Get probabilitiesfor samples * Get probabilitiesfor samples
Option clear = p_sProbability;
p_sProbability(s_active(s)) = p_msProbability(mSolve, s); p_sProbability(s_active(s)) = p_msProbability(mSolve, s);
* SCENRED2 parameters * SCENRED2 parameters
......
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