Subject: Using Randomize() in script Posted: 10/15/2017 Viewed: 10866 times
Hello
I am trying to calibrate a WEAP model by randomly changing some parameters in a script. However, for some reason the parameters do not change after each iteration when i use Rnd(). Furthermore, i would like to have the same parameter for the two scenarios I have (for the same iteration only of course), however, the code generates different numbers for each scenario for each iteration. This is a section of my code.
Does anyone know why this is happening or where the error is?
Thanks in advance
CALL WEAP.PrintToFile("C:\Users\uqjossam\Desktop\SMI\Data&Models\New folder\InputData\ScriptCalibration\BorrarAlbedo.txt",WEAP.Branch("Key\OldSnowAlbedo").Variables("Annual Activity Level").Value(2009,1))
...Print of other variables...
NEXT
Mr. Jack Sieber
Subject: Re: Using Randomize() in script Posted: 10/19/2017 Viewed: 10853 times
Randomize() and Rnd() are Visual Basic functions, not WEAP functions. I do not know why you are not getting different random values each iteration.
WEAP does have a Random function, which generates a random time series, but it will be the same time series each run, for a given branch, variable and scenario. You could give it a different Seed value for each iteration, so that the two iterations had different random time series. However, from your code it looks like you want a single random number for OldSnowAlbedo, not a time series of random numbers.
Jack
Mr. Juan Sebastian Ossa Moreno
Subject: Re: Using Randomize() in script Posted: 10/20/2017 Viewed: 10842 times
Hello Jack
Thanks for your answer.
I know that Randomize() and Rnd() are VB functions thus i run the lines in a very similar context in VB Excel, and it worked fine there, but i still have the problems when using them in WEAP. Also, i saw that other users have used the functions without problems, thus i guess it should be a specific problem of my computer. I gave up with VB and moved to Python, which i know a bit more and managed to solve the problem.
However, am still having problems to define variables for all scenarios with a single line, is this possible? This could help me saving some time in each computation am doing to calibrate my model.
and then i use a similar structure inside a foor loop to set the parameters of each one of the calibrations. Is there any alternative that is more efficient?
Thanks in advance.
Regards
Juan
Mr. Jack Sieber
Subject: Re: Using Randomize() in script Posted: 10/20/2017 Viewed: 10834 times
If you do not enter an expression for a scenario, WEAP will use the expression from its parent -- either the scenario it is derived from or the Current Accounts. Therefore, as long as you have not put an expression into NewSnowAlbedo or OldSnowAlbedo for the scenarios, they will automatically inherit and use the expression you set for the Current Accounts. (If you have set an expression for the scenario, just delete it and WEAP will revert to using the parent's expression.)