Commit ef7bbd63 authored by Erkka Rinne's avatar Erkka Rinne
Browse files

Make calculation of first and last steps of samples faster

Introduced a new set `mst` with combinations of models, samples and t's.
Using projections in for calculating some lower-dimension subsets.
parent a6d0b817
......@@ -117,6 +117,7 @@ Sets
mft(mType, f, t) "Combination of forecasts and t:s in the current model solve"
msf(mType, s, f) "Combination of samples and forecasts in the models"
msft(mType, s, f, t) "Combination of models, samples, forecasts and t's"
mst(mType, s, t) "Combination of models samples and t's"
sft(s, f, t) "Combination of samples, forecasts and t's in the current model solve"
sft_realized(s, f, t) "Realized sft"
sft_realizedNoReset(s, f, t) "Full set of realized sft, facilitates calculation of results"
......
......@@ -161,6 +161,7 @@ Option clear = msft;
Option clear = mft;
Option clear = ft;
Option clear = sft;
Option clear = mst;
Option clear = mst_start, clear = mst_end;
$ifthen declared scenario
if(mSettings(mSolve, 'scenarios'), // Only clear these if using long-term scenarios
......@@ -344,10 +345,8 @@ loop(msf(mSolve, s, f)$msStart(mSolve, s),
);
// Update the model specific sets and the reversed dimension set
mft(mSolve, ft(f, t)) = yes;
ms(mSolve, s)$ms(mSolve, s) = s_active(s);
msf(mSolve, s, f)$msf(mSolve, s, f) = s_active(s);
msft(mSolve, sft(s, f, t)) = yes;
Options mft < msft, ms < msft, msf < msft, mst < msft; // Projection
* Build stochastic tree by definfing previous samples
$ifthen defined scenario
......@@ -431,24 +430,16 @@ mft_lastSteps(mSolve, ft(f,t))
;
// Sample start and end intervals
mst_start(mst(mSolve, s, t))$[ord(t) - tSolveFirst = msStart(mSolve, s)] = yes;
loop(ms(mSolve, s),
tmp = 1;
tmp_ = 1;
loop(t_active(t),
if(tmp and ord(t) - tSolveFirst + 1 > msStart(mSolve, s),
mst_start(mSolve, s, t) = yes;
tmp = 0;
);
if(tmp_ and ord(t) - tSolveFirst + 1 > msEnd(mSolve, s),
mst_end(mSolve, s, t+dt(t)) = yes;
tmp_ = 0;
);
); // END loop(t_active)
// If the last interval of a sample is in mft_lastSteps, the method above does not work
if(tmp_,
mst_end(mSolve, s, t)${sum(f_solve, mft_lastSteps(mSolve, f_solve, t))} = yes;
loop(t_active(t)$[ord(t) - tSolveFirst = msEnd(mSolve, s)],
mst_end(mSolve, s, t + dt(t)) = yes;
);
); // END loop(ms)
);
// If the last interval of a sample is in mft_lastSteps, the method above does not work
mst_end(mst(mSolve, s, t))${sum(f_solve, mft_lastSteps(mSolve, f_solve, t))} = yes;
// Displacement from the first interval of a sample to the previous interval is always -1,
// except for stochastic samples
dt(t_active(t))
......
......@@ -93,11 +93,14 @@ $ifthene.debug2 %debug%>0
$endif.debug2
// Update sets
ms(mSolve, s)$ms(mSolve, s) = yes$p_msProbability(mSolve, s);
ms_central(mSolve, s)$ms_central(mSolve, s) = ms(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);
// Update the model specific sets and the reversed dimension set
Options clear mft, cear=ms, clear=msf, clear=ms_central, clear=msft;
msft(mSolve, sft(s, f, t)) = yes;
Options mft < msft, ms < msft, msf < msft, mst < msft;
Option ms_central < ms;
mst_start(mSolve, s, t)$mst_start(mSolve, s, t) = ms(mSolve, s);
mst_end(mSolve, s, t)$mst_end(mSolve, s, t) = ms(mSolve, s);
......
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