Welcome to WEAP's Website WEAP
WEAP is an initiative of the Stockholm Environment Institute.


About WEAP

Home
Why WEAP?
Features
What's New?
Sample Screens
Demonstration
Publications
History and Credits

Using WEAP
Download
Licensing
User Guide
Tutorial
Videos (YouTube)

User Forum
Discussions
Members List
Edit Profile

Additional Support
Training
University Courses
Collaboration

About Us
SEI-US Water Resources Program
Please Contact Us

LEAP
Interested in Energy?
Read about LEAP: SEI's software for energy planning.

Link WEAP and LEAP for combined Water-Energy planning.
Watch a video demo!
   

User Forum

All Topics | Topic "Using Randomize() in script"
Log in to post new messages or reply to existing messages.
 
Author Message
Mr. Juan Sebastian Ossa Moreno

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

WEAP.Verbose = 1
WEAP.Logfile = WEAP.Directory + "WeapErrors.txt"

WEAP.ActiveArea = "UpperAco"
WEAP.ActiveScenario="Current Accounts"

WEAP.Branch("Key\NewSnowAlbedo").Variables("Annual Activity Level").Expression = Rnd()*0.5+0.5


FOR i= 1 to 2
Randomize()

WEAP.Branch("Key\OldSnowAlbedo").Variables("Annual Activity Level").Expression = Rnd()*0.5
...other changes in parameters...

CALL WEAP.LoadFavorite("JuncalObsSim%")
CALL WEAP.ExportResults("C:\Users\uqjossam\Desktop\SMI\Data&Models\New folder\InputData\ScriptCalibration\" + FormatNumber(i, 0) + ".csv", TRUE, TRUE,TRUE)

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.

Currently i have something like this

import win32com.client, os, random, numpy
WEAP=win32com.client.Dispatch("WEAP.WEAPApplication")

.....

WEAP.ActiveScenario="Current Accounts"

WEAP.Branch("Key\NewSnowAlbedo").Variables("Annual Activity Level").Expression = 0.8
WEAP.Branch("Key\OldSnowAlbedo").Variables("Annual Activity Level").Expression = 0.3
WEAP.ActiveScenario="Reference"

WEAP.Branch("Key\NewSnowAlbedo").Variables("Annual Activity Level").Expression = 0.8
WEAP.Branch("Key\OldSnowAlbedo").Variables("Annual Activity Level").Expression = 0.3
....



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.)

Jack
Topic "Using Randomize() in script"