Page 1 of 1

SIMULATE>SETVAL does not change variable value when running vensim with command file?!

Posted: Mon Mar 11, 2019 8:48 am
by eis
Hello,
I am new to Vensim and try to run Vensim 5.11A from a Windows7 command line:

Code: Select all

vensim.exe treez.cmd
Content of treez.cmd (Please allow to attach *.cmd files and *.dat files to the ticket):

Code: Select all

SPECIAL>NOINTERACTION
SPECIAL>LOADMODEL|treez.mdl
SIMULATE>SETVAL|CarFlow=4
MENU>RUN|o
MENU>VDF2DAT|treez.vdf|treez.dat|treez.lst
MENU>EXIT
The command file treez.cms should:

* load my model treez.mdl,
* set the value of a variable "CarFlow" to 4
* run the simulation
* write the calculated values of CarStock to result file treez.dat

However, the variable CarFlow does not seem to change.
It's value is always 1 as defined in the original treez.mdl file.
Therefore, the last calculated value of CarStock is 100 instead of 400.

=>How do I have to adapt my model or command file to correctly set the variable value?

Do I have to use a different type of variable? Do I need to execute an additional command?

The files treez.mdl, treez.vdf and treez.lst are attached.


I also tried to only use the first three lines of the command file...

Code: Select all

SPECIAL>NOINTERACTION
SPECIAL>LOADMODEL|treez.mdl
SIMULATE>SETVAL|CarFlow=4
... I would expect that I can see a value of 4 for the CarFlow Variable
in the Vensim User Interface but it is 1.

Re: SIMULATE>SETVAL does not change variable value when running vensim with command file?!

Posted: Mon Mar 11, 2019 9:43 am
by Administrator
Do you actually run the model as well? Your CMD file does not show a line such as
MENU>RUN|o

Re: SIMULATE>SETVAL does not change variable value when running vensim with command file?!

Posted: Mon Mar 11, 2019 2:00 pm
by eis
Maybe I don't understand your question. The run command is on line 4 of the first cmd file example. My second example does not include the run command on purpose.

Re: SIMULATE>SETVAL does not change variable value when running vensim with command file?!

Posted: Mon Mar 11, 2019 2:22 pm
by eis
Since I can not edit the orginal post (?!)... here is a screenshot of the treez model as comment:
download/file.php?id=2845

Re: SIMULATE>SETVAL does not change variable value when running vensim with command file?!

Posted: Mon Mar 11, 2019 2:27 pm
by Administrator
There is no cmd file, what happens if you run

Code: Select all

SPECIAL>NOINTERACTION
SPECIAL>LOADMODEL|treez.mdl
SIMULATE>SETVAL|CarFlow=4
MENU>RUN|o

Re: SIMULATE>SETVAL does not change variable value when running vensim with command file?!

Posted: Mon Mar 11, 2019 2:30 pm
by Administrator
Ahh, sorry, I misread your original post.

Try this,

Code: Select all

SPECIAL>NOINTERACTION
SPECIAL>LOADMODEL|treez.mdl
SIMULATE>SETVAL|CarFlow=4
SIMULATE>RUNNAME|treez.vdf
MENU>RUN|o
MENU>VDF2DAT|treez.vdf|treez.dat|treez.lst
MENU>EXIT
My guess is that the default run name is "current.vdf", so running VDF2DAT on treez.vdf will not give the changes.

Re: SIMULATE>SETVAL does not change variable value when running vensim with command file?!

Posted: Mon Mar 11, 2019 2:53 pm
by eis
Running the whole command file works now. The last written value in the treez.dat file is 400.
Thanks a lot!

Is it also possible to reflect the change of the variable values in the GUI, so I can
manually check the values?

If I remove the exit line, I would expect to be able to inspect the altered equations but
the GUI seems to always show the original ones.

Re: SIMULATE>SETVAL does not change variable value when running vensim with command file?!

Posted: Mon Mar 11, 2019 3:06 pm
by Administrator
SIMULATE>SETVAL will only override the value in the model (it will not change it permanently).

Best practice would be to set it to zero in the model, and use a CIN file to hold your constants.

Re: SIMULATE>SETVAL does not change variable value when running vensim with command file?!

Posted: Mon Mar 11, 2019 3:58 pm
by eis

Code: Select all

SPECIAL>NOINTERACTION
SPECIAL>LOADMODEL|treez.mdl
SIMULATE>READCIN|treez.cin
SIMULATE>RUNNAME|treez.vdf
MENU>RUN|o
MENU>VDF2DAT|treez.vdf|treez.dat|treez.lst
neither reflects the changes in the GUI. Nevertheless, it is good to know about the
cin option to write several variable values in a file and separate them from the rest
of the command file. Thanks again.

Re: SIMULATE>SETVAL does not change variable value when running vensim with command file?!

Posted: Mon Mar 11, 2019 4:32 pm
by Administrator
It will never change the model itself (what you see in the GUI).

Best practice is to keep model and data/constants separate.

Re: SIMULATE>SETVAL does not change variable value when running vensim with command file?!

Posted: Mon Mar 11, 2019 4:43 pm
by tomfid
If you really want to ensure separation, you can set the model value to :NA: - that way the model will generate errors or na values if the .cin file does not populate the constant.

I usually have a usable default value in the equation, and use .cin files for experiments or scenarios.