Running games from matlab

Use this forum to post Vensim related questions.
Post Reply
olive
Member
Posts: 22
Joined: Tue Sep 13, 2011 8:30 pm

Running games from matlab

Post by olive »

Good afternoon,
I'm trying to run games from matlab and I'm a little bit confused as to the right function to call and the difference between them...
The Vensim DSS Reference Supplement gives examples (p110 and 111 using VB) with GAME>GAMEINTERVAL, GAME>GAMEON, vensim_continue_simulation, vensim_start_simulation, etc.

But what is the difference between MENU>GAME and vensim_start_simulation? or between GAME>GAMEON and vensim_continue_simulation?
I have created some code in matlab that passes a value to a game variable and run my Vensim model for a specified time interval but when I want to change the value of that variable and run the model for a subsequent time interval, i'm having some issues.
Here is my code:

Code: Select all


clear all

time = zeros(40);
NbAC = zeros(40);

if not(libisloaded('VenDLL32'))
    hfile = ['C:\Documents and Settings\opinon\My Documents\MatlabResearch\vendll.h'];
    loadlibrary('VenDLL32',hfile);
end

%******************* LOAD THE MODEL *******************

LoadModel(50); %Load the model and set the final time

SetupGame(10);   %Set the game interval

%******************* PASS VALUES TO THE MODEL *******************

Model(0);   %Pass growth rate 

game = ['MENU>GAME'];
lp4=libpointer('voidPtr',[int8(game) 0]);
calllib('VenDLL32','vensim_command',game);

%************* CONTINUE  ***************

 ContinueGame();  %GameOn
  
 SetupGame(4);   %Set the game interval
 
 Model(100);
 
 ContinueGame();  %GameOn

%*********************RETRIEVE DATA *************************

rvalPtr1 = libpointer('singlePtr', NbAC);
tvalPtr1 = libpointer('singlePtr', time);
tpoints1 = calllib('VenDLL32','vensim_get_data','Olive2.vdf','Number of aircraft arriving','time',rvalPtr1(1),tvalPtr1(1),40);

rvalPtr1(1).Value

%******************** END THE GAME ********************

result2 = ['GAME>ENDGAME'];
calllib('VenDLL32','vensim_command', result2);

And the functions the main file calls are as follows:

Code: Select all


function LoadModel(FinalTime)
str=['SPECIAL>LOADMODEL|C:\Documents and Settings\opinon\My Documents\MatlabResearch\WorkInProgress\ArrivingAC.vpm'];
calllib('VenDLL32','vensim_be_quiet',0);
calllib('VenDLL32','vensim_command',str);
comstr3 = ['SIMULATE>SETVAL|FINAL TIME =', num2str(FinalTime)];
calllib('VenDLL32','vensim_command',comstr3);
end

function SetupGame(TimeInterval)
gameinterval = ['GAME>GAMEINTERVAL|',num2str(TimeInterval)];
lp5=libpointer('voidPtr',[int8(gameinterval) 0]);
 calllib('VenDLL32','vensim_command',gameinterval);
end

function Model(growthrate)
comstr = ['SIMULATE>SETVAL|Growth rate = ', num2str(growthrate) ];
calllib('VenDLL32','vensim_command',comstr);
end

From the output I get, it looks the model runs for a game interval of 10 and then a time interval of 4 (as desired) but somehow it doesn't take into account the change in the argument of the function Model (from 0 to 100)...
I would really appreciate your help on this as well as regarding the functions i'm using (should i be using vensim_continue_simulation instead?)
Thank you,
Olivia
Administrator
Super Administrator
Posts: 4842
Joined: Wed Mar 05, 2003 3:10 am

Re: Running games from matlab

Post by Administrator »

This might be an obvious question, but is "Growth rate" a gaming parameter?

I only ask as you call
comstr = ['SIMULATE>SETVAL|Growth rate = ', num2str(growthrate) ];
calllib('VenDLL32','vensim_command',comstr);

before MENU>GAME (so growth rate would need to be a constant), and then call it again during the game (so it would need to be a game parameter).
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559
olive
Member
Posts: 22
Joined: Tue Sep 13, 2011 8:30 pm

Re: Running games from matlab

Post by olive »

Yes, Growth rate is a gaming parameter. In the model, it is defined as Auxiliary -> Gaming. Growth rate = GAME(30). however I want to be able to change that value at different time intervals (year) using Matlab.
olive
Member
Posts: 22
Joined: Tue Sep 13, 2011 8:30 pm

Re: Running games from matlab

Post by olive »

I managed to get my code to run the way I wanted. However I would still be interested in hearing your opinion about the use of GAME>GAMEON vs vensim_continue_simulation, etc.
Thank you very much!
Kind regards,
Olivia
Administrator
Super Administrator
Posts: 4842
Joined: Wed Mar 05, 2003 3:10 am

Re: Running games from matlab

Post by Administrator »

I'd suggest sticking to the venapp commands (GAME>GAMEON etc). It's easier to test these commands out in a venapp/command script before implementing them in your code.
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559
Post Reply